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

perf dso: Move dso functions out of dsos.c

Move dso and dso_id functions to dso.c to match the struct declarations.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Anne Macedo <retpolanne@posteo.net>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ben Gainey <ben.gainey@arm.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Chengen Du <chengen.du@canonical.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Ilkka Koskinen <ilkka@os.amperecomputing.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Li Dong <lidong@vivo.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Markus Elfring <Markus.Elfring@web.de>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paran Lee <p4ranlee@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Song Liu <song@kernel.org>
Cc: Sun Haiyong <sunhaiyong@loongson.cn>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Yanteng Si <siyanteng@loongson.cn>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: zhaimingbing <zhaimingbing@cmss.chinamobile.com>
Link: https://lore.kernel.org/r/20240410064214.2755936-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
1d6eff93 73f3fea2

+65 -61
+61
tools/perf/util/dso.c
··· 1269 1269 __dsos__findnew_link_by_longname_id(root, dso, NULL, id); 1270 1270 } 1271 1271 1272 + static int __dso_id__cmp(struct dso_id *a, struct dso_id *b) 1273 + { 1274 + if (a->maj > b->maj) return -1; 1275 + if (a->maj < b->maj) return 1; 1276 + 1277 + if (a->min > b->min) return -1; 1278 + if (a->min < b->min) return 1; 1279 + 1280 + if (a->ino > b->ino) return -1; 1281 + if (a->ino < b->ino) return 1; 1282 + 1283 + /* 1284 + * Synthesized MMAP events have zero ino_generation, avoid comparing 1285 + * them with MMAP events with actual ino_generation. 1286 + * 1287 + * I found it harmful because the mismatch resulted in a new 1288 + * dso that did not have a build ID whereas the original dso did have a 1289 + * build ID. The build ID was essential because the object was not found 1290 + * otherwise. - Adrian 1291 + */ 1292 + if (a->ino_generation && b->ino_generation) { 1293 + if (a->ino_generation > b->ino_generation) return -1; 1294 + if (a->ino_generation < b->ino_generation) return 1; 1295 + } 1296 + 1297 + return 0; 1298 + } 1299 + 1300 + bool dso_id__empty(struct dso_id *id) 1301 + { 1302 + if (!id) 1303 + return true; 1304 + 1305 + return !id->maj && !id->min && !id->ino && !id->ino_generation; 1306 + } 1307 + 1308 + void dso__inject_id(struct dso *dso, struct dso_id *id) 1309 + { 1310 + dso->id.maj = id->maj; 1311 + dso->id.min = id->min; 1312 + dso->id.ino = id->ino; 1313 + dso->id.ino_generation = id->ino_generation; 1314 + } 1315 + 1316 + int dso_id__cmp(struct dso_id *a, struct dso_id *b) 1317 + { 1318 + /* 1319 + * The second is always dso->id, so zeroes if not set, assume passing 1320 + * NULL for a means a zeroed id 1321 + */ 1322 + if (dso_id__empty(a) || dso_id__empty(b)) 1323 + return 0; 1324 + 1325 + return __dso_id__cmp(a, b); 1326 + } 1327 + 1328 + int dso__cmp_id(struct dso *a, struct dso *b) 1329 + { 1330 + return __dso_id__cmp(&a->id, &b->id); 1331 + } 1332 + 1272 1333 void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated) 1273 1334 { 1274 1335 dso__set_long_name_id(dso, name, NULL, name_allocated);
+4
tools/perf/util/dso.h
··· 238 238 dso->loaded = true; 239 239 } 240 240 241 + int dso_id__cmp(struct dso_id *a, struct dso_id *b); 242 + bool dso_id__empty(struct dso_id *id); 243 + 241 244 struct dso *dso__new_id(const char *name, struct dso_id *id); 242 245 struct dso *dso__new(const char *name); 243 246 void dso__delete(struct dso *dso); ··· 248 245 int dso__cmp_id(struct dso *a, struct dso *b); 249 246 void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated); 250 247 void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated); 248 + void dso__inject_id(struct dso *dso, struct dso_id *id); 251 249 252 250 int dso__name_len(const struct dso *dso); 253 251
-61
tools/perf/util/dsos.c
··· 41 41 exit_rwsem(&dsos->lock); 42 42 } 43 43 44 - static int __dso_id__cmp(struct dso_id *a, struct dso_id *b) 45 - { 46 - if (a->maj > b->maj) return -1; 47 - if (a->maj < b->maj) return 1; 48 - 49 - if (a->min > b->min) return -1; 50 - if (a->min < b->min) return 1; 51 - 52 - if (a->ino > b->ino) return -1; 53 - if (a->ino < b->ino) return 1; 54 - 55 - /* 56 - * Synthesized MMAP events have zero ino_generation, avoid comparing 57 - * them with MMAP events with actual ino_generation. 58 - * 59 - * I found it harmful because the mismatch resulted in a new 60 - * dso that did not have a build ID whereas the original dso did have a 61 - * build ID. The build ID was essential because the object was not found 62 - * otherwise. - Adrian 63 - */ 64 - if (a->ino_generation && b->ino_generation) { 65 - if (a->ino_generation > b->ino_generation) return -1; 66 - if (a->ino_generation < b->ino_generation) return 1; 67 - } 68 - 69 - return 0; 70 - } 71 - 72 - static bool dso_id__empty(struct dso_id *id) 73 - { 74 - if (!id) 75 - return true; 76 - 77 - return !id->maj && !id->min && !id->ino && !id->ino_generation; 78 - } 79 - 80 - static void dso__inject_id(struct dso *dso, struct dso_id *id) 81 - { 82 - dso->id.maj = id->maj; 83 - dso->id.min = id->min; 84 - dso->id.ino = id->ino; 85 - dso->id.ino_generation = id->ino_generation; 86 - } 87 - 88 - static int dso_id__cmp(struct dso_id *a, struct dso_id *b) 89 - { 90 - /* 91 - * The second is always dso->id, so zeroes if not set, assume passing 92 - * NULL for a means a zeroed id 93 - */ 94 - if (dso_id__empty(a) || dso_id__empty(b)) 95 - return 0; 96 - 97 - return __dso_id__cmp(a, b); 98 - } 99 - 100 - int dso__cmp_id(struct dso *a, struct dso *b) 101 - { 102 - return __dso_id__cmp(&a->id, &b->id); 103 - } 104 - 105 44 bool __dsos__read_build_ids(struct dsos *dsos, bool with_hits) 106 45 { 107 46 struct list_head *head = &dsos->head;