[PATCH 10/11] perf evsel: Auto allocate resources needed for some methods

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Arnaldo Carvalho de Melo
Date: Monday, January 3, 2011 - 8:48 pm

From: Arnaldo Carvalho de Melo <acme@redhat.com>

While writing the first user of the routines created from the ad-hoc
routines in the existing builtins I noticed that the resulting set of
calls was too long, reduce it by doing some best effort allocations.

Tools that need to operate on multiple threads and cpus should pre-allocate
enough resources by explicitely calling the perf_evsel__alloc_{fd,counters}
methods.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/evsel.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index e44be52..c95267e 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -66,6 +66,9 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
 	if (FD(evsel, cpu, thread) < 0)
 		return -EINVAL;
 
+	if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1) < 0)
+		return -ENOMEM;
+
 	if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0)
 		return -errno;
 
@@ -129,6 +132,9 @@ int perf_evsel__open_per_cpu(struct perf_evsel *evsel, struct cpu_map *cpus)
 {
 	int cpu;
 
+	if (evsel->fd == NULL && perf_evsel__alloc_fd(evsel, cpus->nr, 1) < 0)
+		return -1;
+
 	for (cpu = 0; cpu < cpus->nr; cpu++) {
 		FD(evsel, cpu, 0) = sys_perf_event_open(&evsel->attr, -1,
 							cpus->map[cpu], -1, 0);
@@ -150,6 +156,9 @@ int perf_evsel__open_per_thread(struct perf_evsel *evsel, struct thread_map *thr
 {
 	int thread;
 
+	if (evsel->fd == NULL && perf_evsel__alloc_fd(evsel, 1, threads->nr))
+		return -1;
+
 	for (thread = 0; thread < threads->nr; thread++) {
 		FD(evsel, 0, thread) = sys_perf_event_open(&evsel->attr,
 							   threads->map[thread], -1, -1, 0);
-- 
1.6.2.5

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GIT PULL||RFC 00/11] perf library and regression testing ..., Arnaldo Carvalho de Melo, (Mon Jan 3, 8:48 pm)
[PATCH 01/11] perf tools: Introduce event selectors, Arnaldo Carvalho de Melo, (Mon Jan 3, 8:48 pm)
[PATCH 06/11] perf evsel: Introduce per cpu and per thread ..., Arnaldo Carvalho de Melo, (Mon Jan 3, 8:48 pm)
[PATCH 07/11] perf tools: Refactor cpumap to hold nr and t ..., Arnaldo Carvalho de Melo, (Mon Jan 3, 8:48 pm)
[PATCH 08/11] perf tools: Refactor all_tids to hold nr and ..., Arnaldo Carvalho de Melo, (Mon Jan 3, 8:48 pm)
[PATCH 09/11] perf evsel: Use {cpu,thread}_map to shorten ..., Arnaldo Carvalho de Melo, (Mon Jan 3, 8:48 pm)
[PATCH 10/11] perf evsel: Auto allocate resources needed f ..., Arnaldo Carvalho de Melo, (Mon Jan 3, 8:48 pm)
Re: [GIT PULL||RFC 00/11] perf library and regression test ..., Arnaldo Carvalho de Melo, (Tue Jan 4, 7:03 am)
Re: [GIT PULL||RFC 00/11] perf library and regression test ..., Arnaldo Carvalho de Melo, (Tue Jan 4, 7:12 am)
Re: [GIT PULL||RFC 00/11] perf library and regression test ..., Arnaldo Carvalho de Melo, (Tue Jan 4, 7:19 am)
Re: [GIT PULL||RFC 00/11] perf library and regression test ..., Arnaldo Carvalho de Melo, (Tue Jan 4, 7:27 am)
Re: [GIT PULL||RFC 00/11] perf library and regression test ..., Arnaldo Carvalho de Melo, (Tue Jan 4, 7:34 am)
Re: [GIT PULL||RFC 00/11] perf library and regression test ..., Arnaldo Carvalho de Melo, (Tue Jan 4, 7:36 am)
Re: [GIT PULL||RFC 00/11] perf library and regression test ..., Arnaldo Carvalho de Melo, (Tue Jan 4, 8:24 am)
Re: [GIT PULL||RFC 00/11] perf library and regression test ..., Arnaldo Carvalho de Melo, (Tue Jan 4, 8:30 am)