[PATCH v4 02/14] perf evsel: Refactor evsel__set_config_if_unset() arguments

James Clark posted 14 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH v4 02/14] perf evsel: Refactor evsel__set_config_if_unset() arguments
Posted by James Clark 1 month, 2 weeks ago
Make the evsel argument first to match the other evsel__* functions
and remove the redundant pmu argument, which can be accessed via evsel.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/arch/arm/util/cs-etm.c    | 9 +++------
 tools/perf/arch/arm64/util/arm-spe.c | 2 +-
 tools/perf/arch/x86/util/intel-pt.c  | 3 +--
 tools/perf/util/evsel.h              | 4 ++--
 tools/perf/util/pmu.c                | 6 +++---
 5 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index ea891d12f8f4..c28208361d91 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -441,10 +441,8 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
 	 * when a context switch happened.
 	 */
 	if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) {
-		evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
-					   "timestamp", 1);
-		evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
-					   "contextid", 1);
+		evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1);
+		evsel__set_config_if_unset(cs_etm_evsel, "contextid", 1);
 	}
 
 	/*
@@ -453,8 +451,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
 	 * timestamp tracing.
 	 */
 	if (opts->sample_time_set)
-		evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
-					   "timestamp", 1);
+		evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1);
 
 	/* Add dummy event to keep tracking */
 	err = parse_event(evlist, "dummy:u");
diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index d5ec1408d0ae..51014f8bff97 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -274,7 +274,7 @@ static void arm_spe_setup_evsel(struct evsel *evsel, struct perf_cpu_map *cpus)
 	 */
 	if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) {
 		evsel__set_sample_bit(evsel, CPU);
-		evsel__set_config_if_unset(evsel->pmu, evsel, "ts_enable", 1);
+		evsel__set_config_if_unset(evsel, "ts_enable", 1);
 	}
 
 	/*
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index b394ad9cc635..c131a727774f 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -664,8 +664,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
 		return 0;
 
 	if (opts->auxtrace_sample_mode)
-		evsel__set_config_if_unset(intel_pt_pmu, intel_pt_evsel,
-					   "psb_period", 0);
+		evsel__set_config_if_unset(intel_pt_evsel, "psb_period", 0);
 
 	err = intel_pt_validate_config(intel_pt_pmu, intel_pt_evsel);
 	if (err)
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index a08130ff2e47..2cf87bc67df7 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -575,8 +575,8 @@ void evsel__uniquify_counter(struct evsel *counter);
 	((((src) >> (pos)) & ((1ull << (size)) - 1)) << (63 - ((pos) + (size) - 1)))
 
 u64 evsel__bitfield_swap_branch_flags(u64 value);
-void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel,
-				const char *config_name, u64 val);
+void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,
+				u64 val);
 
 bool evsel__is_offcpu_event(struct evsel *evsel);
 
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 956ea273c2c7..e87c12946d71 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1382,8 +1382,8 @@ bool evsel__is_aux_event(const struct evsel *evsel)
  * something to true, pass 1 for val rather than a pre shifted value.
  */
 #define field_prep(_mask, _val) (((_val) << (ffsll(_mask) - 1)) & (_mask))
-void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel,
-				const char *config_name, u64 val)
+void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,
+				u64 val)
 {
 	u64 user_bits = 0, bits;
 	struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG);
@@ -1391,7 +1391,7 @@ void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel,
 	if (term)
 		user_bits = term->val.cfg_chg;
 
-	bits = perf_pmu__format_bits(pmu, config_name);
+	bits = perf_pmu__format_bits(evsel->pmu, config_name);
 
 	/* Do nothing if the user changed the value */
 	if (bits & user_bits)

-- 
2.34.1
Re: [PATCH v4 02/14] perf evsel: Refactor evsel__set_config_if_unset() arguments
Posted by Arnaldo Carvalho de Melo 3 weeks, 5 days ago
On Mon, Dec 22, 2025 at 03:14:27PM +0000, James Clark wrote:
> Make the evsel argument first to match the other evsel__* functions
> and remove the redundant pmu argument, which can be accessed via evsel.

I haven't checked if this is the exactly where this takes place but
should be in this series, 32-bit build is broken:

   3: almalinux:9-i386WARNING: image platform (linux/386) does not match the expected platform (linux/amd64)
