Commit d46a4cdf authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

pref tools: Make 'struct addr_map_symbol' contain 'struct map_symbol'

So that we pass that substructure around and with it consolidate lots of
functions that receive a (map, symbol) pair and now can receive just a
'struct map_symbol' pointer.

This further paves the way to add 'struct map_groups' to 'struct
map_symbol' so that we can have all we need for annotation so that we
can ditch 'struct map'->groups, i.e. have the map_groups pointer in a
more central place, avoiding the pointer in the 'struct map' that have
tons of instances.

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-fs90ttd9q12l7989fo7pw81q@git.kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 5f0fef8a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
	char *endptr, *tok, *name;
	struct map *map = ms->map;
	struct addr_map_symbol target = {
		.map = map,
		.ms = { .map = map, },
	};

	tok = strchr(ops->raw, ',');
@@ -39,8 +39,8 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
	target.addr = map__objdump_2mem(map, ops->target.addr);

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

	return 0;
}
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ static void process_basic_block(struct addr_map_symbol *start,
				struct addr_map_symbol *end,
				struct branch_flags *flags)
{
	struct symbol *sym = start->sym;
	struct symbol *sym = start->ms.sym;
	struct annotation *notes = sym ? symbol__annotation(sym) : NULL;
	struct block_range_iter iter;
	struct block_range *entry;
+8 −12
Original line number Diff line number Diff line
@@ -2405,16 +2405,15 @@ do_annotate(struct hist_browser *browser, struct popup_action *act)
static int
add_annotate_opt(struct hist_browser *browser __maybe_unused,
		 struct popup_action *act, char **optstr,
		 struct map *map, struct symbol *sym)
		 struct map_symbol *ms)
{
	if (sym == NULL || map->dso->annotate_warned)
	if (ms->sym == NULL || ms->map->dso->annotate_warned)
		return 0;

	if (asprintf(optstr, "Annotate %s", sym->name) < 0)
	if (asprintf(optstr, "Annotate %s", ms->sym->name) < 0)
		return 0;

	act->ms.map = map;
	act->ms.sym = sym;
	act->ms = *ms;
	act->fn = do_annotate;
	return 1;
}
@@ -3115,20 +3114,17 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events,
			nr_options += add_annotate_opt(browser,
						       &actions[nr_options],
						       &options[nr_options],
						       bi->from.map,
						       bi->from.sym);
			if (bi->to.sym != bi->from.sym)
						       &bi->from.ms);
			if (bi->to.ms.sym != bi->from.ms.sym)
				nr_options += add_annotate_opt(browser,
							&actions[nr_options],
							&options[nr_options],
							bi->to.map,
							bi->to.sym);
							&bi->to.ms);
		} else {
			nr_options += add_annotate_opt(browser,
						       &actions[nr_options],
						       &options[nr_options],
						       browser->selection->map,
						       browser->selection->sym);
						       browser->selection);
		}
skip_annotation:
		nr_options += add_thread_opt(browser, &actions[nr_options],
+22 −21
Original line number Diff line number Diff line
@@ -243,7 +243,7 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s
	char *endptr, *tok, *name;
	struct map *map = ms->map;
	struct addr_map_symbol target = {
		.map = map,
		.ms = { .map = map, },
	};

	ops->target.addr = strtoull(ops->raw, &endptr, 16);
@@ -272,8 +272,8 @@ find_target:
	target.addr = map__objdump_2mem(map, ops->target.addr);

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

	return 0;

@@ -332,7 +332,7 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
	struct map *map = ms->map;
	struct symbol *sym = ms->sym;
	struct addr_map_symbol target = {
		.map = map,
		.ms = { .map = map, },
	};
	const char *c = strchr(ops->raw, ',');
	u64 start, end;
@@ -392,8 +392,8 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
	 * the symbol searching and disassembly should be done.
	 */
	if (map_groups__find_ams(map->groups, &target) == 0 &&
	    map__rip_2objdump(target.map, map->map_ip(target.map, target.addr)) == ops->target.addr)
		ops->target.sym = target.sym;
	    map__rip_2objdump(target.ms.map, map->map_ip(target.ms.map, target.addr)) == ops->target.addr)
		ops->target.sym = target.ms.sym;

	if (!ops->target.outside) {
		ops->target.offset = target.addr - start;
@@ -865,14 +865,15 @@ static int __symbol__account_cycles(struct cyc_hist *ch,
	return 0;
}

static int __symbol__inc_addr_samples(struct symbol *sym, struct map *map,
static int __symbol__inc_addr_samples(struct map_symbol *ms,
				      struct annotated_source *src, int evidx, u64 addr,
				      struct perf_sample *sample)
{
	struct symbol *sym = ms->sym;
	unsigned offset;
	struct sym_hist *h;

	pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));
	pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, ms->map->unmap_ip(ms->map, addr));

	if ((addr < sym->start || addr >= sym->end) &&
	    (addr != sym->end || sym->start != sym->end)) {
@@ -939,17 +940,17 @@ alloc_histograms:
	return notes->src;
}

