Linux Perf Users
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Dapeng Mi <dapeng1.mi@linux.intel.com>, Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Dapeng Mi <dapeng1.mi@intel.com>
Subject: Re: [PATCH 2/2] perf x86/topdown: Refine helper arch_is_topdown_metrics()
Date: Wed, 16 Oct 2024 10:37:45 -0700	[thread overview]
Message-ID: <Zw_56b61Ik7UFekS@google.com> (raw)
In-Reply-To: <20241011110207.1032235-2-dapeng1.mi@linux.intel.com>

Hi Ian,

On Fri, Oct 11, 2024 at 11:02:07AM +0000, Dapeng Mi wrote:
> Leverage the existed function perf_pmu__name_from_config() to check if
> an event is topdown metrics event. perf_pmu__name_from_config() goes
> through the defined formats and figures out the config of pre-defined
> topdown events.
> 
> This avoids to figure out the config of topdown pre-defined events with
> hard-coded format strings "event=" and "umask=" and provides more
> flexibility.
> 
> Suggested-by: Ian Rogers <irogers@google.com>
> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>

Are you ok with this now?

Thanks,
Namhyung

> ---
>  tools/perf/arch/x86/util/topdown.c | 39 +++++++-----------------------
>  1 file changed, 9 insertions(+), 30 deletions(-)
> 
> diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/topdown.c
> index cb2c64928bc4..f63747d0abdf 100644
> --- a/tools/perf/arch/x86/util/topdown.c
> +++ b/tools/perf/arch/x86/util/topdown.c
> @@ -41,43 +41,22 @@ bool arch_is_topdown_slots(const struct evsel *evsel)
>  	return false;
>  }
>  
> -static int compare_topdown_event(void *vstate, struct pmu_event_info *info)
> -{
> -	int *config = vstate;
> -	int event = 0;
> -	int umask = 0;
> -	char *str;
> -
> -	if (!strcasestr(info->name, "topdown"))
> -		return 0;
> -
> -	str = strcasestr(info->str, "event=");
> -	if (str)
> -		sscanf(str, "event=%x", &event);
> -
> -	str = strcasestr(info->str, "umask=");
> -	if (str)
> -		sscanf(str, "umask=%x", &umask);
> -
> -	if (event == 0 && *config == (event | umask << 8))
> -		return 1;
> -
> -	return 0;
> -}
> -
>  bool arch_is_topdown_metrics(const struct evsel *evsel)
>  {
> -	struct perf_pmu *pmu = evsel__find_pmu(evsel);
>  	int config = evsel->core.attr.config;
> +	const char *name_from_config;
> +	struct perf_pmu *pmu;
>  
> -	if (!pmu || !pmu->is_core)
> +	/* All topdown events have an event code of 0. */
> +	if ((config & 0xFF) != 0)
>  		return false;
>  
> -	if (perf_pmu__for_each_event(pmu, false, &config,
> -				     compare_topdown_event))
> -		return true;
> +	pmu = evsel__find_pmu(evsel);
> +	if (!pmu || !pmu->is_core)
> +		return false;
>  
> -	return false;
> +	name_from_config = perf_pmu__name_from_config(pmu, config);
> +	return name_from_config && strcasestr(name_from_config, "topdown");
>  }
>  
>  /*
> -- 
> 2.40.1
> 

  reply	other threads:[~2024-10-16 17:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-11 11:02 [PATCH 1/2] perf x86/topdown: Make topdown metrics comparators be symmetric Dapeng Mi
2024-10-11 11:02 ` [PATCH 2/2] perf x86/topdown: Refine helper arch_is_topdown_metrics() Dapeng Mi
2024-10-16 17:37   ` Namhyung Kim [this message]
2024-10-16 17:55     ` Ian Rogers
2024-10-16 17:56 ` [PATCH 1/2] perf x86/topdown: Make topdown metrics comparators be symmetric Ian Rogers
2024-10-17 16:39 ` Namhyung Kim

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=Zw_56b61Ik7UFekS@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dapeng1.mi@intel.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=irogers@google.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --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