Skip to content

Commit 3d39ac5

Browse files
committed
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 <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: David Ahern <[email protected]> Cc: Don Zickus <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 459ce51 commit 3d39ac5

File tree

10 files changed

+39
-80
lines changed

10 files changed

+39
-80
lines changed

tools/perf/tests/hists_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct machine *setup_fake_machine(struct machines *machines)
121121
size_t k;
122122
struct dso *dso;
123123

124-
dso = __dsos__findnew(&machine->user_dsos,
124+
dso = __dsos__findnew(&machine->dsos,
125125
fake_symbols[i].dso_name);
126126
if (dso == NULL)
127127
goto out;

tools/perf/util/build-id.c

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,20 @@ static int write_buildid(const char *name, size_t name_len, u8 *build_id,
162162
return write_padded(fd, name, name_len + 1, len);
163163
}
164164

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)
168166
{
167+
int err = 0;
169168
char nm[PATH_MAX];
170169
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+
}
171177

172-
dsos__for_each_with_build_id(pos, head) {
173-
int err;
178+
dsos__for_each_with_build_id(pos, &machine->dsos.head) {
174179
const char *name;
175180
size_t name_len;
176181

@@ -189,32 +194,12 @@ static int __dsos__write_buildid_table(struct list_head *head,
189194
name_len = pos->long_name_len + 1;
190195
}
191196

192-
err = write_buildid(name, name_len, pos->build_id,
193-
pid, misc, fd);
197+
err = write_buildid(name, name_len, pos->build_id, machine->pid,
198+
pos->kernel ? kmisc : umisc, fd);
194199
if (err)
195-
return err;
196-
}
197-
198-
return 0;
199-
}
200-
201-
static 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;
200+
break;
210201
}
211202

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);
218203
return err;
219204
}
220205

@@ -247,13 +232,7 @@ static int __dsos__hit_all(struct list_head *head)
247232

248233
static int machine__hit_all_dsos(struct machine *machine)
249234
{
250-
int err;
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);
235+
return __dsos__hit_all(&machine->dsos.head);
257236
}
258237

259238
int dsos__hit_all(struct perf_session *session)
@@ -493,9 +472,7 @@ static int __dsos__cache_build_ids(struct list_head *head,
493472

494473
static int machine__cache_build_ids(struct machine *machine)
495474
{
496-
int ret = __dsos__cache_build_ids(&machine->kernel_dsos.head, machine);
497-
ret |= __dsos__cache_build_ids(&machine->user_dsos.head, machine);
498-
return ret;
475+
return __dsos__cache_build_ids(&machine->dsos.head, machine);
499476
}
500477

501478
int perf_session__cache_build_ids(struct perf_session *session)
@@ -520,11 +497,7 @@ int perf_session__cache_build_ids(struct perf_session *session)
520497

521498
static bool machine__read_build_ids(struct machine *machine, bool with_hits)
522499
{
523-
bool ret;
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;
500+
return __dsos__read_build_ids(&machine->dsos.head, with_hits);
528501
}
529502

530503
bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)

tools/perf/util/dso.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
833833
/*
834834
* The kernel dso could be created by build_id processing.
835835
*/
836-
struct dso *dso = __dsos__findnew(&machine->kernel_dsos, name);
836+
struct dso *dso = __dsos__findnew(&machine->dsos, name);
837837

