2021-06-08 03:34:59

by liuqi (BA)

[permalink] [raw]
Subject: [PATCH v3 0/9] drivers/perf: Use general macro to simplify event attributes

This patchset applies a general EVENT_ATTR_ID to simplify event
attributes in many PMU drivers.

Qi Liu (9):
perf: Add EVENT_ATTR_ID to simplify event attributes
drivers/perf: hisi: Simplify EVENT ATTR macro in HiSilicon PMU driver
drivers/perf: Simplify EVENT ATTR macro in SMMU PMU driver
drivers/perf: Simplify EVENT ATTR macro in qcom_l2_pmu.c
drivers/perf: Simplify EVENT ATTR macro in qcom_l3_pmu.c
drivers/perf: Simplify EVENT ATTR macro in xgene_pmu.c
drivers/perf: Simplify EVENT ATTR macro in fsl_imx8_ddr_perf.c
drivers/perf: Simpilfy EVENT ATTR macro in arm_dsu_pmu.c
arm64: perf: Simplify EVENT ATTR macro in perf_event.c

arch/arm64/kernel/perf_event.c | 5 +----
drivers/perf/arm_dsu_pmu.c | 2 +-
drivers/perf/arm_smmuv3_pmu.c | 7 ++-----
drivers/perf/fsl_imx8_ddr_perf.c | 7 ++-----
drivers/perf/hisilicon/hisi_uncore_pmu.c | 7 +++----
drivers/perf/hisilicon/hisi_uncore_pmu.h | 2 +-
drivers/perf/qcom_l2_pmu.c | 7 ++-----
drivers/perf/qcom_l3_pmu.c | 5 +----
drivers/perf/xgene_pmu.c | 11 ++++-------
include/linux/perf_event.h | 6 ++++++
10 files changed, 23 insertions(+), 36 deletions(-)

--
2.7.4


2021-06-08 03:36:09

by liuqi (BA)

[permalink] [raw]
Subject: [PATCH v3 3/9] drivers/perf: Simplify EVENT ATTR macro in SMMU PMU driver

Use common macro PMU_EVENT_ATTR_ID to simplify SMMU_EVENT_ATTR.

Cc: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>
Signed-off-by: Qi Liu <[email protected]>
---
drivers/perf/arm_smmuv3_pmu.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
index ff6fab4..da2ce30 100644
--- a/drivers/perf/arm_smmuv3_pmu.c
+++ b/drivers/perf/arm_smmuv3_pmu.c
@@ -509,11 +509,8 @@ static ssize_t smmu_pmu_event_show(struct device *dev,
return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
}

-#define SMMU_EVENT_ATTR(name, config) \
- (&((struct perf_pmu_events_attr) { \
- .attr = __ATTR(name, 0444, smmu_pmu_event_show, NULL), \
- .id = config, \
- }).attr.attr)
+#define SMMU_EVENT_ATTR(name, config) \
+ PMU_EVENT_ATTR_ID(name, smmu_pmu_event_show, config)

