Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+39 -16
+18 -11
tools/perf/util/comm.c
··· 86 86 return result; 87 87 } 88 88 89 - static int comm_str__cmp(const void *_lhs, const void *_rhs) 90 - { 91 - const struct comm_str *lhs = *(const struct comm_str * const *)_lhs; 92 - const struct comm_str *rhs = *(const struct comm_str * const *)_rhs; 93 - 94 - return strcmp(comm_str__str(lhs), comm_str__str(rhs)); 95 - } 96 - 97 89 static int comm_str__search(const void *_key, const void *_member) 98 90 { 99 91 const char *key = _key; ··· 161 169 } 162 170 result = comm_str__new(str); 163 171 if (result) { 164 - comm_strs->strs[comm_strs->num_strs++] = result; 165 - qsort(comm_strs->strs, comm_strs->num_strs, sizeof(struct comm_str *), 166 - comm_str__cmp); 172 + int low = 0, high = comm_strs->num_strs - 1; 173 + int insert = comm_strs->num_strs; /* Default to inserting at the end. */ 174 + 175 + while (low <= high) { 176 + int mid = low + (high - low) / 2; 177 + int cmp = strcmp(comm_str__str(comm_strs->strs[mid]), str); 178 + 179 + if (cmp < 0) { 180 + low = mid + 1; 181 + } else { 182 + high = mid - 1; 183 + insert = mid; 184 + } 185 + } 186 + memmove(&comm_strs->strs[insert + 1], &comm_strs->strs[insert], 187 + (comm_strs->num_strs - insert) * sizeof(struct comm_str *)); 188 + comm_strs->num_strs++; 189 + comm_strs->strs[insert] = result; 167 190 } 168 191 } 169 192 up_write(&comm_strs->lock);
+21 -5
tools/perf/util/dsos.c
··· 203 203 dsos->dsos = temp; 204 204 dsos->allocated = to_allocate; 205 205 } 206 - dsos->dsos[dsos->cnt++] = dso__get(dso); 207 - if (dsos->cnt >= 2 && dsos->sorted) { 208 - dsos->sorted = dsos__cmp_long_name_id_short_name(&dsos->dsos[dsos->cnt - 2], 209 - &dsos->dsos[dsos->cnt - 1]) 210 - <= 0; 206 + if (!dsos->sorted) { 207 + dsos->dsos[dsos->cnt++] = dso__get(dso); 208 + } else { 209 + int low = 0, high = dsos->cnt - 1; 210 + int insert = dsos->cnt; /* Default to inserting at the end. */ 211 + 212 + while (low <= high) { 213 + int mid = low + (high - low) / 2; 214 + int cmp = dsos__cmp_long_name_id_short_name(&dsos->dsos[mid], &dso); 215 + 216 + if (cmp < 0) { 217 + low = mid + 1; 218 + } else { 219 + high = mid - 1; 220 + insert = mid; 221 + } 222 + } 223 + memmove(&dsos->dsos[insert + 1], &dsos->dsos[insert], 224 + (dsos->cnt - insert) * sizeof(struct dso *)); 225 + dsos->cnt++; 226 + dsos->dsos[insert] = dso__get(dso); 211 227 } 212 228 dso__set_dsos(dso, dsos); 213 229 return 0;