Skip to contentSkip to conversation

perf test: Add test for events re-armed with PERF_EVENT_IOC_REFRESH

PATCH Superseded Francesco Nigro 2 participants 3 messages Oct 21

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf test: Add test for events re-armed with PERF_EVENT_IOC_REFRESH

Open a sampling event with sample_period 1, re-arm it with PERF_EVENT_IOC_REFRESH from its SIGIO handler, as self-profilers such as async-profiler do, and check that each of 1000 events delivers a signal. One case uses a software event (page faults), the other the syscalls:sys_enter_getppid tracepoint.

The tracepoint case fails since
commit 18dbcbfabfff ("perf: Fix the POLL_HUP delivery breakage"):
only the first overflow is delivered. It passes on the parent commit. The software case passes on both.

The test was written with an AI coding assistant (Claude) from a standalone reproducer; I reviewed it and ran it in QEMU on current mainline, on that commit and on its parent.

---

Notes:
To run it on any x86_64 box with virtme-ng:

vng --kconfig && make -j$(nproc)
make -C tools/perf NO_LIBTRACEEVENT=1
vng -- tools/perf/perf test -v REFRESH

Results, 2 vCPUs:

b320789d6883 (parent) Tracepoint event: Ok
18dbcbfabfff Tracepoint event: FAILED, 1000 events, 1 overflows
a804c5742bff (master) Tracepoint event: FAILED, 1000 events, 1 overflows

The software event passes on all three.

Leo Yan's series "perf: Revert direct PMU stop for refresh limit" (linux-perf-users, 2026-05-12) reverts 18dbcbfabfff for a different reason; I haven't tested it against this.

#regzbot introduced: 18dbcbfabfff

 tools/perf/tests/Build           |   1 +
 tools/perf/tests/builtin-test.c  |   1 +
 tools/perf/tests/event_refresh.c | 136 +++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h         |   1 +
 4 files changed, 139 insertions(+)
 create mode 100644 tools/perf/tests/event_refresh.c
tools/perf/tests/Build +1 -0
index 66944a4f4..199e10c8c 100644
@@ -23,6 +23,7 @@ perf-test-y += hists_output.o
 perf-test-y += hists_cumulate.o
 perf-test-y += bp_signal.o
 perf-test-y += bp_signal_overflow.o
+perf-test-y += event_refresh.o
 perf-test-y += bp_account.o
 perf-test-y += wp.o
 perf-test-y += task-exit.o
tools/perf/tests/builtin-test.c +1 -0
index 4d0784b16..2b10f4d7f 100644
@@ -98,6 +98,7 @@ static struct test_suite *generic_tests[] = {
 	&suite__hists_link,
 	&suite__bp_signal,
 	&suite__bp_signal_overflow,
+	&suite__event_refresh,
 	&suite__bp_accounting,
 	&suite__wp,
 	&suite__task_exit,
tools/perf/tests/event_refresh.c new file +136 -0

136 lines not on this page · raw message

tools/perf/tests/tests.h +1 -0
index cee9e6b62..ecc25b5a3 100644
@@ -124,6 +124,7 @@ DECLARE_SUITE(parse_events);
 DECLARE_SUITE(hists_link);
 DECLARE_SUITE(bp_signal);
 DECLARE_SUITE(bp_signal_overflow);
+DECLARE_SUITE(event_refresh);
 DECLARE_SUITE(bp_accounting);
 DECLARE_SUITE(wp);
 DECLARE_SUITE(task_exit);
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf test: missing MADV_NOHUGEPAGE in test__event_refresh_sw() fails on THP --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf test: missing MADV_NOHUGEPAGE in test__event_refresh_sw() fails on THP --

commit f4e87f46b616d4e4e30869fe7bd06aad9b7c96f9
Author: Francesco Nigro <[email protected]>

perf test: Add test for events re-armed with PERF_EVENT_IOC_REFRESH

This commit adds a perf test suite that opens a sampling event with sample_period 1, re-arms it via PERF_EVENT_IOC_REFRESH from a SIGIO handler, and verifies that 1000 software page-fault and tracepoint events each deliver an overflow signal.

Quoted 6 lines
tools/perf/tests/event_refresh.c new file +0 -0
new file mode 100644
index 0000000000000..480f738de9076
@@ -0,0 +1,136 @@

[ ... ]

Quoted 22 lines
tools/perf/tests/event_refresh.c new file +22 -0
+	pr_debug("%d events, %d overflows\n", NR_EVENTS, overflows);
+	if (overflows == NR_EVENTS)
+		err = TEST_OK;
+
+	sigaction(SIGIO, &old_sa, NULL);
+out_close:
+	close(fd);
+	return err;
+}
+
+static char *pages;
+
+static void touch_page(int i)
+{
+	pages[(long)i * page_size] = 1;
+}
+
+static int test__event_refresh_sw(struct test_suite *test __maybe_unused,
+				  int subtest __maybe_unused)
+{
+	struct perf_event_attr attr = {
+		.type = PERF_TYPE_SOFTWARE,

tools/perf/tests/event_refresh.c line 100

Quoted 10 lines
tools/perf/tests/event_refresh.c new file +10 -0
+		.config = PERF_COUNT_SW_PAGE_FAULTS,
+	};
+	int err;
+
+	pages = mmap(NULL, (long)NR_EVENTS * page_size, PROT_READ | PROT_WRITE,
+		     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	if (pages == MAP_FAILED)
+		return TEST_FAIL;
+
+	err = count_overflows(&attr, touch_page);

[Severity: Medium]
In tools/perf/tests/event_refresh.c, test__event_refresh_sw() maps NR_EVENTS * page_size bytes (~4 MiB with 4 KiB base pages) as a private anonymous mapping and relies on each touch_page() write at page_size stride to trigger a distinct PERF_COUNT_SW_PAGE_FAULTS event.

On systems with Transparent Huge Pages (THP) or multi-size THP (mTHP) set to "always" (such as when CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y or /sys/kernel/mm/transparent_hugepage/enabled is set to "always"), the first write in touch_page(0) can be satisfied by __handle_mm_fault() -> create_huge_pmd() with a 2 MiB huge page (or a multi-page folio).

That maps up to 512 base pages in a single page fault, so subsequent touch_page() calls within that huge page hit already-present PTEs/PMDs without faulting. As a result, overflows only reaches 489 (or fewer) instead of NR_EVENTS (1000), and count_overflows() returns TEST_FAIL.

Should test__event_refresh_sw() call madvise(pages, (long)NR_EVENTS * page_size, MADV_NOHUGEPAGE) before count_overflows() so that each touch_page() write faults in a single base page?

Quoted 3 lines
tools/perf/tests/event_refresh.c new file +3 -0
+	munmap(pages, (long)NR_EVENTS * page_size);
+	return err;
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 3 lines

On systems with Transparent Huge Pages (THP) or multi-size THP (mTHP) set to "always" [...] As a result, overflows only reaches 489 (or fewer) instead of NR_EVENTS (1000), and count_overflows() returns TEST_FAIL.

Confirmed: on master with transparent_hugepage=always the software case gets 489 of 1000 overflows. With madvise(MADV_NOHUGEPAGE) on the buffer it gets all 1000, and the tracepoint case still gets 1. I'll send a v2 with that change.

Thanks,
Francesco