static struct attribute *smmu_pmu_events[] = {
SMMU_EVENT_ATTR(cycles, 0),
--
2.7.4

2021-06-08 03:36:27

by liuqi (BA)

[permalink] [raw]
Subject: [PATCH v3 1/9] perf: Add EVENT_ATTR_ID to simplify event attributes

Similar EVENT_ATTR macros are defined in many PMU drivers,
like HiSilicon PMU driver, Arm PMU driver, Arm SMMU PMU
driver. So add a generic macro to simplify code.

Cc: Peter Zijlstra <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Signed-off-by: Qi Liu <[email protected]>
---
include/linux/perf_event.h | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index f5a6a2f..2d510ad 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1576,6 +1576,12 @@ static struct perf_pmu_events_attr _var = { \
.event_str = _str, \
};

+#define PMU_EVENT_ATTR_ID(_name, _show, _id) \
+ (&((struct perf_pmu_events_attr[]) { \
+ { .attr = __ATTR(_name, 0444, _show, NULL), \
+ .id = _id, } \
+ })[0].attr.attr)
+
#define PMU_FORMAT_ATTR(_name, _format) \
static ssize_t \
_name##_show(struct device *dev, \
--
2.7.4

2021-06-08 03:36:29

by liuqi (BA)

[permalink] [raw]
Subject: [PATCH v3 4/9] drivers/perf: Simplify EVENT ATTR macro in qcom_l2_pmu.c

Use common macro PMU_EVENT_ATTR_ID to simplify L2CACHE_EVENT_ATTR.

Cc: Andy Gross <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>
Signed-off-by: Qi Liu <[email protected]>
---
drivers/perf/qcom_l2_pmu.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/perf/qcom_l2_pmu.c b/drivers/perf/qcom_l2_pmu.c
index fc54a80..2cf89de 100644
--- a/drivers/perf/qcom_l2_pmu.c
+++ b/drivers/perf/qcom_l2_pmu.c
@@ -679,11 +679,8 @@ static ssize_t l2cache_pmu_event_show(struct device *dev,
return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
}

-#define L2CACHE_EVENT_ATTR(_name, _id) \
- (&((struct perf_pmu_events_attr[]) { \
- { .attr = __ATTR(_name, 0444, l2cache_pmu_event_show, NULL), \
- .id = _id, } \
- })[0].attr.attr)
+#define L2CACHE_EVENT_ATTR(_name, _id) \
+ PMU_EVENT_ATTR_ID(_name, l2cache_pmu_event_show, _id)

static struct attribute *l2_cache_pmu_events[] = {
L2CACHE_EVENT_ATTR(cycles, L2_EVENT_CYCLES),
--
2.7.4

2021-06-08 03:36:59

by liuqi (BA)

[permalink] [raw]
Subject: [PATCH v3 2/9] drivers/perf: hisi: Simplify EVENT ATTR macro in HiSilicon PMU driver

Use common macro PMU_EVENT_ATTR_ID to simplify HISI_PMU_EVENT_ATTR.

Cc: Shaokun Zhang <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>
Signed-off-by: Qi Liu <[email protected]>
---
drivers/perf/hisilicon/hisi_uncore_pmu.c | 7 +++----
drivers/perf/hisilicon/hisi_uncore_pmu.h | 2 +-
2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
index 13c68b5..52e3bcb 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
+++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
@@ -43,11 +43,10 @@ EXPORT_SYMBOL_GPL(hisi_format_sysfs_show);
ssize_t hisi_event_sysfs_show(struct device *dev,
struct device_attribute *attr, char *page)
{
- struct dev_ext_attribute *eattr;
-
- eattr = container_of(attr, struct dev_ext_attribute, attr);
+ struct perf_pmu_events_attr *pmu_attr =
+ container_of(attr, struct perf_pmu_events_attr, attr);

- return sysfs_emit(page, "config=0x%lx\n", (unsigned long)eattr->var);
+ return sysfs_emit(page, "config=0x%llx\n", pmu_attr->id);
}
EXPORT_SYMBOL_GPL(hisi_event_sysfs_show);

diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.h b/drivers/perf/hisilicon/hisi_uncore_pmu.h
index ea9d89b..b2504d4 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pmu.h
+++ b/drivers/perf/hisilicon/hisi_uncore_pmu.h
@@ -35,7 +35,7 @@
#define HISI_PMU_FORMAT_ATTR(_name, _config) \
HISI_PMU_ATTR(_name, hisi_format_sysfs_show, (void *)_config)
#define HISI_PMU_EVENT_ATTR(_name, _config) \
- HISI_PMU_ATTR(_name, hisi_event_sysfs_show, (unsigned long)_config)
+ PMU_EVENT_ATTR_ID(_name, hisi_event_sysfs_show, _config)

#define HISI_PMU_EVENT_ATTR_EXTRACTOR(name, config, hi, lo) \
static inline u32 hisi_get_##name(struct perf_event *event) \
--
2.7.4

2021-06-08 03:37:37

by liuqi (BA)

[permalink] [raw]
Subject: [PATCH v3 9/9] arm64: perf: Simplify EVENT ATTR macro in perf_event.c

Use common macro PMU_EVENT_ATTR_ID to simplify ARMV8_EVENT_ATTR.

Cc: Peter Zijlstra <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Qi Liu <[email protected]>
---
arch/arm64/kernel/perf_event.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index f594957..3101c42 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -165,10 +165,7 @@ armv8pmu_events_sysfs_show(struct device *dev,
}

#define ARMV8_EVENT_ATTR(name, config) \
- (&((struct perf_pmu_events_attr) { \
- .attr = __ATTR(name, 0444, armv8pmu_events_sysfs_show, NULL), \
- .id = config, \
- }).attr.attr)
+ PMU_EVENT_ATTR_ID(name, armv8pmu_events_sysfs_show, config)

static struct attribute *armv8_pmuv3_event_attrs[] = {
ARMV8_EVENT_ATTR(sw_incr, ARMV8_PMUV3_PERFCTR_SW_INCR),
--
2.7.4

2021-06-08 03:37:42

by liuqi (BA)

[permalink] [raw]
Subject: [PATCH v3 8/9] drivers/perf: Simpilfy EVENT ATTR macro in arm_dsu_pmu.c

Use common macro PMU_EVENT_ATTR_ID to simplify DSU_EVENT_ATTR.

Cc: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>
Signed-off-by: Qi Liu <[email protected]>
---
drivers/perf/arm_dsu_pmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c
index 196faea..bed8376 100644
--- a/drivers/perf/arm_dsu_pmu.c
+++ b/drivers/perf/arm_dsu_pmu.c
@@ -82,7 +82,7 @@
})[0].attr.attr)