838838
/*
839839
* We need to run this in all cases, since during the build_id

tools/perf/util/header.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,6 @@ static int __event_process_build_id(struct build_id_event *bev,
12381238
struct perf_session *session)
12391239
{
12401240
int err = -1;
1241-
struct dsos *dsos;
12421241
struct machine *machine;
12431242
u16 misc;
12441243
struct dso *dso;
@@ -1253,22 +1252,19 @@ static int __event_process_build_id(struct build_id_event *bev,
12531252
switch (misc) {
12541253
case PERF_RECORD_MISC_KERNEL:
12551254
dso_type = DSO_TYPE_KERNEL;
1256-
dsos = &machine->kernel_dsos;
12571255
break;
12581256
case PERF_RECORD_MISC_GUEST_KERNEL:
12591257
dso_type = DSO_TYPE_GUEST_KERNEL;
1260-
dsos = &machine->kernel_dsos;
12611258
break;
12621259
case PERF_RECORD_MISC_USER:
12631260
case PERF_RECORD_MISC_GUEST_USER:
12641261
dso_type = DSO_TYPE_USER;
1265-
dsos = &machine->user_dsos;
12661262
break;
12671263
default:
12681264
goto out;
12691265
}
12701266

1271-
dso = __dsos__findnew(dsos, filename);
1267+
dso = __dsos__findnew(&machine->dsos, filename);
12721268
if (dso != NULL) {
12731269
char sbuild_id[BUILD_ID_SIZE * 2 + 1];
12741270

tools/perf/util/machine.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
2626
{
2727
map_groups__init(&machine->kmaps, machine);
2828
RB_CLEAR_NODE(&machine->rb_node);
29-
dsos__init(&machine->user_dsos);
30-
dsos__init(&machine->kernel_dsos);
29+
dsos__init(&machine->dsos);
3130

3231
machine->threads = RB_ROOT;
3332
pthread_rwlock_init(&machine->threads_lock, NULL);
@@ -111,8 +110,7 @@ void machine__delete_threads(struct machine *machine)
111110
void machine__exit(struct machine *machine)
112111
{
113112
map_groups__exit(&machine->kmaps);
114-
dsos__delete(&machine->user_dsos);
115-
dsos__delete(&machine->kernel_dsos);
113+
dsos__delete(&machine->dsos);
116114
vdso__exit(machine);
117115
zfree(&machine->root_dir);
118116
zfree(&machine->current_tid);
@@ -490,9 +488,9 @@ machine__module_dso(struct machine *machine, struct kmod_path *m,
490488
{
491489
struct dso *dso;
492490

493-
dso = dsos__find(&machine->kernel_dsos, m->name, true);
491+
dso = dsos__find(&machine->dsos, m->name, true);
494492
if (!dso) {
495-
dso = dsos__addnew(&machine->kernel_dsos, m->name);
493+
dso = dsos__addnew(&machine->dsos, m->name);
496494
if (dso == NULL)
497495
return NULL;
498496

@@ -561,13 +559,11 @@ struct map *machine__new_module(struct machine *machine, u64 start,
561559
size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
562560
{
563561
struct rb_node *nd;
564-
size_t ret = __dsos__fprintf(&machines->host.kernel_dsos.head, fp) +
565-
__dsos__fprintf(&machines->host.user_dsos.head, fp);
562+
size_t ret = __dsos__fprintf(&machines->host.dsos.head, fp);
566563

567564
for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
568565
struct machine *pos = rb_entry(nd, struct machine, rb_node);
569-
ret += __dsos__fprintf(&pos->kernel_dsos.head, fp);
570-
ret += __dsos__fprintf(&pos->user_dsos.head, fp);
566+
ret += __dsos__fprintf(&pos->dsos.head, fp);
571567
}
572568

573569
return ret;
@@ -576,8 +572,7 @@ size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
576572
size_t machine__fprintf_dsos_buildid(struct machine *m, FILE *fp,
577573
bool (skip)(struct dso *dso, int parm), int parm)
578574
{
579-
return __dsos__fprintf_buildid(&m->kernel_dsos.head, fp, skip, parm) +
580-
__dsos__fprintf_buildid(&m->user_dsos.head, fp, skip, parm);
575+
return __dsos__fprintf_buildid(&m->dsos.head, fp, skip, parm);
581576
}
582577

583578
size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
@@ -1106,7 +1101,7 @@ static bool machine__uses_kcore(struct machine *machine)
11061101
{
11071102
struct dso *dso;
11081103

1109-
list_for_each_entry(dso, &machine->kernel_dsos.head, node) {
1104+
list_for_each_entry(dso, &machine->dsos.head, node) {
11101105
if (dso__is_kcore(dso))
11111106
return true;
11121107
}
@@ -1153,17 +1148,16 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
11531148
struct dso *kernel = NULL;
11541149
struct dso *dso;
11551150

1156-
list_for_each_entry(dso, &machine->kernel_dsos.head, node) {
1157-
if (is_kernel_module(dso->long_name))
1151+
list_for_each_entry(dso, &machine->dsos.head, node) {
1152+
if (dso->kernel && is_kernel_module(dso->long_name))
11581153
continue;
11591154

11601155
kernel = dso;
11611156
break;
11621157
}
11631158

11641159
if (kernel == NULL)
1165-
kernel = __dsos__findnew(&machine->kernel_dsos,
1166-
kmmap_prefix);
1160+
kernel = __dsos__findnew(&machine->dsos, kmmap_prefix);
11671161
if (kernel == NULL)
11681162
goto out_problem;
11691163

tools/perf/util/machine.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ struct machine {
3434
struct list_head dead_threads;
3535
struct thread *last_match;
3636
struct vdso_info *vdso_info;
37-
struct dsos user_dsos;
38-
struct dsos kernel_dsos;
37+
struct dsos dsos;
3938
struct map_groups kmaps;
4039
struct map *vmlinux_maps[MAP__NR_TYPES];
4140
u64 kernel_start;

tools/perf/util/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
180180
pgoff = 0;
181181
dso = vdso__dso_findnew(machine, thread);
182182
} else
183-
dso = __dsos__findnew(&machine->user_dsos, filename);
183+
dso = __dsos__findnew(&machine->dsos, filename);
184184

185185
if (dso == NULL)
186186
goto out_delete;

tools/perf/util/probe-event.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
256256
int ret = 0;
257257

258258
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;
261262
if (strncmp(dso->short_name + 1, module,
262263
dso->short_name_len - 2) == 0)
263264
goto found;

tools/perf/util/symbol-elf.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,11 +1031,7 @@ int dso__load_sym(struct dso *dso, struct map *map,
10311031
}
10321032
curr_dso->symtab_type = dso->symtab_type;
10331033
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);
10391035
dso__set_loaded(curr_dso, map->type);
10401036
} else
10411037
curr_dso = curr_map->dso;

tools/perf/util/vdso.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static struct dso *vdso__new(struct machine *machine, const char *short_name,
127127

128128
dso = dso__new(short_name);
129129
if (dso != NULL) {
130-
dsos__add(&machine->user_dsos, dso);
130+
dsos__add(&machine->dsos, dso);
131131
dso__set_long_name(dso, long_name, false);
132132
}
133133

@@ -236,7 +236,7 @@ static struct dso *vdso__findnew_compat(struct machine *machine,
236236
const char *file_name;
237237
struct dso *dso;
238238

239-
dso = dsos__find(&machine->user_dsos, vdso_file->dso_name, true);
239+
dso = dsos__find(&machine->dsos, vdso_file->dso_name, true);
240240
if (dso)
241241
return dso;
242242

@@ -299,7 +299,7 @@ struct dso *vdso__dso_findnew(struct machine *machine,
299299
return dso;
300300
#endif
301301

302-
dso = dsos__find(&machine->user_dsos, DSO__NAME_VDSO, true);
302+
dso = dsos__find(&machine->dsos, DSO__NAME_VDSO, true);
303303
if (!dso) {
304304
char *file;
305305

0 commit comments

Comments
 (0)