perf symbols: Encapsulate dsos list head into struct dsos
authorWaiman Long <Waiman.Long@hp.com>
Mon, 29 Sep 2014 20:07:28 +0000 (16:07 -0400)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 30 Sep 2014 15:11:49 +0000 (12:11 -0300)
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>
tools/perf/util/dso.c
tools/perf/util/dso.h
tools/perf/util/header.c
tools/perf/util/machine.c
tools/perf/util/machine.h
tools/perf/util/probe-event.c
tools/perf/util/symbol-elf.c

index 55e39dc1bcda7023eeafaa9a6757c71e77c79a88..901a58fa3f229f2d04314f7a723de78e763470b0 100644 (file)
@@ -851,35 +851,36 @@ bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
        return have_build_id;
 }
 
-void dsos__add(struct list_head *head, struct dso *dso)
+void dsos__add(struct dsos *dsos, struct dso *dso)
 {
-       list_add_tail(&dso->node, head);
+       list_add_tail(&dso->node, &dsos->head);
 }
 
-struct dso *dsos__find(const struct list_head *head, const char *name, bool cmp_short)
+struct dso *dsos__find(const struct dsos *dsos, const char *name,
+                      bool cmp_short)
 {
        struct dso *pos;
 
        if (cmp_short) {
-               list_for_each_entry(pos, head, node)
+               list_for_each_entry(pos, &dsos->head, node)
                        if (strcmp(pos->short_name, name) == 0)
                                return pos;
                return NULL;
        }
-       list_for_each_entry(pos, head, node)
+       list_for_each_entry(pos, &dsos->head, node)
                if (strcmp(pos->long_name, name) == 0)
                        return pos;
        return NULL;
 }
 
-struct dso *__dsos__findnew(struct list_head *head, const char *name)
+struct dso *__dsos__findnew(struct dsos *dsos, const char *name)
 {
-       struct dso *dso = dsos__find(head, name, false);
+       struct dso *dso = dsos__find(dsos, name, false);
 
        if (!dso) {
                dso = dso__new(name);
                if (dso != NULL) {
-                       dsos__add(head, dso);
+                       dsos__add(dsos, dso);
                        dso__set_basename(dso);
                }
        }
index 5e463c0964d442b23a44c67377ec016925f68363..b63dc98ad71d56f5dccd3fb4c4e4cae04e45ffc6 100644 (file)
@@ -90,6 +90,13 @@ struct dso_cache {
        char data[0];
 };
 
+/*
+ * DSOs are put into a list for fast iteration.
+ */
+struct dsos {
+       struct list_head head;
+};
+
 struct dso {
        struct list_head node;
        struct rb_root   symbols[MAP__NR_TYPES];
@@ -224,10 +231,10 @@ struct map *dso__new_map(const char *name);
 struct dso *dso__kernel_findnew(struct machine *machine, const char *name,
                                const char *short_name, int dso_type);
 
-void dsos__add(struct list_head *head, struct dso *dso);
-struct dso *dsos__find(const struct list_head *head, const char *name,
+void dsos__add(struct dsos *dsos, struct dso *dso);
+struct dso *dsos__find(const struct dsos *dsos, const char *name,
                       bool cmp_short);
-struct dso *__dsos__findnew(struct list_head *head, const char *name);
+struct dso *__dsos__findnew(struct dsos *dsos, const char *name);
 bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
 
 size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
index 158c787ce0c40e8bc673e3e73062dcaef3872c4f..ce0de00399da381accf00472f66c6064cdcee20a 100644 (file)
@@ -214,11 +214,11 @@ static int machine__hit_all_dsos(struct machine *machine)
 {
        int err;
 
-       err = __dsos__hit_all(&machine->kernel_dsos);
+       err = __dsos__hit_all(&machine->kernel_dsos.head);
        if (err)
                return err;
 
-       return __dsos__hit_all(&machine->user_dsos);
+       return __dsos__hit_all(&machine->user_dsos.head);
 }
 
 int dsos__hit_all(struct perf_session *session)
@@ -288,11 +288,12 @@ static int machine__write_buildid_table(struct machine *machine, int fd)
                umisc = PERF_RECORD_MISC_GUEST_USER;
        }
 
-       err = __dsos__write_buildid_table(&machine->kernel_dsos, machine,
+       err = __dsos__write_buildid_table(&machine->kernel_dsos.head, machine,
                                          machine->pid, kmisc, fd);
        if (err == 0)
-               err = __dsos__write_buildid_table(&machine->user_dsos, machine,
-                                                 machine->pid, umisc, fd);
+               err = __dsos__write_buildid_table(&machine->user_dsos.head,
+                                                 machine, machine->pid, umisc,
+                                                 fd);
        return err;
 }
 
@@ -455,9 +456,10 @@ static int __dsos__cache_build_ids(struct list_head *head,
 
 static int machine__cache_build_ids(struct machine *machine, const char *debugdir)
 {
-       int ret = __dsos__cache_build_ids(&machine->kernel_dsos, machine,
+       int ret = __dsos__cache_build_ids(&machine->kernel_dsos.head, machine,
                                          debugdir);
-       ret |= __dsos__cache_build_ids(&machine->user_dsos, machine, debugdir);
+       ret |= __dsos__cache_build_ids(&machine->user_dsos.head, machine,
+                                      debugdir);
        return ret;
 }
 
@@ -483,8 +485,10 @@ static int perf_session__cache_build_ids(struct perf_session *session)
 
 static bool machine__read_build_ids(struct machine *machine, bool with_hits)
 {
-       bool ret = __dsos__read_build_ids(&machine->kernel_dsos, with_hits);
-       ret |= __dsos__read_build_ids(&machine->user_dsos, with_hits);
+       bool ret;
+
+       ret  = __dsos__read_build_ids(&machine->kernel_dsos.head, with_hits);
+       ret |= __dsos__read_build_ids(&machine->user_dsos.head, with_hits);
        return ret;
 }
 
@@ -1548,7 +1552,7 @@ static int __event_process_build_id(struct build_id_event *bev,
                                    struct perf_session *session)
 {
        int err = -1;
-       struct list_head *head;
+       struct dsos *dsos;
        struct machine *machine;
        u16 misc;
        struct dso *dso;
@@ -1563,22 +1567,22 @@ static int __event_process_build_id(struct build_id_event *bev,
        switch (misc) {
        case PERF_RECORD_MISC_KERNEL:
                dso_type = DSO_TYPE_KERNEL;
-               head = &machine->kernel_dsos;
+               dsos = &machine->kernel_dsos;
                break;
        case PERF_RECORD_MISC_GUEST_KERNEL:
                dso_type = DSO_TYPE_GUEST_KERNEL;
-               head = &machine->kernel_dsos;
+               dsos = &machine->kernel_dsos;
                break;
        case PERF_RECORD_MISC_USER:
        case PERF_RECORD_MISC_GUEST_USER:
                dso_type = DSO_TYPE_USER;
-               head = &machine->user_dsos;
+               dsos = &machine->user_dsos;
                break;
        default:
                goto out;
        }
 
-       dso = __dsos__findnew(head, filename);
+       dso = __dsos__findnew(dsos, filename);
        if (dso != NULL) {
                char sbuild_id[BUILD_ID_SIZE * 2 + 1];
 
index b2ec38bf211ebc95105bd3c3e01f39d8a00c826f..49a75ec4c47bd582a96290092d77ee1d62bb0924 100644 (file)
@@ -17,8 +17,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
 {
        map_groups__init(&machine->kmaps);
        RB_CLEAR_NODE(&machine->rb_node);
-       INIT_LIST_HEAD(&machine->user_dsos);
-       INIT_LIST_HEAD(&machine->kernel_dsos);
+       INIT_LIST_HEAD(&machine->user_dsos.head);
+       INIT_LIST_HEAD(&machine->kernel_dsos.head);
 
        machine->threads = RB_ROOT;
        INIT_LIST_HEAD(&machine->dead_threads);
@@ -72,11 +72,11 @@ out_delete:
        return NULL;
 }
 
-static void dsos__delete(struct list_head *dsos)
+static void dsos__delete(struct dsos *dsos)
 {
        struct dso *pos, *n;
 
-       list_for_each_entry_safe(pos, n, dsos, node) {
+       list_for_each_entry_safe(pos, n, &dsos->head, node) {
                list_del(&pos->node);
                dso__delete(pos);
        }
@@ -477,23 +477,23 @@ struct map *machine__new_module(struct machine *machine, u64 start,
 size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
 {
        struct rb_node *nd;
-       size_t ret = __dsos__fprintf(&machines->host.kernel_dsos, fp) +
-                    __dsos__fprintf(&machines->host.user_dsos, fp);
+       size_t ret = __dsos__fprintf(&machines->host.kernel_dsos.head, fp) +
+                    __dsos__fprintf(&machines->host.user_dsos.head, fp);
 
        for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
                struct machine *pos = rb_entry(nd, struct machine, rb_node);
-               ret += __dsos__fprintf(&pos->kernel_dsos, fp);
-               ret += __dsos__fprintf(&pos->user_dsos, fp);
+               ret += __dsos__fprintf(&pos->kernel_dsos.head, fp);
+               ret += __dsos__fprintf(&pos->user_dsos.head, fp);
        }
 
        return ret;
 }
 
-size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
+size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp,
                                     bool (skip)(struct dso *dso, int parm), int parm)
 {
-       return __dsos__fprintf_buildid(&machine->kernel_dsos, fp, skip, parm) +
-              __dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm);
+       return __dsos__fprintf_buildid(&m->kernel_dsos.head, fp, skip, parm) +
+              __dsos__fprintf_buildid(&m->user_dsos.head, fp, skip, parm);
 }
 
 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
@@ -994,7 +994,7 @@ static bool machine__uses_kcore(struct machine *machine)
 {
        struct dso *dso;
 
-       list_for_each_entry(dso, &machine->kernel_dsos, node) {
+       list_for_each_entry(dso, &machine->kernel_dsos.head, node) {
                if (dso__is_kcore(dso))
                        return true;
        }
index 6a6bcc1cff54449db4f767d68d572b9e402d7f26..2b651a7f5d0d113c59461f4badbd35c9ad870a45 100644 (file)
@@ -4,6 +4,7 @@
 #include <sys/types.h>
 #include <linux/rbtree.h>
 #include "map.h"
+#include "dso.h"
 #include "event.h"
 
 struct addr_location;
@@ -32,8 +33,8 @@ struct machine {
        struct list_head  dead_threads;
        struct thread     *last_match;
        struct vdso_info  *vdso_info;
-       struct list_head  user_dsos;
-       struct list_head  kernel_dsos;
+       struct dsos       user_dsos;
+       struct dsos       kernel_dsos;
        struct map_groups kmaps;
        struct map        *vmlinux_maps[MAP__NR_TYPES];
        u64               kernel_start;
index be37b5aca33522f735d32224f23281d1ce8183c5..c150ca4343eb216c81244abb73bec70703f142ea 100644 (file)
@@ -184,7 +184,8 @@ static struct dso *kernel_get_module_dso(const char *module)
        const char *vmlinux_name;
 
        if (module) {
-               list_for_each_entry(dso, &host_machine->kernel_dsos, node) {
+               list_for_each_entry(dso, &host_machine->kernel_dsos.head,
+                                   node) {
                        if (strncmp(dso->short_name + 1, module,
                                    dso->short_name_len - 2) == 0)
                                goto found;
index 2a92e10317c5056ef10f10ebab7847233af9489e..1e23a5bfb044a4cf39f2a0dfbbb5bf26bbad4b4b 100644 (file)
@@ -6,6 +6,7 @@
 #include <inttypes.h>
 
 #include "symbol.h"
+#include "machine.h"
 #include "vdso.h"
 #include <symbol/kallsyms.h>
 #include "debug.h"
@@ -929,7 +930,11 @@ int dso__load_sym(struct dso *dso, struct map *map,
                                }
                                curr_dso->symtab_type = dso->symtab_type;
                                map_groups__insert(kmap->kmaps, curr_map);
-                               dsos__add(&dso->node, curr_dso);
+                               /*
+                                * The new DSO should go to the kernel DSOS
+                                */
+                               dsos__add(&map->groups->machine->kernel_dsos,
+                                         curr_dso);
                                dso__set_loaded(curr_dso, map->type);
                        } else
                                curr_dso = curr_map->dso;