mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: linux-kernel@vger.kernel.org
Cc: acme@kernel.org, alexander.shishkin@linux.intel.com,
	ganapatrao.kulkarni@cavium.com, mark.rutland@arm.com
Subject: [PATCH 1/2] perf evsel: add per{cpu,thread} close helpers
Date: Fri, 28 Apr 2017 12:47:09 +0100	[thread overview]
Message-ID: <1493380030-4683-2-git-send-email-mark.rutland@arm.com> (raw)
In-Reply-To: <1493380030-4683-1-git-send-email-mark.rutland@arm.com>

We have perf_evsel__open_per_{cpu,thread}() helpers for opening events,
but we have no corresponding helpers for closing events.

This results in callers having to duplicate logic to determine the
number of cpus and threads when closing an event, and makes it harder
than necessary to determine whether open/close are correctly balanced.

This patch adds new perf_evsel__close_per_{cpu,thread}() helpers, which
can be paired with their open counterpart. A subsequent patch will make
use of these.

For consistency, the functions are shuffled in evsel.c so that the
per-{cpu,thread} variants of open/close immediately follow their
respective common implementation.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: linux-kernel@vger.kernel.org
---
 tools/perf/util/evsel.c | 26 ++++++++++++++++++++------
 tools/perf/util/evsel.h |  4 ++++
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 0e87909..27abed8 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1682,6 +1682,18 @@ int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 	return err;
 }
 
+int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
+			     struct cpu_map *cpus)
+{
+	return perf_evsel__open(evsel, cpus, NULL);
+}
+
+int perf_evsel__open_per_thread(struct perf_evsel *evsel,
+				struct thread_map *threads)
+{
+	return perf_evsel__open(evsel, NULL, threads);
+}
+
 void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads)
 {
 	if (evsel->fd == NULL)
@@ -1691,16 +1703,18 @@ void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads)
 	perf_evsel__free_fd(evsel);
 }
 
-int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
-			     struct cpu_map *cpus)
+void perf_evsel__close_per_cpu(struct perf_evsel *evsel,
+			       struct cpu_map *cpus)
 {
-	return perf_evsel__open(evsel, cpus, NULL);
+	int ncpus = cpus ? cpus->nr : 1;
+	perf_evsel__close(evsel, ncpus, 1);
 }
 
-int perf_evsel__open_per_thread(struct perf_evsel *evsel,
-				struct thread_map *threads)
+void perf_evsel__close_per_thread(struct perf_evsel *evsel,
+				  struct thread_map *threads)
 {
-	return perf_evsel__open(evsel, NULL, threads);
+	int nthreads = threads ? threads->nr : 1;
+	perf_evsel__close(evsel, 1, nthreads);
 }
 
 static int perf_evsel__parse_id_sample(const struct perf_evsel *evsel,
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index d101695..6f61a49 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -257,6 +257,10 @@ int perf_evsel__open_per_thread(struct perf_evsel *evsel,
 				struct thread_map *threads);
 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 		     struct thread_map *threads);
+void perf_evsel__close_per_cpu(struct perf_evsel *evsel,
+			       struct cpu_map *cpus);
+void perf_evsel__close_per_thread(struct perf_evsel *evsel,
+				  struct thread_map *threads);
 void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
 
 struct perf_sample;
-- 
1.9.1

  reply	other threads:[~2017-04-28 11:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-28 11:47 [PATCH 0/2] perf stat: fix segfault when closing events Mark Rutland
2017-04-28 11:47 ` Mark Rutland [this message]
2017-04-28 11:47 ` [PATCH 2/2] perf stat: balance opening/closing of events Mark Rutland
2017-05-23 10:04 ` [PATCH 0/2] perf stat: fix segfault when closing events Mark Rutland
2017-05-23 15:14   ` Ganapatrao Kulkarni
2017-06-09  4:33     ` Ganapatrao Kulkarni
2017-07-12  7:16       ` Ganapatrao Kulkarni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1493380030-4683-2-git-send-email-mark.rutland@arm.com \
    --to=mark.rutland@arm.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ganapatrao.kulkarni@cavium.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®