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

perf dsos: Attempt to better abstract DSOs internals

Move functions from machine and build-id to dsos. Pass 'struct dsos'
rather than internal state.

Rename some functions to better represent which data structure they
operate on.

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-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
83acca9f 792bc998

+97 -86
+1 -1
tools/perf/builtin-inject.c
··· 2122 2122 */ 2123 2123 if (perf_header__has_feat(&session->header, HEADER_BUILD_ID) && 2124 2124 inject->have_auxtrace && !inject->itrace_synth_opts.set) 2125 - dsos__hit_all(session); 2125 + perf_session__dsos_hit_all(session); 2126 2126 /* 2127 2127 * The AUX areas have been removed and replaced with 2128 2128 * synthesized hardware events, so clear the feature flag.
+1 -1
tools/perf/builtin-record.c
··· 1788 1788 process_buildids(rec); 1789 1789 1790 1790 if (rec->buildid_all) 1791 - dsos__hit_all(rec->session); 1791 + perf_session__dsos_hit_all(rec->session); 1792 1792 } 1793 1793 perf_session__write_header(rec->session, rec->evlist, fd, true); 1794 1794
+1 -37
tools/perf/util/build-id.c
··· 390 390 return err; 391 391 } 392 392 393 - static int __dsos__hit_all(struct list_head *head) 394 - { 395 - struct dso *pos; 396 - 397 - list_for_each_entry(pos, head, node) 398 - pos->hit = true; 399 - 400 - return 0; 401 - } 402 - 403 - static int machine__hit_all_dsos(struct machine *machine) 404 - { 405 - return __dsos__hit_all(&machine->dsos.head); 406 - } 407 - 408 - int dsos__hit_all(struct perf_session *session) 409 - { 410 - struct rb_node *nd; 411 - int err; 412 - 413 - err = machine__hit_all_dsos(&session->machines.host); 414 - if (err) 415 - return err; 416 - 417 - for (nd = rb_first_cached(&session->machines.guests); nd; 418 - nd = rb_next(nd)) { 419 - struct machine *pos = rb_entry(nd, struct machine, rb_node); 420 - 421 - err = machine__hit_all_dsos(pos); 422 - if (err) 423 - return err; 424 - } 425 - 426 - return 0; 427 - } 428 - 429 393 void disable_buildid_cache(void) 430 394 { 431 395 no_buildid_cache = true; ··· 956 992 957 993 static bool machine__read_build_ids(struct machine *machine, bool with_hits) 958 994 { 959 - return __dsos__read_build_ids(&machine->dsos.head, with_hits); 995 + return __dsos__read_build_ids(&machine->dsos, with_hits); 960 996 } 961 997 962 998 bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)
-2
tools/perf/util/build-id.h
··· 39 39 struct perf_sample *sample, struct evsel *evsel, 40 40 struct machine *machine); 41 41 42 - int dsos__hit_all(struct perf_session *session); 43 - 44 42 int perf_event__inject_buildid(struct perf_tool *tool, union perf_event *event, 45 43 struct perf_sample *sample, struct evsel *evsel, 46 44 struct machine *machine);
-6
tools/perf/util/dso.h
··· 233 233 #define dso__for_each_symbol(dso, pos, n) \ 234 234 symbols__for_each_entry(&(dso)->symbols, pos, n) 235 235 236 - #define dsos__for_each_with_build_id(pos, head) \ 237 - list_for_each_entry(pos, head, node) \ 238 - if (!pos->has_build_id) \ 239 - continue; \ 240 - else 241 - 242 236 static inline void dso__set_loaded(struct dso *dso) 243 237 { 244 238 dso->loaded = true;
+46 -3
tools/perf/util/dsos.c
··· 12 12 #include <symbol.h> // filename__read_build_id 13 13 #include <unistd.h> 14 14 15 + void dsos__init(struct dsos *dsos) 16 + { 17 + INIT_LIST_HEAD(&dsos->head); 18 + dsos->root = RB_ROOT; 19 + init_rwsem(&dsos->lock); 20 + } 21 + 22 + static void dsos__purge(struct dsos *dsos) 23 + { 24 + struct dso *pos, *n; 25 + 26 + down_write(&dsos->lock); 27 + 28 + list_for_each_entry_safe(pos, n, &dsos->head, node) { 29 + RB_CLEAR_NODE(&pos->rb_node); 30 + pos->root = NULL; 31 + list_del_init(&pos->node); 32 + dso__put(pos); 33 + } 34 + 35 + up_write(&dsos->lock); 36 + } 37 + 38 + void dsos__exit(struct dsos *dsos) 39 + { 40 + dsos__purge(dsos); 41 + exit_rwsem(&dsos->lock); 42 + } 43 + 15 44 static int __dso_id__cmp(struct dso_id *a, struct dso_id *b) 16 45 { 17 46 if (a->maj > b->maj) return -1; ··· 102 73 return __dso_id__cmp(&a->id, &b->id); 103 74 } 104 75 105 - bool __dsos__read_build_ids(struct list_head *head, bool with_hits) 76 + bool __dsos__read_build_ids(struct dsos *dsos, bool with_hits) 106 77 { 78 + struct list_head *head = &dsos->head; 107 79 bool have_build_id = false; 108 80 struct dso *pos; 109 81 struct nscookie nsc; ··· 333 303 return dso; 334 304 } 335 305 336 - size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, 306 + size_t __dsos__fprintf_buildid(struct dsos *dsos, FILE *fp, 337 307 bool (skip)(struct dso *dso, int parm), int parm) 338 308 { 309 + struct list_head *head = &dsos->head; 339 310 struct dso *pos; 340 311 size_t ret = 0; 341 312 ··· 351 320 return ret; 352 321 } 353 322 354 - size_t __dsos__fprintf(struct list_head *head, FILE *fp) 323 + size_t __dsos__fprintf(struct dsos *dsos, FILE *fp) 355 324 { 325 + struct list_head *head = &dsos->head; 356 326 struct dso *pos; 357 327 size_t ret = 0; 358 328 ··· 362 330 } 363 331 364 332 return ret; 333 + } 334 + 335 + int __dsos__hit_all(struct dsos *dsos) 336 + { 337 + struct list_head *head = &dsos->head; 338 + struct dso *pos; 339 + 340 + list_for_each_entry(pos, head, node) 341 + pos->hit = true; 342 + 343 + return 0; 365 344 }
+15 -4
tools/perf/util/dsos.h
··· 21 21 struct rw_semaphore lock; 22 22 }; 23 23 24 + #define dsos__for_each_with_build_id(pos, head) \ 25 + list_for_each_entry(pos, head, node) \ 26 + if (!pos->has_build_id) \ 27 + continue; \ 28 + else 29 + 30 + void dsos__init(struct dsos *dsos); 31 + void dsos__exit(struct dsos *dsos); 32 + 24 33 void __dsos__add(struct dsos *dsos, struct dso *dso); 25 34 void dsos__add(struct dsos *dsos, struct dso *dso); 26 35 struct dso *__dsos__addnew(struct dsos *dsos, const char *name); ··· 37 28 38 29 struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct dso_id *id); 39 30 31 + bool __dsos__read_build_ids(struct dsos *dsos, bool with_hits); 32 + 40 33 struct dso *__dsos__findnew_link_by_longname_id(struct rb_root *root, struct dso *dso, 41 34 const char *name, struct dso_id *id); 42 35 43 - bool __dsos__read_build_ids(struct list_head *head, bool with_hits); 44 - 45 - size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, 36 + size_t __dsos__fprintf_buildid(struct dsos *dsos, FILE *fp, 46 37 bool (skip)(struct dso *dso, int parm), int parm); 47 - size_t __dsos__fprintf(struct list_head *head, FILE *fp); 38 + size_t __dsos__fprintf(struct dsos *dsos, FILE *fp); 39 + 40 + int __dsos__hit_all(struct dsos *dsos); 48 41 49 42 #endif /* __PERF_DSOS */
+8 -32
tools/perf/util/machine.c
··· 48 48 return map__dso(machine->vmlinux_map); 49 49 } 50 50 51 - static void dsos__init(struct dsos *dsos) 52 - { 53 - INIT_LIST_HEAD(&dsos->head); 54 - dsos->root = RB_ROOT; 55 - init_rwsem(&dsos->lock); 56 - } 57 - 58 51 static int machine__set_mmap_name(struct machine *machine) 59 52 { 60 53 if (machine__is_host(machine)) ··· 156 163 } 157 164 158 165 return machine; 159 - } 160 - 161 - static void dsos__purge(struct dsos *dsos) 162 - { 163 - struct dso *pos, *n; 164 - 165 - down_write(&dsos->lock); 166 - 167 - list_for_each_entry_safe(pos, n, &dsos->head, node) { 168 - RB_CLEAR_NODE(&pos->rb_node); 169 - pos->root = NULL; 170 - list_del_init(&pos->node); 171 - dso__put(pos); 172 - } 173 - 174 - up_write(&dsos->lock); 175 - } 176 - 177 - static void dsos__exit(struct dsos *dsos) 178 - { 179 - dsos__purge(dsos); 180 - exit_rwsem(&dsos->lock); 181 166 } 182 167 183 168 void machine__delete_threads(struct machine *machine) ··· 878 907 size_t machines__fprintf_dsos(struct machines *machines, FILE *fp) 879 908 { 880 909 struct rb_node *nd; 881 - size_t ret = __dsos__fprintf(&machines->host.dsos.head, fp); 910 + size_t ret = __dsos__fprintf(&machines->host.dsos, fp); 882 911 883 912 for (nd = rb_first_cached(&machines->guests); nd; nd = rb_next(nd)) { 884 913 struct machine *pos = rb_entry(nd, struct machine, rb_node); 885 - ret += __dsos__fprintf(&pos->dsos.head, fp); 914 + ret += __dsos__fprintf(&pos->dsos, fp); 886 915 } 887 916 888 917 return ret; ··· 891 920 size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp, 892 921 bool (skip)(struct dso *dso, int parm), int parm) 893 922 { 894 - return __dsos__fprintf_buildid(&m->dsos.head, fp, skip, parm); 923 + return __dsos__fprintf_buildid(&m->dsos, fp, skip, parm); 895 924 } 896 925 897 926 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, ··· 3276 3305 } 3277 3306 3278 3307 return false; 3308 + } 3309 + 3310 + int machine__hit_all_dsos(struct machine *machine) 3311 + { 3312 + return __dsos__hit_all(&machine->dsos); 3279 3313 }
+2
tools/perf/util/machine.h
··· 306 306 int machine__resolve(struct machine *machine, struct addr_location *al, 307 307 struct perf_sample *sample); 308 308 309 + int machine__hit_all_dsos(struct machine *machine); 310 + 309 311 #endif /* __PERF_MACHINE_H */
+21
tools/perf/util/session.c
··· 2916 2916 } 2917 2917 return 0; 2918 2918 } 2919 + 2920 + int perf_session__dsos_hit_all(struct perf_session *session) 2921 + { 2922 + struct rb_node *nd; 2923 + int err; 2924 + 2925 + err = machine__hit_all_dsos(&session->machines.host); 2926 + if (err) 2927 + return err; 2928 + 2929 + for (nd = rb_first_cached(&session->machines.guests); nd; 2930 + nd = rb_next(nd)) { 2931 + struct machine *pos = rb_entry(nd, struct machine, rb_node); 2932 + 2933 + err = machine__hit_all_dsos(pos); 2934 + if (err) 2935 + return err; 2936 + } 2937 + 2938 + return 0; 2939 + }
+2
tools/perf/util/session.h
··· 156 156 union perf_event *event, 157 157 struct perf_sample *sample); 158 158 159 + int perf_session__dsos_hit_all(struct perf_session *session); 160 + 159 161 int perf_event__process_id_index(struct perf_session *session, 160 162 union perf_event *event); 161 163