Commit 4376e966 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'perf-tools-fixes-for-v6.10-2024-07-08' of...

Merge tag 'perf-tools-fixes-for-v6.10-2024-07-08' of git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools

Pull perf tools fixes from Namhyung Kim:
 "Fix performance issue for v6.10

  These address the performance issues reported by Matt, Namhyung and
  Linus. Recently perf changed the processing of the comm string and DSO
  using sorted arrays but this caused it to sort the array whenever
  adding a new entry.

  This caused a performance issue and the fix is to enhance the sorting
  by finding the insertion point in the sorted array and to shift
  righthand side using memmove()"

* tag 'perf-tools-fixes-for-v6.10-2024-07-08' of git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools:
  perf dsos: When adding a dso into sorted dsos maintain the sort order
  perf comm str: Avoid sort during insert
parents 256abd8e 7b2450bb
......@@ -86,14 +86,6 @@ static struct comm_str *comm_str__new(const char *str)
return result;
}
static int comm_str__cmp(const void *_lhs, const void *_rhs)
{
const struct comm_str *lhs = *(const struct comm_str * const *)_lhs;
const struct comm_str *rhs = *(const struct comm_str * const *)_rhs;
return strcmp(comm_str__str(lhs), comm_str__str(rhs));
}
static int comm_str__search(const void *_key, const void *_member)
{
const char *key = _key;
......@@ -169,9 +161,24 @@ static struct comm_str *comm_strs__findnew(const char *str)
}
result = comm_str__new(str);
if (result) {
comm_strs->strs[comm_strs->num_strs++] = result;
qsort(comm_strs->strs, comm_strs->num_strs, sizeof(struct comm_str *),
comm_str__cmp);
int low = 0, high = comm_strs->num_strs - 1;
int insert = comm_strs->num_strs; /* Default to inserting at the end. */
while (low <= high) {
int mid = low + (high - low) / 2;
int cmp = strcmp(comm_str__str(comm_strs->strs[mid]), str);
if (cmp < 0) {
low = mid + 1;
} else {
high = mid - 1;
insert = mid;
}
}
memmove(&comm_strs->strs[insert + 1], &comm_strs->strs[insert],
(comm_strs->num_strs - insert) * sizeof(struct comm_str *));
comm_strs->num_strs++;
comm_strs->strs[insert] = result;
}
}
up_write(&comm_strs->lock);
......
......@@ -203,11 +203,27 @@ int __dsos__add(struct dsos *dsos, struct dso *dso)
dsos->dsos = temp;
dsos->allocated = to_allocate;
}
dsos->dsos[dsos->cnt++] = dso__get(dso);
if (dsos->cnt >= 2 && dsos->sorted) {
dsos->sorted = dsos__cmp_long_name_id_short_name(&dsos->dsos[dsos->cnt - 2],
&dsos->dsos[dsos->cnt - 1])
<= 0;
if (!dsos->sorted) {
dsos->dsos[dsos->cnt++] = dso__get(dso);
} else {
int low = 0, high = dsos->cnt - 1;
int insert = dsos->cnt; /* Default to inserting at the end. */
while (low <= high) {
int mid = low + (high - low) / 2;
int cmp = dsos__cmp_long_name_id_short_name(&dsos->dsos[mid], &dso);
if (cmp < 0) {
low = mid + 1;
} else {
high = mid - 1;
insert = mid;
}
}
memmove(&dsos->dsos[insert + 1], &dsos->dsos[insert],
(dsos->cnt - insert) * sizeof(struct dso *));
dsos->cnt++;
dsos->dsos[insert] = dso__get(dso);
}
dso__set_dsos(dso, dsos);
return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment