diff options
author | Waiman Long <Waiman.Long@hp.com> | 2014-09-29 16:07:28 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-09-30 11:11:49 -0400 |
commit | 8fa7d87f91479f7124142ca4ad93a37b80f8c1c0 (patch) | |
tree | 7ec17d252a3a55636abf4542e7d944e41345c8e1 /tools/perf | |
parent | e19685ed24b518440c0717719ff02e74c0e6d2cb (diff) |
perf symbols: Encapsulate dsos list head into struct dsos
This is a precursor patch to enable long name searching of DSOs using
a rbtree.
In this patch, a new dsos structure is created which contains only a
list head structure for the moment.
The new dsos structure is used, in turn, in the machine structure for
the user_dsos and kernel_dsos fields.
Only the following 3 dsos functions are modified to accept the new dsos
structure parameter instead of list_head:
- dsos__add()
- dsos__find()
- __dsos__findnew()
Signed-off-by: Waiman Long <Waiman.Long@hp.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Douglas Hatch <doug.hatch@hp.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Scott J Norton <scott.norton@hp.com>
Link: http://lkml.kernel.org/r/1412021249-19201-2-git-send-email-Waiman.Long@hp.com
[ Move struct dsos to dso.h to reduce the dso methods depends on machine.h ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/dso.c | 17 | ||||
-rw-r--r-- | tools/perf/util/dso.h | 13 | ||||
-rw-r--r-- | tools/perf/util/header.c | 32 | ||||
-rw-r--r-- | tools/perf/util/machine.c | 24 | ||||
-rw-r--r-- | tools/perf/util/machine.h | 5 | ||||
-rw-r--r-- | tools/perf/util/probe-event.c | 3 | ||||
-rw-r--r-- | tools/perf/util/symbol-elf.c | 7 |
7 files changed, 60 insertions, 41 deletions
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 55e39dc1bcda..901a58fa3f22 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c | |||
@@ -851,35 +851,36 @@ bool __dsos__read_build_ids(struct list_head *head, bool with_hits) | |||
851 | return have_build_id; | 851 | return have_build_id; |
852 | } | 852 | } |
853 | 853 | ||
854 | void dsos__add(struct list_head *head, struct dso *dso) | 854 | void dsos__add(struct dsos *dsos, struct dso *dso) |
855 | { | 855 | { |
856 | list_add_tail(&dso->node, head); | 856 | list_add_tail(&dso->node, &dsos->head); |
857 | } | 857 | } |
858 | 858 | ||
859 | struct dso *dsos__find(const struct list_head *head, const char *name, bool cmp_short) | 859 | struct dso *dsos__find(const struct dsos *dsos, const char *name, |
860 | bool cmp_short) | ||
860 | { | 861 | { |
861 | struct dso *pos; | 862 | struct dso *pos; |
862 | 863 | ||
863 | if (cmp_short) { | 864 | if (cmp_short) { |
864 | list_for_each_entry(pos, head, node) | 865 | list_for_each_entry(pos, &dsos->head, node) |
865 | if (strcmp(pos->short_name, name) == 0) | 866 | if (strcmp(pos->short_name, name) == 0) |
866 | return pos; | 867 | return pos; |
867 | return NULL; | 868 | return NULL; |
868 | } | 869 | } |
869 | list_for_each_entry(pos, head, node) | 870 | list_for_each_entry(pos, &dsos->head, node) |
870 | if (strcmp(pos->long_name, name) == 0) | 871 | if (strcmp(pos->long_name, name) == 0) |
871 | return pos; | 872 | return pos; |
872 | return NULL; | 873 | return NULL; |
873 | } | 874 | } |
874 | 875 | ||
875 | struct dso *__dsos__findnew(struct list_head *head, const char *name) | 876 | struct dso *__dsos__findnew(struct dsos *dsos, const char *name) |
876 | { | 877 | { |
877 | struct dso *dso = dsos__find(head, name, false); | 878 | struct dso *dso = dsos__find(dsos, name, false); |
878 | 879 | ||
879 | if (!dso) { | 880 | if (!dso) { |
880 | dso = dso__new(name); | 881 | dso = dso__new(name); |
881 | if (dso != NULL) { | 882 | if (dso != NULL) { |
882 | dsos__add(head, dso); | 883 | dsos__add(dsos, dso); |
883 | dso__set_basename(dso); | 884 | dso__set_basename(dso); |
884 | } | 885 | } |
885 | } | 886 | } |
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 5e463c0964d4..b63dc98ad71d 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h | |||
@@ -90,6 +90,13 @@ struct dso_cache { | |||
90 | char data[0]; | 90 | char data[0]; |
91 | }; | 91 | }; |
92 | 92 | ||
93 | /* | ||
94 | * DSOs are put into a list for fast iteration. | ||
95 | */ | ||
96 | struct dsos { | ||
97 | struct list_head head; | ||
98 | }; | ||
99 | |||
93 | struct dso { | 100 | struct dso { |
94 | struct list_head node; | 101 | struct list_head node; |
95 | struct rb_root symbols[MAP__NR_TYPES]; | 102 | struct rb_root symbols[MAP__NR_TYPES]; |
@@ -224,10 +231,10 @@ struct map *dso__new_map(const char *name); | |||
224 | struct dso *dso__kernel_findnew(struct machine *machine, const char *name, | 231 | struct dso *dso__kernel_findnew(struct machine *machine, const char *name, |
225 | const char *short_name, int dso_type); | 232 | const char *short_name, int dso_type); |
226 | 233 | ||
227 | void dsos__add(struct list_head *head, struct dso *dso); | 234 | void dsos__add(struct dsos *dsos, struct dso *dso); |
228 | struct dso *dsos__find(const struct list_head *head, const char *name, | 235 | struct dso *dsos__find(const struct dsos *dsos, const char *name, |
229 | bool cmp_short); | 236 | bool cmp_short); |
230 | struct dso *__dsos__findnew(struct list_head *head, const char *name); | 237 | struct dso *__dsos__findnew(struct dsos *dsos, const char *name); |
231 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits); | 238 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits); |
232 | 239 | ||
233 | size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, | 240 | size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 158c787ce0c4..ce0de00399da 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -214,11 +214,11 @@ static int machine__hit_all_dsos(struct machine *machine) | |||
214 | { | 214 | { |
215 | int err; | 215 | int err; |
216 | 216 | ||
217 | err = __dsos__hit_all(&machine->kernel_dsos); | 217 | err = __dsos__hit_all(&machine->kernel_dsos.head); |
218 | if (err) | 218 | if (err) |
219 | return err; | 219 | return err; |
220 | 220 | ||
221 | return __dsos__hit_all(&machine->user_dsos); | 221 | return __dsos__hit_all(&machine->user_dsos.head); |
222 | } | 222 | } |
223 | 223 | ||
224 | int dsos__hit_all(struct perf_session *session) | 224 | int dsos__hit_all(struct perf_session *session) |
@@ -288,11 +288,12 @@ static int machine__write_buildid_table(struct machine *machine, int fd) | |||
288 | umisc = PERF_RECORD_MISC_GUEST_USER; | 288 | umisc = PERF_RECORD_MISC_GUEST_USER; |
289 | } | 289 | } |
290 | 290 | ||
291 | err = __dsos__write_buildid_table(&machine->kernel_dsos, machine, | 291 | err = __dsos__write_buildid_table(&machine->kernel_dsos.head, machine, |
292 | machine->pid, kmisc, fd); | 292 | machine->pid, kmisc, fd); |
293 | if (err == 0) | 293 | if (err == 0) |
294 | err = __dsos__write_buildid_table(&machine->user_dsos, machine, | 294 | err = __dsos__write_buildid_table(&machine->user_dsos.head, |
295 | machine->pid, umisc, fd); | 295 | machine, machine->pid, umisc, |
296 | fd); | ||
296 | return err; | 297 | return err; |
297 | } | 298 | } |
298 | 299 | ||
@@ -455,9 +456,10 @@ static int __dsos__cache_build_ids(struct list_head *head, | |||
455 | 456 | ||
456 | static int machine__cache_build_ids(struct machine *machine, const char *debugdir) | 457 | static int machine__cache_build_ids(struct machine *machine, const char *debugdir) |
457 | { | 458 | { |
458 | int ret = __dsos__cache_build_ids(&machine->kernel_dsos, machine, | 459 | int ret = __dsos__cache_build_ids(&machine->kernel_dsos.head, machine, |
459 | debugdir); | 460 | debugdir); |
460 | ret |= __dsos__cache_build_ids(&machine->user_dsos, machine, debugdir); | 461 | ret |= __dsos__cache_build_ids(&machine->user_dsos.head, machine, |
462 | debugdir); | ||
461 | return ret; | 463 | return ret; |
462 | } | 464 | } |
463 | 465 | ||
@@ -483,8 +485,10 @@ static int perf_session__cache_build_ids(struct perf_session *session) | |||
483 | 485 | ||
484 | static bool machine__read_build_ids(struct machine *machine, bool with_hits) | 486 | static bool machine__read_build_ids(struct machine *machine, bool with_hits) |
485 | { | 487 | { |
486 | bool ret = __dsos__read_build_ids(&machine->kernel_dsos, with_hits); | 488 | bool ret; |
487 | ret |= __dsos__read_build_ids(&machine->user_dsos, with_hits); | 489 | |
490 | ret = __dsos__read_build_ids(&machine->kernel_dsos.head, with_hits); | ||
491 | ret |= __dsos__read_build_ids(&machine->user_dsos.head, with_hits); | ||
488 | return ret; | 492 | return ret; |
489 | } | 493 | } |
490 | 494 | ||
@@ -1548,7 +1552,7 @@ static int __event_process_build_id(struct build_id_event *bev, | |||
1548 | struct perf_session *session) | 1552 | struct perf_session *session) |
1549 | { | 1553 | { |
1550 | int err = -1; | 1554 | int err = -1; |
1551 | struct list_head *head; | 1555 | struct dsos *dsos; |
1552 | struct machine *machine; | 1556 | struct machine *machine; |
1553 | u16 misc; | 1557 | u16 misc; |
1554 | struct dso *dso; | 1558 | struct dso *dso; |
@@ -1563,22 +1567,22 @@ static int __event_process_build_id(struct build_id_event *bev, | |||
1563 | switch (misc) { | 1567 | switch (misc) { |
1564 | case PERF_RECORD_MISC_KERNEL: | 1568 | case PERF_RECORD_MISC_KERNEL: |
1565 | dso_type = DSO_TYPE_KERNEL; | 1569 | dso_type = DSO_TYPE_KERNEL; |
1566 | head = &machine->kernel_dsos; | 1570 | dsos = &machine->kernel_dsos; |
1567 | break; | 1571 | break; |
1568 | case PERF_RECORD_MISC_GUEST_KERNEL: | 1572 | case PERF_RECORD_MISC_GUEST_KERNEL: |
1569 | dso_type = DSO_TYPE_GUEST_KERNEL; | 1573 | dso_type = DSO_TYPE_GUEST_KERNEL; |
1570 | head = &machine->kernel_dsos; | 1574 | dsos = &machine->kernel_dsos; |
1571 | break; | 1575 | break; |
1572 | case PERF_RECORD_MISC_USER: | 1576 | case PERF_RECORD_MISC_USER: |
1573 | case PERF_RECORD_MISC_GUEST_USER: | 1577 | case PERF_RECORD_MISC_GUEST_USER: |
1574 | dso_type = DSO_TYPE_USER; | 1578 | dso_type = DSO_TYPE_USER; |
1575 | head = &machine->user_dsos; | 1579 | dsos = &machine->user_dsos; |
1576 | break; | 1580 | break; |
1577 | default: | 1581 | default: |
1578 | goto out; | 1582 | goto out; |
1579 | } | 1583 | } |
1580 | 1584 | ||
1581 | dso = __dsos__findnew(head, filename); | 1585 | dso = __dsos__findnew(dsos, filename); |
1582 | if (dso != NULL) { | 1586 | if (dso != NULL) { |
1583 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | 1587 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; |
1584 | 1588 | ||
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index b2ec38bf211e..49a75ec4c47b 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c | |||
@@ -17,8 +17,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) | |||
17 | { | 17 | { |
18 | map_groups__init(&machine->kmaps); | 18 | map_groups__init(&machine->kmaps); |
19 | RB_CLEAR_NODE(&machine->rb_node); | 19 | RB_CLEAR_NODE(&machine->rb_node); |
20 | INIT_LIST_HEAD(&machine->user_dsos); | 20 | INIT_LIST_HEAD(&machine->user_dsos.head); |
21 | INIT_LIST_HEAD(&machine->kernel_dsos); | 21 | INIT_LIST_HEAD(&machine->kernel_dsos.head); |
22 | 22 | ||
23 | machine->threads = RB_ROOT; | 23 | machine->threads = RB_ROOT; |
24 | INIT_LIST_HEAD(&machine->dead_threads); | 24 | INIT_LIST_HEAD(&machine->dead_threads); |
@@ -72,11 +72,11 @@ out_delete: | |||
72 | return NULL; | 72 | return NULL; |
73 | } | 73 | } |
74 | 74 | ||
75 | static void dsos__delete(struct list_head *dsos) | 75 | static void dsos__delete(struct dsos *dsos) |
76 | { | 76 | { |
77 | struct dso *pos, *n; | 77 | struct dso *pos, *n; |
78 | 78 | ||
79 | list_for_each_entry_safe(pos, n, dsos, node) { | 79 | list_for_each_entry_safe(pos, n, &dsos->head, node) { |
80 | list_del(&pos->node); | 80 | list_del(&pos->node); |
81 | dso__delete(pos); | 81 | dso__delete(pos); |
82 | } | 82 | } |
@@ -477,23 +477,23 @@ struct map *machine__new_module(struct machine *machine, u64 start, | |||
477 | size_t machines__fprintf_dsos(struct machines *machines, FILE *fp) | 477 | size_t machines__fprintf_dsos(struct machines *machines, FILE *fp) |
478 | { | 478 | { |
479 | struct rb_node *nd; | 479 | struct rb_node *nd; |
480 | size_t ret = __dsos__fprintf(&machines->host.kernel_dsos, fp) + | 480 | size_t ret = __dsos__fprintf(&machines->host.kernel_dsos.head, fp) + |
481 | __dsos__fprintf(&machines->host.user_dsos, fp); | 481 | __dsos__fprintf(&machines->host.user_dsos.head, fp); |
482 | 482 | ||
483 | for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) { | 483 | for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) { |
484 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | 484 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
485 | ret += __dsos__fprintf(&pos->kernel_dsos, fp); | 485 | ret += __dsos__fprintf(&pos->kernel_dsos.head, fp); |
486 | ret += __dsos__fprintf(&pos->user_dsos, fp); | 486 | ret += __dsos__fprintf(&pos->user_dsos.head, fp); |
487 | } | 487 | } |
488 | 488 | ||
489 | return ret; | 489 | return ret; |
490 | } | 490 | } |
491 | 491 | ||
492 | size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp, | 492 | size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp, |
493 | bool (skip)(struct dso *dso, int parm), int parm) | 493 | bool (skip)(struct dso *dso, int parm), int parm) |
494 | { | 494 | { |
495 | return __dsos__fprintf_buildid(&machine->kernel_dsos, fp, skip, parm) + | 495 | return __dsos__fprintf_buildid(&m->kernel_dsos.head, fp, skip, parm) + |
496 | __dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm); | 496 | __dsos__fprintf_buildid(&m->user_dsos.head, fp, skip, parm); |
497 | } | 497 | } |
498 | 498 | ||
499 | size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, | 499 | size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, |
@@ -994,7 +994,7 @@ static bool machine__uses_kcore(struct machine *machine) | |||
994 | { | 994 | { |
995 | struct dso *dso; | 995 | struct dso *dso; |
996 | 996 | ||
997 | list_for_each_entry(dso, &machine->kernel_dsos, node) { | 997 | list_for_each_entry(dso, &machine->kernel_dsos.head, node) { |
998 | if (dso__is_kcore(dso)) | 998 | if (dso__is_kcore(dso)) |
999 | return true; | 999 | return true; |
1000 | } | 1000 | } |
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 6a6bcc1cff54..2b651a7f5d0d 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <sys/types.h> | 4 | #include <sys/types.h> |
5 | #include <linux/rbtree.h> | 5 | #include <linux/rbtree.h> |
6 | #include "map.h" | 6 | #include "map.h" |
7 | #include "dso.h" | ||
7 | #include "event.h" | 8 | #include "event.h" |
8 | 9 | ||
9 | struct addr_location; | 10 | struct addr_location; |
@@ -32,8 +33,8 @@ struct machine { | |||
32 | struct list_head dead_threads; | 33 | struct list_head dead_threads; |
33 | struct thread *last_match; | 34 | struct thread *last_match; |
34 | struct vdso_info *vdso_info; | 35 | struct vdso_info *vdso_info; |
35 | struct list_head user_dsos; | 36 | struct dsos user_dsos; |
36 | struct list_head kernel_dsos; | 37 | struct dsos kernel_dsos; |
37 | struct map_groups kmaps; | 38 | struct map_groups kmaps; |
38 | struct map *vmlinux_maps[MAP__NR_TYPES]; | 39 | struct map *vmlinux_maps[MAP__NR_TYPES]; |
39 | u64 kernel_start; | 40 | u64 kernel_start; |
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index be37b5aca335..c150ca4343eb 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -184,7 +184,8 @@ static struct dso *kernel_get_module_dso(const char *module) | |||
184 | const char *vmlinux_name; | 184 | const char *vmlinux_name; |
185 | 185 | ||
186 | if (module) { | 186 | if (module) { |
187 | list_for_each_entry(dso, &host_machine->kernel_dsos, node) { | 187 | list_for_each_entry(dso, &host_machine->kernel_dsos.head, |
188 | node) { | ||
188 | if (strncmp(dso->short_name + 1, module, | 189 | if (strncmp(dso->short_name + 1, module, |
189 | dso->short_name_len - 2) == 0) | 190 | dso->short_name_len - 2) == 0) |
190 | goto found; | 191 | goto found; |
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 2a92e10317c5..1e23a5bfb044 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <inttypes.h> | 6 | #include <inttypes.h> |
7 | 7 | ||
8 | #include "symbol.h" | 8 | #include "symbol.h" |
9 | #include "machine.h" | ||
9 | #include "vdso.h" | 10 | #include "vdso.h" |
10 | #include <symbol/kallsyms.h> | 11 | #include <symbol/kallsyms.h> |
11 | #include "debug.h" | 12 | #include "debug.h" |
@@ -929,7 +930,11 @@ int dso__load_sym(struct dso *dso, struct map *map, | |||
929 | } | 930 | } |
930 | curr_dso->symtab_type = dso->symtab_type; | 931 | curr_dso->symtab_type = dso->symtab_type; |
931 | map_groups__insert(kmap->kmaps, curr_map); | 932 | map_groups__insert(kmap->kmaps, curr_map); |
932 | dsos__add(&dso->node, curr_dso); | 933 | /* |
934 | * The new DSO should go to the kernel DSOS | ||
935 | */ | ||
936 | dsos__add(&map->groups->machine->kernel_dsos, | ||
937 | curr_dso); | ||
933 | dso__set_loaded(curr_dso, map->type); | 938 | dso__set_loaded(curr_dso, map->type); |
934 | } else | 939 | } else |
935 | curr_dso = curr_map->dso; | 940 | curr_dso = curr_map->dso; |