All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: acme@ghostprotocols.net, linux-kernel@vger.kernel.org
Cc: mingo@kernel.org, peterz@infradead.org, fweisbec@gmail.com,
	David Ahern <dsahern@gmail.com>
Subject: [PATCH 8/9] perf stat: move to perf_evlist__open_counters
Date: Mon, 29 Oct 2012 10:31:48 -0600	[thread overview]
Message-ID: <1351528309-87705-9-git-send-email-dsahern@gmail.com> (raw)
In-Reply-To: <1351528309-87705-1-git-send-email-dsahern@gmail.com>

Removes a lot of duplicated code moving to the common
open method.

Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
---
 tools/perf/builtin-stat.c |  103 ++++++++++-----------------------------------
 1 file changed, 22 insertions(+), 81 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index e12002b..dc9850c 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -126,55 +126,6 @@ static struct stats runtime_itlb_cache_stats[MAX_NR_CPUS];
 static struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS];
 static struct stats walltime_nsecs_stats;
 
-static int create_perf_stat_counter(struct perf_evsel *evsel,
-				    struct perf_evsel *first,
-				    struct perf_record_opts *opts)
-{
-	struct perf_target *target = &opts->target;
-	struct perf_event_attr *attr = &evsel->attr;
-	bool exclude_guest_missing = false;
-	int ret;
-
-	if (scale)
-		attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
-				    PERF_FORMAT_TOTAL_TIME_RUNNING;
-
-	attr->inherit = !opts->no_inherit;
-
-retry:
-	if (exclude_guest_missing)
-		evsel->attr.exclude_guest = evsel->attr.exclude_host = 0;
-
-	if (perf_target__has_cpu(target)) {
-		ret = perf_evsel__open_per_cpu(evsel,
-					       perf_evsel__cpus(evsel, target));
-		if (ret)
-			goto check_ret;
-		return 0;
-	}
-
-	if (!perf_target__has_task(target) &&
-	    (!opts->group || evsel == first)) {
-		attr->disabled = 1;
-		attr->enable_on_exec = 1;
-	}
-
-	ret = perf_evsel__open_per_thread(evsel, evsel_list->threads);
-	if (!ret)
-		return 0;
-	/* fall through */
-check_ret:
-	if (ret && errno == EINVAL) {
-		if (!exclude_guest_missing &&
-		    (evsel->attr.exclude_guest || evsel->attr.exclude_host)) {
-			pr_debug("Old kernel, cannot exclude "
-				 "guest or host samples.\n");
-			exclude_guest_missing = true;
-			goto retry;
-		}
-	}
-	return ret;
-}
 
 /*
  * Does the counter have nsecs as a unit?
@@ -281,6 +232,7 @@ static int __run_perf_stat(int argc __maybe_unused,
 	unsigned long long t0, t1;
 	struct perf_evsel *counter, *first;
 	struct cpu_map *cmap;
+	struct perf_target *target = &opts->target;
 	int status = 0;
 	int child_ready_pipe[2], go_pipe[2];
 	const bool forks = (argc > 0);
@@ -324,7 +276,7 @@ static int __run_perf_stat(int argc __maybe_unused,
 			exit(-1);
 		}
 
-		if (perf_target__none(&opts->target))
+		if (perf_target__none(target))
 			evsel_list->threads->map[0] = child_pid;
 
 		/*
@@ -343,38 +295,27 @@ static int __run_perf_stat(int argc __maybe_unused,
 	first = perf_evlist__first(evsel_list);
 
 	list_for_each_entry(counter, &evsel_list->entries, node) {
-		if (create_perf_stat_counter(counter, first, opts) < 0) {
-			/*
-			 * PPC returns ENXIO for HW counters until 2.6.37
-			 * (behavior changed with commit b0a873e).
-			 */
-			if (errno == EINVAL || errno == ENOSYS ||
-			    errno == ENOENT || errno == EOPNOTSUPP ||
-			    errno == ENXIO) {
-				if (verbose)
-					ui__warning("%s event is not supported by the kernel.\n",
-						    perf_evsel__name(counter));
-				counter->supported = false;
-				continue;
-			}
-
-			if (errno == EPERM || errno == EACCES) {
-				error("You may not have permission to collect %sstats.\n"
-				      "\t Consider tweaking"
-				      " /proc/sys/kernel/perf_event_paranoid or running as root.",
-				      opts->target.system_wide ? "system-wide " : "");
-			} else {
-				error("open_counter returned with %d (%s). "
-				      "/bin/dmesg may provide additional information.\n",
-				       errno, strerror(errno));
-			}
-			if (child_pid != -1)
-				kill(child_pid, SIGTERM);
-
-			pr_err("Not all events could be opened.\n");
-			return -1;
+		struct perf_event_attr *attr = &counter->attr;
+
+		if (scale)
+			attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
+					    PERF_FORMAT_TOTAL_TIME_RUNNING;
+
+		attr->inherit = !opts->no_inherit;
+
+		if (perf_target__none(target) &&
+		    (!opts->group || counter == first)) {
+			attr->disabled = 1;
+			attr->enable_on_exec = 1;
 		}
-		counter->supported = true;
+	}
+
+	if (perf_evlist__open_counters(evsel_list, opts, true) != 0) {
+		if (child_pid != -1)
+			kill(child_pid, SIGTERM);
+
+		pr_err("Not all events could be opened.\n");
+		return -1;
 	}
 
 	if (perf_evlist__apply_filters(evsel_list)) {
-- 
1.7.10.1


  parent reply	other threads:[~2012-10-29 16:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-29 16:31 [PATCH 0/9 v2] perf: consolidate all the open counters loops David Ahern
2012-10-29 16:31 ` [PATCH 1/9] perf python: add ui stubs file David Ahern
2012-10-30  7:24   ` Namhyung Kim
2012-10-30 14:45     ` David Ahern
2012-10-30 15:53       ` Arnaldo Carvalho de Melo
2012-10-31  7:18         ` Namhyung Kim
2012-10-29 16:31 ` [PATCH 2/9] perf top: make use of perf_record_opts David Ahern
2012-10-30  7:27   ` Namhyung Kim
2012-10-30 13:31     ` David Ahern
2012-10-29 16:31 ` [PATCH 3/9] perf evlist: introduce open counters method David Ahern
2012-10-29 16:31 ` [PATCH 4/9] perf top: use the new perf_evlist__open_counters method David Ahern
2012-10-29 16:31 ` [PATCH 5/9] perf record: " David Ahern
2012-10-29 16:31 ` [PATCH 6/9] perf stat: move user options to perf_record_opts David Ahern
2012-10-29 16:31 ` [PATCH 7/9] perf evlist: add stat unique code to open_counters method David Ahern
2012-10-29 16:31 ` David Ahern [this message]
2012-10-29 16:31 ` [PATCH 9/9] perf evsel: remove perf_evsel__open_per_cpu David Ahern
  -- strict thread matches above, loose matches on Subject: below --
2012-10-11  4:25 [PATCH 0/9] perf: consolidate all the open counters loops David Ahern
2012-10-11  4:25 ` [PATCH 8/9] perf stat: move to perf_evlist__open_counters David Ahern

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=1351528309-87705-9-git-send-email-dsahern@gmail.com \
    --to=dsahern@gmail.com \
    --cc=acme@ghostprotocols.net \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.