public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf/x86: Unify format of events sysfs show
@ 2022-03-24  3:19 Yang Jihong
  2022-03-24 10:11 ` Peter Zijlstra
  2022-04-05  8:36 ` [tip: perf/core] " tip-bot2 for Yang Jihong
  0 siblings, 2 replies; 5+ messages in thread
From: Yang Jihong @ 2022-03-24  3:19 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
	namhyung, tglx, bp, dave.hansen, x86, hpa, linux-perf-users,
	linux-kernel
  Cc: yangjihong1

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 <yangjihong1@huawei.com>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf/x86: Unify format of events sysfs show
  2022-03-24  3:19 [PATCH] perf/x86: Unify format of events sysfs show Yang Jihong
@ 2022-03-24 10:11 ` Peter Zijlstra
  2022-03-25  1:38   ` Yang Jihong
  2022-04-05  8:36 ` [tip: perf/core] " tip-bot2 for Yang Jihong
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Zijlstra @ 2022-03-24 10:11 UTC (permalink / raw)
  To: Yang Jihong
  Cc: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung,
	tglx, bp, dave.hansen, x86, hpa, linux-perf-users, linux-kernel

On Thu, Mar 24, 2022 at 11:19:57AM +0800, Yang Jihong wrote:
> 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".

Did you test all the userspace that consumes these fields to make sure
none of them break? I suppose it's mostly perf tool, but I'm fairly sure
there's others out there as well.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf/x86: Unify format of events sysfs show
  2022-03-24 10:11 ` Peter Zijlstra
@ 2022-03-25  1:38   ` Yang Jihong
  2022-03-28 10:25     ` Peter Zijlstra
  0 siblings, 1 reply; 5+ messages in thread
From: Yang Jihong @ 2022-03-25  1:38 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung,
	tglx, bp, dave.hansen, x86, hpa, linux-perf-users, linux-kernel

Hi Peter,

On 2022/3/24 18:11, Peter Zijlstra wrote:
> On Thu, Mar 24, 2022 at 11:19:57AM +0800, Yang Jihong wrote:
>> 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".
> 
> Did you test all the userspace that consumes these fields to make sure
> none of them break? I suppose it's mostly perf tool, but I'm fairly sure
> there's others out there as well.
> 
Yes, I tested "perf record" and "perf stat" commands on my machine 
against the modified events, and the results are as follows:

$ perf stat -e 
topdown-fetch-bubbles,topdown-recovery-bubbles,topdown-slots-issued,topdown-slots-retired,topdown-total-slots 
-a sleep 1

  Performance counter stats for 'system wide':

            2356235      topdown-fetch-bubbles     #   1211.9% frontend 
bound
             226132      topdown-recovery-bubbles  #    182.9% bad 
speculation
            1073595      topdown-slots-issued      #  -1780.4% backend bound
             944133      topdown-slots-retired     #    485.6% retiring
             194420      topdown-total-slots

        0.987394388 seconds time elapsed


$ perf record -e 
topdown-fetch-bubbles,topdown-recovery-bubbles,topdown-slots-issued,topdown-slots-retired,topdown-total-slots 
-a sleep 1
Lowering default frequency rate from 4000 to 3000.
Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
Couldn't synthesize bpf events.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.300 MB perf.data (2620 samples) ]

$ perf evlist
topdown-fetch-bubbles
topdown-recovery-bubbles
topdown-slots-issued
topdown-slots-retired
topdown-total-slots
dummy:HG

.


Thanks,
Jihong
> .
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf/x86: Unify format of events sysfs show
  2022-03-25  1:38   ` Yang Jihong
@ 2022-03-28 10:25     ` Peter Zijlstra
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2022-03-28 10:25 UTC (permalink / raw)
  To: Yang Jihong
  Cc: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung,
	tglx, bp, dave.hansen, x86, hpa, linux-perf-users, linux-kernel

On Fri, Mar 25, 2022 at 09:38:47AM +0800, Yang Jihong wrote:
> Hi Peter,
> 
> On 2022/3/24 18:11, Peter Zijlstra wrote:
> > On Thu, Mar 24, 2022 at 11:19:57AM +0800, Yang Jihong wrote:
> > > 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".
> > 
> > Did you test all the userspace that consumes these fields to make sure
> > none of them break? I suppose it's mostly perf tool, but I'm fairly sure
> > there's others out there as well.
> > 
> Yes, I tested "perf record" and "perf stat" commands on my machine against
> the modified events, and the results are as follows:

Fair enough, I'll queue it for after -rc1.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tip: perf/core] perf/x86: Unify format of events sysfs show
  2022-03-24  3:19 [PATCH] perf/x86: Unify format of events sysfs show Yang Jihong
  2022-03-24 10:11 ` Peter Zijlstra
@ 2022-04-05  8:36 ` tip-bot2 for Yang Jihong
  1 sibling, 0 replies; 5+ messages in thread
From: tip-bot2 for Yang Jihong @ 2022-04-05  8:36 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Yang Jihong, Peter Zijlstra (Intel), x86, linux-kernel

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 <yangjihong1@huawei.com>
AuthorDate:    Thu, 24 Mar 2022 11:19:57 +08:00
Committer:     Peter Zijlstra <peterz@infradead.org>
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 <yangjihong1@huawei.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220324031957.135595-1-yangjihong1@huawei.com
---
 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);
 }

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-05 11:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-24  3:19 [PATCH] perf/x86: Unify format of events sysfs show Yang Jihong
2022-03-24 10:11 ` Peter Zijlstra
2022-03-25  1:38   ` Yang Jihong
2022-03-28 10:25     ` Peter Zijlstra
2022-04-05  8:36 ` [tip: perf/core] " tip-bot2 for Yang Jihong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox