diff mbox series

[v4,08/10] drivers/perf: hisi: Export associated CPUs of each PMU through sysfs

Message ID 20241203125049.39458-9-yangyicong@huawei.com (mailing list archive)
State New
Headers show
Series Refactor the common parts to the HiSilicon Uncore PMU core and cleanups | expand

Commit Message

Yicong Yang Dec. 3, 2024, 12:50 p.m. UTC
From: Yicong Yang <yangyicong@hisilicon.com>

Although the event of the uncore PMU can only be opened on a single
CPU, some PMU does have the affinity on a range of CPUs. For example
the L3C PMU is associated to the CPUs sharing the L3T it monitors.
Users may infer this affinity by the PMU name which may have SCCL ID
and CCL ID encoded (for L3C etc), but it's not that straightforward.
So export this information by adding an "associated_cpus" sysfs
attribute then user can get this directly.

Reviewed-by: Jonathan Cameron <Joanthan.Cameron@huawei.com>
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
 Documentation/admin-guide/perf/hisi-pmu.rst |  5 ++++-
 drivers/perf/hisilicon/hisi_uncore_pmu.c    | 10 ++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

Comments

Will Deacon Dec. 9, 2024, 3:48 p.m. UTC | #1
On Tue, Dec 03, 2024 at 08:50:47PM +0800, Yicong Yang wrote:
> From: Yicong Yang <yangyicong@hisilicon.com>
> 
> Although the event of the uncore PMU can only be opened on a single
> CPU, some PMU does have the affinity on a range of CPUs. For example
> the L3C PMU is associated to the CPUs sharing the L3T it monitors.
> Users may infer this affinity by the PMU name which may have SCCL ID
> and CCL ID encoded (for L3C etc), but it's not that straightforward.
> So export this information by adding an "associated_cpus" sysfs
> attribute then user can get this directly.
> 
> Reviewed-by: Jonathan Cameron <Joanthan.Cameron@huawei.com>
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
> ---
>  Documentation/admin-guide/perf/hisi-pmu.rst |  5 ++++-
>  drivers/perf/hisilicon/hisi_uncore_pmu.c    | 10 ++++++++++
>  2 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/admin-guide/perf/hisi-pmu.rst b/Documentation/admin-guide/perf/hisi-pmu.rst
> index 5cc248d18c63..48992a0b8e94 100644
> --- a/Documentation/admin-guide/perf/hisi-pmu.rst
> +++ b/Documentation/admin-guide/perf/hisi-pmu.rst
> @@ -35,7 +35,10 @@ e.g. hisi_sccl1_hha0/rx_operations is RX_OPERATIONS event of HHA index #0 in
>  SCCL ID #1.
>  
>  The driver also provides a "cpumask" sysfs attribute, which shows the CPU core
> -ID used to count the uncore PMU event.
> +ID used to count the uncore PMU event. An "associated_cpus" sysfs attribute is
> +also provided to show the CPUs associated with this PMU. The "cpumask" indicates
> +the CPUs to open the events, usually as a hint for userspaces tools like perf.
> +It only contains one associated CPU from the "associated_cpus".

What is userspace expected to do with this information? Can you point me
to patches that add the corresponding support to the 'perf' tool, please?