#define DSU_EVENT_ATTR(_name, _config) \
- DSU_EXT_ATTR(_name, dsu_pmu_sysfs_event_show, (unsigned long)_config)
+ PMU_EVENT_ATTR_ID(_name, dsu_pmu_sysfs_event_show, _config)

#define DSU_FORMAT_ATTR(_name, _config) \
DSU_EXT_ATTR(_name, dsu_pmu_sysfs_format_show, (char *)_config)
--
2.7.4

2021-06-08 03:38:07

by liuqi (BA)

[permalink] [raw]
Subject: [PATCH v3 7/9] drivers/perf: Simplify EVENT ATTR macro in fsl_imx8_ddr_perf.c

Use common macro PMU_EVENT_ATTR_ID to simplify IMX8_DDR_PMU_EVENT_ATTR.

Cc: Frank Li <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>
Reviewed by Frank Li <Frank [email protected]>
Signed-off-by: Qi Liu <[email protected]>
---
drivers/perf/fsl_imx8_ddr_perf.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c
index 2bbb931..0406215 100644
--- a/drivers/perf/fsl_imx8_ddr_perf.c
+++ b/drivers/perf/fsl_imx8_ddr_perf.c
@@ -222,11 +222,8 @@ ddr_pmu_event_show(struct device *dev, struct device_attribute *attr,
return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
}

-#define IMX8_DDR_PMU_EVENT_ATTR(_name, _id) \
- (&((struct perf_pmu_events_attr[]) { \
- { .attr = __ATTR(_name, 0444, ddr_pmu_event_show, NULL),\
- .id = _id, } \
- })[0].attr.attr)
+#define IMX8_DDR_PMU_EVENT_ATTR(_name, _id) \
+ PMU_EVENT_ATTR_ID(_name, ddr_pmu_event_show, _id)

