Skip to contentSkip to conversation

perf pmu: Make pmu_alias_terms weak again

PATCH Superseded Ian Rogers 2 participants 8 messages Oct 29, 2025 – Nov 6, 2025 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/2 perf pmu: Make pmu_alias_terms weak again

The terms for a json event should be weak so they don't override command line options.

Fixes 84bae3af20d0 ("perf pmu: Don't eagerly parse event terms")
---
 tools/perf/util/pmu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/perf/util/pmu.c +8 -0
index d597263fab4f..f14f2a12d061 100644
@@ -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;
Signature · 1 line
2.51.1.851.g4ebd6896fd-goog
author reviewer
#1 lore raw

PATCH 2/2 perf test: Add test that command line period overrides sysfs/json values

The behavior of weak terms is subtle, add a test that they aren't accidentally broken.

---
 tools/perf/tests/shell/record_weak_term.sh | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100755 tools/perf/tests/shell/record_weak_term.sh
tools/perf/tests/shell/record_weak_term.sh new file +25 -0
new file mode 100755
index 000000000000..7b747b383796
@@ -0,0 +1,25 @@
+#!/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
+
+
+event=$(perf list --json | $PYTHON -c "import json,sys; next((print(e['EventName']) for e in json.load(sys.stdin) if e.get('Encoding') and 'period=' in e.get('Encoding')))")
+if [[ "$?" != "0" ]]
+then
+  echo "No sysfs/json events with inbuilt period."
+  exit 2
+fi
+
+if ! perf record -c 1000 -vv -e "$event" -o /dev/null true 2>&1 | \
+  grep -q -F '{ sample_period, sample_freq }   1000'
+then
+  echo "Unexpected verbose output and sample period"
+  exit 1
+fi
+exit 0
Signature · 1 line
2.51.1.851.g4ebd6896fd-goog
maintainer
#2 lore raw

Re: [PATCH v1 2/2] perf test: Add test that command line period overrides sysfs/json values

Quoted 17 lines · Ian Rogers

The behavior of weak terms is subtle, add a test that they aren't accidentally broken.

---
 tools/perf/tests/shell/record_weak_term.sh | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100755 tools/perf/tests/shell/record_weak_term.sh
tools/perf/tests/shell/record_weak_term.sh new file +2 -0
new file mode 100755
index 000000000000..7b747b383796
@@ -0,0 +1,25 @@
+#!/bin/bash
+# record weak terms

tools/perf/tests/shell/record_weak_term.sh line 12

Quoted 10 lines
tools/perf/tests/shell/record_weak_term.sh new file +10 -0
+# 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
+
+
+event=$(perf list --json | $PYTHON -c "import json,sys; next((print(e['EventName']) for e in json.load(sys.stdin) if e.get('Encoding') and 'period=' in e.get('Encoding')))")

This line is too long and needs some explanation like what's like the original text and what it does.

Thanks,
Namhyung

Quoted 16 lines
tools/perf/tests/shell/record_weak_term.sh new file +13 -0
+if [[ "$?" != "0" ]]
+then
+  echo "No sysfs/json events with inbuilt period."
+  exit 2
+fi
+
+if ! perf record -c 1000 -vv -e "$event" -o /dev/null true 2>&1 | \
+  grep -q -F '{ sample_period, sample_freq }   1000'
+then
+  echo "Unexpected verbose output and sample period"
+  exit 1
+fi
+exit 0
Signature · 1 line
2.51.1.851.g4ebd6896fd-goog
author reviewer
#3 lore raw

Re: [PATCH v1 2/2] perf test: Add test that command line period overrides sysfs/json values

Quoted 23 lines · Namhyung Kim
Quoted 21 lines · Ian Rogers

The behavior of weak terms is subtle, add a test that they aren't accidentally broken.

---
 tools/perf/tests/shell/record_weak_term.sh | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100755 tools/perf/tests/shell/record_weak_term.sh
tools/perf/tests/shell/record_weak_term.sh new file +6 -0
new file mode 100755
index 000000000000..7b747b383796
@@ -0,0 +1,25 @@
+#!/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
+
Quoted 8 lines

tools/perf/tests/shell/record_weak_term.sh line 12

Quoted 6 lines
tools/perf/tests/shell/record_weak_term.sh new file +6 -0
+shelldir=$(dirname "$0")
+# shellcheck source=lib/setup_python.sh
+. "${shelldir}"/lib/setup_python.sh
+
+
+event=$(perf list --json | $PYTHON -c "import json,sys; next((print(e['EventName']) for e in json.load(sys.stdin) if e.get('Encoding') and 'period=' in e.get('Encoding')))")

This line is too long

Is there a good way to split such a line?

Quoted 1 line

and needs some explanation like what's like the original text and what it does.

I thought that was covered in the "if" below:

Quoted 5 lines

tools/perf/tests/shell/record_weak_term.sh line 17

Quoted 5 lines
tools/perf/tests/shell/record_weak_term.sh new file +5 -0
+if [[ "$?" != "0" ]]
+then
+  echo "No sysfs/json events with inbuilt period."
+  exit 2
+fi

Thanks,
Ian

Quoted 11 lines
Quoted 11 lines
tools/perf/tests/shell/record_weak_term.sh new file +8 -1
+
+if ! perf record -c 1000 -vv -e "$event" -o /dev/null true 2>&1 | \
+  grep -q -F '{ sample_period, sample_freq }   1000'
+then
+  echo "Unexpected verbose output and sample period"
+  exit 1
+fi
+exit 0
--