Will
Yicong Yang Dec. 10, 2024, 10:49 a.m. UTC | #2
On 2024/12/9 23:48, Will Deacon wrote:
> On Tue, Dec 03, 2024 at 08:50:47PM +0800, Yicong Yang wrote:
>> From: Yicong Yang <yangyicong@hisilicon.com>
>>
>> Although the event of the uncore PMU can only be opened on a single
>> CPU, some PMU does have the affinity on a range of CPUs. For example
>> the L3C PMU is associated to the CPUs sharing the L3T it monitors.
>> Users may infer this affinity by the PMU name which may have SCCL ID
>> and CCL ID encoded (for L3C etc), but it's not that straightforward.
>> So export this information by adding an "associated_cpus" sysfs
>> attribute then user can get this directly.
>>
>> Reviewed-by: Jonathan Cameron <Joanthan.Cameron@huawei.com>
>> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
>> ---
>>  Documentation/admin-guide/perf/hisi-pmu.rst |  5 ++++-
>>  drivers/perf/hisilicon/hisi_uncore_pmu.c    | 10 ++++++++++
>>  2 files changed, 14 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/admin-guide/perf/hisi-pmu.rst b/Documentation/admin-guide/perf/hisi-pmu.rst
>> index 5cc248d18c63..48992a0b8e94 100644
>> --- a/Documentation/admin-guide/perf/hisi-pmu.rst
>> +++ b/Documentation/admin-guide/perf/hisi-pmu.rst
>> @@ -35,7 +35,10 @@ e.g. hisi_sccl1_hha0/rx_operations is RX_OPERATIONS event of HHA index #0 in
>>  SCCL ID #1.
>>  
>>  The driver also provides a "cpumask" sysfs attribute, which shows the CPU core
>> -ID used to count the uncore PMU event.
>> +ID used to count the uncore PMU event. An "associated_cpus" sysfs attribute is
>> +also provided to show the CPUs associated with this PMU. The "cpumask" indicates
>> +the CPUs to open the events, usually as a hint for userspaces tools like perf.
>> +It only contains one associated CPU from the "associated_cpus".
> 
> What is userspace expected to do with this information? Can you point me
> to patches that add the corresponding support to the 'perf' tool, please?
> 

two attributes here, "cpumask" and "associated_cpus". For "cpumask" it's used in
perf [1], this patch does no change to this attribute but only update the
description in the doc.

I think you're questioning about the "associated_cpus" introduced by this patch,
which is not intended to be used by the perf tools but provides a hint for the
user to know the CPUs monitored by which uncore PMU, for example which uncore
L3C PMU's monitoring the events by the CPU(s) the application's running on, or
if the counts is imbalanced among the L3C PMUs user can figure out what's running
on the CPUs provided by the "associated_cpus". As described in the commit this
can also inferred by the PMU name to map SICL ID and CCL ID to certain CPU cluster,
but these ID's aren't readable enough and it'll be more straightforward and
friendly to provide an "associated_cpus" information, considering we've already
maintain it in the drvier.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/pmu.c?h=v6.13-rc2#n748