static int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
static int symbol__inc_addr_samples(struct map_symbol *ms,
				    struct evsel *evsel, u64 addr,
				    struct perf_sample *sample)
{
	struct symbol *sym = ms->sym;
	struct annotated_source *src;

	if (sym == NULL)
		return 0;
	src = symbol__hists(sym, evsel->evlist->core.nr_entries);
	return (src) ?  __symbol__inc_addr_samples(sym, map, src, evsel->idx,
						   addr, sample) : 0;
	return src ? __symbol__inc_addr_samples(ms, src, evsel->idx, addr, sample) : 0;
}

static int symbol__account_cycles(u64 addr, u64 start,
@@ -997,17 +998,17 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
	 * it starts on the function start.
	 */
	if (start &&
		(start->sym == ams->sym ||
		 (ams->sym &&
		   start->addr == ams->sym->start + ams->map->start)))
		(start->ms.sym == ams->ms.sym ||
		 (ams->ms.sym &&
		   start->addr == ams->ms.sym->start + ams->ms.map->start)))
		saddr = start->al_addr;
	if (saddr == 0)
		pr_debug2("BB with bad start: addr %"PRIx64" start %"PRIx64" sym %"PRIx64" saddr %"PRIx64"\n",
			ams->addr,
			start ? start->addr : 0,
			ams->sym ? ams->sym->start + ams->map->start : 0,
			ams->ms.sym ? ams->ms.sym->start + ams->ms.map->start : 0,
			saddr);
	err = symbol__account_cycles(ams->al_addr, saddr, ams->sym, cycles);
	err = symbol__account_cycles(ams->al_addr, saddr, ams->ms.sym, cycles);
	if (err)
		pr_debug2("account_cycles failed %d\n", err);
	return err;
@@ -1093,13 +1094,13 @@ void annotation__compute_ipc(struct annotation *notes, size_t size)
int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample,
				 struct evsel *evsel)
{
	return symbol__inc_addr_samples(ams->sym, ams->map, evsel, ams->al_addr, sample);
	return symbol__inc_addr_samples(&ams->ms, evsel, ams->al_addr, sample);
}

int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample,
				 struct evsel *evsel, u64 ip)
{
	return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evsel, ip, sample);
	return symbol__inc_addr_samples(&he->ms, evsel, ip, sample);
}

static void disasm_line__init_ins(struct disasm_line *dl, struct arch *arch, struct map_symbol *ms)
@@ -1540,13 +1541,13 @@ static int symbol__parse_objdump_line(struct symbol *sym,
	/* kcore has no symbols, so add the call target symbol */
	if (dl->ins.ops && ins__is_call(&dl->ins) && !dl->ops.target.sym) {
		struct addr_map_symbol target = {
			.map = map,
			.addr = dl->ops.target.addr,
			.ms = { .map = map, },
		};

		if (!map_groups__find_ams(map->groups, &target) &&
		    target.sym->start == target.al_addr)
			dl->ops.target.sym = target.sym;
		    target.ms.sym->start == target.al_addr)
			dl->ops.target.sym = target.ms.sym;
	}

	annotation_line__add(&dl->al, &notes->src->source);
