linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: James Clark <james.clark@linaro.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Howard Chu <howardchu95@gmail.com>,
	Thomas Falcon <thomas.falcon@intel.com>,
	Chun-Tse Shao <ctshao@google.com>,
	Dapeng Mi <dapeng1.mi@linux.intel.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] perf stat: Move create_perf_stat_counter to builtin-stat
Date: Fri, 3 Oct 2025 12:31:11 +0100	[thread overview]
Message-ID: <640baace-99c7-435e-a754-a46a49c32deb@linaro.org> (raw)
In-Reply-To: <20251002220727.1889799-1-irogers@google.com>



On 02/10/2025 11:07 pm, Ian Rogers wrote:
> The function create_perf_stat_counter is only used in builtin-stat.c
> and contains logic about retrying events specific to
> builtin-stat.c. Move the code to builtin-stat to tidy this up.
> 
> Signed-off-by: Ian Rogers <irogers@google.com>

Reviewed-by: James Clark <james.clark@linaro.org>

> ---
>   tools/perf/builtin-stat.c | 60 +++++++++++++++++++++++++++++++++++++--
>   tools/perf/util/stat.c    | 56 ------------------------------------
>   tools/perf/util/stat.h    |  4 ---
>   3 files changed, 58 insertions(+), 62 deletions(-)
> 
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index ab567919b89a..75b9979c6c05 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -676,6 +676,62 @@ static enum counter_recovery stat_handle_error(struct evsel *counter, int err)
>   	return COUNTER_FATAL;
>   }
>   
> +static int create_perf_stat_counter(struct evsel *evsel,
> +				    struct perf_stat_config *config,
> +				    int cpu_map_idx)
> +{
> +	struct perf_event_attr *attr = &evsel->core.attr;
> +	struct evsel *leader = evsel__leader(evsel);
> +
> +	/* Reset supported flag as creating a stat counter is retried. */
> +	attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
> +			    PERF_FORMAT_TOTAL_TIME_RUNNING;
> +
> +	/*
> +	 * The event is part of non trivial group, let's enable
> +	 * the group read (for leader) and ID retrieval for all
> +	 * members.
> +	 */
> +	if (leader->core.nr_members > 1)
> +		attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP;
> +
> +	attr->inherit = !config->no_inherit && list_empty(&evsel->bpf_counter_list);
> +
> +	/*
> +	 * Some events get initialized with sample_(period/type) set,
> +	 * like tracepoints. Clear it up for counting.
> +	 */
> +	attr->sample_period = 0;
> +
> +	if (config->identifier)
> +		attr->sample_type = PERF_SAMPLE_IDENTIFIER;
> +
> +	if (config->all_user) {
> +		attr->exclude_kernel = 1;
> +		attr->exclude_user   = 0;
> +	}
> +
> +	if (config->all_kernel) {
> +		attr->exclude_kernel = 0;
> +		attr->exclude_user   = 1;
> +	}
> +
> +	/*
> +	 * Disabling all counters initially, they will be enabled
> +	 * either manually by us or by kernel via enable_on_exec
> +	 * set later.
> +	 */
> +	if (evsel__is_group_leader(evsel)) {
> +		attr->disabled = 1;
> +
> +		if (target__enable_on_exec(&target))
> +			attr->enable_on_exec = 1;
> +	}
> +
> +	return evsel__open_per_cpu_and_thread(evsel, evsel__cpus(evsel), cpu_map_idx,
> +					      evsel->core.threads);
> +}
> +
>   static int __run_perf_stat(int argc, const char **argv, int run_idx)
>   {
>   	int interval = stat_config.interval;
> @@ -736,7 +792,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
>   		if (evsel__is_bperf(counter))
>   			continue;
>   try_again:
> -		if (create_perf_stat_counter(counter, &stat_config, &target,
> +		if (create_perf_stat_counter(counter, &stat_config,
>   					     evlist_cpu_itr.cpu_map_idx) < 0) {
>   
>   			/*
> @@ -794,7 +850,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
>   				continue;
>   try_again_reset:
>   			pr_debug2("reopening weak %s\n", evsel__name(counter));
> -			if (create_perf_stat_counter(counter, &stat_config, &target,
> +			if (create_perf_stat_counter(counter, &stat_config,
>   						     evlist_cpu_itr.cpu_map_idx) < 0) {
>   
>   				switch (stat_handle_error(counter, errno)) {
> diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
> index 50b1a92d16df..101ed6c497bc 100644
> --- a/tools/perf/util/stat.c
> +++ b/tools/perf/util/stat.c
> @@ -716,59 +716,3 @@ size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp)
>   
>   	return ret;
>   }
> -
> -int create_perf_stat_counter(struct evsel *evsel,
> -			     struct perf_stat_config *config,
> -			     struct target *target,
> -			     int cpu_map_idx)
> -{
> -	struct perf_event_attr *attr = &evsel->core.attr;
> -	struct evsel *leader = evsel__leader(evsel);
> -
> -	attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
> -			    PERF_FORMAT_TOTAL_TIME_RUNNING;
> -
> -	/*
> -	 * The event is part of non trivial group, let's enable
> -	 * the group read (for leader) and ID retrieval for all
> -	 * members.
> -	 */
> -	if (leader->core.nr_members > 1)
> -		attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP;
> -
> -	attr->inherit = !config->no_inherit && list_empty(&evsel->bpf_counter_list);
> -
> -	/*
> -	 * Some events get initialized with sample_(period/type) set,
> -	 * like tracepoints. Clear it up for counting.
> -	 */
> -	attr->sample_period = 0;
> -
> -	if (config->identifier)
> -		attr->sample_type = PERF_SAMPLE_IDENTIFIER;
> -
> -	if (config->all_user) {
> -		attr->exclude_kernel = 1;
> -		attr->exclude_user   = 0;
> -	}
> -
> -	if (config->all_kernel) {
> -		attr->exclude_kernel = 0;
> -		attr->exclude_user   = 1;
> -	}
> -
> -	/*
> -	 * Disabling all counters initially, they will be enabled
> -	 * either manually by us or by kernel via enable_on_exec
> -	 * set later.
> -	 */
> -	if (evsel__is_group_leader(evsel)) {
> -		attr->disabled = 1;
> -
> -		if (target__enable_on_exec(target))
> -			attr->enable_on_exec = 1;
> -	}
> -
> -	return evsel__open_per_cpu_and_thread(evsel, evsel__cpus(evsel), cpu_map_idx,
> -					      evsel->core.threads);
> -}
> diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
> index 4b0f14ae4e5f..34f30a295f89 100644
> --- a/tools/perf/util/stat.h
> +++ b/tools/perf/util/stat.h
> @@ -223,10 +223,6 @@ size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
>   size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
>   size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
>   
> -int create_perf_stat_counter(struct evsel *evsel,
> -			     struct perf_stat_config *config,
> -			     struct target *target,
> -			     int cpu_map_idx);
>   void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *config,
>   			    struct target *_target, struct timespec *ts, int argc, const char **argv);
>   


      parent reply	other threads:[~2025-10-03 11:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-02 22:07 [PATCH v2 1/2] perf stat: Move create_perf_stat_counter to builtin-stat Ian Rogers
2025-10-02 22:07 ` [PATCH v2 2/2] perf stat: Refactor retry/skip/fatal error handling Ian Rogers
2025-10-03 12:03   ` James Clark
2025-10-03 19:08     ` Arnaldo Carvalho de Melo
2025-10-03 22:10       ` Ian Rogers
2025-10-03 11:31 ` James Clark [this message]

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=640baace-99c7-435e-a754-a46a49c32deb@linaro.org \
    --to=james.clark@linaro.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ctshao@google.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=howardchu95@gmail.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=thomas.falcon@intel.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;
as well as URLs for NNTP newsgroup(s).