Thanks.
Will Deacon Dec. 10, 2024, 11:39 a.m. UTC | #3
On Tue, Dec 10, 2024 at 06:49:15PM +0800, Yicong Yang wrote:
> On 2024/12/9 23:48, Will Deacon wrote:
> > On Tue, Dec 03, 2024 at 08:50:47PM +0800, Yicong Yang wrote:
> >> From: Yicong Yang <yangyicong@hisilicon.com>
> >>
> >> Although the event of the uncore PMU can only be opened on a single
> >> CPU, some PMU does have the affinity on a range of CPUs. For example
> >> the L3C PMU is associated to the CPUs sharing the L3T it monitors.
> >> Users may infer this affinity by the PMU name which may have SCCL ID
> >> and CCL ID encoded (for L3C etc), but it's not that straightforward.
> >> So export this information by adding an "associated_cpus" sysfs
> >> attribute then user can get this directly.
> >>
> >> Reviewed-by: Jonathan Cameron <Joanthan.Cameron@huawei.com>
> >> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
> >> ---
> >>  Documentation/admin-guide/perf/hisi-pmu.rst |  5 ++++-
> >>  drivers/perf/hisilicon/hisi_uncore_pmu.c    | 10 ++++++++++
> >>  2 files changed, 14 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/Documentation/admin-guide/perf/hisi-pmu.rst b/Documentation/admin-guide/perf/hisi-pmu.rst
> >> index 5cc248d18c63..48992a0b8e94 100644
> >> --- a/Documentation/admin-guide/perf/hisi-pmu.rst
> >> +++ b/Documentation/admin-guide/perf/hisi-pmu.rst
> >> @@ -35,7 +35,10 @@ e.g. hisi_sccl1_hha0/rx_operations is RX_OPERATIONS event of HHA index #0 in
> >>  SCCL ID #1.
> >>  
> >>  The driver also provides a "cpumask" sysfs attribute, which shows the CPU core
> >> -ID used to count the uncore PMU event.
> >> +ID used to count the uncore PMU event. An "associated_cpus" sysfs attribute is
> >> +also provided to show the CPUs associated with this PMU. The "cpumask" indicates
> >> +the CPUs to open the events, usually as a hint for userspaces tools like perf.
> >> +It only contains one associated CPU from the "associated_cpus".
> > 
> > What is userspace expected to do with this information? Can you point me
> > to patches that add the corresponding support to the 'perf' tool, please?
> > 
> 
> two attributes here, "cpumask" and "associated_cpus". For "cpumask" it's used in
> perf [1], this patch does no change to this attribute but only update the
> description in the doc.
> 
> I think you're questioning about the "associated_cpus" introduced by this patch,
> which is not intended to be used by the perf tools but provides a hint for the
> user to know the CPUs monitored by which uncore PMU, for example which uncore
> L3C PMU's monitoring the events by the CPU(s) the application's running on, or
> if the counts is imbalanced among the L3C PMUs user can figure out what's running
> on the CPUs provided by the "associated_cpus". As described in the commit this
> can also inferred by the PMU name to map SICL ID and CCL ID to certain CPU cluster,
> but these ID's aren't readable enough and it'll be more straightforward and
> friendly to provide an "associated_cpus" information, considering we've already
> maintain it in the drvier.

Bah. I just noticed that there's precedent for this in the Arm CSPMU driver,
so I don't really have a leg to stand on despite my objections to funneling
firmware information through to userspace without a confirmed user.

Will
Yicong Yang Dec. 10, 2024, 1:02 p.m. UTC | #4
On 2024/12/10 19:39, Will Deacon wrote:
> On Tue, Dec 10, 2024 at 06:49:15PM +0800, Yicong Yang wrote:
>> On 2024/12/9 23:48, Will Deacon wrote:
>>> On Tue, Dec 03, 2024 at 08:50:47PM +0800, Yicong Yang wrote:
>>>> From: Yicong Yang <yangyicong@hisilicon.com>
>>>>
>>>> Although the event of the uncore PMU can only be opened on a single
>>>> CPU, some PMU does have the affinity on a range of CPUs. For example
>>>> the L3C PMU is associated to the CPUs sharing the L3T it monitors.
>>>> Users may infer this affinity by the PMU name which may have SCCL ID
>>>> and CCL ID encoded (for L3C etc), but it's not that straightforward.
>>>> So export this information by adding an "associated_cpus" sysfs
>>>> attribute then user can get this directly.
>>>>
>>>> Reviewed-by: Jonathan Cameron <Joanthan.Cameron@huawei.com>
>>>> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
>>>> ---
>>>>  Documentation/admin-guide/perf/hisi-pmu.rst |  5 ++++-
>>>>  drivers/perf/hisilicon/hisi_uncore_pmu.c    | 10 ++++++++++
>>>>  2 files changed, 14 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/Documentation/admin-guide/perf/hisi-pmu.rst b/Documentation/admin-guide/perf/hisi-pmu.rst
>>>> index 5cc248d18c63..48992a0b8e94 100644
>>>> --- a/Documentation/admin-guide/perf/hisi-pmu.rst
>>>> +++ b/Documentation/admin-guide/perf/hisi-pmu.rst
>>>> @@ -35,7 +35,10 @@ e.g. hisi_sccl1_hha0/rx_operations is RX_OPERATIONS event of HHA index #0 in
>>>>  SCCL ID #1.
>>>>  
>>>>  The driver also provides a "cpumask" sysfs attribute, which shows the CPU core
>>>> -ID used to count the uncore PMU event.
>>>> +ID used to count the uncore PMU event. An "associated_cpus" sysfs attribute is
>>>> +also provided to show the CPUs associated with this PMU. The "cpumask" indicates
>>>> +the CPUs to open the events, usually as a hint for userspaces tools like perf.
>>>> +It only contains one associated CPU from the "associated_cpus".
>>>
>>> What is userspace expected to do with this information? Can you point me
>>> to patches that add the corresponding support to the 'perf' tool, please?
>>>
>>
>> two attributes here, "cpumask" and "associated_cpus". For "cpumask" it's used in
>> perf [1], this patch does no change to this attribute but only update the
>> description in the doc.
>>
>> I think you're questioning about the "associated_cpus" introduced by this patch,
>> which is not intended to be used by the perf tools but provides a hint for the
>> user to know the CPUs monitored by which uncore PMU, for example which uncore
>> L3C PMU's monitoring the events by the CPU(s) the application's running on, or
>> if the counts is imbalanced among the L3C PMUs user can figure out what's running
>> on the CPUs provided by the "associated_cpus". As described in the commit this
>> can also inferred by the PMU name to map SICL ID and CCL ID to certain CPU cluster,
>> but these ID's aren't readable enough and it'll be more straightforward and
>> friendly to provide an "associated_cpus" information, considering we've already
>> maintain it in the drvier.
> 
> Bah. I just noticed that there's precedent for this in the Arm CSPMU driver,
> so I don't really have a leg to stand on despite my objections to funneling
> firmware information through to userspace without a confirmed user.
> 