WARNING: image platform (linux/386) does not match the expected platform (linux/amd64)
    21.72 almalinux:9-i386              : FAIL gcc version 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC)
     1378 |         perf_pmu__format_pack(&bits, val, vp, /*zero=*/true);
          |                               ^~~~~
          |                               |
          |                               u64 * {aka long long unsigned int *}
    In file included from util/evsel.h:14,
                     from util/evsel.c:38:
    util/pmu.h:282:43: note: expected ‘long unsigned int *’ but argument is of type ‘u64 *’ {aka ‘long long unsigned int *’}
      282 | void perf_pmu__format_pack(unsigned long *format, __u64 value, __u64 *v,
          |                            ~~~~~~~~~~~~~~~^~~~~~


What I have is in perf-tools-next/tmp.perf-tools-next BTW, I'll try and
fix this tomorrow if you don't do it first. :-)

There are some more build problems in other containers/distros, I'll be
reporting as replies to the patches that looks related

- Arnaldo
 
> Signed-off-by: James Clark <james.clark@linaro.org>
> ---
>  tools/perf/arch/arm/util/cs-etm.c    | 9 +++------
>  tools/perf/arch/arm64/util/arm-spe.c | 2 +-
>  tools/perf/arch/x86/util/intel-pt.c  | 3 +--
>  tools/perf/util/evsel.h              | 4 ++--
>  tools/perf/util/pmu.c                | 6 +++---
>  5 files changed, 10 insertions(+), 14 deletions(-)
> 
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index ea891d12f8f4..c28208361d91 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -441,10 +441,8 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
>  	 * when a context switch happened.
>  	 */
>  	if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) {
> -		evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
> -					   "timestamp", 1);
> -		evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
> -					   "contextid", 1);
> +		evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1);
> +		evsel__set_config_if_unset(cs_etm_evsel, "contextid", 1);
>  	}
>  
>  	/*
> @@ -453,8 +451,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
>  	 * timestamp tracing.
>  	 */
>  	if (opts->sample_time_set)
> -		evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
> -					   "timestamp", 1);
> +		evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1);
>  
>  	/* Add dummy event to keep tracking */
>  	err = parse_event(evlist, "dummy:u");
> diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
> index d5ec1408d0ae..51014f8bff97 100644
> --- a/tools/perf/arch/arm64/util/arm-spe.c
> +++ b/tools/perf/arch/arm64/util/arm-spe.c
> @@ -274,7 +274,7 @@ static void arm_spe_setup_evsel(struct evsel *evsel, struct perf_cpu_map *cpus)
>  	 */
>  	if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) {
>  		evsel__set_sample_bit(evsel, CPU);
> -		evsel__set_config_if_unset(evsel->pmu, evsel, "ts_enable", 1);
> +		evsel__set_config_if_unset(evsel, "ts_enable", 1);
>  	}
>  
>  	/*
> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
> index b394ad9cc635..c131a727774f 100644
> --- a/tools/perf/arch/x86/util/intel-pt.c
> +++ b/tools/perf/arch/x86/util/intel-pt.c
> @@ -664,8 +664,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
>  		return 0;
>  
>  	if (opts->auxtrace_sample_mode)
> -		evsel__set_config_if_unset(intel_pt_pmu, intel_pt_evsel,
> -					   "psb_period", 0);
> +		evsel__set_config_if_unset(intel_pt_evsel, "psb_period", 0);
>  
>  	err = intel_pt_validate_config(intel_pt_pmu, intel_pt_evsel);
>  	if (err)
> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> index a08130ff2e47..2cf87bc67df7 100644
> --- a/tools/perf/util/evsel.h
> +++ b/tools/perf/util/evsel.h
> @@ -575,8 +575,8 @@ void evsel__uniquify_counter(struct evsel *counter);
>  	((((src) >> (pos)) & ((1ull << (size)) - 1)) << (63 - ((pos) + (size) - 1)))
>  
>  u64 evsel__bitfield_swap_branch_flags(u64 value);
> -void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel,
> -				const char *config_name, u64 val);
> +void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,
> +				u64 val);
>  
>  bool evsel__is_offcpu_event(struct evsel *evsel);
>  
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 956ea273c2c7..e87c12946d71 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -1382,8 +1382,8 @@ bool evsel__is_aux_event(const struct evsel *evsel)
>   * something to true, pass 1 for val rather than a pre shifted value.
>   */
>  #define field_prep(_mask, _val) (((_val) << (ffsll(_mask) - 1)) & (_mask))
> -void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel,
> -				const char *config_name, u64 val)
> +void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,
> +				u64 val)
>  {
>  	u64 user_bits = 0, bits;
>  	struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG);
> @@ -1391,7 +1391,7 @@ void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel,
>  	if (term)
>  		user_bits = term->val.cfg_chg;
>  
> -	bits = perf_pmu__format_bits(pmu, config_name);
> +	bits = perf_pmu__format_bits(evsel->pmu, config_name);
>  
>  	/* Do nothing if the user changed the value */
>  	if (bits & user_bits)
> 
> -- 
> 2.34.1
> 
Re: [PATCH v4 02/14] perf evsel: Refactor evsel__set_config_if_unset() arguments
Posted by James Clark 3 weeks, 5 days ago

