Skip to content

Commit

Permalink
perf maps: Merge 'struct maps' with 'struct map_groups'
Browse files Browse the repository at this point in the history
And pick the shortest name: 'struct maps'.

The split existed because we used to have two groups of maps, one for
functions and one for variables, but that only complicated things,
sometimes we needed to figure out what was at some address and then had
to first try it on the functions group and if that failed, fall back to
the variables one.

That split is long gone, so for quite a while we had only one struct
maps per struct map_groups, simplify things by combining those structs.

First patch is the minimum needed to merge both, follow up patches will
rename 'thread->mg' to 'thread->maps', etc.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-hom6639ro7020o708trhxh59@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Nov 26, 2019
1 parent 9adab03 commit 79b6bb7
Show file tree
Hide file tree
Showing 33 changed files with 209 additions and 275 deletions.
2 changes: 1 addition & 1 deletion tools/perf/arch/arm/tests/dwarf-unwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static int sample_ustack(struct perf_sample *sample,

sp = (unsigned long) regs[PERF_REG_ARM_SP];

map = map_groups__find(thread->mg, (u64)sp);
map = maps__find(thread->mg, (u64)sp);
if (!map) {
pr_debug("failed to get stack map\n");
free(buf);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/arch/arm64/tests/dwarf-unwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static int sample_ustack(struct perf_sample *sample,

sp = (unsigned long) regs[PERF_REG_ARM64_SP];

map = map_groups__find(thread->mg, (u64)sp);
map = maps__find(thread->mg, (u64)sp);
if (!map) {
pr_debug("failed to get stack map\n");
free(buf);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/arch/powerpc/tests/dwarf-unwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static int sample_ustack(struct perf_sample *sample,

sp = (unsigned long) regs[PERF_REG_POWERPC_R1];

map = map_groups__find(thread->mg, (u64)sp);
map = maps__find(thread->mg, (u64)sp);
if (!map) {
pr_debug("failed to get stack map\n");
free(buf);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/arch/s390/annotate/instructions.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
return -1;
target.addr = map__objdump_2mem(map, ops->target.addr);

if (map_groups__find_ams(ms->mg, &target) == 0 &&
if (maps__find_ams(ms->mg, &target) == 0 &&
map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
ops->target.sym = target.ms.sym;

Expand Down
2 changes: 1 addition & 1 deletion tools/perf/arch/x86/tests/dwarf-unwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static int sample_ustack(struct perf_sample *sample,

sp = (unsigned long) regs[PERF_REG_X86_SP];

map = map_groups__find(thread->mg, (u64)sp);
map = maps__find(thread->mg, (u64)sp);
if (!map) {
pr_debug("failed to get stack map\n");
free(buf);
Expand Down
5 changes: 2 additions & 3 deletions tools/perf/arch/x86/util/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
{
int rc = 0;
struct map *pos;
struct map_groups *kmaps = &machine->kmaps;
struct maps *maps = &kmaps->maps;
struct maps *kmaps = &machine->kmaps;
union perf_event *event = zalloc(sizeof(event->mmap) +
machine->id_hdr_size);

Expand All @@ -29,7 +28,7 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
return -1;
}

maps__for_each_entry(maps, pos) {
maps__for_each_entry(kmaps, pos) {
struct kmap *kmap;
size_t size;

Expand Down
7 changes: 1 addition & 6 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,6 @@ static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
return printed;
}

static int map_groups__fprintf_task(struct map_groups *mg, int indent, FILE *fp)
{
return maps__fprintf_task(&mg->maps, indent, fp);
}

static void task__print_level(struct task *task, FILE *fp, int level)
{
struct thread *thread = task->thread;
Expand All @@ -795,7 +790,7 @@ static void task__print_level(struct task *task, FILE *fp, int level)

fprintf(fp, "%s\n", thread__comm_str(thread));

map_groups__fprintf_task(thread->mg, comm_indent, fp);
maps__fprintf_task(thread->mg, comm_indent, fp);

if (!list_empty(&task->children)) {
list_for_each_entry(child, &task->children, list)
Expand Down
16 changes: 8 additions & 8 deletions tools/perf/tests/map_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ struct map_def {
u64 end;
};

static int check_maps(struct map_def *merged, unsigned int size, struct map_groups *mg)
static int check_maps(struct map_def *merged, unsigned int size, struct maps *maps)
{
struct map *map;
unsigned int i = 0;

map_groups__for_each_entry(mg, map) {
maps__for_each_entry(maps, map) {
if (i > 0)
TEST_ASSERT_VAL("less maps expected", (map && i < size) || (!map && i == size));

Expand All @@ -35,7 +35,7 @@ static int check_maps(struct map_def *merged, unsigned int size, struct map_grou

int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __maybe_unused)
{
struct map_groups mg;
struct maps mg;
unsigned int i;
struct map_def bpf_progs[] = {
{ "bpf_prog_1", 200, 300 },
Expand Down Expand Up @@ -64,7 +64,7 @@ int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __mayb
struct map *map_kcore1, *map_kcore2, *map_kcore3;
int ret;

map_groups__init(&mg, NULL);
maps__init(&mg, NULL);

for (i = 0; i < ARRAY_SIZE(bpf_progs); i++) {
struct map *map;
Expand All @@ -74,7 +74,7 @@ int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __mayb

map->start = bpf_progs[i].start;
map->end = bpf_progs[i].end;
map_groups__insert(&mg, map);
maps__insert(&mg, map);
map__put(map);
}

Expand All @@ -99,19 +99,19 @@ int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __mayb
map_kcore3->start = 880;
map_kcore3->end = 1100;

ret = map_groups__merge_in(&mg, map_kcore1);
ret = maps__merge_in(&mg, map_kcore1);
TEST_ASSERT_VAL("failed to merge map", !ret);

ret = check_maps(merged12, ARRAY_SIZE(merged12), &mg);
TEST_ASSERT_VAL("merge check failed", !ret);

ret = map_groups__merge_in(&mg, map_kcore2);
ret = maps__merge_in(&mg, map_kcore2);
TEST_ASSERT_VAL("failed to merge map", !ret);

ret = check_maps(merged12, ARRAY_SIZE(merged12), &mg);
TEST_ASSERT_VAL("merge check failed", !ret);

ret = map_groups__merge_in(&mg, map_kcore3);
ret = maps__merge_in(&mg, map_kcore3);
TEST_ASSERT_VAL("failed to merge map", !ret);

ret = check_maps(merged3, ARRAY_SIZE(merged3), &mg);
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/tests/thread-mg-share.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ int test__thread_mg_share(struct test *test __maybe_unused, int subtest __maybe_
/* thread group */
struct thread *leader;
struct thread *t1, *t2, *t3;
struct map_groups *mg;
struct maps *mg;

/* other process */
struct thread *other, *other_leader;
struct map_groups *other_mg;
struct maps *other_mg;

/*
* This test create 2 processes abstractions (struct thread)
* with several threads and checks they properly share and
* maintain map groups info (struct map_groups).
* maintain maps info (struct maps).
*
* thread group (pid: 0, tids: 0, 1, 2, 3)
* other group (pid: 4, tids: 4, 5)
Expand Down
9 changes: 4 additions & 5 deletions tools/perf/tests/vmlinux-kallsyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,9 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
* so use the short name, less descriptive but the same ("[kernel]" in
* both cases.
*/
pair = map_groups__find_by_name(&kallsyms.kmaps,
(map->dso->kernel ?
map->dso->short_name :
map->dso->name));
pair = maps__find_by_name(&kallsyms.kmaps, (map->dso->kernel ?
map->dso->short_name :
map->dso->name));
if (pair) {
pair->priv = 1;
} else {
Expand All @@ -213,7 +212,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
mem_end = vmlinux_map->unmap_ip(vmlinux_map, map->end);

pair = map_groups__find(&kallsyms.kmaps, mem_start);
pair = maps__find(&kallsyms.kmaps, mem_start);
if (pair == NULL || pair->priv)
continue;

Expand Down
2 changes: 1 addition & 1 deletion tools/perf/ui/stdio/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
}

if (h->ms.map == NULL && verbose > 1) {
map_groups__fprintf(h->thread->mg, fp);
maps__fprintf(h->thread->mg, fp);
fprintf(fp, "%.10s end\n", graph_dotted_line);
}
}
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/util/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s
find_target:
target.addr = map__objdump_2mem(map, ops->target.addr);

if (map_groups__find_ams(ms->mg, &target) == 0 &&
if (maps__find_ams(ms->mg, &target) == 0 &&
map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
ops->target.sym = target.ms.sym;

Expand Down Expand Up @@ -391,7 +391,7 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
* Actual navigation will come next, with further understanding of how
* the symbol searching and disassembly should be done.
*/
if (map_groups__find_ams(ms->mg, &target) == 0 &&
if (maps__find_ams(ms->mg, &target) == 0 &&
map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
ops->target.sym = target.ms.sym;

Expand Down Expand Up @@ -1545,7 +1545,7 @@ static int symbol__parse_objdump_line(struct symbol *sym,
.ms = { .map = map, },
};

if (!map_groups__find_ams(args->ms.mg, &target) &&
if (!maps__find_ams(args->ms.mg, &target) &&
target.ms.sym->start == target.al_addr)
dl->ops.target.sym = target.ms.sym;
}
Expand Down
4 changes: 1 addition & 3 deletions tools/perf/util/bpf-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ static int machine__process_bpf_event_load(struct machine *machine,
for (i = 0; i < info_linear->info.nr_jited_ksyms; i++) {
u64 *addrs = (u64 *)(uintptr_t)(info_linear->info.jited_ksyms);
u64 addr = addrs[i];
struct map *map;

map = map_groups__find(&machine->kmaps, addr);
struct map *map = maps__find(&machine->kmaps, addr);

if (map) {
map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/cs-etm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2569,7 +2569,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
if (err)
goto err_delete_thread;

if (thread__init_map_groups(etm->unknown_thread, etm->machine)) {
if (thread__init_maps(etm->unknown_thread, etm->machine)) {
err = -ENOMEM;
goto err_delete_thread;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/util/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
struct addr_location *al)
{
struct map_groups *mg = thread->mg;
struct maps *mg = thread->mg;
struct machine *machine = mg->machine;
bool load_map = false;

Expand Down Expand Up @@ -500,7 +500,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
return NULL;
}

al->map = map_groups__find(mg, al->addr);
al->map = maps__find(mg, al->addr);
if (al->map != NULL) {
/*
* Kernel maps might be changed when loading symbols so loading
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/intel-pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3296,7 +3296,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
err = thread__set_comm(pt->unknown_thread, "unknown", 0);
if (err)
goto err_delete_thread;
if (thread__init_map_groups(pt->unknown_thread, pt->machine)) {
if (thread__init_maps(pt->unknown_thread, pt->machine)) {
err = -ENOMEM;
goto err_delete_thread;
}
Expand Down
Loading

0 comments on commit 79b6bb7

Please sign in to comment.