aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2015-05-28 12:06:42 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-05-29 11:43:43 -0400
commit3d39ac538629e4f00a6e1c38d46346f1b8e69505 (patch)
tree91649aa3c3fb8099ed0a1ab5919308c0c42d7a93 /tools
parent459ce518d9b563a99faa73aa340b764e0b3fb143 (diff)
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/tests/hists_common.c2
-rw-r--r--tools/perf/util/build-id.c59
-rw-r--r--tools/perf/util/dso.c2
-rw-r--r--tools/perf/util/header.c6
-rw-r--r--tools/perf/util/machine.c28
-rw-r--r--tools/perf/util/machine.h3
-rw-r--r--tools/perf/util/map.c2
-rw-r--r--tools/perf/util/probe-event.c5
-rw-r--r--tools/perf/util/symbol-elf.c6
-rw-r--r--tools/perf/util/vdso.c6
10 files changed, 39 insertions, 80 deletions
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c
index 456f884eb27b..bcde1d27919c 100644
--- a/tools/perf/tests/hists_common.c
+++ b/tools/perf/tests/hists_common.c
@@ -121,7 +121,7 @@ struct machine *setup_fake_machine(struct machines *machines)
121 size_t k; 121 size_t k;
122 struct dso *dso; 122 struct dso *dso;
123 123
124 dso = __dsos__findnew(&machine->user_dsos, 124 dso = __dsos__findnew(&machine->dsos,
125 fake_symbols[i].dso_name); 125 fake_symbols[i].dso_name);
126 if (dso == NULL) 126 if (dso == NULL)
127 goto out; 127 goto out;
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index ad8cfcbaa25d..1f6fc2323ef9 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -162,15 +162,20 @@ static int write_buildid(const char *name, size_t name_len, u8 *build_id,
162 return write_padded(fd, name, name_len + 1, len); 162 return write_padded(fd, name, name_len + 1, len);
163} 163}
164 164
165static int __dsos__write_buildid_table(struct list_head *head, 165static int machine__write_buildid_table(struct machine *machine, int fd)
166 struct machine *machine,
167 pid_t pid, u16 misc, int fd)
168{ 166{
167 int err = 0;
169 char nm[PATH_MAX]; 168 char nm[PATH_MAX];
170 struct dso *pos; 169 struct dso *pos;
170 u16 kmisc = PERF_RECORD_MISC_KERNEL,
171 umisc = PERF_RECORD_MISC_USER;
172
173 if (!machine__is_host(machine)) {
174 kmisc = PERF_RECORD_MISC_GUEST_KERNEL;
175 umisc = PERF_RECORD_MISC_GUEST_USER;
176 }
171 177
172 dsos__for_each_with_build_id(pos, head) { 178 dsos__for_each_with_build_id(pos, &machine->dsos.head) {
173 int err;
174 const char *name; 179 const char *name;
175 size_t name_len; 180 size_t name_len;
176 181
@@ -189,32 +194,12 @@ static int __dsos__write_buildid_table(struct list_head *head,
189 name_len = pos->long_name_len + 1; 194 name_len = pos->long_name_len + 1;
190 } 195 }
191 196
192 err = write_buildid(name, name_len, pos->build_id, 197 err = write_buildid(name, name_len, pos->build_id, machine->pid,
193 pid, misc, fd); 198 pos->kernel ? kmisc : umisc, fd);
194 if (err) 199 if (err)
195 return err; 200 break;
196 }
197
198 return 0;
199}
200
201static int machine__write_buildid_table(struct machine *machine, int fd)
202{
203 int err;
204 u16 kmisc = PERF_RECORD_MISC_KERNEL,
205 umisc = PERF_RECORD_MISC_USER;
206
207 if (!machine__is_host(machine)) {
208 kmisc = PERF_RECORD_MISC_GUEST_KERNEL;
209 umisc = PERF_RECORD_MISC_GUEST_USER;
210 } 201 }
211 202
212 err = __dsos__write_buildid_table(&machine->kernel_dsos.head, machine,
213 machine->pid, kmisc, fd);
214 if (err == 0)
215 err = __dsos__write_buildid_table(&machine->user_dsos.head,
216 machine, machine->pid, umisc,
217 fd);
218 return err; 203 return err;
219} 204}
220 205
@@ -247,13 +232,7 @@ static int __dsos__hit_all(struct list_head *head)
247 232
248static int machine__hit_all_dsos(struct machine *machine) 233static int machine__hit_all_dsos(struct machine *machine)
249{ 234{
250 int err; 235 return __dsos__hit_all(&machine->dsos.head);
251
252 err = __dsos__hit_all(&machine->kernel_dsos.head);
253 if (err)
254 return err;
255
256 return __dsos__hit_all(&machine->user_dsos.head);
257} 236}
258 237
259int dsos__hit_all(struct perf_session *session) 238int dsos__hit_all(struct perf_session *session)
@@ -493,9 +472,7 @@ static int __dsos__cache_build_ids(struct list_head *head,
493 472
494static int machine__cache_build_ids(struct machine *machine) 473static int machine__cache_build_ids(struct machine *machine)
495{ 474{
496 int ret = __dsos__cache_build_ids(&machine->kernel_dsos.head, machine); 475 return __dsos__cache_build_ids(&machine->dsos.head, machine);
497 ret |= __dsos__cache_build_ids(&machine->user_dsos.head, machine);
498 return ret;
499} 476}
500 477
501int perf_session__cache_build_ids(struct perf_session *session) 478int perf_session__cache_build_ids(struct perf_session *session)
@@ -520,11 +497,7 @@ int perf_session__cache_build_ids(struct perf_session *session)
520 497
521static bool machine__read_build_ids(struct machine *machine, bool with_hits) 498static bool machine__read_build_ids(struct machine *machine, bool with_hits)
522{ 499{
523 bool ret; 500 return __dsos__read_build_ids(&machine->dsos.head, with_hits);
524
525 ret = __dsos__read_build_ids(&machine->kernel_dsos.head, with_hits);
526 ret |= __dsos__read_build_ids(&machine->user_dsos.head, with_hits);
527 return ret;
528} 501}
529 502
530bool perf_session__read_build_ids(struct perf_session *session, bool with_hits) 503bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index fe5236833164..ff040b0569d6 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -833,7 +833,7 @@ struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
833 /* 833 /*
834 * The kernel dso could be created by build_id processing. 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 * We need to run this in all cases, since during the build_id 839 * We need to run this in all cases, since during the build_id
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 3f0d809d853a..a900e9441fb5 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1238,7 +1238,6 @@ static int __event_process_build_id(struct build_id_event *bev,
1238 struct perf_session *session) 1238 struct perf_session *session)
1239{ 1239{
1240 int err = -1; 1240 int err = -1;
1241 struct dsos *dsos;
1242 struct machine *machine; 1241 struct machine *machine;
1243 u16 misc; 1242 u16 misc;
1244 struct dso *dso; 1243 struct dso *dso;
@@ -1253,22 +1252,19 @@ static int __event_process_build_id(struct build_id_event *bev,
1253 switch (misc) { 1252 switch (misc) {
1254 case PERF_RECORD_MISC_KERNEL: 1253 case PERF_RECORD_MISC_KERNEL:
1255 dso_type = DSO_TYPE_KERNEL; 1254 dso_type = DSO_TYPE_KERNEL;
1256 dsos = &machine->kernel_dsos;
1257 break; 1255 break;
1258 case PERF_RECORD_MISC_GUEST_KERNEL: 1256 case PERF_RECORD_MISC_GUEST_KERNEL:
1259 dso_type = DSO_TYPE_GUEST_KERNEL; 1257 dso_type = DSO_TYPE_GUEST_KERNEL;
1260 dsos = &machine->kernel_dsos;
1261 break; 1258 break;
1262 case PERF_RECORD_MISC_USER: 1259 case PERF_RECORD_MISC_USER:
1263 case PERF_RECORD_MISC_GUEST_USER: 1260 case PERF_RECORD_MISC_GUEST_USER:
1264 dso_type = DSO_TYPE_USER; 1261 dso_type = DSO_TYPE_USER;
1265 dsos = &machine->user_dsos;
1266 break; 1262 break;
1267 default: 1263 default:
1268 goto out; 1264 goto out;
1269 } 1265 }
1270 1266
1271 dso = __dsos__findnew(dsos, filename); 1267 dso = __dsos__findnew(&machine->dsos, filename);
1272 if (dso != NULL) { 1268 if (dso != NULL) {
1273 char sbuild_id[BUILD_ID_SIZE * 2 + 1]; 1269 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
1274 1270
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 8934dc4345fe..ffd31079d447 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -26,8 +26,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
26{ 26{
27 map_groups__init(&machine->kmaps, machine); 27 map_groups__init(&machine->kmaps, machine);
28 RB_CLEAR_NODE(&machine->rb_node); 28 RB_CLEAR_NODE(&machine->rb_node);
29 dsos__init(&machine->user_dsos); 29 dsos__init(&machine->dsos);
30 dsos__init(&machine->kernel_dsos);
31 30
32 machine->threads = RB_ROOT; 31 machine->threads = RB_ROOT;
33 pthread_rwlock_init(&machine->threads_lock, NULL); 32 pthread_rwlock_init(&machine->threads_lock, NULL);
@@ -111,8 +110,7 @@ void machine__delete_threads(struct machine *machine)
111void machine__exit(struct machine *machine) 110void machine__exit(struct machine *machine)
112{ 111{
113 map_groups__exit(&machine->kmaps); 112 map_groups__exit(&machine->kmaps);
114 dsos__delete(&machine->user_dsos); 113 dsos__delete(&machine->dsos);
115 dsos__delete(&machine->kernel_dsos);
116 vdso__exit(machine); 114 vdso__exit(machine);
117 zfree(&machine->root_dir); 115 zfree(&machine->root_dir);
118 zfree(&machine->current_tid); 116 zfree(&machine->current_tid);
@@ -490,9 +488,9 @@ machine__module_dso(struct machine *machine, struct kmod_path *m,
490{ 488{
491 struct dso *dso; 489 struct dso *dso;
492 490
493 dso = dsos__find(&machine->kernel_dsos, m->name, true); 491 dso = dsos__find(&machine->dsos, m->name, true);
494 if (!dso) { 492 if (!dso) {
495 dso = dsos__addnew(&machine->kernel_dsos, m->name); 493 dso = dsos__addnew(&machine->dsos, m->name);
496 if (dso == NULL) 494 if (dso == NULL)
497 return NULL; 495 return NULL;
498 496
@@ -561,13 +559,11 @@ out:
561size_t machines__fprintf_dsos(struct machines *machines, FILE *fp) 559size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
562{ 560{
563 struct rb_node *nd; 561 struct rb_node *nd;
564 size_t ret = __dsos__fprintf(&machines->host.kernel_dsos.head, fp) + 562 size_t ret = __dsos__fprintf(&machines->host.dsos.head, fp);
565 __dsos__fprintf(&machines->host.user_dsos.head, fp);
566 563
567 for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) { 564 for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
568 struct machine *pos = rb_entry(nd, struct machine, rb_node); 565 struct machine *pos = rb_entry(nd, struct machine, rb_node);
569 ret += __dsos__fprintf(&pos->kernel_dsos.head, fp); 566 ret += __dsos__fprintf(&pos->dsos.head, fp);
570 ret += __dsos__fprintf(&pos->user_dsos.head, fp);
571 } 567 }
572 568
573 return ret; 569 return ret;
@@ -576,8 +572,7 @@ size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
576size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp, 572size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp,
577 bool (skip)(struct dso *dso, int parm), int parm) 573 bool (skip)(struct dso *dso, int parm), int parm)
578{ 574{
579 return __dsos__fprintf_buildid(&m->kernel_dsos.head, fp, skip, parm) + 575 return __dsos__fprintf_buildid(&m->dsos.head, fp, skip, parm);
580 __dsos__fprintf_buildid(&m->user_dsos.head, fp, skip, parm);
581} 576}
582 577
583size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, 578size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
@@ -1106,7 +1101,7 @@ static bool machine__uses_kcore(struct machine *machine)
1106{ 1101{
1107 struct dso *dso; 1102 struct dso *dso;
1108 1103
1109 list_for_each_entry(dso, &machine->kernel_dsos.head, node) { 1104 list_for_each_entry(dso, &machine->dsos.head, node) {
1110 if (dso__is_kcore(dso)) 1105 if (dso__is_kcore(dso))
1111 return true; 1106 return true;
1112 } 1107 }
@@ -1153,8 +1148,8 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
1153 struct dso *kernel = NULL; 1148 struct dso *kernel = NULL;
1154 struct dso *dso; 1149 struct dso *dso;
1155 1150
1156 list_for_each_entry(dso, &machine->kernel_dsos.head, node) { 1151 list_for_each_entry(dso, &machine->dsos.head, node) {
1157 if (is_kernel_module(dso->long_name)) 1152 if (dso->kernel && is_kernel_module(dso->long_name))
1158 continue; 1153 continue;
1159 1154
1160 kernel = dso; 1155 kernel = dso;
@@ -1162,8 +1157,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
1162 } 1157 }
1163 1158
1164 if (kernel == NULL) 1159 if (kernel == NULL)
1165 kernel = __dsos__findnew(&machine->kernel_dsos, 1160 kernel = __dsos__findnew(&machine->dsos, kmmap_prefix);
1166 kmmap_prefix);
1167 if (kernel == NULL) 1161 if (kernel == NULL)
1168 goto out_problem; 1162 goto out_problem;
1169 1163
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index c7963c63c474..aabca583e655 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -34,8 +34,7 @@ struct machine {
34 struct list_head dead_threads; 34 struct list_head dead_threads;
35 struct thread *last_match; 35 struct thread *last_match;
36 struct vdso_info *vdso_info; 36 struct vdso_info *vdso_info;
37 struct dsos user_dsos; 37 struct dsos dsos;
38 struct dsos kernel_dsos;
39 struct map_groups kmaps; 38 struct map_groups kmaps;
40 struct map *vmlinux_maps[MAP__NR_TYPES]; 39 struct map *vmlinux_maps[MAP__NR_TYPES];
41 u64 kernel_start; 40 u64 kernel_start;
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index af572322586d..57ff0256c22c 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -180,7 +180,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
180 pgoff = 0; 180 pgoff = 0;
181 dso = vdso__dso_findnew(machine, thread); 181 dso = vdso__dso_findnew(machine, thread);
182 } else 182 } else
183 dso = __dsos__findnew(&machine->user_dsos, filename); 183 dso = __dsos__findnew(&machine->dsos, filename);
184 184
185 if (dso == NULL) 185 if (dso == NULL)
186 goto out_delete; 186 goto out_delete;
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index e6a02b1ffd6d..d27edef5eb5b 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -256,8 +256,9 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
256 int ret = 0; 256 int ret = 0;
257 257
258 if (module) { 258 if (module) {
259 list_for_each_entry(dso, &host_machine->kernel_dsos.head, 259 list_for_each_entry(dso, &host_machine->dsos.head, node) {
260 node) { 260 if (!dso->kernel)
261 continue;
261 if (strncmp(dso->short_name + 1, module, 262 if (strncmp(dso->short_name + 1, module,
262 dso->short_name_len - 2) == 0) 263 dso->short_name_len - 2) == 0)
263 goto found; 264 goto found;
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index fa10116a12ab..a93ba85509b2 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -1031,11 +1031,7 @@ int dso__load_sym(struct dso *dso, struct map *map,
1031 } 1031 }
1032 curr_dso->symtab_type = dso->symtab_type; 1032 curr_dso->symtab_type = dso->symtab_type;
1033 map_groups__insert(kmaps, curr_map); 1033 map_groups__insert(kmaps, curr_map);
1034 /* 1034 dsos__add(&map->groups->machine->dsos, curr_dso);
1035 * The new DSO should go to the kernel DSOS
1036 */
1037 dsos__add(&map->groups->machine->kernel_dsos,
1038 curr_dso);
1039 dso__set_loaded(curr_dso, map->type); 1035 dso__set_loaded(curr_dso, map->type);
1040 } else 1036 } else
1041 curr_dso = curr_map->dso; 1037 curr_dso = curr_map->dso;
diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c
index 5c7dd796979d..d3651b43e945 100644
--- a/tools/perf/util/vdso.c
+++ b/tools/perf/util/vdso.c
@@ -127,7 +127,7 @@ static struct dso *vdso__new(struct machine *machine, const char *short_name,
127 127
128 dso = dso__new(short_name); 128 dso = dso__new(short_name);
129 if (dso != NULL) { 129 if (dso != NULL) {
130 dsos__add(&machine->user_dsos, dso); 130 dsos__add(&machine->dsos, dso);
131 dso__set_long_name(dso, long_name, false); 131 dso__set_long_name(dso, long_name, false);
132 } 132 }
133 133
@@ -236,7 +236,7 @@ static struct dso *vdso__findnew_compat(struct machine *machine,
236 const char *file_name; 236 const char *file_name;
237 struct dso *dso; 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 if (dso) 240 if (dso)
241 return dso; 241 return dso;
242 242
@@ -299,7 +299,7 @@ struct dso *vdso__dso_findnew(struct machine *machine,
299 return dso; 299 return dso;
300#endif 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 if (!dso) { 303 if (!dso) {
304 char *file; 304 char *file;
305 305