static struct attribute *ddr_perf_events_attrs[] = {
IMX8_DDR_PMU_EVENT_ATTR(cycles, EVENT_CYCLES_ID),
--
2.7.4

2021-06-08 03:39:14

by liuqi (BA)

[permalink] [raw]
Subject: [PATCH v3 6/9] drivers/perf: Simplify EVENT ATTR macro in xgene_pmu.c

Use common macro PMU_EVENT_ATTR_ID to simplify XGENE_PMU_EVENT_ATTR.

Cc: Khuong Dinh <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>
Signed-off-by: Qi Liu <[email protected]>
---
drivers/perf/xgene_pmu.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
index ffe3bde..9b47bcd 100644
--- a/drivers/perf/xgene_pmu.c
+++ b/drivers/perf/xgene_pmu.c
@@ -278,17 +278,14 @@ static const struct attribute_group mc_pmu_v3_format_attr_group = {
static ssize_t xgene_pmu_event_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct dev_ext_attribute *eattr;
+ struct perf_pmu_events_attr *pmu_attr =
+ container_of(attr, struct perf_pmu_events_attr, attr);

- eattr = container_of(attr, struct dev_ext_attribute, attr);
- return sysfs_emit(buf, "config=0x%lx\n", (unsigned long) eattr->var);
+ return sysfs_emit(buf, "config=0x%llx\n", pmu_attr->id);
}

#define XGENE_PMU_EVENT_ATTR(_name, _config) \
- (&((struct dev_ext_attribute[]) { \
- { .attr = __ATTR(_name, S_IRUGO, xgene_pmu_event_show, NULL), \
- .var = (void *) _config, } \
- })[0].attr.attr)
+ PMU_EVENT_ATTR_ID(_name, xgene_pmu_event_show, _config)

static struct attribute *l3c_pmu_events_attrs[] = {
XGENE_PMU_EVENT_ATTR(cycle-count, 0x00),
--
2.7.4

2021-06-08 03:39:52

by liuqi (BA)

[permalink] [raw]
Subject: [PATCH v3 5/9] drivers/perf: Simplify EVENT ATTR macro in qcom_l3_pmu.c

Use common macro PMU_EVENT_ATTR_ID to simplify L3CACHE_EVENT_ATTR.

Cc: Andy Gross <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>
Signed-off-by: Qi Liu <[email protected]>
---
drivers/perf/qcom_l3_pmu.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/perf/qcom_l3_pmu.c b/drivers/perf/qcom_l3_pmu.c
index bba0780..2b18e44 100644
--- a/drivers/perf/qcom_l3_pmu.c
+++ b/drivers/perf/qcom_l3_pmu.c
@@ -647,10 +647,7 @@ static ssize_t l3cache_pmu_event_show(struct device *dev,
}

#define L3CACHE_EVENT_ATTR(_name, _id) \
- (&((struct perf_pmu_events_attr[]) { \
- { .attr = __ATTR(_name, 0444, l3cache_pmu_event_show, NULL), \
- .id = _id, } \
- })[0].attr.attr)
+ PMU_EVENT_ATTR_ID(_name, l3cache_pmu_event_show, _id)

static struct attribute *qcom_l3_cache_pmu_events[] = {
L3CACHE_EVENT_ATTR(cycles, L3_EVENT_CYCLES),
--
2.7.4

2021-06-08 06:09:32

by liuqi (BA)

[permalink] [raw]
Subject: Re: [PATCH v3 0/9] drivers/perf: Use general macro to simplify event attributes

Hi Will,

Please ignore this patchset, as I forget to add changelog.
I'll resend this latter.

Thanks,
Qi

On 2021/6/8 11:33, Qi Liu wrote:
> This patchset applies a general EVENT_ATTR_ID to simplify event
> attributes in many PMU drivers.
>
> Qi Liu (9):
> perf: Add EVENT_ATTR_ID to simplify event attributes
> drivers/perf: hisi: Simplify EVENT ATTR macro in HiSilicon PMU driver
> drivers/perf: Simplify EVENT ATTR macro in SMMU PMU driver
> drivers/perf: Simplify EVENT ATTR macro in qcom_l2_pmu.c
> drivers/perf: Simplify EVENT ATTR macro in qcom_l3_pmu.c
> drivers/perf: Simplify EVENT ATTR macro in xgene_pmu.c
> drivers/perf: Simplify EVENT ATTR macro in fsl_imx8_ddr_perf.c
> drivers/perf: Simpilfy EVENT ATTR macro in arm_dsu_pmu.c
> arm64: perf: Simplify EVENT ATTR macro in perf_event.c
>
> arch/arm64/kernel/perf_event.c | 5 +----
> drivers/perf/arm_dsu_pmu.c | 2 +-
> drivers/perf/arm_smmuv3_pmu.c | 7 ++-----
> drivers/perf/fsl_imx8_ddr_perf.c | 7 ++-----
> drivers/perf/hisilicon/hisi_uncore_pmu.c | 7 +++----
> drivers/perf/hisilicon/hisi_uncore_pmu.h | 2 +-
> drivers/perf/qcom_l2_pmu.c | 7 ++-----
> drivers/perf/qcom_l3_pmu.c | 5 +----
> drivers/perf/xgene_pmu.c | 11 ++++-------
> include/linux/perf_event.h | 6 ++++++
> 10 files changed, 23 insertions(+), 36 deletions(-)
>

2021-06-08 08:54:06

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH v3 8/9] drivers/perf: Simpilfy EVENT ATTR macro in arm_dsu_pmu.c

On Tue, Jun 08, 2021 at 11:33:20AM +0800, Qi Liu wrote:
> Use common macro PMU_EVENT_ATTR_ID to simplify DSU_EVENT_ATTR.
>
> Cc: Will Deacon <[email protected]>
> Cc: Mark Rutland <[email protected]>
> Signed-off-by: Qi Liu <[email protected]>
> ---
> drivers/perf/arm_dsu_pmu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c
> index 196faea..bed8376 100644
> --- a/drivers/perf/arm_dsu_pmu.c
> +++ b/drivers/perf/arm_dsu_pmu.c
> @@ -82,7 +82,7 @@
> })[0].attr.attr)
>
> #define DSU_EVENT_ATTR(_name, _config) \
> - DSU_EXT_ATTR(_name, dsu_pmu_sysfs_event_show, (unsigned long)_config)
> + PMU_EVENT_ATTR_ID(_name, dsu_pmu_sysfs_event_show, _config)
>
> #define DSU_FORMAT_ATTR(_name, _config) \
> DSU_EXT_ATTR(_name, dsu_pmu_sysfs_format_show, (char *)_config)

