Commit 0dd5041c authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf addr_location: Add init/exit/copy functions



struct addr_location holds references to multiple reference counted
objects. Add init/exit functions to make maintenance of those more
consistent with the rest of the code and to try to avoid
leaks. Modification of thread reference counts isn't included in this
change.

Committer notes:

I needed to initialize result to sample->ip to make sure is set to
something, fixing a compile time error, mostly keeping the previous
logic as build_alloc_func_list() already does debugging/error prints
about what went wrong if it takes the 'goto out'.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ali Saidi <alisaidi@amazon.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Brian Robbins <brianrob@linux.microsoft.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
Cc: Fangrui Song <maskray@google.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ivan Babrou <ivan@cloudflare.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Wenyu Liu <liuwenyu7@huawei.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
Cc: Yuan Can <yuancan@huawei.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230608232823.4027869-7-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 620be847
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,

static int process_branch_callback(struct evsel *evsel,
				   struct perf_sample *sample,
				   struct addr_location *al __maybe_unused,
				   struct addr_location *al,
				   struct perf_annotate *ann,
				   struct machine *machine)
{
@@ -195,21 +195,29 @@ static int process_branch_callback(struct evsel *evsel,
		.hide_unresolved	= symbol_conf.hide_unresolved,
		.ops		= &hist_iter_branch,
	};

	struct addr_location a;
	int ret;

	if (machine__resolve(machine, &a, sample) < 0)
		return -1;
	addr_location__init(&a);
	if (machine__resolve(machine, &a, sample) < 0) {
		ret = -1;
		goto out;
	}

	if (a.sym == NULL)
		return 0;
	if (a.sym == NULL) {
		ret = 0;
		goto out;
	}

	if (a.map != NULL)
		map__dso(a.map)->hit = 1;

	hist__account_cycles(sample->branch_stack, al, sample, false, NULL);

	return hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
	ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
out:
	addr_location__exit(&a);
	return ret;
}

static bool has_annotation(struct perf_annotate *ann)
@@ -272,10 +280,12 @@ static int process_sample_event(struct perf_tool *tool,
	struct addr_location al;
	int ret = 0;

	addr_location__init(&al);
	if (machine__resolve(machine, &al, sample) < 0) {
		pr_warning("problem processing %d event, skipping it.\n",
			   event->header.type);
		return -1;
		ret = -1;
		goto out_put;
	}

	if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap))
@@ -288,7 +298,7 @@ static int process_sample_event(struct perf_tool *tool,
		ret = -1;
	}
out_put:
	addr_location__put(&al);
	addr_location__exit(&al);
	return ret;
}

+8 −4
Original line number Diff line number Diff line
@@ -286,10 +286,12 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
	struct mem_info *mi, *mi_dup;
	int ret;

	addr_location__init(&al);
	if (machine__resolve(machine, &al, sample) < 0) {
		pr_debug("problem processing %d event, skipping it.\n",
			 event->header.type);
		return -1;
		ret = -1;
		goto out;
	}

	if (c2c.stitch_lbr)
@@ -301,8 +303,10 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
		goto out;

	mi = sample__resolve_mem(sample, &al);
	if (mi == NULL)
		return -ENOMEM;
	if (mi == NULL) {
		ret = -ENOMEM;
		goto out;
	}

	/*
	 * The mi object is released in hists__add_entry_ops,
@@ -368,7 +372,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
	}

out:
	addr_location__put(&al);
	addr_location__exit(&al);
	return ret;

free_mi:
+9 −7
Original line number Diff line number Diff line
@@ -409,15 +409,17 @@ static int diff__process_sample_event(struct perf_tool *tool,
		return 0;
	}

	addr_location__init(&al);
	if (machine__resolve(machine, &al, sample) < 0) {
		pr_warning("problem processing %d event, skipping it.\n",
			   event->header.type);
		return -1;
		ret = -1;
		goto out;
	}

	if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) {
		ret = 0;
		goto out_put;
		goto out;
	}

	switch (compute) {
@@ -426,7 +428,7 @@ static int diff__process_sample_event(struct perf_tool *tool,
					  NULL, NULL, NULL, sample, true)) {
			pr_warning("problem incrementing symbol period, "
				   "skipping event\n");
			goto out_put;
			goto out;
		}

		hist__account_cycles(sample->branch_stack, &al, sample, false,
@@ -437,7 +439,7 @@ static int diff__process_sample_event(struct perf_tool *tool,
		if (hist_entry_iter__add(&iter, &al, PERF_MAX_STACK_DEPTH,
					 NULL)) {
			pr_debug("problem adding hist entry, skipping event\n");
			goto out_put;
			goto out;
		}
		break;

@@ -446,7 +448,7 @@ static int diff__process_sample_event(struct perf_tool *tool,
				      true)) {
			pr_warning("problem incrementing symbol period, "
				   "skipping event\n");
			goto out_put;
			goto out;
		}
	}

@@ -460,8 +462,8 @@ static int diff__process_sample_event(struct perf_tool *tool,
	if (!al.filtered)
		hists->stats.total_non_filtered_period += sample->period;
	ret = 0;
out_put:
	addr_location__put(&al);
out:
	addr_location__exit(&al);
	return ret;
}

+2 −0
Original line number Diff line number Diff line
@@ -743,6 +743,7 @@ int perf_event__inject_buildid(struct perf_tool *tool, union perf_event *event,
	struct addr_location al;
	struct thread *thread;

	addr_location__init(&al);
	thread = machine__findnew_thread(machine, sample->pid, sample->tid);
	if (thread == NULL) {
		pr_err("problem processing %d event, skipping it.\n",
@@ -763,6 +764,7 @@ int perf_event__inject_buildid(struct perf_tool *tool, union perf_event *event,
	thread__put(thread);
repipe:
	perf_event__repipe(tool, event, sample, machine);
	addr_location__exit(&al);
	return 0;
}

+7 −3
Original line number Diff line number Diff line
@@ -399,7 +399,9 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
	struct addr_location al;
	struct machine *machine = &kmem_session->machines.host;
	struct callchain_cursor_node *node;
	u64 result = sample->ip;

	addr_location__init(&al);
	if (alloc_func_list == NULL) {
		if (build_alloc_func_list() < 0)
			goto out;
@@ -427,16 +429,18 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
			else
				addr = node->ip;

			return addr;
			result = addr;
			goto out;
		} else
			pr_debug3("skipping alloc function: %s\n", caller->name);

		callchain_cursor_advance(&callchain_cursor);
	}

out:
	pr_debug2("unknown callsite: %"PRIx64 "\n", sample->ip);
	return sample->ip;
out:
	addr_location__exit(&al);
	return result;
}

struct sort_dimension {
Loading