From: sashiko-bot@kernel.org
To: "Francesco Nigro" <nigro.fra@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf test: Add test for events re-armed with PERF_EVENT_IOC_REFRESH
Date: Wed, 21 Oct 2026 13:20:34 +0000 [thread overview]
Message-ID: <sashiko-outbox-180295@kernel.org> (raw)
In-Reply-To: <20261021131006.2101248-1-nigro.fra@gmail.com>
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 <nigro.fra@gmail.com>
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.
Link: https://github.com/async-profiler/async-profiler/issues/1813
> diff --git a/tools/perf/tests/event_refresh.c b/tools/perf/tests/event_refresh.c
> new file mode 100644
> index 0000000000000..480f738de9076
> --- /dev/null
> +++ b/tools/perf/tests/event_refresh.c
> @@ -0,0 +1,136 @@
[ ... ]
> + 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,
> + .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?
> + munmap(pages, (long)NR_EVENTS * page_size);
> + return err;
> +}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261021131006.2101248-1-nigro.fra@gmail.com?part=1
next prev parent reply other threads:[~2026-10-21 13:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 13:10 [PATCH] perf test: Add test for events re-armed with PERF_EVENT_IOC_REFRESH Francesco Nigro
2026-10-21 13:20 ` sashiko-bot [this message]
2026-10-21 14:16 ` Francesco Nigro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-180295@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=nigro.fra@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox