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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 459ce518
...@@ -121,7 +121,7 @@ struct machine *setup_fake_machine(struct machines *machines) ...@@ -121,7 +121,7 @@ struct machine *setup_fake_machine(struct machines *machines)
size_t k; size_t k;
struct dso *dso; struct dso *dso;
dso = __dsos__findnew(&machine->user_dsos, dso = __dsos__findnew(&machine->dsos,
fake_symbols[i].dso_name); fake_symbols[i].dso_name);
if (dso == NULL) if (dso == NULL)
goto out; goto out;
......
...@@ -162,15 +162,20 @@ static int write_buildid(const char *name, size_t name_len, u8 *build_id, ...@@ -162,15 +162,20 @@ static int write_buildid(const char *name, size_t name_len, u8 *build_id,
return write_padded(fd, name, name_len + 1, len); return write_padded(fd, name, name_len + 1, len);
} }
static int __dsos__write_buildid_table(struct list_head *head, static int machine__write_buildid_table(struct machine *machine, int fd)
struct machine *machine,
pid_t pid, u16 misc, int fd)
{ {
int err = 0;
char nm[PATH_MAX]; char nm[PATH_MAX];
struct dso *pos; struct dso *pos;
u16 kmisc = PERF_RECORD_MISC_KERNEL,
umisc = PERF_RECORD_MISC_USER;
dsos__for_each_with_build_id(pos, head) { if (!machine__is_host(machine)) {
int err; kmisc = PERF_RECORD_MISC_GUEST_KERNEL;
umisc = PERF_RECORD_MISC_GUEST_USER;
}
dsos__for_each_with_build_id(pos, &machine->dsos.head) {
const char *name; const char *name;
size_t name_len; size_t name_len;
...@@ -189,32 +194,12 @@ static int __dsos__write_buildid_table(struct list_head *head, ...@@ -189,32 +194,12 @@ static int __dsos__write_buildid_table(struct list_head *head,
name_len = pos->long_name_len + 1; name_len = pos->long_name_len + 1;
} }
err = write_buildid(name, name_len, pos->build_id, err = write_buildid(name, name_len, pos->build_id, machine->pid,
pid, misc, fd); pos->kernel ? kmisc : umisc, fd);
if (err) if (err)
return err; break;
}
return 0;
}
static int machine__write_buildid_table(struct machine *machine, int fd)
{
int err;
u16 kmisc = PERF_RECORD_MISC_KERNEL,
umisc = PERF_RECORD_MISC_USER;
if (!machine__is_host(machine)) {
kmisc = PERF_RECORD_MISC_GUEST_KERNEL;
umisc = PERF_RECORD_MISC_GUEST_USER;
} }
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.head,
machine, machine->pid, umisc,
fd);
return err; return err;
} }
...@@ -247,13 +232,7 @@ static int __dsos__hit_all(struct list_head *head) ...@@ -247,13 +232,7 @@ static int __dsos__hit_all(struct list_head *head)
static int machine__hit_all_dsos(struct machine *machine) static int machine__hit_all_dsos(struct machine *machine)
{ {
int err; return __dsos__hit_all(&machine->dsos.head);
err = __dsos__hit_all(&machine->kernel_dsos.head);
if (err)
return err;
return __dsos__hit_all(&machine->user_dsos.head);
} }
int dsos__hit_all(struct perf_session *session) int dsos__hit_all(struct perf_session *session)
...@@ -493,9 +472,7 @@ static int __dsos__cache_build_ids(struct list_head *head, ...@@ -493,9 +472,7 @@ static int __dsos__cache_build_ids(struct list_head *head,
static int machine__cache_build_ids(struct machine *machine) static int machine__cache_build_ids(struct machine *machine)
{ {
int ret = __dsos__cache_build_ids(&machine->kernel_dsos.head, machine); return __dsos__cache_build_ids(&machine->dsos.head, machine);
ret |= __dsos__cache_build_ids(&machine->user_dsos.head, machine);
return ret;
} }
int perf_session__cache_build_ids(struct perf_session *session) int perf_session__cache_build_ids(struct perf_session *session)
...@@ -520,11 +497,7 @@ int perf_session__cache_build_ids(struct perf_session *session) ...@@ -520,11 +497,7 @@ int perf_session__cache_build_ids(struct perf_session *session)
static bool machine__read_build_ids(struct machine *machine, bool with_hits) static bool machine__read_build_ids(struct machine *machine, bool with_hits)
{ {
bool ret; return __dsos__read_build_ids(&machine->dsos.head, with_hits);
ret = __dsos__read_build_ids(&machine->kernel_dsos.head, with_hits);
ret |= __dsos__read_build_ids(&machine->user_dsos.head, with_hits);
return ret;
} }
bool perf_session__read_build_ids(struct perf_session *session, bool with_hits) bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)
......
...@@ -833,7 +833,7 @@ struct dso *machine__findnew_kernel(struct machine *machine, const char *name, ...@@ -833,7 +833,7 @@ struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
/* /*
* The kernel dso could be created by build_id processing. * The kernel dso could be created by build_id processing.
*/ */
struct dso *dso = __dsos__findnew(&machine->kernel_dsos, name); struct dso *dso = __dsos__findnew(&machine->dsos, name);
/* /*
* We need to run this in all cases, since during the build_id * We need to run this in all cases, since during the build_id
......
...@@ -1238,7 +1238,6 @@ static int __event_process_build_id(struct build_id_event *bev, ...@@ -1238,7 +1238,6 @@ static int __event_process_build_id(struct build_id_event *bev,
struct perf_session *session) struct perf_session *session)
{ {
int err = -1; int err = -1;
struct dsos *dsos;
struct machine *machine; struct machine *machine;
u16 misc; u16 misc;
struct dso *dso; struct dso *dso;
...@@ -1253,22 +1252,19 @@ static int __event_process_build_id(struct build_id_event *bev, ...@@ -1253,22 +1252,19 @@ static int __event_process_build_id(struct build_id_event *bev,
switch (misc) { switch (misc) {
case PERF_RECORD_MISC_KERNEL: case PERF_RECORD_MISC_KERNEL:
dso_type = DSO_TYPE_KERNEL; dso_type = DSO_TYPE_KERNEL;
dsos = &machine->kernel_dsos;
break; break;
case PERF_RECORD_MISC_GUEST_KERNEL: case PERF_RECORD_MISC_GUEST_KERNEL:
dso_type = DSO_TYPE_GUEST_KERNEL; dso_type = DSO_TYPE_GUEST_KERNEL;
dsos = &machine->kernel_dsos;
break; break;
case PERF_RECORD_MISC_USER: case PERF_RECORD_MISC_USER:
case PERF_RECORD_MISC_GUEST_USER: case PERF_RECORD_MISC_GUEST_USER:
dso_type = DSO_TYPE_USER; dso_type = DSO_TYPE_USER;
dsos = &machine->user_dsos;
break; break;
default: default:
goto out; goto out;
} }
dso = __dsos__findnew(dsos, filename); dso = __dsos__findnew(&machine->dsos, filename);
if (dso != NULL) { if (dso != NULL) {
char sbuild_id[BUILD_ID_SIZE * 2 + 1]; char sbuild_id[BUILD_ID_SIZE * 2 + 1];
......
...@@ -26,8 +26,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) ...@@ -26,8 +26,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
{ {
map_groups__init(&machine->kmaps, machine); map_groups__init(&machine->kmaps, machine);
RB_CLEAR_NODE(&machine->rb_node); RB_CLEAR_NODE(&machine->rb_node);
dsos__init(&machine->user_dsos); dsos__init(&machine->dsos);
dsos__init(&machine->kernel_dsos);
machine->threads = RB_ROOT; machine->threads = RB_ROOT;
pthread_rwlock_init(&machine->threads_lock, NULL); pthread_rwlock_init(&machine->threads_lock, NULL);
...@@ -111,8 +110,7 @@ void machine__delete_threads(struct machine *machine) ...@@ -111,8 +110,7 @@ void machine__delete_threads(struct machine *machine)
void machine__exit(struct machine *machine) void machine__exit(struct machine *machine)
{ {
map_groups__exit(&machine->kmaps); map_groups__exit(&machine->kmaps);
dsos__delete(&machine->user_dsos); dsos__delete(&machine->dsos);
dsos__delete(&machine->kernel_dsos);
vdso__exit(machine); vdso__exit(machine);
zfree(&machine->root_dir); zfree(&machine->root_dir);
zfree(&machine->current_tid); zfree(&machine->current_tid);
...@@ -490,9 +488,9 @@ machine__module_dso(struct machine *machine, struct kmod_path *m, ...@@ -490,9 +488,9 @@ machine__module_dso(struct machine *machine, struct kmod_path *m,
{ {
struct dso *dso; struct dso *dso;
dso = dsos__find(&machine->kernel_dsos, m->name, true); dso = dsos__find(&machine->dsos, m->name, true);
if (!dso) { if (!dso) {
dso = dsos__addnew(&machine->kernel_dsos, m->name); dso = dsos__addnew(&machine->dsos, m->name);
if (dso == NULL) if (dso == NULL)
return NULL; return NULL;
...@@ -561,13 +559,11 @@ struct map *machine__new_module(struct machine *machine, u64 start, ...@@ -561,13 +559,11 @@ struct map *machine__new_module(struct machine *machine, u64 start,
size_t machines__fprintf_dsos(struct machines *machines, FILE *fp) size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
{ {
struct rb_node *nd; struct rb_node *nd;
size_t ret = __dsos__fprintf(&machines->host.kernel_dsos.head, fp) + size_t ret = __dsos__fprintf(&machines->host.dsos.head, fp);
__dsos__fprintf(&machines->host.user_dsos.head, fp);
for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) { for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
struct machine *pos = rb_entry(nd, struct machine, rb_node); struct machine *pos = rb_entry(nd, struct machine, rb_node);
ret += __dsos__fprintf(&pos->kernel_dsos.head, fp); ret += __dsos__fprintf(&pos->dsos.head, fp);
ret += __dsos__fprintf(&pos->user_dsos.head, fp);
} }
return ret; return ret;
...@@ -576,8 +572,7 @@ size_t machines__fprintf_dsos(struct machines *machines, FILE *fp) ...@@ -576,8 +572,7 @@ size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp, size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp,
bool (skip)(struct dso *dso, int parm), int parm) bool (skip)(struct dso *dso, int parm), int parm)
{ {
return __dsos__fprintf_buildid(&m->kernel_dsos.head, fp, skip, parm) + return __dsos__fprintf_buildid(&m->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, size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
...@@ -1106,7 +1101,7 @@ static bool machine__uses_kcore(struct machine *machine) ...@@ -1106,7 +1101,7 @@ static bool machine__uses_kcore(struct machine *machine)
{ {
struct dso *dso; struct dso *dso;
list_for_each_entry(dso, &machine->kernel_dsos.head, node) { list_for_each_entry(dso, &machine->dsos.head, node) {
if (dso__is_kcore(dso)) if (dso__is_kcore(dso))
return true; return true;
} }
...@@ -1153,8 +1148,8 @@ static int machine__process_kernel_mmap_event(struct machine *machine, ...@@ -1153,8 +1148,8 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
struct dso *kernel = NULL; struct dso *kernel = NULL;
struct dso *dso; struct dso *dso;
list_for_each_entry(dso, &machine->kernel_dsos.head, node) { list_for_each_entry(dso, &machine->dsos.head, node) {
if (is_kernel_module(dso->long_name)) if (dso->kernel && is_kernel_module(dso->long_name))
continue; continue;
kernel = dso; kernel = dso;
...@@ -1162,8 +1157,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine, ...@@ -1162,8 +1157,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
} }
if (kernel == NULL) if (kernel == NULL)
kernel = __dsos__findnew(&machine->kernel_dsos, kernel = __dsos__findnew(&machine->dsos, kmmap_prefix);
kmmap_prefix);
if (kernel == NULL) if (kernel == NULL)
goto out_problem; goto out_problem;
......
...@@ -34,8 +34,7 @@ struct machine { ...@@ -34,8 +34,7 @@ struct machine {
struct list_head dead_threads; struct list_head dead_threads;
struct thread *last_match; struct thread *last_match;
struct vdso_info *vdso_info; struct vdso_info *vdso_info;
struct dsos user_dsos; struct dsos dsos;
struct dsos kernel_dsos;
struct map_groups kmaps; struct map_groups kmaps;
struct map *vmlinux_maps[MAP__NR_TYPES]; struct map *vmlinux_maps[MAP__NR_TYPES];
u64 kernel_start; u64 kernel_start;
......
...@@ -180,7 +180,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, ...@@ -180,7 +180,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
pgoff = 0; pgoff = 0;
dso = vdso__dso_findnew(machine, thread); dso = vdso__dso_findnew(machine, thread);
} else } else
dso = __dsos__findnew(&machine->user_dsos, filename); dso = __dsos__findnew(&machine->dsos, filename);
if (dso == NULL) if (dso == NULL)
goto out_delete; goto out_delete;
......
...@@ -256,8 +256,9 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso) ...@@ -256,8 +256,9 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
int ret = 0; int ret = 0;
if (module) { if (module) {
list_for_each_entry(dso, &host_machine->kernel_dsos.head, list_for_each_entry(dso, &host_machine->dsos.head, node) {
node) { if (!dso->kernel)
continue;
if (strncmp(dso->short_name + 1, module, if (strncmp(dso->short_name + 1, module,
dso->short_name_len - 2) == 0) dso->short_name_len - 2) == 0)
goto found; goto found;
......
...@@ -1031,11 +1031,7 @@ int dso__load_sym(struct dso *dso, struct map *map, ...@@ -1031,11 +1031,7 @@ int dso__load_sym(struct dso *dso, struct map *map,
} }
curr_dso->symtab_type = dso->symtab_type; curr_dso->symtab_type = dso->symtab_type;
map_groups__insert(kmaps, curr_map); map_groups__insert(kmaps, curr_map);
/* dsos__add(&map->groups->machine->dsos, 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); dso__set_loaded(curr_dso, map->type);
} else } else
curr_dso = curr_map->dso; curr_dso = curr_map->dso;
......
...@@ -127,7 +127,7 @@ static struct dso *vdso__new(struct machine *machine, const char *short_name, ...@@ -127,7 +127,7 @@ static struct dso *vdso__new(struct machine *machine, const char *short_name,
dso = dso__new(short_name); dso = dso__new(short_name);
if (dso != NULL) { if (dso != NULL) {
dsos__add(&machine->user_dsos, dso); dsos__add(&machine->dsos, dso);
dso__set_long_name(dso, long_name, false); dso__set_long_name(dso, long_name, false);
} }
...@@ -236,7 +236,7 @@ static struct dso *vdso__findnew_compat(struct machine *machine, ...@@ -236,7 +236,7 @@ static struct dso *vdso__findnew_compat(struct machine *machine,
const char *file_name; const char *file_name;
struct dso *dso; struct dso *dso;
dso = dsos__find(&machine->user_dsos, vdso_file->dso_name, true); dso = dsos__find(&machine->dsos, vdso_file->dso_name, true);
if (dso) if (dso)
return dso; return dso;
...@@ -299,7 +299,7 @@ struct dso *vdso__dso_findnew(struct machine *machine, ...@@ -299,7 +299,7 @@ struct dso *vdso__dso_findnew(struct machine *machine,
return dso; return dso;
#endif #endif
dso = dsos__find(&machine->user_dsos, DSO__NAME_VDSO, true); dso = dsos__find(&machine->dsos, DSO__NAME_VDSO, true);
if (!dso) { if (!dso) {
char *file; char *file;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment