From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: kan.liang@intel.com
Cc: a.p.zijlstra@chello.nl, linux-kernel@vger.kernel.org,
ak@linux.intel.com, Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH 2/5] perf,tools: check and re-organize evsel cpu maps
Date: Tue, 3 Mar 2015 13:09:29 -0300 [thread overview]
Message-ID: <20150303160929.GI5187@kernel.org> (raw)
In-Reply-To: <1425372886-33397-2-git-send-email-kan.liang@intel.com>
Em Tue, Mar 03, 2015 at 03:54:43AM -0500, kan.liang@intel.com escreveu:
> From: Kan Liang <kan.liang@intel.com>
>
> With the patch 1/5, it's possible to group read events from different
> pmus. "-C" can be used to set cpu list. The cpu list may be incompatible
> with pmu's cpumask.
> This patch checks the event's cpu maps, and discard the incompatible cpu
> maps.
> event's cpu maps is saved in evsel->cpus during option parse. Then the
> evlist's cpu maps is created in perf_evlist__create_maps. So the cpu
> maps can be check and re-organized in perf_evlist__create_maps.
> Only cpu_list need to check the cpu maps.
Humm, I had something done in this area...
Stephane complained about the confusion about which cpumap to use with
pmus, so I wrote a patch and sent an RFC, which I think I got no
comments, lemme dig it...
- Arnaldo
> 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 5fb8723..f40d1d6 100644
> --- a/tools/perf/builtin-top.c
> +++ b/tools/perf/builtin-top.c
> @@ -1218,9 +1218,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");
> @@ -1229,6 +1226,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 8d0b623..3c6115c 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -1026,6 +1026,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)
> + 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)
> {
> evlist->threads = thread_map__new_str(target->pid, target->tid,
> @@ -1042,6 +1110,10 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
> if (evlist->cpus == NULL)
> goto out_delete_threads;
>
> + 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-03-03 16:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-03 8:54 [PATCH 1/5] perf,core: allow invalid context events to be part of sw/hw groups kan.liang
2015-03-03 8:54 ` [PATCH 2/5] perf,tools: check and re-organize evsel cpu maps kan.liang
2015-03-03 16:09 ` Arnaldo Carvalho de Melo [this message]
2015-03-03 16:11 ` Arnaldo Carvalho de Melo
2015-03-03 17:09 ` Liang, Kan
2015-03-04 0:15 ` Arnaldo Carvalho de Melo
2015-03-18 12:31 ` Liang, Kan
2015-03-03 8:54 ` [PATCH 3/5] perf,tools: change perf stat to use event's cpu map kan.liang
2015-03-03 8:54 ` [PATCH 4/5] perf,tools: open/mmap event according to event's cpu map not evlist's kan.liang
2015-03-03 8:54 ` [PATCH 5/5] perf/x86/intel/uncore: do not implicitly set uncore event cpu kan.liang
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=20150303160929.GI5187@kernel.org \
--to=acme@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=kan.liang@intel.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 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.