2022-03-25 19:49:32

by Yang Jihong

[permalink] [raw]
Subject: [PATCH] perf/x86: Unify format of events sysfs show

Sysfs show formats of files in /sys/devices/cpu/events/ are not unified,
some end with "\n", and some do not. Modify sysfs show format of events
defined by EVENT_ATTR_STR to end with "\n".

Before:
$ ls /sys/devices/cpu/events/* | xargs -i sh -c 'echo -n "{}: "; cat -A {}; echo'
branch-instructions: event=0xc4$

branch-misses: event=0xc5$

bus-cycles: event=0x3c,umask=0x01$

cache-misses: event=0x2e,umask=0x41$

cache-references: event=0x2e,umask=0x4f$

cpu-cycles: event=0x3c$

instructions: event=0xc0$

ref-cycles: event=0x00,umask=0x03$

slots: event=0x00,umask=0x4
topdown-bad-spec: event=0x00,umask=0x81
topdown-be-bound: event=0x00,umask=0x83
topdown-fe-bound: event=0x00,umask=0x82
topdown-retiring: event=0x00,umask=0x80

After:
$ ls /sys/devices/cpu/events/* | xargs -i sh -c 'echo -n "{}: "; cat -A {}; echo'
/sys/devices/cpu/events/branch-instructions: event=0xc4$

/sys/devices/cpu/events/branch-misses: event=0xc5$

/sys/devices/cpu/events/bus-cycles: event=0x3c,umask=0x01$

/sys/devices/cpu/events/cache-misses: event=0x2e,umask=0x41$

/sys/devices/cpu/events/cache-references: event=0x2e,umask=0x4f$

/sys/devices/cpu/events/cpu-cycles: event=0x3c$

/sys/devices/cpu/events/instructions: event=0xc0$

/sys/devices/cpu/events/ref-cycles: event=0x00,umask=0x03$

/sys/devices/cpu/events/slots: event=0x00,umask=0x4$

Signed-off-by: Yang Jihong <[email protected]>
---
arch/x86/events/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index eef816fc216d..e3cc099886ab 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1837,7 +1837,7 @@ ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, cha

/* string trumps id */
if (pmu_attr->event_str)
- return sprintf(page, "%s", pmu_attr->event_str);
+ return sprintf(page, "%s\n", pmu_attr->event_str);

return x86_pmu.events_sysfs_show(page, config);
}
--
2.30.GIT


Subject: [tip: perf/core] perf/x86: Unify format of events sysfs show

The following commit has been merged into the perf/core branch of tip:

Commit-ID: 7bebfe9dd802b80abff5a43e00ab68d98893a22c
Gitweb: https://git.kernel.org/tip/7bebfe9dd802b80abff5a43e00ab68d98893a22c
Author: Yang Jihong <[email protected]>
AuthorDate: Thu, 24 Mar 2022 11:19:57 +08:00
Committer: Peter Zijlstra <[email protected]>
CommitterDate: Tue, 05 Apr 2022 10:24:39 +02:00

perf/x86: Unify format of events sysfs show

Sysfs show formats of files in /sys/devices/cpu/events/ are not unified,
some end with "\n", and some do not. Modify sysfs show format of events
defined by EVENT_ATTR_STR to end with "\n".

Before:
$ ls /sys/devices/cpu/events/* | xargs -i sh -c 'echo -n "{}: "; cat -A {}; echo'
branch-instructions: event=0xc4$

branch-misses: event=0xc5$

bus-cycles: event=0x3c,umask=0x01$

cache-misses: event=0x2e,umask=0x41$

cache-references: event=0x2e,umask=0x4f$

cpu-cycles: event=0x3c$

instructions: event=0xc0$

ref-cycles: event=0x00,umask=0x03$

slots: event=0x00,umask=0x4
topdown-bad-spec: event=0x00,umask=0x81
topdown-be-bound: event=0x00,umask=0x83
topdown-fe-bound: event=0x00,umask=0x82
topdown-retiring: event=0x00,umask=0x80

After:
$ ls /sys/devices/cpu/events/* | xargs -i sh -c 'echo -n "{}: "; cat -A {}; echo'
/sys/devices/cpu/events/branch-instructions: event=0xc4$

/sys/devices/cpu/events/branch-misses: event=0xc5$

/sys/devices/cpu/events/bus-cycles: event=0x3c,umask=0x01$

/sys/devices/cpu/events/cache-misses: event=0x2e,umask=0x41$

/sys/devices/cpu/events/cache-references: event=0x2e,umask=0x4f$

/sys/devices/cpu/events/cpu-cycles: event=0x3c$

/sys/devices/cpu/events/instructions: event=0xc0$

/sys/devices/cpu/events/ref-cycles: event=0x00,umask=0x03$

/sys/devices/cpu/events/slots: event=0x00,umask=0x4$

Signed-off-by: Yang Jihong <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
arch/x86/events/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 54f992e..b08052b 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1852,7 +1852,7 @@ ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, cha

/* string trumps id */
if (pmu_attr->event_str)
- return sprintf(page, "%s", pmu_attr->event_str);
+ return sprintf(page, "%s\n", pmu_attr->event_str);

return x86_pmu.events_sysfs_show(page, config);
}