I'm not convinced this is any simpler. We still have two users of the
DSU_EXT_ATTR macro and the net effect is no change in line count.

Will

2021-06-09 17:03:44

by liuqi (BA)

[permalink] [raw]
Subject: Re: [PATCH v3 8/9] drivers/perf: Simpilfy EVENT ATTR macro in arm_dsu_pmu.c


Hi Will,
On 2021/6/8 16:52, Will Deacon wrote:
> On Tue, Jun 08, 2021 at 11:33:20AM +0800, Qi Liu wrote:
>> Use common macro PMU_EVENT_ATTR_ID to simplify DSU_EVENT_ATTR.
>>
>> Cc: Will Deacon <[email protected]>
>> Cc: Mark Rutland <[email protected]>
>> Signed-off-by: Qi Liu <[email protected]>
>> ---
>> drivers/perf/arm_dsu_pmu.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c
>> index 196faea..bed8376 100644
>> --- a/drivers/perf/arm_dsu_pmu.c
>> +++ b/drivers/perf/arm_dsu_pmu.c
>> @@ -82,7 +82,7 @@
>> })[0].attr.attr)
>>
>> #define DSU_EVENT_ATTR(_name, _config) \
>> - DSU_EXT_ATTR(_name, dsu_pmu_sysfs_event_show, (unsigned long)_config)
>> + PMU_EVENT_ATTR_ID(_name, dsu_pmu_sysfs_event_show, _config)
>>
>> #define DSU_FORMAT_ATTR(_name, _config) \
>> DSU_EXT_ATTR(_name, dsu_pmu_sysfs_format_show, (char *)_config)
>
> I'm not convinced this is any simpler. We still have two users of the
> DSU_EXT_ATTR macro and the net effect is no change in line count.
>
Got it, I'll drop this patch and sent a new patchset.

Thanks,
Qi
> Will
> .
>