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

perf machine: No need to have two DSOs lists

We can, given a DSO, figure out if it is a kernel, a kernel module or
a userlevel DSO, so stop having to process two lists in several
functions.

If searching becomes an issue at some point, we can have them in a
rbtree, etc.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-s4yb0onpdywu6dj2xl9lxi4t@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+39 -80
+1 -1
tools/perf/tests/hists_common.c
··· 121 121 size_t k; 122 122 struct dso *dso; 123 123 124 - dso = __dsos__findnew(&machine->user_dsos, 124 + dso = __dsos__findnew(&machine->dsos, 125 125 fake_symbols[i].dso_name); 126 126 if (dso == NULL) 127 127 goto out;
+16 -43
tools/perf/util/build-id.c
··· 162 162 return write_padded(fd, name, name_len + 1, len); 163 163 } 164 164 165 - static int __dsos__write_buildid_table(struct list_head *head, 166 - struct machine *machine, 167 - pid_t pid, u16 misc, int fd) 165 + static int machine__write_buildid_table(struct machine *machine, int fd) 168 166 { 167 + int err = 0; 169 168 char nm[PATH_MAX]; 170 169 struct dso *pos; 170 + u16 kmisc = PERF_RECORD_MISC_KERNEL, 171 + umisc = PERF_RECORD_MISC_USER; 171 172 172 - dsos__for_each_with_build_id(pos, head) { 173 - int err; 173 + if (!machine__is_host(machine)) { 174 + kmisc = PERF_RECORD_MISC_GUEST_KERNEL; 175 + umisc = PERF_RECORD_MISC_GUEST_USER; 176 + } 177 + 178 + dsos__for_each_with_build_id(pos, &machine->dsos.head) { 174 179 const char *name; 175 180 size_t name_len; 176 181 ··· 194 189 name_len = pos->long_name_len + 1; 195 190 } 196 191 197 - err = write_buildid(name, name_len, pos->build_id, 198 - pid, misc, fd); 192 + err = write_buildid(name, name_len, pos->build_id, machine->pid, 193 + pos->kernel ? kmisc : umisc, fd); 199 194 if (err) 200 - return err; 195 + break; 201 196 } 202 197 203 - return 0; 204 - } 205 - 206 - static int machine__write_buildid_table(struct machine *machine, int fd) 207 - { 208 - int err; 209 - u16 kmisc = PERF_RECORD_MISC_KERNEL, 210 - umisc = PERF_RECORD_MISC_USER; 211 - 212 - if (!machine__is_host(machine)) { 213 - kmisc = PERF_RECORD_MISC_GUEST_KERNEL; 214 - umisc = PERF_RECORD_MISC_GUEST_USER; 215 - } 216 - 217 - err = __dsos__write_buildid_table(&machine->kernel_dsos.head, machine, 218 - machine->pid, kmisc, fd); 219 - if (err == 0) 220 - err = __dsos__write_buildid_table(&machine->user_dsos.head, 221 - machine, machine->pid, umisc, 222 - fd); 223 198 return err; 224 199 } 225 200 ··· 232 247 233 248 static int machine__hit_all_dsos(struct machine *machine) 234 249 { 235 - int err; 236 - 237 - err = __dsos__hit_all(&machine->kernel_dsos.head); 238 - if (err) 239 - return err; 240 - 241 - return __dsos__hit_all(&machine->user_dsos.head); 250 + return __dsos__hit_all(&machine->dsos.head); 242 251 } 243 252 244 253 int dsos__hit_all(struct perf_session *session) ··· 472 493 473 494 static int machine__cache_build_ids(struct machine *machine) 474 495 { 475 - int ret = __dsos__cache_build_ids(&machine->kernel_dsos.head, machine); 476 - ret |= __dsos__cache_build_ids(&machine->user_dsos.head, machine); 477 - return ret; 496 + return __dsos__cache_build_ids(&machine->dsos.head, machine); 478 497 } 479 498 480 499 int perf_session__cache_build_ids(struct perf_session *session) ··· 497 520 498 521 static bool machine__read_build_ids(struct machine *machine, bool with_hits) 499 522 { 500 - bool ret; 501 - 502 - ret = __dsos__read_build_ids(&machine->kernel_dsos.head, with_hits); 503 - ret |= __dsos__read_build_ids(&machine->user_dsos.head, with_hits); 504 - return ret; 523 + return __dsos__read_build_ids(&machine->dsos.head, with_hits); 505 524 } 506 525 507 526 bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)
+1 -1
tools/perf/util/dso.c
··· 833 833 /* 834 834 * The kernel dso could be created by build_id processing. 835 835 */ 836 - struct dso *dso = __dsos__findnew(&machine->kernel_dsos, name); 836 + struct dso *dso = __dsos__findnew(&machine->dsos, name); 837 837 838 838 /* 839 839 * We need to run this in all cases, since during the build_id
+1 -5
tools/perf/util/header.c
··· 1238 1238 struct perf_session *session) 1239 1239 { 1240 1240 int err = -1; 1241 - struct dsos *dsos; 1242 1241 struct machine *machine; 1243 1242 u16 misc; 1244 1243 struct dso *dso; ··· 1252 1253 switch (misc) { 1253 1254 case PERF_RECORD_MISC_KERNEL: 1254 1255 dso_type = DSO_TYPE_KERNEL; 1255 - dsos = &machine->kernel_dsos; 1256 1256 break; 1257 1257 case PERF_RECORD_MISC_GUEST_KERNEL: 1258 1258 dso_type = DSO_TYPE_GUEST_KERNEL; 1259 - dsos = &machine->kernel_dsos; 1260 1259 break; 1261 1260 case PERF_RECORD_MISC_USER: 1262 1261 case PERF_RECORD_MISC_GUEST_USER: 1263 1262 dso_type = DSO_TYPE_USER; 1264 - dsos = &machine->user_dsos; 1265 1263 break; 1266 1264 default: 1267 1265 goto out; 1268 1266 } 1269 1267 1270 - dso = __dsos__findnew(dsos, filename); 1268 + dso = __dsos__findnew(&machine->dsos, filename); 1271 1269 if (dso != NULL) { 1272 1270 char sbuild_id[BUILD_ID_SIZE * 2 + 1]; 1273 1271
+11 -17
tools/perf/util/machine.c
··· 26 26 { 27 27 map_groups__init(&machine->kmaps, machine); 28 28 RB_CLEAR_NODE(&machine->rb_node); 29 - dsos__init(&machine->user_dsos); 30 - dsos__init(&machine->kernel_dsos); 29 + dsos__init(&machine->dsos); 31 30 32 31 machine->threads = RB_ROOT; 33 32 pthread_rwlock_init(&machine->threads_lock, NULL); ··· 110 111 void machine__exit(struct machine *machine) 111 112 { 112 113 map_groups__exit(&machine->kmaps); 113 - dsos__delete(&machine->user_dsos); 114 - dsos__delete(&machine->kernel_dsos); 114 + dsos__delete(&machine->dsos); 115 115 vdso__exit(machine); 116 116 zfree(&machine->root_dir); 117 117 zfree(&machine->current_tid); ··· 488 490 { 489 491 struct dso *dso; 490 492 491 - dso = dsos__find(&machine->kernel_dsos, m->name, true); 493 + dso = dsos__find(&machine->dsos, m->name, true); 492 494 if (!dso) { 493 - dso = dsos__addnew(&machine->kernel_dsos, m->name); 495 + dso = dsos__addnew(&machine->dsos, m->name); 494 496 if (dso == NULL) 495 497 return NULL; 496 498 ··· 559 561 size_t machines__fprintf_dsos(struct machines *machines, FILE *fp) 560 562 { 561 563 struct rb_node *nd; 562 - size_t ret = __dsos__fprintf(&machines->host.kernel_dsos.head, fp) + 563 - __dsos__fprintf(&machines->host.user_dsos.head, fp); 564 + size_t ret = __dsos__fprintf(&machines->host.dsos.head, fp); 564 565 565 566 for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) { 566 567 struct machine *pos = rb_entry(nd, struct machine, rb_node); 567 - ret += __dsos__fprintf(&pos->kernel_dsos.head, fp); 568 - ret += __dsos__fprintf(&pos->user_dsos.head, fp); 568 + ret += __dsos__fprintf(&pos->dsos.head, fp); 569 569 } 570 570 571 571 return ret; ··· 572 576 size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp, 573 577 bool (skip)(struct dso *dso, int parm), int parm) 574 578 { 575 - return __dsos__fprintf_buildid(&m->kernel_dsos.head, fp, skip, parm) + 576 - __dsos__fprintf_buildid(&m->user_dsos.head, fp, skip, parm); 579 + return __dsos__fprintf_buildid(&m->dsos.head, fp, skip, parm); 577 580 } 578 581 579 582 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, ··· 1101 1106 { 1102 1107 struct dso *dso; 1103 1108 1104 - list_for_each_entry(dso, &machine->kernel_dsos.head, node) { 1109 + list_for_each_entry(dso, &machine->dsos.head, node) { 1105 1110 if (dso__is_kcore(dso)) 1106 1111 return true; 1107 1112 } ··· 1148 1153 struct dso *kernel = NULL; 1149 1154 struct dso *dso; 1150 1155 1151 - list_for_each_entry(dso, &machine->kernel_dsos.head, node) { 1152 - if (is_kernel_module(dso->long_name)) 1156 + list_for_each_entry(dso, &machine->dsos.head, node) { 1157 + if (dso->kernel && is_kernel_module(dso->long_name)) 1153 1158 continue; 1154 1159 1155 1160 kernel = dso; ··· 1157 1162 } 1158 1163 1159 1164 if (kernel == NULL) 1160 - kernel = __dsos__findnew(&machine->kernel_dsos, 1161 - kmmap_prefix); 1165 + kernel = __dsos__findnew(&machine->dsos, kmmap_prefix); 1162 1166 if (kernel == NULL) 1163 1167 goto out_problem; 1164 1168
+1 -2
tools/perf/util/machine.h
··· 34 34 struct list_head dead_threads; 35 35 struct thread *last_match; 36 36 struct vdso_info *vdso_info; 37 - struct dsos user_dsos; 38 - struct dsos kernel_dsos; 37 + struct dsos dsos; 39 38 struct map_groups kmaps; 40 39 struct map *vmlinux_maps[MAP__NR_TYPES]; 41 40 u64 kernel_start;
+1 -1
tools/perf/util/map.c
··· 180 180 pgoff = 0; 181 181 dso = vdso__dso_findnew(machine, thread); 182 182 } else 183 - dso = __dsos__findnew(&machine->user_dsos, filename); 183 + dso = __dsos__findnew(&machine->dsos, filename); 184 184 185 185 if (dso == NULL) 186 186 goto out_delete;
+3 -2
tools/perf/util/probe-event.c
··· 256 256 int ret = 0; 257 257 258 258 if (module) { 259 - list_for_each_entry(dso, &host_machine->kernel_dsos.head, 260 - node) { 259 + list_for_each_entry(dso, &host_machine->dsos.head, node) { 260 + if (!dso->kernel) 261 + continue; 261 262 if (strncmp(dso->short_name + 1, module, 262 263 dso->short_name_len - 2) == 0) 263 264 goto found;
+1 -5
tools/perf/util/symbol-elf.c
··· 1031 1031 } 1032 1032 curr_dso->symtab_type = dso->symtab_type; 1033 1033 map_groups__insert(kmaps, curr_map); 1034 - /* 1035 - * The new DSO should go to the kernel DSOS 1036 - */ 1037 - dsos__add(&map->groups->machine->kernel_dsos, 1038 - curr_dso); 1034 + dsos__add(&map->groups->machine->dsos, curr_dso); 1039 1035 dso__set_loaded(curr_dso, map->type); 1040 1036 } else 1041 1037 curr_dso = curr_map->dso;
+3 -3
tools/perf/util/vdso.c
··· 127 127 128 128 dso = dso__new(short_name); 129 129 if (dso != NULL) { 130 - dsos__add(&machine->user_dsos, dso); 130 + dsos__add(&machine->dsos, dso); 131 131 dso__set_long_name(dso, long_name, false); 132 132 } 133 133 ··· 236 236 const char *file_name; 237 237 struct dso *dso; 238 238 239 - dso = dsos__find(&machine->user_dsos, vdso_file->dso_name, true); 239 + dso = dsos__find(&machine->dsos, vdso_file->dso_name, true); 240 240 if (dso) 241 241 return dso; 242 242 ··· 299 299 return dso; 300 300 #endif 301 301 302 - dso = dsos__find(&machine->user_dsos, DSO__NAME_VDSO, true); 302 + dso = dsos__find(&machine->dsos, DSO__NAME_VDSO, true); 303 303 if (!dso) { 304 304 char *file; 305 305