* [PATCH v2 1/2] perf pmu: Make pmu_alias_terms weak again
@ 2025-11-06 23:37 Ian Rogers
2025-11-06 23:37 ` [PATCH v2 2/2] perf test: Add test that command line period overrides sysfs/json values Ian Rogers
0 siblings, 1 reply; 4+ messages in thread
From: Ian Rogers @ 2025-11-06 23:37 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, Kan Liang, James Clark, linux-kernel,
linux-perf-users
The terms for a json event should be weak so they don't override
command line options.
Before:
```
$ perf record -vv -c 1000 -e uops_issued.any -o /dev/null true 2>&1
|grep "{ sample_period, sample_freq }"
{ sample_period, sample_freq } 200003
{ sample_period, sample_freq } 2000003
{ sample_period, sample_freq } 1000
```
After:
```
$ perf record -vv -c 1000 -e uops_issued.any -o /dev/null true 2>&1
|grep "{ sample_period, sample_freq }"
{ sample_period, sample_freq } 1000
{ sample_period, sample_freq } 1000
{ sample_period, sample_freq } 1000
```
Fixes: 84bae3af20d0 ("perf pmu: Don't eagerly parse event terms")
Signed-off-by: Ian Rogers <irogers@google.com>
---
v2: Expand the commit message with an example (Namhyung).
---
tools/perf/util/pmu.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index d597263fab4f..f14f2a12d061 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -802,6 +802,7 @@ static int pmu_aliases_parse_eager(struct perf_pmu *pmu, int sysfs_fd)
static int pmu_alias_terms(struct perf_pmu_alias *alias, struct list_head *terms)
{
struct parse_events_terms alias_terms;
+ struct parse_events_term *term;
int ret;
parse_events_terms__init(&alias_terms);
@@ -812,6 +813,13 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias, struct list_head *terms
parse_events_terms__exit(&alias_terms);
return ret;
}
+ list_for_each_entry(term, &alias_terms.terms, list) {
+ /*
+ * Weak terms don't override command line options,
+ * which we don't want for implicit terms in aliases.
+ */
+ term->weak = true;
+ }
list_splice_init(&alias_terms.terms, terms);
parse_events_terms__exit(&alias_terms);
return 0;
--
2.51.2.1041.gc1ab5b90ca-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/2] perf test: Add test that command line period overrides sysfs/json values
2025-11-06 23:37 [PATCH v2 1/2] perf pmu: Make pmu_alias_terms weak again Ian Rogers
@ 2025-11-06 23:37 ` Ian Rogers
2025-11-07 1:39 ` Namhyung Kim
0 siblings, 1 reply; 4+ messages in thread
From: Ian Rogers @ 2025-11-06 23:37 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, Kan Liang, James Clark, linux-kernel,
linux-perf-users
The behavior of weak terms is subtle, add a test that they aren't
accidentally broken.
Signed-off-by: Ian Rogers <irogers@google.com>
---
v2: Add more comments to the test code and reduce the line length (Namhyung).
---
tools/perf/tests/shell/record_weak_term.sh | 36 ++++++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100755 tools/perf/tests/shell/record_weak_term.sh
diff --git a/tools/perf/tests/shell/record_weak_term.sh b/tools/perf/tests/shell/record_weak_term.sh
new file mode 100755
index 000000000000..ee4bcc792aeb
--- /dev/null
+++ b/tools/perf/tests/shell/record_weak_term.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# record weak terms
+# SPDX-License-Identifier: GPL-2.0
+# Test that command line options override weak terms from sysfs or inbuilt json.
+set -e
+
+shelldir=$(dirname "$0")
+# shellcheck source=lib/setup_python.sh
+. "${shelldir}"/lib/setup_python.sh
+
+# Find the first event with a specified period, such as
+# "cpu_core/event=0x24,period=200003,umask=0xff/"
+event=$(perf list --json | $PYTHON -c '
+import json, sys
+for e in json.load(sys.stdin):
+ if "Encoding" in e and "period=" in e["Encoding"]:
+ print(e["EventName"])
+ sys.exit(0)
+sys.exit(1)
+')
+if [[ "$?" != "0" ]]
+then
+ echo "Skip: No sysfs/json events with inbuilt period."
+ exit 2
+fi
+
+echo "Testing that for $event the period is overridden with 1000"
+perf list --detail "$event"
+if ! perf record -c 1000 -vv -e "$event" -o /dev/null true 2>&1 | \
+ grep -q -F '{ sample_period, sample_freq } 1000'
+then
+ echo "Fail: Unexpected verbose output and sample period"
+ exit 1
+fi
+echo "Success"
+exit 0
--
2.51.2.1041.gc1ab5b90ca-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2 2/2] perf test: Add test that command line period overrides sysfs/json values
2025-11-06 23:37 ` [PATCH v2 2/2] perf test: Add test that command line period overrides sysfs/json values Ian Rogers
@ 2025-11-07 1:39 ` Namhyung Kim
2025-11-07 17:29 ` Ian Rogers
0 siblings, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2025-11-07 1:39 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Kan Liang,
James Clark, linux-kernel, linux-perf-users
On Thu, Nov 06, 2025 at 03:37:10PM -0800, Ian Rogers wrote:
> The behavior of weak terms is subtle, add a test that they aren't
> accidentally broken.
I've got this error.
$ sudo ./perf test -v 'record weak terms'
--- start ---
test child forked, pid 4014275
Testing that for cpu/event=0..0xfff,edge,inv,.../modifier the period is overridden with 1000
Fail: Unexpected verbose output and sample period
---- end(-1) ----
92: record weak terms : FAILED!
Thanks,
Namhyung
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> v2: Add more comments to the test code and reduce the line length (Namhyung).
> ---
> tools/perf/tests/shell/record_weak_term.sh | 36 ++++++++++++++++++++++
> 1 file changed, 36 insertions(+)
> create mode 100755 tools/perf/tests/shell/record_weak_term.sh
>
> diff --git a/tools/perf/tests/shell/record_weak_term.sh b/tools/perf/tests/shell/record_weak_term.sh
> new file mode 100755
> index 000000000000..ee4bcc792aeb
> --- /dev/null
> +++ b/tools/perf/tests/shell/record_weak_term.sh
> @@ -0,0 +1,36 @@
> +#!/bin/bash
> +# record weak terms
> +# SPDX-License-Identifier: GPL-2.0
> +# Test that command line options override weak terms from sysfs or inbuilt json.
> +set -e
> +
> +shelldir=$(dirname "$0")
> +# shellcheck source=lib/setup_python.sh
> +. "${shelldir}"/lib/setup_python.sh
> +
> +# Find the first event with a specified period, such as
> +# "cpu_core/event=0x24,period=200003,umask=0xff/"
> +event=$(perf list --json | $PYTHON -c '
> +import json, sys
> +for e in json.load(sys.stdin):
> + if "Encoding" in e and "period=" in e["Encoding"]:
> + print(e["EventName"])
> + sys.exit(0)
> +sys.exit(1)
> +')
> +if [[ "$?" != "0" ]]
> +then
> + echo "Skip: No sysfs/json events with inbuilt period."
> + exit 2
> +fi
> +
> +echo "Testing that for $event the period is overridden with 1000"
> +perf list --detail "$event"
> +if ! perf record -c 1000 -vv -e "$event" -o /dev/null true 2>&1 | \
> + grep -q -F '{ sample_period, sample_freq } 1000'
> +then
> + echo "Fail: Unexpected verbose output and sample period"
> + exit 1
> +fi
> +echo "Success"
> +exit 0
> --
> 2.51.2.1041.gc1ab5b90ca-goog
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2 2/2] perf test: Add test that command line period overrides sysfs/json values
2025-11-07 1:39 ` Namhyung Kim
@ 2025-11-07 17:29 ` Ian Rogers
0 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2025-11-07 17:29 UTC (permalink / raw)
To: Namhyung Kim
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Kan Liang,
James Clark, linux-kernel, linux-perf-users
On Thu, Nov 6, 2025 at 5:39 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Thu, Nov 06, 2025 at 03:37:10PM -0800, Ian Rogers wrote:
> > The behavior of weak terms is subtle, add a test that they aren't
> > accidentally broken.
>
> I've got this error.
>
> $ sudo ./perf test -v 'record weak terms'
> --- start ---
> test child forked, pid 4014275
> Testing that for cpu/event=0..0xfff,edge,inv,.../modifier the period is overridden with 1000
> Fail: Unexpected verbose output and sample period
Ah, the raw encoding from:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/pmus.c?h=perf-tools-next#n745
this will need skipping.
Thanks,
Ian
> ---- end(-1) ----
> 92: record weak terms : FAILED!
>
> Thanks,
> Namhyung
>
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> > v2: Add more comments to the test code and reduce the line length (Namhyung).
> > ---
> > tools/perf/tests/shell/record_weak_term.sh | 36 ++++++++++++++++++++++
> > 1 file changed, 36 insertions(+)
> > create mode 100755 tools/perf/tests/shell/record_weak_term.sh
> >
> > diff --git a/tools/perf/tests/shell/record_weak_term.sh b/tools/perf/tests/shell/record_weak_term.sh
> > new file mode 100755
> > index 000000000000..ee4bcc792aeb
> > --- /dev/null
> > +++ b/tools/perf/tests/shell/record_weak_term.sh
> > @@ -0,0 +1,36 @@
> > +#!/bin/bash
> > +# record weak terms
> > +# SPDX-License-Identifier: GPL-2.0
> > +# Test that command line options override weak terms from sysfs or inbuilt json.
> > +set -e
> > +
> > +shelldir=$(dirname "$0")
> > +# shellcheck source=lib/setup_python.sh
> > +. "${shelldir}"/lib/setup_python.sh
> > +
> > +# Find the first event with a specified period, such as
> > +# "cpu_core/event=0x24,period=200003,umask=0xff/"
> > +event=$(perf list --json | $PYTHON -c '
> > +import json, sys
> > +for e in json.load(sys.stdin):
> > + if "Encoding" in e and "period=" in e["Encoding"]:
> > + print(e["EventName"])
> > + sys.exit(0)
> > +sys.exit(1)
> > +')
> > +if [[ "$?" != "0" ]]
> > +then
> > + echo "Skip: No sysfs/json events with inbuilt period."
> > + exit 2
> > +fi
> > +
> > +echo "Testing that for $event the period is overridden with 1000"
> > +perf list --detail "$event"
> > +if ! perf record -c 1000 -vv -e "$event" -o /dev/null true 2>&1 | \
> > + grep -q -F '{ sample_period, sample_freq } 1000'
> > +then
> > + echo "Fail: Unexpected verbose output and sample period"
> > + exit 1
> > +fi
> > +echo "Success"
> > +exit 0
> > --
> > 2.51.2.1041.gc1ab5b90ca-goog
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-07 17:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-06 23:37 [PATCH v2 1/2] perf pmu: Make pmu_alias_terms weak again Ian Rogers
2025-11-06 23:37 ` [PATCH v2 2/2] perf test: Add test that command line period overrides sysfs/json values Ian Rogers
2025-11-07 1:39 ` Namhyung Kim
2025-11-07 17:29 ` Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).