2.51.1.851.g4ebd6896fd-goog

maintainer
#4 lore raw

Re: [PATCH v1 2/2] perf test: Add test that command line period overrides sysfs/json values

Quoted 33 lines · Ian Rogers
Quoted 23 lines · Namhyung Kim
Quoted 21 lines · Ian Rogers

The behavior of weak terms is subtle, add a test that they aren't accidentally broken.

---
 tools/perf/tests/shell/record_weak_term.sh | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100755 tools/perf/tests/shell/record_weak_term.sh
tools/perf/tests/shell/record_weak_term.sh new file +6 -0
new file mode 100755
index 000000000000..7b747b383796
@@ -0,0 +1,25 @@
+#!/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
+
Quoted 8 lines

tools/perf/tests/shell/record_weak_term.sh line 12

Quoted 6 lines
tools/perf/tests/shell/record_weak_term.sh new file +6 -0
+shelldir=$(dirname "$0")
+# shellcheck source=lib/setup_python.sh
+. "${shelldir}"/lib/setup_python.sh
+
+
+event=$(perf list --json | $PYTHON -c "import json,sys; next((print(e['EventName']) for e in json.load(sys.stdin) if e.get('Encoding') and 'period=' in e.get('Encoding')))")

This line is too long

Quoted 1 line

Is there a good way to split such a line?

Wouldn't this work?

event=$(perf list --json | python -c '
import sys, json
for e in json.load(sys.stdin):
if e.get("Encoding") and "period=" in e.get("Encoding"):
print(e["EventName"])')

Quoted 4 lines
Quoted 2 lines

and needs some explanation like what's like the original text and what it does.

I thought that was covered in the "if" below:

Yeah, but I think it's useful to have an example JSON text.

Thanks,
Namhyung

Quoted 21 lines
Quoted 6 lines

tools/perf/tests/shell/record_weak_term.sh line 17

Quoted 6 lines
tools/perf/tests/shell/record_weak_term.sh new file +5 -0
+if [[ "$?" != "0" ]]
+then
+  echo "No sysfs/json events with inbuilt period."
+  exit 2
+fi

Thanks,
Ian

Quoted 11 lines
Quoted 11 lines
tools/perf/tests/shell/record_weak_term.sh new file +8 -1
+
+if ! perf record -c 1000 -vv -e "$event" -o /dev/null true 2>&1 | \
+  grep -q -F '{ sample_period, sample_freq }   1000'
+then
+  echo "Unexpected verbose output and sample period"
+  exit 1
+fi
+exit 0
--

2.51.1.851.g4ebd6896fd-goog

maintainer
#5 lore raw
In reply to Ian Rogers

Hi Ian,

Quoted 2 lines · Ian Rogers

The terms for a json event should be weak so they don't override command line options.

Can you please give an example command line and the error?

Thanks,
Namhyung

Quoted 36 lines
Fixes 84bae3af20d0 ("perf pmu: Don't eagerly parse event terms")
---
 tools/perf/util/pmu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/perf/util/pmu.c +8 -0
index d597263fab4f..f14f2a12d061 100644
@@ -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;
Signature · 1 line
2.51.1.851.g4ebd6896fd-goog
author reviewer
#6 lore raw
Quoted 8 lines · Namhyung Kim

Hi Ian,

Quoted 2 lines · Ian Rogers

The terms for a json event should be weak so they don't override command line options.

Can you please give an example command line and the error?

Sure, it is also covered in the test.

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
```

Thanks,
Ian

Quoted 39 lines

Thanks,
Namhyung

Quoted 36 lines
Fixes 84bae3af20d0 ("perf pmu: Don't eagerly parse event terms")
---
 tools/perf/util/pmu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/perf/util/pmu.c +8 -1
index d597263fab4f..f14f2a12d061 100644
@@ -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.1.851.g4ebd6896fd-goog

maintainer
#7 lore raw
Quoted 11 lines · Ian Rogers
Quoted 8 lines · Namhyung Kim

Hi Ian,

Quoted 2 lines · Ian Rogers

The terms for a json event should be weak so they don't override command line options.

Can you please give an example command line and the error?

Sure, it is also covered in the test.

Yep, but lazy maintainers want to see it in the commit message. :)

Quoted 10 lines

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
```
Quoted 8 lines

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
```

Thanks, it ignored command line options. I can see the default period is in the JSON description.

  $ perf list -j | grep -C 5 uops_issued.any
  	"Encoding": "cpu/event=0xb1,period=2000003,umask=0x10/"
  },
  {
  	"Unit": "cpu",
  	"Topic": "pipeline",
  	"EventName": "uops_issued.any",
  	"EventType": "Kernel PMU event",
  	"BriefDescription": "Uops that RAT issues to RS",
  	"PublicDescription": "Counts the number of uops that the Resource Allocation Table (RAT) issues to the Reservation Station (RS)",
  	"Encoding": "cpu/event=0xe,period=2000003,umask=1/"
  },

It'd be great if you could include this kind of info in the commit log so that others can understand the problem clearly and test the patch easily.

Thanks,
Namhyung

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Fixes 84bae3af20d0 ("perf pmu: Don't eagerly parse event terms")
---
 tools/perf/util/pmu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/perf/util/pmu.c +8 -1
index d597263fab4f..f14f2a12d061 100644
@@ -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.1.851.g4ebd6896fd-goog