On 13/01/2026 10:13 pm, Arnaldo Carvalho de Melo wrote:
> On Mon, Dec 22, 2025 at 03:14:27PM +0000, James Clark wrote:
>> Make the evsel argument first to match the other evsel__* functions
>> and remove the redundant pmu argument, which can be accessed via evsel.
> 
> I haven't checked if this is the exactly where this takes place but
> should be in this series, 32-bit build is broken:
> 
>     3: almalinux:9-i386WARNING: image platform (linux/386) does not match the expected platform (linux/amd64)
> WARNING: image platform (linux/386) does not match the expected platform (linux/amd64)
>      21.72 almalinux:9-i386              : FAIL gcc version 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC)
>       1378 |         perf_pmu__format_pack(&bits, val, vp, /*zero=*/true);
>            |                               ^~~~~
>            |                               |
>            |                               u64 * {aka long long unsigned int *}
>      In file included from util/evsel.h:14,
>                       from util/evsel.c:38:
>      util/pmu.h:282:43: note: expected ‘long unsigned int *’ but argument is of type ‘u64 *’ {aka ‘long long unsigned int *’}
>        282 | void perf_pmu__format_pack(unsigned long *format, __u64 value, __u64 *v,
>            |                            ~~~~~~~~~~~~~~~^~~~~~
> 
> 
> What I have is in perf-tools-next/tmp.perf-tools-next BTW, I'll try and
> fix this tomorrow if you don't do it first. :-)

Taking a look, but I'm wondering if this is already not working 
properly. There are existing "unsigned long"s in pmu.c that operate on 
the config bits which is what I copied.

On this target an unsigned long is 32bits but struct 
perf_event_attr->configs are __u64. So it looks like it might leave the 
top bits unset sometimes.

I'll look at a fix for that which should fix the compilation error at 
the same time.

Another question is, do we actually care about this platform?

> 
> There are some more build problems in other containers/distros, I'll be
> reporting as replies to the patches that looks related
> 
> - Arnaldo
>   
>> Signed-off-by: James Clark <james.clark@linaro.org>
>> ---
>>   tools/perf/arch/arm/util/cs-etm.c    | 9 +++------
>>   tools/perf/arch/arm64/util/arm-spe.c | 2 +-
>>   tools/perf/arch/x86/util/intel-pt.c  | 3 +--
>>   tools/perf/util/evsel.h              | 4 ++--
>>   tools/perf/util/pmu.c                | 6 +++---
>>   5 files changed, 10 insertions(+), 14 deletions(-)
>>
>> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
>> index ea891d12f8f4..c28208361d91 100644
>> --- a/tools/perf/arch/arm/util/cs-etm.c
>> +++ b/tools/perf/arch/arm/util/cs-etm.c
>> @@ -441,10 +441,8 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
>>   	 * when a context switch happened.
>>   	 */
>>   	if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) {
>> -		evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
>> -					   "timestamp", 1);
>> -		evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
>> -					   "contextid", 1);
>> +		evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1);
>> +		evsel__set_config_if_unset(cs_etm_evsel, "contextid", 1);
>>   	}
>>   
>>   	/*
>> @@ -453,8 +451,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
>>   	 * timestamp tracing.
>>   	 */
>>   	if (opts->sample_time_set)
>> -		evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
>> -					   "timestamp", 1);
>> +		evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1);
>>   
>>   	/* Add dummy event to keep tracking */
>>   	err = parse_event(evlist, "dummy:u");
>> diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
>> index d5ec1408d0ae..51014f8bff97 100644
>> --- a/tools/perf/arch/arm64/util/arm-spe.c
>> +++ b/tools/perf/arch/arm64/util/arm-spe.c
>> @@ -274,7 +274,7 @@ static void arm_spe_setup_evsel(struct evsel *evsel, struct perf_cpu_map *cpus)
>>   	 */
>>   	if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) {
>>   		evsel__set_sample_bit(evsel, CPU);
>> -		evsel__set_config_if_unset(evsel->pmu, evsel, "ts_enable", 1);
>> +		evsel__set_config_if_unset(evsel, "ts_enable", 1);
>>   	}
>>   
>>   	/*
>> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
>> index b394ad9cc635..c131a727774f 100644
>> --- a/tools/perf/arch/x86/util/intel-pt.c
>> +++ b/tools/perf/arch/x86/util/intel-pt.c
>> @@ -664,8 +664,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
>>   		return 0;
>>   
>>   	if (opts->auxtrace_sample_mode)
>> -		evsel__set_config_if_unset(intel_pt_pmu, intel_pt_evsel,
>> -					   "psb_period", 0);
>> +		evsel__set_config_if_unset(intel_pt_evsel, "psb_period", 0);
>>   
>>   	err = intel_pt_validate_config(intel_pt_pmu, intel_pt_evsel);
>>   	if (err)
>> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
>> index a08130ff2e47..2cf87bc67df7 100644
>> --- a/tools/perf/util/evsel.h
>> +++ b/tools/perf/util/evsel.h
>> @@ -575,8 +575,8 @@ void evsel__uniquify_counter(struct evsel *counter);
>>   	((((src) >> (pos)) & ((1ull << (size)) - 1)) << (63 - ((pos) + (size) - 1)))
>>   
>>   u64 evsel__bitfield_swap_branch_flags(u64 value);
>> -void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel,
>> -				const char *config_name, u64 val);
>> +void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,
>> +				u64 val);
>>   
>>   bool evsel__is_offcpu_event(struct evsel *evsel);
>>   
>> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
>> index 956ea273c2c7..e87c12946d71 100644
>> --- a/tools/perf/util/pmu.c
>> +++ b/tools/perf/util/pmu.c
>> @@ -1382,8 +1382,8 @@ bool evsel__is_aux_event(const struct evsel *evsel)
>>    * something to true, pass 1 for val rather than a pre shifted value.
>>    */
>>   #define field_prep(_mask, _val) (((_val) << (ffsll(_mask) - 1)) & (_mask))
>> -void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel,
>> -				const char *config_name, u64 val)
>> +void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,
>> +				u64 val)
>>   {
>>   	u64 user_bits = 0, bits;
>>   	struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG);
>> @@ -1391,7 +1391,7 @@ void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel,
>>   	if (term)
>>   		user_bits = term->val.cfg_chg;
>>   
>> -	bits = perf_pmu__format_bits(pmu, config_name);
>> +	bits = perf_pmu__format_bits(evsel->pmu, config_name);
>>   
>>   	/* Do nothing if the user changed the value */
>>   	if (bits & user_bits)
>>
>> -- 
>> 2.34.1
>>