+27 −27
Original line number Diff line number Diff line
@@ -112,13 +112,13 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
		hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen);

	if (h->branch_info) {
		if (h->branch_info->from.sym) {
			symlen = (int)h->branch_info->from.sym->namelen + 4;
		if (h->branch_info->from.ms.sym) {
			symlen = (int)h->branch_info->from.ms.sym->namelen + 4;
			if (verbose > 0)
				symlen += BITS_PER_LONG / 4 + 2 + 3;
			hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);

			symlen = dso__name_len(h->branch_info->from.map->dso);
			symlen = dso__name_len(h->branch_info->from.ms.map->dso);
			hists__new_col_len(hists, HISTC_DSO_FROM, symlen);
		} else {
			symlen = unresolved_col_width + 4 + 2;
@@ -126,13 +126,13 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
			hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM);
		}

		if (h->branch_info->to.sym) {
			symlen = (int)h->branch_info->to.sym->namelen + 4;
		if (h->branch_info->to.ms.sym) {
			symlen = (int)h->branch_info->to.ms.sym->namelen + 4;
			if (verbose > 0)
				symlen += BITS_PER_LONG / 4 + 2 + 3;
			hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);

			symlen = dso__name_len(h->branch_info->to.map->dso);
			symlen = dso__name_len(h->branch_info->to.ms.map->dso);
			hists__new_col_len(hists, HISTC_DSO_TO, symlen);
		} else {
			symlen = unresolved_col_width + 4 + 2;
@@ -149,8 +149,8 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
	}

	if (h->mem_info) {
		if (h->mem_info->daddr.sym) {
			symlen = (int)h->mem_info->daddr.sym->namelen + 4
		if (h->mem_info->daddr.ms.sym) {
			symlen = (int)h->mem_info->daddr.ms.sym->namelen + 4
			       + unresolved_col_width + 2;
			hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL,
					   symlen);
@@ -164,8 +164,8 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
					   symlen);
		}

		if (h->mem_info->iaddr.sym) {
			symlen = (int)h->mem_info->iaddr.sym->namelen + 4
		if (h->mem_info->iaddr.ms.sym) {
			symlen = (int)h->mem_info->iaddr.ms.sym->namelen + 4
			       + unresolved_col_width + 2;
			hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL,
					   symlen);
@@ -175,8 +175,8 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
					   symlen);
		}

		if (h->mem_info->daddr.map) {
			symlen = dso__name_len(h->mem_info->daddr.map->dso);
		if (h->mem_info->daddr.ms.map) {
			symlen = dso__name_len(h->mem_info->daddr.ms.map->dso);
			hists__new_col_len(hists, HISTC_MEM_DADDR_DSO,
					   symlen);
		} else {
@@ -443,13 +443,13 @@ static int hist_entry__init(struct hist_entry *he,
		memcpy(he->branch_info, template->branch_info,
		       sizeof(*he->branch_info));

		map__get(he->branch_info->from.map);
		map__get(he->branch_info->to.map);
		map__get(he->branch_info->from.ms.map);
		map__get(he->branch_info->to.ms.map);
	}

	if (he->mem_info) {
		map__get(he->mem_info->iaddr.map);
		map__get(he->mem_info->daddr.map);
		map__get(he->mem_info->iaddr.ms.map);
		map__get(he->mem_info->daddr.ms.map);
	}

	if (hist_entry__has_callchains(he) && symbol_conf.use_callchain)
@@ -492,13 +492,13 @@ err_rawdata:

err_infos:
	if (he->branch_info) {
		map__put(he->branch_info->from.map);
		map__put(he->branch_info->to.map);
		map__put(he->branch_info->from.ms.map);
		map__put(he->branch_info->to.ms.map);
		zfree(&he->branch_info);
	}
	if (he->mem_info) {
		map__put(he->mem_info->iaddr.map);
		map__put(he->mem_info->daddr.map);
		map__put(he->mem_info->iaddr.ms.map);
		map__put(he->mem_info->daddr.ms.map);
	}
err:
	map__zput(he->ms.map);
@@ -893,8 +893,8 @@ iter_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al)
	if (iter->curr >= iter->total)
		return 0;

	al->map = bi[i].to.map;
	al->sym = bi[i].to.sym;
	al->map = bi[i].to.ms.map;
	al->sym = bi[i].to.ms.sym;
	al->addr = bi[i].to.addr;
	return 1;
}
@@ -912,7 +912,7 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a

	bi = iter->priv;

	if (iter->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym))
	if (iter->hide_unresolved && !(bi[i].from.ms.sym && bi[i].to.ms.sym))
		goto out;

	/*
@@ -1251,16 +1251,16 @@ void hist_entry__delete(struct hist_entry *he)
	map__zput(he->ms.map);

	if (he->branch_info) {
		map__zput(he->branch_info->from.map);
		map__zput(he->branch_info->to.map);
		map__zput(he->branch_info->from.ms.map);
		map__zput(he->branch_info->to.ms.map);
		free_srcline(he->branch_info->srcline_from);
		free_srcline(he->branch_info->srcline_to);
		zfree(&he->branch_info);
	}

	if (he->mem_info) {
		map__zput(he->mem_info->iaddr.map);
		map__zput(he->mem_info->daddr.map);
		map__zput(he->mem_info->iaddr.ms.map);
		map__zput(he->mem_info->daddr.ms.map);
		mem_info__zput(he->mem_info);
	}

Loading