From: Kan Liang <kan.liang@intel.com>
To: acme@kernel.org, a.p.zijlstra@chello.nl
Cc: eranian@google.com, andi@firstfloor.org,
linux-kernel@vger.kernel.org, Kan Liang <kan.liang@intel.com>
Subject: [PATCH V2 4/6] perf,tools: check and re-organize evsel cpu maps
Date: Wed, 15 Apr 2015 03:56:14 -0400 [thread overview]
Message-ID: <1429084576-1078-4-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1429084576-1078-1-git-send-email-kan.liang@intel.com>
From: Kan Liang <kan.liang@intel.com>
"-C" can be used to set cpu list. The cpu list may be incompatible with
event's cpumask. This patch discard the incompatible cpu. Only available
cpu can be stored in evsel->cpus->map.
If there is no cpu from cpu list compatible with event's cpumask. It
will error out.
Signed-off-by: Kan Liang <kan.liang@intel.com>
---
tools/perf/builtin-top.c | 6 ++--
tools/perf/util/evlist.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 1cb3436..5aba1b2 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1220,9 +1220,6 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
if (target__none(target))
target->system_wide = true;
- if (perf_evlist__create_maps(top.evlist, target) < 0)
- usage_with_options(top_usage, options);
-
if (!top.evlist->nr_entries &&
perf_evlist__add_default(top.evlist) < 0) {
ui__error("Not enough memory for event selector list\n");
@@ -1231,6 +1228,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
symbol_conf.nr_events = top.evlist->nr_entries;
+ if (perf_evlist__create_maps(top.evlist, target) < 0)
+ usage_with_options(top_usage, options);
+
if (top.delay_secs < 1)
top.delay_secs = 1;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index a065150..16319b4 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1068,6 +1068,74 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
return perf_evlist__mmap_per_cpu(evlist, &mp);
}
+static int cmp_ids(const void *a, const void *b)
+{
+ return *(int *)a - *(int *)b;
+}
+
+/*
+ * Check evsel cpu map according to pmu cpumask and input
+ * Only available cpu can be stored in evsel->cpus->map.
+ */
+static int perf_evlist__check_evsel_cpus(struct perf_evlist *evlist)
+{
+ const struct cpu_map *cpus = evlist->cpus;
+ const int ncpus = cpu_map__nr(evlist->cpus);
+ struct perf_evsel *evsel;
+ int i, j, cpu_nr, tmp;
+
+ /* ensure we process id in increasing order */
+ qsort(evlist->cpus->map, evlist->cpus->nr, sizeof(int), cmp_ids);
+
+ evlist__for_each(evlist, evsel) {
+ if (evsel->cpus == cpus)
+ continue;
+
+ cpu_nr = 0;
+ j = 0;
+ for (i = 0; i < cpu_map__nr(evsel->cpus);) {
+
+ if (j >= ncpus) {
+ evsel->cpus->map[i++] = -1;
+ continue;
+ }
+ for (; j < ncpus; j++) {
+ if (cpus->map[j] < evsel->cpus->map[i])
+ continue;
+ if (cpus->map[j] == evsel->cpus->map[i]) {
+ cpu_nr++;
+ j++;
+ i++;
+ } else
+ evsel->cpus->map[i++] = -1;
+ break;
+ }
+ }
+
+ if (cpu_nr == cpu_map__nr(evsel->cpus))
+ continue;
+ if (cpu_nr == 0) {
+ perror("failed to create CPUs map, please check cpumask");
+ return -1;
+ }
+
+ tmp = 0;
+ for (i = 0; i < cpu_nr; i++) {
+ if (evsel->cpus->map[i] == -1) {
+ while (evsel->cpus->map[tmp] == -1) {
+ tmp++;
+ BUG_ON(tmp >= cpu_map__nr(evsel->cpus));
+ }
+ evsel->cpus->map[i] = evsel->cpus->map[tmp];
+ evsel->cpus->map[tmp] = -1;
+ }
+ tmp++;
+ }
+ evsel->cpus->nr = cpu_nr;
+ }
+ return 0;
+}
+
int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
{
struct cpu_map *cpus;
@@ -1088,6 +1156,10 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
perf_evlist__set_cpus(evlist, cpus);
+ if (target->cpu_list &&
+ (perf_evlist__check_evsel_cpus(evlist) < 0))
+ goto out_delete_threads;
+
return 0;
out_delete_threads:
--
1.8.3.1
next prev parent reply other threads:[~2015-04-15 15:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-15 7:56 [PATCH V2 1/6] perf,core: allow invalid context events to be part of sw/hw groups Kan Liang
2015-04-15 7:56 ` [PATCH V2 2/6] perf evsel: Set evsel->cpus to the evlist->cpus when not constrained Kan Liang
2015-04-15 7:56 ` [PATCH V2 3/6] perf,tools: get real cpu id for print_aggr Kan Liang
2015-04-15 7:56 ` Kan Liang [this message]
2015-04-16 16:33 ` [PATCH V2 4/6] perf,tools: check and re-organize evsel cpu maps Mark Rutland
2015-04-15 7:56 ` [PATCH V2 5/6] perf,tools: open/mmap event uses event's cpu map Kan Liang
2015-04-15 7:56 ` [PATCH V2 6/6] perf/x86/intel/uncore: do not implicitly set uncore event cpu Kan Liang
2015-04-16 16:36 ` Mark Rutland
2015-04-15 16:15 ` [PATCH V2 1/6] perf,core: allow invalid context events to be part of sw/hw groups Peter Zijlstra
2015-04-15 16:21 ` Andi Kleen
2015-04-15 16:55 ` Peter Zijlstra
2015-04-15 17:28 ` Peter Zijlstra
2015-04-16 14:53 ` Liang, Kan
2015-04-16 16:31 ` Mark Rutland
2015-04-16 16:43 ` Mark Rutland
2015-04-16 17:16 ` Mark Rutland
2015-04-16 21:23 ` Andi Kleen
2015-04-17 9:47 ` Mark Rutland
2015-04-18 0:47 ` Andi Kleen
2015-04-20 10:15 ` Mark Rutland
2015-04-20 16:57 ` Andi Kleen
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=1429084576-1078-4-git-send-email-kan.liang@intel.com \
--to=kan.liang@intel.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=andi@firstfloor.org \
--cc=eranian@google.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
Powered by JetHome