Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932498AbbDOPJE (ORCPT ); Wed, 15 Apr 2015 11:09:04 -0400 Received: from mga14.intel.com ([192.55.52.115]:56224 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756041AbbDOPIy (ORCPT ); Wed, 15 Apr 2015 11:08:54 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,582,1422950400"; d="scan'208";a="714104615" From: Kan Liang To: acme@kernel.org, a.p.zijlstra@chello.nl Cc: eranian@google.com, andi@firstfloor.org, linux-kernel@vger.kernel.org, Kan Liang Subject: [PATCH V2 4/6] perf,tools: check and re-organize evsel cpu maps Date: Wed, 15 Apr 2015 03:56:14 -0400 Message-Id: <1429084576-1078-4-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1429084576-1078-1-git-send-email-kan.liang@intel.com> References: <1429084576-1078-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3896 Lines: 136 From: Kan Liang "-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 --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/