public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Ian Rogers <irogers@google.com>,
	Caleb Biggers <caleb.biggers@intel.com>,
	Perry Taylor <perry.taylor@intel.com>,
	Kshipra Bopardikar <kshipra.bopardikar@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Ravi Bangoria <ravi.bangoria@amd.com>,
	Andi Kleen <ak@linux.intel.com>, Haowen Bai <baihaowen@meizu.com>,
	Riccardo Mancini <rickyman7@gmail.com>,
	Kim Phillips <kim.phillips@amd.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Shunsuke Nakamura <nakamura.shun@fujitsu.com>,
	Florian Fischer <florian.fischer@muhq.space>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Cc: Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH 1/2] perf evlist: Keep topdown counters in weak group
Date: Thu, 5 May 2022 07:56:36 -0400	[thread overview]
Message-ID: <87b89e2c-da5c-52c3-40dc-448e874cb5d8@linux.intel.com> (raw)
In-Reply-To: <20220505043846.3165303-1-irogers@google.com>

Hi Ian,

Thanks for the patches.

On 5/5/2022 12:38 AM, Ian Rogers wrote:
> On Intel Icelake, topdown events must always be grouped with a slots
> event as leader. When a metric is parsed a weak group is formed and
> retried if perf_event_open fails. The retried events aren't grouped
> breaking the slots leader requirement. This change modifies the weak
> group "reset" behavior so that topdown events aren't broken from the
> group for the retry.
> 
> $ perf stat -e '{slots,topdown-bad-spec,topdown-be-bound,topdown-fe-bound,topdown-retiring,branch-instructions,branch-misses,bus-cycles,cache-misses,cache-references,cpu-cycles,instructions,mem-loads,mem-stores,ref-cycles,baclears.any,ARITH.DIVIDER_ACTIVE}:W' -a sleep 1
> 
>   Performance counter stats for 'system wide':
> 
>      47,867,188,483      slots                                                         (92.27%)
>     <not supported>      topdown-bad-spec
>     <not supported>      topdown-be-bound
>     <not supported>      topdown-fe-bound
>     <not supported>      topdown-retiring
>       2,173,346,937      branch-instructions                                           (92.27%)
>          10,540,253      branch-misses             #    0.48% of all branches          (92.29%)
>          96,291,140      bus-cycles                                                    (92.29%)
>           6,214,202      cache-misses              #   20.120 % of all cache refs      (92.29%)
>          30,886,082      cache-references                                              (76.91%)
>      11,773,726,641      cpu-cycles                                                    (84.62%)
>      11,807,585,307      instructions              #    1.00  insn per cycle           (92.31%)
>                   0      mem-loads                                                     (92.32%)
>       2,212,928,573      mem-stores                                                    (84.69%)
>      10,024,403,118      ref-cycles                                                    (92.35%)
>          16,232,978      baclears.any                                                  (92.35%)
>          23,832,633      ARITH.DIVIDER_ACTIVE                                          (84.59%)
> 
>         0.981070734 seconds time elapsed
> 
> After:
> 
> $ perf stat -e '{slots,topdown-bad-spec,topdown-be-bound,topdown-fe-bound,topdown-retiring,branch-instructions,branch-misses,bus-cycles,cache-misses,cache-references,cpu-cycles,instructions,mem-loads,mem-stores,ref-cycles,baclears.any,ARITH.DIVIDER_ACTIVE}:W' -a sleep 1
> 
>   Performance counter stats for 'system wide':
> 
>         31040189283      slots                                                         (92.27%)
>          8997514811      topdown-bad-spec          #     28.2% bad speculation         (92.27%)
>         10997536028      topdown-be-bound          #     34.5% backend bound           (92.27%)
>          4778060526      topdown-fe-bound          #     15.0% frontend bound          (92.27%)
>          7086628768      topdown-retiring          #     22.2% retiring                (92.27%)
>          1417611942      branch-instructions                                           (92.26%)
>             5285529      branch-misses             #    0.37% of all branches          (92.28%)
>            62922469      bus-cycles                                                    (92.29%)
>             1440708      cache-misses              #    8.292 % of all cache refs      (92.30%)
>            17374098      cache-references                                              (76.94%)
>          8040889520      cpu-cycles                                                    (84.63%)
>          7709992319      instructions              #    0.96  insn per cycle           (92.32%)
>                   0      mem-loads                                                     (92.32%)
>          1515669558      mem-stores                                                    (84.68%)
>          6542411177      ref-cycles                                                    (92.35%)
>             4154149      baclears.any                                                  (92.35%)
>            20556152      ARITH.DIVIDER_ACTIVE                                          (84.59%)
> 
>         1.010799593 seconds time elapsed
> 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>   tools/perf/arch/x86/util/evsel.c | 12 ++++++++++++
>   tools/perf/util/evlist.c         | 16 ++++++++++++++--
>   tools/perf/util/evsel.c          | 10 ++++++++++
>   tools/perf/util/evsel.h          |  3 +++
>   4 files changed, 39 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c
> index ac2899a25b7a..40b171de2086 100644
> --- a/tools/perf/arch/x86/util/evsel.c
> +++ b/tools/perf/arch/x86/util/evsel.c
> @@ -3,6 +3,7 @@
>   #include <stdlib.h>
>   #include "util/evsel.h"
>   #include "util/env.h"
> +#include "util/pmu.h"
>   #include "linux/string.h"
>   
>   void arch_evsel__set_sample_weight(struct evsel *evsel)
> @@ -29,3 +30,14 @@ void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr)
>   
>   	free(env.cpuid);
>   }
> +
> +bool arch_evsel__must_be_in_group(const struct evsel *evsel)
> +{
> +	if ((evsel->pmu_name && strcmp(evsel->pmu_name, "cpu")) ||
> +	    !pmu_have_event("cpu", "slots"))
> +		return false;
> +

The big core of ADL also supports Perf_metrics. At least, we should 
check both "cpu" and "cpu_core" here.

Thanks,
Kan
> +	return evsel->name &&
> +		(!strcasecmp(evsel->name, "slots") ||
> +		 !strncasecmp(evsel->name, "topdown", 7));
> +}
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index 52ea004ba01e..dfa65a383502 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -1790,8 +1790,17 @@ struct evsel *evlist__reset_weak_group(struct evlist *evsel_list, struct evsel *
>   		if (evsel__has_leader(c2, leader)) {
>   			if (is_open && close)
>   				perf_evsel__close(&c2->core);
> -			evsel__set_leader(c2, c2);
> -			c2->core.nr_members = 0;
> +			/*
> +			 * We want to close all members of the group and reopen
> +			 * them. Some events, like Intel topdown, require being
> +			 * in a group and so keep these in the group.
> +			 */
> +			if (!evsel__must_be_in_group(c2) && c2 != leader) {
> +				evsel__set_leader(c2, c2);
> +				c2->core.nr_members = 0;
> +				leader->core.nr_members--;
> +			}
> +
>   			/*
>   			 * Set this for all former members of the group
>   			 * to indicate they get reopened.
> @@ -1799,6 +1808,9 @@ struct evsel *evlist__reset_weak_group(struct evlist *evsel_list, struct evsel *
>   			c2->reset_group = true;
>   		}
>   	}
> +	/* Reset the leader count if all entries were removed. */
> +	if (leader->core.nr_members)
> +		leader->core.nr_members = 0;
>   	return leader;
>   }
>   
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index d38722560e80..b7c0c9775673 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -3082,3 +3082,13 @@ int evsel__source_count(const struct evsel *evsel)
>   	}
>   	return count;
>   }
> +
> +bool __weak arch_evsel__must_be_in_group(const struct evsel *evsel __maybe_unused)
> +{
> +	return false;
> +}
> +
> +bool evsel__must_be_in_group(const struct evsel *evsel)
> +{
> +	return arch_evsel__must_be_in_group(evsel);
> +}
> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> index 45d674812239..0ed2850b7ebb 100644
> --- a/tools/perf/util/evsel.h
> +++ b/tools/perf/util/evsel.h
> @@ -488,6 +488,9 @@ bool evsel__has_leader(struct evsel *evsel, struct evsel *leader);
>   bool evsel__is_leader(struct evsel *evsel);
>   void evsel__set_leader(struct evsel *evsel, struct evsel *leader);
>   int evsel__source_count(const struct evsel *evsel);
> +bool evsel__must_be_in_group(const struct evsel *evsel);
> +
> +bool arch_evsel__must_be_in_group(const struct evsel *evsel);
>   
>   /*
>    * Macro to swap the bit-field postition and size.

  parent reply	other threads:[~2022-05-05 11:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05  4:38 [PATCH 1/2] perf evlist: Keep topdown counters in weak group Ian Rogers
2022-05-05  4:38 ` [PATCH 2/2] perf test: Add basic stat and topdown group test Ian Rogers
2022-05-05 12:12   ` Liang, Kan
2022-05-05 15:22     ` Ian Rogers
2022-05-05 18:19       ` Liang, Kan
2022-05-05 18:35         ` Ian Rogers
2022-05-05 20:27           ` Liang, Kan
2022-05-05 11:56 ` Liang, Kan [this message]
2022-05-05 15:18   ` [PATCH 1/2] perf evlist: Keep topdown counters in weak group Ian Rogers
2022-05-05 18:15     ` Liang, Kan
2022-05-05 18:31       ` Ian Rogers
2022-05-05 19:43         ` Liang, Kan
2022-05-09 17:28           ` Ian Rogers
2022-05-09 21:01             ` Liang, Kan
2022-05-10 16:58               ` Ian Rogers
2022-05-10 19:24                 ` Liang, Kan

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=87b89e2c-da5c-52c3-40dc-448e874cb5d8@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=baihaowen@meizu.com \
    --cc=caleb.biggers@intel.com \
    --cc=eranian@google.com \
    --cc=florian.fischer@muhq.space \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kim.phillips@amd.com \
    --cc=kshipra.bopardikar@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=nakamura.shun@fujitsu.com \
    --cc=namhyung@kernel.org \
    --cc=perry.taylor@intel.com \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=rickyman7@gmail.com \
    /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