it's bit complex to identify the uncore PMU in the system for better usage
of monitoring or performance analyzing since there are many instances like L3C
and DDRC PMU in the system. So this maybe an easier and cheaper way for the
user to map the PMU to the CPUs where interested tasks' running on without
much knowledge/documentation of the platform specific information like ID
mapping which may varies from different products.

Thanks.
diff mbox series

Patch

diff --git a/Documentation/admin-guide/perf/hisi-pmu.rst b/Documentation/admin-guide/perf/hisi-pmu.rst
index 5cc248d18c63..48992a0b8e94 100644
--- a/Documentation/admin-guide/perf/hisi-pmu.rst
+++ b/Documentation/admin-guide/perf/hisi-pmu.rst
@@ -35,7 +35,10 @@  e.g. hisi_sccl1_hha0/rx_operations is RX_OPERATIONS event of HHA index #0 in
 SCCL ID #1.
 
 The driver also provides a "cpumask" sysfs attribute, which shows the CPU core
-ID used to count the uncore PMU event.
+ID used to count the uncore PMU event. An "associated_cpus" sysfs attribute is
+also provided to show the CPUs associated with this PMU. The "cpumask" indicates
+the CPUs to open the events, usually as a hint for userspaces tools like perf.
+It only contains one associated CPU from the "associated_cpus".
 
 Example usage of perf::
 
diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
index 339e346e94ee..f86aba567224 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
+++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
@@ -51,8 +51,18 @@  EXPORT_SYMBOL_NS_GPL(hisi_cpumask_sysfs_show, HISI_PMU);
 
 static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL);
 
+static ssize_t hisi_associated_cpus_sysfs_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	struct hisi_pmu *hisi_pmu = to_hisi_pmu(dev_get_drvdata(dev));
+
+	return cpumap_print_to_pagebuf(true, buf, &hisi_pmu->associated_cpus);
+}
+static DEVICE_ATTR(associated_cpus, 0444, hisi_associated_cpus_sysfs_show, NULL);
+
 static struct attribute *hisi_pmu_cpumask_attrs[] = {
 	&dev_attr_cpumask.attr,
+	&dev_attr_associated_cpus.attr,
 	NULL
 };