* [PATCH v1 1/6] perf header: Replace hardcoded max cpus by MAX_NR_CPUS
2026-01-27 18:49 [PATCH v1 0/6] perf sched stats: Fixes and improvements Swapnil Sapkal
@ 2026-01-27 18:49 ` Swapnil Sapkal
2026-01-28 7:39 ` Shrikanth Hegde
2026-01-27 18:49 ` [PATCH v1 2/6] perf util: Fix NULL check in cpumask_to_cpulist() Swapnil Sapkal
` (5 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Swapnil Sapkal @ 2026-01-27 18:49 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, irogers, james.clark
Cc: mark.rutland, alexander.shishkin, jolsa, adrian.hunter,
thomas.falcon, ashelat, yu.c.chen, sshegde, gautham.shenoy,
ravi.bangoria, swapnil.sapkal, linux-kernel, linux-perf-users
cpumask and cpulist from cpu-domain header have hardcoded max_cpus value
of 1024. Current systems have more cpus than this value. Replace it with
MAX_NR_CPUS. Also define a macro to represent domain name length.
Fixes: d40c68a49f69 ("perf header: Support CPU DOMAIN relation info")
Reported-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
---
| 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index eefd1cd73b6a..31c3bab1b10a 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -76,6 +76,7 @@ static const u64 __perf_magic2 = 0x32454c4946524550ULL;
static const u64 __perf_magic2_sw = 0x50455246494c4532ULL;
#define PERF_MAGIC __perf_magic2
+#define DNAME_LEN 16
const char perf_version_string[] = PERF_VERSION;
@@ -1616,10 +1617,10 @@ static int write_pmu_caps(struct feat_fd *ff,
struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *max_sched_domains, u32 nr)
{
+ char dname[DNAME_LEN], cpumask[MAX_NR_CPUS];
struct domain_info *domain_info;
struct cpu_domain_map **cd_map;
- char dname[16], cpumask[256];
- char cpulist[1024];
+ char cpulist[MAX_NR_CPUS];
char *line = NULL;
u32 cpu, domain;
u32 dcount = 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v1 1/6] perf header: Replace hardcoded max cpus by MAX_NR_CPUS
2026-01-27 18:49 ` [PATCH v1 1/6] perf header: Replace hardcoded max cpus by MAX_NR_CPUS Swapnil Sapkal
@ 2026-01-28 7:39 ` Shrikanth Hegde
2026-01-28 16:25 ` Swapnil Sapkal
0 siblings, 1 reply; 13+ messages in thread
From: Shrikanth Hegde @ 2026-01-28 7:39 UTC (permalink / raw)
To: Swapnil Sapkal
Cc: mark.rutland, alexander.shishkin, jolsa, adrian.hunter,
thomas.falcon, ashelat, yu.c.chen, gautham.shenoy, ravi.bangoria,
linux-kernel, linux-perf-users, peterz, mingo, acme, namhyung,
irogers, james.clark
On 1/28/26 12:19 AM, Swapnil Sapkal wrote:
> cpumask and cpulist from cpu-domain header have hardcoded max_cpus value
> of 1024. Current systems have more cpus than this value. Replace it with
> MAX_NR_CPUS. Also define a macro to represent domain name length.
>
> Fixes: d40c68a49f69 ("perf header: Support CPU DOMAIN relation info")
> Reported-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
> ---
> tools/perf/util/header.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index eefd1cd73b6a..31c3bab1b10a 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -76,6 +76,7 @@ static const u64 __perf_magic2 = 0x32454c4946524550ULL;
> static const u64 __perf_magic2_sw = 0x50455246494c4532ULL;
>
> #define PERF_MAGIC __perf_magic2
> +#define DNAME_LEN 16
>
> const char perf_version_string[] = PERF_VERSION;
>
> @@ -1616,10 +1617,10 @@ static int write_pmu_caps(struct feat_fd *ff,
>
> struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *max_sched_domains, u32 nr)
> {
> + char dname[DNAME_LEN], cpumask[MAX_NR_CPUS];
> struct domain_info *domain_info;
> struct cpu_domain_map **cd_map;
> - char dname[16], cpumask[256];
> - char cpulist[1024];
> + char cpulist[MAX_NR_CPUS];
> char *line = NULL;
> u32 cpu, domain;
> u32 dcount = 0;
Looking at
https://lore.kernel.org/all/20260119175833.340369-3-swapnil.sapkal@amd.com/
There was one more "char cpus[1024]" in tools/perf/util/util.c.
You may need to fix that too. It is unlikely but, if one has created exclusive
cpusets comprising of only one cpu from a core, maybe you will run out the length.
So better use the MAX_NR_CPUS there as well.
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v1 1/6] perf header: Replace hardcoded max cpus by MAX_NR_CPUS
2026-01-28 7:39 ` Shrikanth Hegde
@ 2026-01-28 16:25 ` Swapnil Sapkal
2026-01-28 18:13 ` Arnaldo Carvalho de Melo
2026-01-28 18:15 ` Arnaldo Carvalho de Melo
0 siblings, 2 replies; 13+ messages in thread
From: Swapnil Sapkal @ 2026-01-28 16:25 UTC (permalink / raw)
To: Shrikanth Hegde, acme
Cc: mark.rutland, alexander.shishkin, jolsa, adrian.hunter,
thomas.falcon, ashelat, yu.c.chen, gautham.shenoy, ravi.bangoria,
linux-kernel, linux-perf-users, peterz, mingo, namhyung, irogers,
james.clark
Hi Srikanth, Arnaldo,
Thank you for reviewing the patches.
On 28-01-2026 13:09, Shrikanth Hegde wrote:
>
>
> On 1/28/26 12:19 AM, Swapnil Sapkal wrote:
>> cpumask and cpulist from cpu-domain header have hardcoded max_cpus value
>> of 1024. Current systems have more cpus than this value. Replace it with
>> MAX_NR_CPUS. Also define a macro to represent domain name length.
>>
>> Fixes: d40c68a49f69 ("perf header: Support CPU DOMAIN relation info")
>> Reported-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>> Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
>> ---
>> tools/perf/util/header.c | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
>> index eefd1cd73b6a..31c3bab1b10a 100644
>> --- a/tools/perf/util/header.c
>> +++ b/tools/perf/util/header.c
>> @@ -76,6 +76,7 @@ static const u64 __perf_magic2 =
>> 0x32454c4946524550ULL;
>> static const u64 __perf_magic2_sw = 0x50455246494c4532ULL;
>> #define PERF_MAGIC __perf_magic2
>> +#define DNAME_LEN 16
>> const char perf_version_string[] = PERF_VERSION;
>> @@ -1616,10 +1617,10 @@ static int write_pmu_caps(struct feat_fd *ff,
>> struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version,
>> u32 *max_sched_domains, u32 nr)
>> {
>> + char dname[DNAME_LEN], cpumask[MAX_NR_CPUS];
>> struct domain_info *domain_info;
>> struct cpu_domain_map **cd_map;
>> - char dname[16], cpumask[256];
>> - char cpulist[1024];
>> + char cpulist[MAX_NR_CPUS];
>> char *line = NULL;
>> u32 cpu, domain;
>> u32 dcount = 0;
>
> Looking at
> https://lore.kernel.org/all/20260119175833.340369-3-swapnil.sapkal@amd.com/
>
> There was one more "char cpus[1024]" in tools/perf/util/util.c.
> You may need to fix that too. It is unlikely but, if one has created
> exclusive
> cpusets comprising of only one cpu from a core, maybe you will run out
> the length.
> So better use the MAX_NR_CPUS there as well.
Yes, I missed this.
Arnaldo, can you please consider the below diff? Let me know if you'd
like me to respin the patch.
--
Thanks and Regards,
Swapnil
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index c83e59e8c787..3795d5182ce8 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -262,7 +262,7 @@ void cpumask_to_cpulist(char *cpumask, char *cpulist)
int i, j, bm_size, nbits;
int len = strlen(cpumask);
unsigned long *bm;
- char cpus[1024];
+ char cpus[MAX_NR_CPUS];
for (i = 0; i < len; i++) {
if (cpumask[i] == ',') {
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 394dbfa944ac..c43f17137efd 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -6,6 +6,7 @@
/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
#define _DEFAULT_SOURCE 1
+#include "perf.h"
#include <dirent.h>
#include <fcntl.h>
#include <stdbool.h>
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v1 1/6] perf header: Replace hardcoded max cpus by MAX_NR_CPUS
2026-01-28 16:25 ` Swapnil Sapkal
@ 2026-01-28 18:13 ` Arnaldo Carvalho de Melo
2026-01-28 18:15 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-28 18:13 UTC (permalink / raw)
To: Swapnil Sapkal
Cc: Shrikanth Hegde, mark.rutland, alexander.shishkin, jolsa,
adrian.hunter, thomas.falcon, ashelat, yu.c.chen, gautham.shenoy,
ravi.bangoria, linux-kernel, linux-perf-users, peterz, mingo,
namhyung, irogers, james.clark
On Wed, Jan 28, 2026 at 09:55:05PM +0530, Swapnil Sapkal wrote:
> Hi Srikanth, Arnaldo,
>
> Thank you for reviewing the patches.
>
> On 28-01-2026 13:09, Shrikanth Hegde wrote:
> >
> >
> > On 1/28/26 12:19 AM, Swapnil Sapkal wrote:
> > > cpumask and cpulist from cpu-domain header have hardcoded max_cpus value
> > > of 1024. Current systems have more cpus than this value. Replace it with
> > > MAX_NR_CPUS. Also define a macro to represent domain name length.
> > >
> > > Fixes: d40c68a49f69 ("perf header: Support CPU DOMAIN relation info")
> > > Reported-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> > > Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
> > > ---
> > > tools/perf/util/header.c | 5 +++--
> > > 1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> > > index eefd1cd73b6a..31c3bab1b10a 100644
> > > --- a/tools/perf/util/header.c
> > > +++ b/tools/perf/util/header.c
> > > @@ -76,6 +76,7 @@ static const u64 __perf_magic2 =
> > > 0x32454c4946524550ULL;
> > > static const u64 __perf_magic2_sw = 0x50455246494c4532ULL;
> > > #define PERF_MAGIC __perf_magic2
> > > +#define DNAME_LEN 16
> > > const char perf_version_string[] = PERF_VERSION;
> > > @@ -1616,10 +1617,10 @@ static int write_pmu_caps(struct feat_fd *ff,
> > > struct cpu_domain_map **build_cpu_domain_map(u32
> > > *schedstat_version, u32 *max_sched_domains, u32 nr)
> > > {
> > > + char dname[DNAME_LEN], cpumask[MAX_NR_CPUS];
> > > struct domain_info *domain_info;
> > > struct cpu_domain_map **cd_map;
> > > - char dname[16], cpumask[256];
> > > - char cpulist[1024];
> > > + char cpulist[MAX_NR_CPUS];
> > > char *line = NULL;
> > > u32 cpu, domain;
> > > u32 dcount = 0;
> >
> > Looking at
> > https://lore.kernel.org/all/20260119175833.340369-3-swapnil.sapkal@amd.com/
> >
> > There was one more "char cpus[1024]" in tools/perf/util/util.c.
> > You may need to fix that too. It is unlikely but, if one has created
> > exclusive
> > cpusets comprising of only one cpu from a core, maybe you will run out
> > the length.
> > So better use the MAX_NR_CPUS there as well.
>
> Yes, I missed this.
>
> Arnaldo, can you please consider the below diff? Let me know if you'd like
> me to respin the patch.
Sure, will add it.
- Arnaldo
> --
> Thanks and Regards,
> Swapnil
>
> diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
> index c83e59e8c787..3795d5182ce8 100644
> --- a/tools/perf/util/util.c
> +++ b/tools/perf/util/util.c
> @@ -262,7 +262,7 @@ void cpumask_to_cpulist(char *cpumask, char *cpulist)
> int i, j, bm_size, nbits;
> int len = strlen(cpumask);
> unsigned long *bm;
> - char cpus[1024];
> + char cpus[MAX_NR_CPUS];
>
> for (i = 0; i < len; i++) {
> if (cpumask[i] == ',') {
> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> index 394dbfa944ac..c43f17137efd 100644
> --- a/tools/perf/util/util.h
> +++ b/tools/perf/util/util.h
> @@ -6,6 +6,7 @@
> /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
> #define _DEFAULT_SOURCE 1
>
> +#include "perf.h"
> #include <dirent.h>
> #include <fcntl.h>
> #include <stdbool.h>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v1 1/6] perf header: Replace hardcoded max cpus by MAX_NR_CPUS
2026-01-28 16:25 ` Swapnil Sapkal
2026-01-28 18:13 ` Arnaldo Carvalho de Melo
@ 2026-01-28 18:15 ` Arnaldo Carvalho de Melo
2026-01-28 18:29 ` Swapnil Sapkal
1 sibling, 1 reply; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-28 18:15 UTC (permalink / raw)
To: Swapnil Sapkal
Cc: Shrikanth Hegde, mark.rutland, alexander.shishkin, jolsa,
adrian.hunter, thomas.falcon, ashelat, yu.c.chen, gautham.shenoy,
ravi.bangoria, linux-kernel, linux-perf-users, peterz, mingo,
namhyung, irogers, james.clark
On Wed, Jan 28, 2026 at 09:55:05PM +0530, Swapnil Sapkal wrote:
> Hi Srikanth, Arnaldo,
>
> Thank you for reviewing the patches.
>
> On 28-01-2026 13:09, Shrikanth Hegde wrote:
> >
> >
> > On 1/28/26 12:19 AM, Swapnil Sapkal wrote:
> > > cpumask and cpulist from cpu-domain header have hardcoded max_cpus value
> > > of 1024. Current systems have more cpus than this value. Replace it with
> > > MAX_NR_CPUS. Also define a macro to represent domain name length.
> > >
> > > Fixes: d40c68a49f69 ("perf header: Support CPU DOMAIN relation info")
> > > Reported-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> > > Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
> > > ---
> > > tools/perf/util/header.c | 5 +++--
> > > 1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> > > index eefd1cd73b6a..31c3bab1b10a 100644
> > > --- a/tools/perf/util/header.c
> > > +++ b/tools/perf/util/header.c
> > > @@ -76,6 +76,7 @@ static const u64 __perf_magic2 =
> > > 0x32454c4946524550ULL;
> > > static const u64 __perf_magic2_sw = 0x50455246494c4532ULL;
> > > #define PERF_MAGIC __perf_magic2
> > > +#define DNAME_LEN 16
> > > const char perf_version_string[] = PERF_VERSION;
> > > @@ -1616,10 +1617,10 @@ static int write_pmu_caps(struct feat_fd *ff,
> > > struct cpu_domain_map **build_cpu_domain_map(u32
> > > *schedstat_version, u32 *max_sched_domains, u32 nr)
> > > {
> > > + char dname[DNAME_LEN], cpumask[MAX_NR_CPUS];
> > > struct domain_info *domain_info;
> > > struct cpu_domain_map **cd_map;
> > > - char dname[16], cpumask[256];
> > > - char cpulist[1024];
> > > + char cpulist[MAX_NR_CPUS];
> > > char *line = NULL;
> > > u32 cpu, domain;
> > > u32 dcount = 0;
> >
> > Looking at
> > https://lore.kernel.org/all/20260119175833.340369-3-swapnil.sapkal@amd.com/
> >
> > There was one more "char cpus[1024]" in tools/perf/util/util.c.
> > You may need to fix that too. It is unlikely but, if one has created
> > exclusive
> > cpusets comprising of only one cpu from a core, maybe you will run out
> > the length.
> > So better use the MAX_NR_CPUS there as well.
>
> Yes, I missed this.
>
> Arnaldo, can you please consider the below diff? Let me know if you'd like
> me to respin the patch.
>
> --
> Thanks and Regards,
> Swapnil
>
> diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
> index c83e59e8c787..3795d5182ce8 100644
> --- a/tools/perf/util/util.c
> +++ b/tools/perf/util/util.c
> @@ -262,7 +262,7 @@ void cpumask_to_cpulist(char *cpumask, char *cpulist)
> int i, j, bm_size, nbits;
> int len = strlen(cpumask);
> unsigned long *bm;
> - char cpus[1024];
> + char cpus[MAX_NR_CPUS];
>
> for (i = 0; i < len; i++) {
> if (cpumask[i] == ',') {
> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> index 394dbfa944ac..c43f17137efd 100644
> --- a/tools/perf/util/util.h
> +++ b/tools/perf/util/util.h
> @@ -6,6 +6,7 @@
> /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
> #define _DEFAULT_SOURCE 1
>
> +#include "perf.h"
Why add it to util.h? I'll add it to where it is used, util.c, ok?
- Arnaldo
> #include <dirent.h>
> #include <fcntl.h>
> #include <stdbool.h>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v1 1/6] perf header: Replace hardcoded max cpus by MAX_NR_CPUS
2026-01-28 18:15 ` Arnaldo Carvalho de Melo
@ 2026-01-28 18:29 ` Swapnil Sapkal
0 siblings, 0 replies; 13+ messages in thread
From: Swapnil Sapkal @ 2026-01-28 18:29 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Shrikanth Hegde, mark.rutland, alexander.shishkin, jolsa,
adrian.hunter, thomas.falcon, ashelat, yu.c.chen, gautham.shenoy,
ravi.bangoria, linux-kernel, linux-perf-users, peterz, mingo,
namhyung, irogers, james.clark
Hello Arnaldo,
On 28-01-2026 23:45, Arnaldo Carvalho de Melo wrote:
> On Wed, Jan 28, 2026 at 09:55:05PM +0530, Swapnil Sapkal wrote:
>> Hi Srikanth, Arnaldo,
>>
>> Thank you for reviewing the patches.
>>
>> On 28-01-2026 13:09, Shrikanth Hegde wrote:
>>>
>>>
>>> On 1/28/26 12:19 AM, Swapnil Sapkal wrote:
>>>> cpumask and cpulist from cpu-domain header have hardcoded max_cpus value
>>>> of 1024. Current systems have more cpus than this value. Replace it with
>>>> MAX_NR_CPUS. Also define a macro to represent domain name length.
>>>>
>>>> Fixes: d40c68a49f69 ("perf header: Support CPU DOMAIN relation info")
>>>> Reported-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>>>> Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
>>>> ---
>>>> tools/perf/util/header.c | 5 +++--
>>>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
>>>> index eefd1cd73b6a..31c3bab1b10a 100644
>>>> --- a/tools/perf/util/header.c
>>>> +++ b/tools/perf/util/header.c
>>>> @@ -76,6 +76,7 @@ static const u64 __perf_magic2 =
>>>> 0x32454c4946524550ULL;
>>>> static const u64 __perf_magic2_sw = 0x50455246494c4532ULL;
>>>> #define PERF_MAGIC __perf_magic2
>>>> +#define DNAME_LEN 16
>>>> const char perf_version_string[] = PERF_VERSION;
>>>> @@ -1616,10 +1617,10 @@ static int write_pmu_caps(struct feat_fd *ff,
>>>> struct cpu_domain_map **build_cpu_domain_map(u32
>>>> *schedstat_version, u32 *max_sched_domains, u32 nr)
>>>> {
>>>> + char dname[DNAME_LEN], cpumask[MAX_NR_CPUS];
>>>> struct domain_info *domain_info;
>>>> struct cpu_domain_map **cd_map;
>>>> - char dname[16], cpumask[256];
>>>> - char cpulist[1024];
>>>> + char cpulist[MAX_NR_CPUS];
>>>> char *line = NULL;
>>>> u32 cpu, domain;
>>>> u32 dcount = 0;
>>>
>>> Looking at
>>> https://lore.kernel.org/all/20260119175833.340369-3-swapnil.sapkal@amd.com/
>>>
>>> There was one more "char cpus[1024]" in tools/perf/util/util.c.
>>> You may need to fix that too. It is unlikely but, if one has created
>>> exclusive
>>> cpusets comprising of only one cpu from a core, maybe you will run out
>>> the length.
>>> So better use the MAX_NR_CPUS there as well.
>>
>> Yes, I missed this.
>>
>> Arnaldo, can you please consider the below diff? Let me know if you'd like
>> me to respin the patch.
>>
>> --
>> Thanks and Regards,
>> Swapnil
>>
>> diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
>> index c83e59e8c787..3795d5182ce8 100644
>> --- a/tools/perf/util/util.c
>> +++ b/tools/perf/util/util.c
>> @@ -262,7 +262,7 @@ void cpumask_to_cpulist(char *cpumask, char *cpulist)
>> int i, j, bm_size, nbits;
>> int len = strlen(cpumask);
>> unsigned long *bm;
>> - char cpus[1024];
>> + char cpus[MAX_NR_CPUS];
>>
>> for (i = 0; i < len; i++) {
>> if (cpumask[i] == ',') {
>> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
>> index 394dbfa944ac..c43f17137efd 100644
>> --- a/tools/perf/util/util.h
>> +++ b/tools/perf/util/util.h
>> @@ -6,6 +6,7 @@
>> /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
>> #define _DEFAULT_SOURCE 1
>>
>> +#include "perf.h"
>
> Why add it to util.h? I'll add it to where it is used, util.c, ok?
>
This doesn't need to be in util.h. Please move it to util.c
--
Thanks and Regards,
Swapnil
> - Arnaldo
>
>> #include <dirent.h>
>> #include <fcntl.h>
>> #include <stdbool.h>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v1 2/6] perf util: Fix NULL check in cpumask_to_cpulist()
2026-01-27 18:49 [PATCH v1 0/6] perf sched stats: Fixes and improvements Swapnil Sapkal
2026-01-27 18:49 ` [PATCH v1 1/6] perf header: Replace hardcoded max cpus by MAX_NR_CPUS Swapnil Sapkal
@ 2026-01-27 18:49 ` Swapnil Sapkal
2026-01-27 18:49 ` [PATCH v1 3/6] perf sched stats: Add NULL check for cd_map Swapnil Sapkal
` (4 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Swapnil Sapkal @ 2026-01-27 18:49 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, irogers, james.clark
Cc: mark.rutland, alexander.shishkin, jolsa, adrian.hunter,
thomas.falcon, ashelat, yu.c.chen, sshegde, gautham.shenoy,
ravi.bangoria, swapnil.sapkal, linux-kernel, linux-perf-users
The function cpumask_to_cpulist() allocates memory with calloc() and
stores the result in 'bm', but then incorrectly checks 'cpumask' for
NULL instead of 'bm'. This means that if the allocation fails, the
function will dereference a NULL pointer when trying to access 'bm'.
Fix the check to test the correct variable 'bm'.
Fixes: d40c68a49f69 ("perf header: Support CPU DOMAIN relation info")
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
---
tools/perf/util/util.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 03a603fbcd7d..c83e59e8c787 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -278,7 +278,7 @@ void cpumask_to_cpulist(char *cpumask, char *cpulist)
return;
bm = calloc(bm_size, sizeof(unsigned long));
- if (!cpumask)
+ if (!bm)
goto free_bm;
for (i = 0; i < bm_size; i++) {
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v1 3/6] perf sched stats: Add NULL check for cd_map
2026-01-27 18:49 [PATCH v1 0/6] perf sched stats: Fixes and improvements Swapnil Sapkal
2026-01-27 18:49 ` [PATCH v1 1/6] perf header: Replace hardcoded max cpus by MAX_NR_CPUS Swapnil Sapkal
2026-01-27 18:49 ` [PATCH v1 2/6] perf util: Fix NULL check in cpumask_to_cpulist() Swapnil Sapkal
@ 2026-01-27 18:49 ` Swapnil Sapkal
2026-01-27 18:49 ` [PATCH v1 4/6] perf sched stats: correct spelling of function name Swapnil Sapkal
` (3 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Swapnil Sapkal @ 2026-01-27 18:49 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, irogers, james.clark
Cc: mark.rutland, alexander.shishkin, jolsa, adrian.hunter,
thomas.falcon, ashelat, yu.c.chen, sshegde, gautham.shenoy,
ravi.bangoria, swapnil.sapkal, linux-kernel, linux-perf-users
In perf_sched__schedstat_live(), build_cpu_domain_map() returns the
pointer to cpu_domain_map which can also be NULL. Add NULL check for the
same to avoid NULL pointer dereference.
Fixes: 00093b313398 ("perf sched stats: Add support for live mode")
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
---
tools/perf/builtin-sched.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index b190e928117c..f5e449bd6823 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -4714,6 +4714,11 @@ static int perf_sched__schedstat_live(struct perf_sched *sched,
nr = cpu__max_present_cpu().cpu;
cd_map = build_cpu_domain_map(&sv, &md, nr);
+ if (!cd_map) {
+ pr_err("Unable to generate cpu-domain relation info");
+ goto out;
+ }
+
show_schedstat_data(&cpu_head, cd_map, NULL, NULL, false);
free_cpu_domain_info(cd_map, sv, nr);
out:
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v1 4/6] perf sched stats: correct spelling of function name
2026-01-27 18:49 [PATCH v1 0/6] perf sched stats: Fixes and improvements Swapnil Sapkal
` (2 preceding siblings ...)
2026-01-27 18:49 ` [PATCH v1 3/6] perf sched stats: Add NULL check for cd_map Swapnil Sapkal
@ 2026-01-27 18:49 ` Swapnil Sapkal
2026-01-27 18:49 ` [PATCH v1 5/6] perf sched stats: Define macro for SEP_LEN Swapnil Sapkal
` (2 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Swapnil Sapkal @ 2026-01-27 18:49 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, irogers, james.clark
Cc: mark.rutland, alexander.shishkin, jolsa, adrian.hunter,
thomas.falcon, ashelat, yu.c.chen, sshegde, gautham.shenoy,
ravi.bangoria, swapnil.sapkal, linux-kernel, linux-perf-users
Replace store_schedtstat_cpu_diff() with store_schedstat_cpu_diff()
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
---
tools/perf/builtin-sched.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index f5e449bd6823..1a24c4869331 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -3946,7 +3946,7 @@ static struct schedstat_domain *domain_second_pass;
static bool after_workload_flag;
static bool verbose_field;
-static void store_schedtstat_cpu_diff(struct schedstat_cpu *after_workload)
+static void store_schedstat_cpu_diff(struct schedstat_cpu *after_workload)
{
struct perf_record_schedstat_cpu *before = cpu_second_pass->cpu_data;
struct perf_record_schedstat_cpu *after = after_workload->cpu_data;
@@ -4437,7 +4437,7 @@ static int perf_sched__process_schedstat(const struct perf_tool *tool __maybe_un
}
domain_second_pass = list_first_entry(&cpu_second_pass->domain_head,
struct schedstat_domain, domain_list);
- store_schedtstat_cpu_diff(temp);
+ store_schedstat_cpu_diff(temp);
}
} else if (event->header.type == PERF_RECORD_SCHEDSTAT_DOMAIN) {
struct schedstat_cpu *cpu_tail;
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v1 5/6] perf sched stats: Define macro for SEP_LEN
2026-01-27 18:49 [PATCH v1 0/6] perf sched stats: Fixes and improvements Swapnil Sapkal
` (3 preceding siblings ...)
2026-01-27 18:49 ` [PATCH v1 4/6] perf sched stats: correct spelling of function name Swapnil Sapkal
@ 2026-01-27 18:49 ` Swapnil Sapkal
2026-01-27 18:50 ` [PATCH v1 6/6] perf sched stats: Fixes in man page Swapnil Sapkal
2026-01-28 8:03 ` [PATCH v1 0/6] perf sched stats: Fixes and improvements Shrikanth Hegde
6 siblings, 0 replies; 13+ messages in thread
From: Swapnil Sapkal @ 2026-01-27 18:49 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, irogers, james.clark
Cc: mark.rutland, alexander.shishkin, jolsa, adrian.hunter,
thomas.falcon, ashelat, yu.c.chen, sshegde, gautham.shenoy,
ravi.bangoria, swapnil.sapkal, linux-kernel, linux-perf-users
Define a macro for separator length of the line in perf sched stats
report.
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
---
tools/perf/builtin-sched.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 1a24c4869331..3f509cfdd58c 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -55,6 +55,7 @@
#define SYM_LEN 129
#define MAX_PID 1024000
#define MAX_PRIO 140
+#define SEP_LEN 100
static const char *cpu_list;
static struct perf_cpu_map *user_requested_cpus;
@@ -3997,7 +3998,7 @@ static inline void print_cpu_stats(struct perf_record_schedstat_cpu *cs1,
"PCT_CHANGE1", "PCT_CHANGE2");
printf("\n");
- print_separator2(100, "", 0);
+ print_separator2(SEP_LEN, "", 0);
#define CALC_PCT(_x, _y) ((_y) ? ((double)(_x) / (_y)) * 100 : 0.0)
@@ -4047,8 +4048,8 @@ static inline void print_domain_stats(struct perf_record_schedstat_domain *ds1,
#define DOMAIN_CATEGORY(_desc) \
do { \
size_t _len = strlen(_desc); \
- size_t _pre_dash_cnt = (100 - _len) / 2; \
- size_t _post_dash_cnt = 100 - _len - _pre_dash_cnt; \
+ size_t _pre_dash_cnt = (SEP_LEN - _len) / 2; \
+ size_t _post_dash_cnt = SEP_LEN - _len - _pre_dash_cnt; \
print_separator2((int)_pre_dash_cnt, _desc, (int)_post_dash_cnt);\
} while (0)
@@ -4238,14 +4239,14 @@ static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map **
int ret = 0;
printf("Description\n");
- print_separator2(100, "", 0);
+ print_separator2(SEP_LEN, "", 0);
printf("%-30s-> %s\n", "DESC", "Description of the field");
printf("%-30s-> %s\n", "COUNT", "Value of the field");
printf("%-30s-> %s\n", "PCT_CHANGE", "Percent change with corresponding base value");
printf("%-30s-> %s\n", "AVG_JIFFIES",
"Avg time in jiffies between two consecutive occurrence of event");
- print_separator2(100, "", 0);
+ print_separator2(SEP_LEN, "", 0);
printf("\n");
printf("%-65s: ", "Time elapsed (in jiffies)");
@@ -4286,16 +4287,16 @@ static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map **
return -1;
}
- print_separator2(100, "", 0);
+ print_separator2(SEP_LEN, "", 0);
if (is_summary)
printf("CPU: <ALL CPUS SUMMARY>\n");
else
printf("CPU: %d\n", cs1->cpu);
- print_separator2(100, "", 0);
+ print_separator2(SEP_LEN, "", 0);
print_cpu_stats(cs1, cs2);
- print_separator2(100, "", 0);
+ print_separator2(SEP_LEN, "", 0);
list_for_each_entry(dptr1, &cptr1->domain_head, domain_list) {
struct domain_info *dinfo1 = NULL, *dinfo2 = NULL;
@@ -4329,9 +4330,9 @@ static int show_schedstat_data(struct list_head *head1, struct cpu_domain_map **
printf("%s\n", dinfo1->cpulist);
}
- print_separator2(100, "", 0);
+ print_separator2(SEP_LEN, "", 0);
print_domain_stats(ds1, ds2, jiffies1, jiffies2);
- print_separator2(100, "", 0);
+ print_separator2(SEP_LEN, "", 0);
if (dptr2)
dptr2 = list_next_entry(dptr2, domain_list);
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v1 6/6] perf sched stats: Fixes in man page
2026-01-27 18:49 [PATCH v1 0/6] perf sched stats: Fixes and improvements Swapnil Sapkal
` (4 preceding siblings ...)
2026-01-27 18:49 ` [PATCH v1 5/6] perf sched stats: Define macro for SEP_LEN Swapnil Sapkal
@ 2026-01-27 18:50 ` Swapnil Sapkal
2026-01-28 8:03 ` [PATCH v1 0/6] perf sched stats: Fixes and improvements Shrikanth Hegde
6 siblings, 0 replies; 13+ messages in thread
From: Swapnil Sapkal @ 2026-01-27 18:50 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, irogers, james.clark
Cc: mark.rutland, alexander.shishkin, jolsa, adrian.hunter,
thomas.falcon, ashelat, yu.c.chen, sshegde, gautham.shenoy,
ravi.bangoria, swapnil.sapkal, linux-kernel, linux-perf-users
Fix the incorrect description of the schedstats report. Also fix the
spelling errors in man page.
Fixes: 800af362d689 ("perf sched stats: Add details in man page")
Reported-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
---
tools/perf/Documentation/perf-sched.txt | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index 5bfb7bb6c633..4d9981609c04 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -86,7 +86,7 @@ There are several variants of 'perf sched':
exposed through the file ``/proc/schedstat``. These counters are enabled or disabled
via the sysctl governed by the file ``/proc/sys/kernel/sched_schedstats``. These
counters accounts for many scheduler events such as ``schedule()`` calls, load-balancing
- events, ``try_to_wakeup()`` call among others. This is useful in understading the
+ events, ``try_to_wakeup()`` call among others. This is useful in understanding the
scheduler behavior for the workload.
Note: The tool will not give correct results if there is topological reordering or
@@ -100,7 +100,7 @@ There are several variants of 'perf sched':
A detailed description of the schedstats can be found in the Kernel Documentation:
https://www.kernel.org/doc/html/latest/scheduler/sched-stats.html
- The result can be interprested as follows:
+ The result can be interpreted as follows:
The `perf sched stats report` starts with description of the columns present in
the report. These column names are given before cpu and domain stats to improve
@@ -116,7 +116,7 @@ There are several variants of 'perf sched':
Next is the total profiling time in terms of jiffies:
----------------------------------------------------------------------------------------------------
- Time elapsed (in jiffies) : 24537
+ Time elapsed (in jiffies) : 2323
----------------------------------------------------------------------------------------------------
Next is CPU scheduling statistics. These are simple diffs of /proc/schedstat CPU lines
@@ -210,7 +210,7 @@ There are several variants of 'perf sched':
While profiling was active, the load-balancer found 28490 times the load
needs to be balanced on a newly idle CPU 0. Following value encapsulated
- inside $ is average jiffies between two events (28490 / 24537 = 0.08).
+ inside $ is average jiffies between two events (2323 / 28490 = 0.08).
Next are active_load_balance() stats. alb did not trigger while the
profiling was active, hence it's all 0s.
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v1 0/6] perf sched stats: Fixes and improvements
2026-01-27 18:49 [PATCH v1 0/6] perf sched stats: Fixes and improvements Swapnil Sapkal
` (5 preceding siblings ...)
2026-01-27 18:50 ` [PATCH v1 6/6] perf sched stats: Fixes in man page Swapnil Sapkal
@ 2026-01-28 8:03 ` Shrikanth Hegde
6 siblings, 0 replies; 13+ messages in thread
From: Shrikanth Hegde @ 2026-01-28 8:03 UTC (permalink / raw)
To: Swapnil Sapkal
Cc: mark.rutland, alexander.shishkin, jolsa, adrian.hunter,
thomas.falcon, ashelat, yu.c.chen, gautham.shenoy, ravi.bangoria,
linux-kernel, linux-perf-users, peterz, mingo, acme, namhyung,
irogers, james.clark
On 1/28/26 12:19 AM, Swapnil Sapkal wrote:
> These patches contain fixes and improvements related to perf sched stats
> code. The series includes:
>
> * Bug fixes
> - Add NULL check for cd_map in perf sched stats to prevent potential
> NULL pointer dereference
> - Fix NULL check in cpumask_to_cpulist() in perf util
>
> * Code quality improvements:
> - Replace hardcoded max cpus value with MAX_NR_CPUS constant in perf
> header
> - Define SEP_LEN macro to replace magic number in perf sched stats
> - Correct spelling of function name in perf sched stats
>
> * Documentation:
> - Fix various issues in the perf sched stats man page
>
> Swapnil Sapkal (6):
> perf header: Replace hardcoded max cpus by MAX_NR_CPUS
> perf util: Fix NULL check in cpumask_to_cpulist()
> perf sched stats: Add NULL check for cd_map
> perf sched stats: correct spelling of function name
> perf sched stats: Define macro for SEP_LEN
> perf sched stats: Fixes in man page
>
> tools/perf/Documentation/perf-sched.txt | 8 +++----
> tools/perf/builtin-sched.c | 30 +++++++++++++++----------
> tools/perf/util/header.c | 5 +++--
> tools/perf/util/util.c | 2 +-
> 4 files changed, 26 insertions(+), 19 deletions(-)
>
Other than the comment in Patch 1/6, rest looks good to me.
For the series:
Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>
^ permalink raw reply [flat|nested] 13+ messages in thread