linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephane Eranian <eranian@google.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Jiri Olsa <jolsa@kernel.org>, Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH 02/10] perf, tools, stat: Force --per-core mode for .agg-per-core aliases
Date: Wed, 16 Dec 2015 06:16:05 -0800	[thread overview]
Message-ID: <CABPqkBQCnECLuffmOjbT=zzaWGpVngyKN-vwqWZkCEw_iWeZpw@mail.gmail.com> (raw)
In-Reply-To: <1450227266-2501-3-git-send-email-andi@firstfloor.org>

On Tue, Dec 15, 2015 at 4:54 PM, Andi Kleen <andi@firstfloor.org> wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> When an event alias is used that the kernel marked as .agg-per-core, force
> --per-core mode (and also require -a and forbid cgroups or per thread mode).
> This in term means, --topdown forces --per-core mode.
>
> This is needed for TopDown in SMT mode, because it needs to measure
> all threads in a core together and merge the values to compute the correct
> percentages of how the pipeline is limited.
>
> We do this if any alias is agg-per-core.
>
I would rather call this attribute aggr-per-core. That would be more consistent
with how perf calls this.

> Add the code to parse the .agg-per-core attributes and propagate
> the information to the evsel. Then the main stat code does
> the necessary checks and forces per core mode.
>
> Open issue: in combination with -C ... we get wrong values. I think that's
> a existing bug that needs to be debugged/fixed separately.
>
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
>  tools/perf/builtin-stat.c      | 18 ++++++++++++++++++
>  tools/perf/util/evsel.h        |  1 +
>  tools/perf/util/parse-events.c |  1 +
>  tools/perf/util/pmu.c          | 23 +++++++++++++++++++++++
>  tools/perf/util/pmu.h          |  2 ++
>  5 files changed, 45 insertions(+)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 4777355..0c7cdda 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -1540,6 +1540,7 @@ static int add_default_attributes(void)
>
>  int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
>  {
> +       struct perf_evsel *counter;
>         const char * const stat_usage[] = {
>                 "perf stat [<options>] [<command>]",
>                 NULL
> @@ -1674,6 +1675,23 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
>         if (add_default_attributes())
>                 goto out;
>
> +       evlist__for_each (evsel_list, counter) {
> +               /* Enable per core mode if only a single event requires it. */
> +               if (counter->agg_per_core) {
> +                       if (stat_config.aggr_mode != AGGR_GLOBAL &&
> +                           stat_config.aggr_mode != AGGR_CORE) {
> +                               pr_err("per core event configuration requires per core mode\n");
> +                               goto out;
> +                       }
> +                       stat_config.aggr_mode = AGGR_CORE;
> +                       if (nr_cgroups || !target__has_cpu(&target)) {
> +                               pr_err("per core event configuration requires system-wide mode (-a)\n");
> +                               goto out;
> +                       }
> +                       break;
> +               }
> +       }
> +
>         target__validate(&target);
>
>         if (perf_evlist__create_maps(evsel_list, &target) < 0) {
> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> index 5ded1fc..efc7f7c 100644
> --- a/tools/perf/util/evsel.h
> +++ b/tools/perf/util/evsel.h
> @@ -114,6 +114,7 @@ struct perf_evsel {
>         bool                    tracking;
>         bool                    per_pkg;
>         bool                    precise_max;
> +       bool                    agg_per_core;
>         /* parse modifier helper */
>         int                     exclude_GH;
>         int                     nr_members;
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 6fc8cd7..66d8ebd 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -1027,6 +1027,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
>                 evsel->unit = info.unit;
>                 evsel->scale = info.scale;
>                 evsel->per_pkg = info.per_pkg;
> +               evsel->agg_per_core = info.agg_per_core;
>                 evsel->snapshot = info.snapshot;
>         }
>
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 8a520e9..5a52dac 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -189,6 +189,23 @@ perf_pmu__parse_per_pkg(struct perf_pmu_alias *alias, char *dir, char *name)
>         return 0;
>  }
>
> +static void
> +perf_pmu__parse_agg_per_core(struct perf_pmu_alias *alias, char *dir, char *name)
> +{
> +       char path[PATH_MAX];
> +       FILE *f;
> +       int flag;
> +
> +       snprintf(path, PATH_MAX, "%s/%s.agg-per-core", dir, name);
> +
> +       f = fopen(path, "r");
> +       if (f && fscanf(f, "%d", &flag) == 1) {
> +               alias->agg_per_core = flag != 0;
> +               fclose(f);
> +       }
> +}
> +
> +
>  static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,
>                                     char *dir, char *name)
>  {
> @@ -237,6 +254,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
>                 perf_pmu__parse_scale(alias, dir, name);
>                 perf_pmu__parse_per_pkg(alias, dir, name);
>                 perf_pmu__parse_snapshot(alias, dir, name);
> +               perf_pmu__parse_agg_per_core(alias, dir, name);
>         }
>
>         list_add_tail(&alias->list, list);
> @@ -271,6 +289,8 @@ static inline bool pmu_alias_info_file(char *name)
>                 return true;
>         if (len > 9 && !strcmp(name + len - 9, ".snapshot"))
>                 return true;
> +       if (len > 13 && !strcmp(name + len - 13, ".agg-per-core"))
> +               return true;
>
>         return false;
>  }
> @@ -847,6 +867,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
>         int ret;
>
>         info->per_pkg = false;
> +       info->agg_per_core = false;
>
>         /*
>          * Mark unit and scale as not set
> @@ -870,6 +891,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
>
>                 if (alias->per_pkg)
>                         info->per_pkg = true;
> +               if (alias->agg_per_core)
> +                       info->agg_per_core = true;
>
>                 list_del(&term->list);
>                 free(term);
> diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
> index 5d7e844..5a43719 100644
> --- a/tools/perf/util/pmu.h
> +++ b/tools/perf/util/pmu.h
> @@ -32,6 +32,7 @@ struct perf_pmu_info {
>         double scale;
>         bool per_pkg;
>         bool snapshot;
> +       bool agg_per_core;
>  };
>
>  #define UNIT_MAX_LEN   31 /* max length for event unit name */
> @@ -44,6 +45,7 @@ struct perf_pmu_alias {
>         double scale;
>         bool per_pkg;
>         bool snapshot;
> +       bool agg_per_core;
>  };
>
>  struct perf_pmu *perf_pmu__find(const char *name);
> --
> 2.4.3
>

  reply	other threads:[~2015-12-16 14:16 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-16  0:54 Add top down metrics to perf stat v2 Andi Kleen
2015-12-16  0:54 ` [PATCH 01/10] perf, tools: Dont stop PMU parsing on alias parse error Andi Kleen
2015-12-21 16:08   ` Jiri Olsa
2015-12-16  0:54 ` [PATCH 02/10] perf, tools, stat: Force --per-core mode for .agg-per-core aliases Andi Kleen
2015-12-16 14:16   ` Stephane Eranian [this message]
2015-12-21 16:14   ` Jiri Olsa
2015-12-21 16:16   ` Jiri Olsa
2015-12-16  0:54 ` [PATCH 03/10] perf, tools, stat: Avoid fractional digits for integer scales Andi Kleen
2015-12-16 14:22   ` Stephane Eranian
2015-12-16  0:54 ` [PATCH 04/10] perf, tools, stat: Scale values by unit before metrics Andi Kleen
2015-12-16  0:54 ` [PATCH 05/10] perf, tools, stat: Basic support for TopDown in perf stat Andi Kleen
2015-12-16 14:32   ` Stephane Eranian
2015-12-16 21:21     ` Andi Kleen
2015-12-17  9:26       ` Stephane Eranian
2015-12-17 14:03         ` Andi Kleen
2015-12-16  0:54 ` [PATCH 06/10] perf, tools, stat: Add computation of TopDown formulas Andi Kleen
2015-12-16  0:54 ` [PATCH 07/10] perf, tools, stat: Add extra output of counter values with -v Andi Kleen
2015-12-16  0:54 ` [PATCH 08/10] x86, perf: Support sysfs files depending on SMT status Andi Kleen
2015-12-16  8:53   ` Peter Zijlstra
2015-12-16 12:48   ` Stephane Eranian
2015-12-16 16:26     ` Andi Kleen
2015-12-16  0:54 ` [PATCH 09/10] x86, perf: Add Top Down events to Intel Core Andi Kleen
2015-12-16  0:54 ` [PATCH 10/10] x86, perf: Add Top Down events to Intel Atom Andi Kleen
2015-12-17 10:27 ` Add top down metrics to perf stat v2 Stephane Eranian
2015-12-17 14:01   ` Andi Kleen
2015-12-17 23:31     ` Stephane Eranian
2015-12-18  1:55       ` Andi Kleen
2015-12-18  9:31         ` Stephane Eranian
2015-12-18 21:38           ` 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='CABPqkBQCnECLuffmOjbT=zzaWGpVngyKN-vwqWZkCEw_iWeZpw@mail.gmail.com' \
    --to=eranian@google.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).