Re: [PATCH v4 02/14] perf evsel: Refactor evsel__set_config_if_unset() arguments
Posted by Arnaldo Carvalho de Melo 3 weeks, 5 days ago
On Wed, Jan 14, 2026 at 12:14:43PM +0000, James Clark wrote:
> On 13/01/2026 10:13 pm, Arnaldo Carvalho de Melo wrote:
> > On Mon, Dec 22, 2025 at 03:14:27PM +0000, James Clark wrote:
> > > Make the evsel argument first to match the other evsel__* functions
> > > and remove the redundant pmu argument, which can be accessed via evsel.

> > I haven't checked if this is the exactly where this takes place but
> > should be in this series, 32-bit build is broken:

> >     3: almalinux:9-i386WARNING: image platform (linux/386) does not match the expected platform (linux/amd64)
> > WARNING: image platform (linux/386) does not match the expected platform (linux/amd64)
> >      21.72 almalinux:9-i386              : FAIL gcc version 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC)
> >       1378 |         perf_pmu__format_pack(&bits, val, vp, /*zero=*/true);
> >            |                               ^~~~~
> >            |                               |
> >            |                               u64 * {aka long long unsigned int *}
> >      In file included from util/evsel.h:14,
> >                       from util/evsel.c:38:
> >      util/pmu.h:282:43: note: expected ‘long unsigned int *’ but argument is of type ‘u64 *’ {aka ‘long long unsigned int *’}
> >        282 | void perf_pmu__format_pack(unsigned long *format, __u64 value, __u64 *v,
> >            |                            ~~~~~~~~~~~~~~~^~~~~~
 
> > What I have is in perf-tools-next/tmp.perf-tools-next BTW, I'll try and
> > fix this tomorrow if you don't do it first. :-)
 
> Taking a look, but I'm wondering if this is already not working properly.
> There are existing "unsigned long"s in pmu.c that operate on the config bits
> which is what I copied.
 
> On this target an unsigned long is 32bits but struct
> perf_event_attr->configs are __u64. So it looks like it might leave the top
> bits unset sometimes.
 
> I'll look at a fix for that which should fix the compilation error at the
> same time.
 
> Another question is, do we actually care about this platform?

It failed for other 32-bit platforms too, so the question is if we care
about 32-bit at all.

- Arnaldo
Re: [PATCH v4 02/14] perf evsel: Refactor evsel__set_config_if_unset() arguments
Posted by James Clark 3 weeks, 5 days ago

On 14/01/2026 3:47 pm, Arnaldo Carvalho de Melo wrote:
> On Wed, Jan 14, 2026 at 12:14:43PM +0000, James Clark wrote:
>> On 13/01/2026 10:13 pm, Arnaldo Carvalho de Melo wrote:
>>> On Mon, Dec 22, 2025 at 03:14:27PM +0000, James Clark wrote:
>>>> Make the evsel argument first to match the other evsel__* functions
>>>> and remove the redundant pmu argument, which can be accessed via evsel.
> 
>>> I haven't checked if this is the exactly where this takes place but
>>> should be in this series, 32-bit build is broken:
> 
>>>      3: almalinux:9-i386WARNING: image platform (linux/386) does not match the expected platform (linux/amd64)
>>> WARNING: image platform (linux/386) does not match the expected platform (linux/amd64)
>>>       21.72 almalinux:9-i386              : FAIL gcc version 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC)
>>>        1378 |         perf_pmu__format_pack(&bits, val, vp, /*zero=*/true);
>>>             |                               ^~~~~
>>>             |                               |
>>>             |                               u64 * {aka long long unsigned int *}
>>>       In file included from util/evsel.h:14,
>>>                        from util/evsel.c:38:
>>>       util/pmu.h:282:43: note: expected ‘long unsigned int *’ but argument is of type ‘u64 *’ {aka ‘long long unsigned int *’}
>>>         282 | void perf_pmu__format_pack(unsigned long *format, __u64 value, __u64 *v,
>>>             |                            ~~~~~~~~~~~~~~~^~~~~~
>   
>>> What I have is in perf-tools-next/tmp.perf-tools-next BTW, I'll try and
>>> fix this tomorrow if you don't do it first. :-)
>   
>> Taking a look, but I'm wondering if this is already not working properly.
>> There are existing "unsigned long"s in pmu.c that operate on the config bits
>> which is what I copied.
>   
>> On this target an unsigned long is 32bits but struct
>> perf_event_attr->configs are __u64. So it looks like it might leave the top
>> bits unset sometimes.
>   
>> I'll look at a fix for that which should fix the compilation error at the
>> same time.
>   
>> Another question is, do we actually care about this platform?
> 
> It failed for other 32-bit platforms too, so the question is if we care
> about 32-bit at all.
> 
> - Arnaldo

I suppose the answer is we still do then.

I sent another version. A couple of patches were changed a bit where I 
used more bitfields instead of converting to u64s which was probably the 
right thing to do regardless of the build issue.

Re: [PATCH v4 02/14] perf evsel: Refactor evsel__set_config_if_unset() arguments
Posted by James Clark 3 weeks, 5 days ago

On 14/01/2026 12:14 pm, James Clark wrote:
> 
> 
> On 13/01/2026 10:13 pm, Arnaldo Carvalho de Melo wrote:
>> On Mon, Dec 22, 2025 at 03:14:27PM +0000, James Clark wrote:
>>> Make the evsel argument first to match the other evsel__* functions
>>> and remove the redundant pmu argument, which can be accessed via evsel.
>>
>> I haven't checked if this is the exactly where this takes place but
>> should be in this series, 32-bit build is broken:
>>
>>     3: almalinux:9-i386WARNING: image platform (linux/386) does not 
>> match the expected platform (linux/amd64)
>> WARNING: image platform (linux/386) does not match the expected 
>> platform (linux/amd64)
>>      21.72 almalinux:9-i386              : FAIL gcc version 11.4.1 
>> 20231218 (Red Hat 11.4.1-3) (GCC)
>>       1378 |         perf_pmu__format_pack(&bits, val, vp, /*zero=*/ 
>> true);
>>            |                               ^~~~~
>>            |                               |
>>            |                               u64 * {aka long long 
>> unsigned int *}
>>      In file included from util/evsel.h:14,
>>                       from util/evsel.c:38:
>>      util/pmu.h:282:43: note: expected ‘long unsigned int *’ but 
>> argument is of type ‘u64 *’ {aka ‘long long unsigned int *’}
>>        282 | void perf_pmu__format_pack(unsigned long *format, __u64 
>> value, __u64 *v,
>>            |                            ~~~~~~~~~~~~~~~^~~~~~
>>
>>
>> What I have is in perf-tools-next/tmp.perf-tools-next BTW, I'll try and
>> fix this tomorrow if you don't do it first. :-)
> 
> Taking a look, but I'm wondering if this is already not working 
> properly. There are existing "unsigned long"s in pmu.c that operate on 
> the config bits which is what I copied.
> 
> On this target an unsigned long is 32bits but struct perf_event_attr- 
>  >configs are __u64. So it looks like it might leave the top bits unset 
> sometimes.
> 
> I'll look at a fix for that which should fix the compilation error at 
> the same time.

False alarm, I was confusing a pointer to a single unsigned long with 
what are actually DECLARE_BITMAP()s. So they're two longs in this case 
for 64 bits.

I'll send a fix for the compilation issue and double check the patches 
to make sure that misunderstanding hasn't caused any issues.

> 
> Another question is, do we actually care about this platform?
> 
>>
>> There are some more build problems in other containers/distros, I'll be
>> reporting as replies to the patches that looks related
>>
>> - Arnaldo
>>> Signed-off-by: James Clark <james.clark@linaro.org>
>>> ---
>>>   tools/perf/arch/arm/util/cs-etm.c    | 9 +++------
>>>   tools/perf/arch/arm64/util/arm-spe.c | 2 +-
>>>   tools/perf/arch/x86/util/intel-pt.c  | 3 +--
>>>   tools/perf/util/evsel.h              | 4 ++--
>>>   tools/perf/util/pmu.c                | 6 +++---
>>>   5 files changed, 10 insertions(+), 14 deletions(-)
>>>
>>> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/ 
>>> util/cs-etm.c
>>> index ea891d12f8f4..c28208361d91 100644
>>> --- a/tools/perf/arch/arm/util/cs-etm.c
>>> +++ b/tools/perf/arch/arm/util/cs-etm.c
>>> @@ -441,10 +441,8 @@ static int cs_etm_recording_options(struct 
>>> auxtrace_record *itr,
>>>        * when a context switch happened.
>>>        */
>>>       if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) {
>>> -        evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
>>> -                       "timestamp", 1);
>>> -        evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
>>> -                       "contextid", 1);
>>> +        evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1);
>>> +        evsel__set_config_if_unset(cs_etm_evsel, "contextid", 1);
>>>       }
>>>       /*
>>> @@ -453,8 +451,7 @@ static int cs_etm_recording_options(struct 
>>> auxtrace_record *itr,
>>>        * timestamp tracing.
>>>        */
>>>       if (opts->sample_time_set)
>>> -        evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel,
>>> -                       "timestamp", 1);
>>> +        evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1);
>>>       /* Add dummy event to keep tracking */
>>>       err = parse_event(evlist, "dummy:u");
>>> diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/ 
>>> arm64/util/arm-spe.c
>>> index d5ec1408d0ae..51014f8bff97 100644
>>> --- a/tools/perf/arch/arm64/util/arm-spe.c
>>> +++ b/tools/perf/arch/arm64/util/arm-spe.c
>>> @@ -274,7 +274,7 @@ static void arm_spe_setup_evsel(struct evsel 
>>> *evsel, struct perf_cpu_map *cpus)
>>>        */
>>>       if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) {
>>>           evsel__set_sample_bit(evsel, CPU);
>>> -        evsel__set_config_if_unset(evsel->pmu, evsel, "ts_enable", 1);
>>> +        evsel__set_config_if_unset(evsel, "ts_enable", 1);
>>>       }
>>>       /*
>>> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/ 
>>> x86/util/intel-pt.c
>>> index b394ad9cc635..c131a727774f 100644
>>> --- a/tools/perf/arch/x86/util/intel-pt.c
>>> +++ b/tools/perf/arch/x86/util/intel-pt.c
>>> @@ -664,8 +664,7 @@ static int intel_pt_recording_options(struct 
>>> auxtrace_record *itr,
>>>           return 0;
>>>       if (opts->auxtrace_sample_mode)
>>> -        evsel__set_config_if_unset(intel_pt_pmu, intel_pt_evsel,
>>> -                       "psb_period", 0);
>>> +        evsel__set_config_if_unset(intel_pt_evsel, "psb_period", 0);
>>>       err = intel_pt_validate_config(intel_pt_pmu, intel_pt_evsel);
>>>       if (err)
>>> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
>>> index a08130ff2e47..2cf87bc67df7 100644
>>> --- a/tools/perf/util/evsel.h
>>> +++ b/tools/perf/util/evsel.h
>>> @@ -575,8 +575,8 @@ void evsel__uniquify_counter(struct evsel *counter);
>>>       ((((src) >> (pos)) & ((1ull << (size)) - 1)) << (63 - ((pos) + 
>>> (size) - 1)))
>>>   u64 evsel__bitfield_swap_branch_flags(u64 value);
>>> -void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel 
>>> *evsel,
>>> -                const char *config_name, u64 val);
>>> +void evsel__set_config_if_unset(struct evsel *evsel, const char 
>>> *config_name,
>>> +                u64 val);
>>>   bool evsel__is_offcpu_event(struct evsel *evsel);
>>> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
>>> index 956ea273c2c7..e87c12946d71 100644
>>> --- a/tools/perf/util/pmu.c
>>> +++ b/tools/perf/util/pmu.c
>>> @@ -1382,8 +1382,8 @@ bool evsel__is_aux_event(const struct evsel 
>>> *evsel)
>>>    * something to true, pass 1 for val rather than a pre shifted value.
>>>    */
>>>   #define field_prep(_mask, _val) (((_val) << (ffsll(_mask) - 1)) & 
>>> (_mask))
>>> -void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel 
>>> *evsel,
>>> -                const char *config_name, u64 val)
>>> +void evsel__set_config_if_unset(struct evsel *evsel, const char 
>>> *config_name,
>>> +                u64 val)
>>>   {
>>>       u64 user_bits = 0, bits;
>>>       struct evsel_config_term *term = evsel__get_config_term(evsel, 
>>> CFG_CHG);
>>> @@ -1391,7 +1391,7 @@ void evsel__set_config_if_unset(struct perf_pmu 
>>> *pmu, struct evsel *evsel,
>>>       if (term)
>>>           user_bits = term->val.cfg_chg;
>>> -    bits = perf_pmu__format_bits(pmu, config_name);
>>> +    bits = perf_pmu__format_bits(evsel->pmu, config_name);
>>>       /* Do nothing if the user changed the value */
>>>       if (bits & user_bits)
>>>
>>> -- 
>>> 2.34.1
>>>
>