diff mbox series

[1/9] perf: Add EVENT_ATTR_ID to simplify event attributes

Message ID 1621322628-9945-2-git-send-email-liuqi115@huawei.com (mailing list archive)
State New, archived
Headers show
Series drivers/perf: Use general macro to simplify event attributes | expand

Commit Message

liuqi (BA) May 18, 2021, 7:23 a.m. UTC
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.

Signed-off-by: Qi Liu <liuqi115@huawei.com>
---
 include/linux/perf_event.h | 6 ++++++
 kernel/events/core.c       | 2 ++
 2 files changed, 8 insertions(+)

Comments

John Garry May 18, 2021, 8:07 a.m. UTC | #1
On 18/05/2021 08:23, Qi Liu wrote:
> 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.
> 
> Signed-off-by: Qi Liu <liuqi115@huawei.com>
> ---
>   include/linux/perf_event.h | 6 ++++++
>   kernel/events/core.c       | 2 ++
>   2 files changed, 8 insertions(+)
> 

I think that you need to resend with all the maintainers for these files 
included.

Thanks
diff mbox series

Patch

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index f5a6a2f..d0aa74e 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, _id)					     \
+	(&((struct perf_pmu_events_attr[]) {				     \
+		{ .attr = __ATTR(_name, 0444, perf_event_sysfs_show, NULL),  \
+		  .id = _id, }						     \
+	})[0].attr.attr)
+
 #define PMU_FORMAT_ATTR(_name, _format)					\
 static ssize_t								\
 _name##_show(struct device *dev,					\
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 0ac818b..330d9cc 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -13295,6 +13295,8 @@  ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
 
 	if (pmu_attr->event_str)
 		return sprintf(page, "%s\n", pmu_attr->event_str);
+	else
+		return sprintf(page, "config=%#llx\n", pmu_attr->id);
 
 	return 0;
 }