[PATCH] selftests/tracing: Run sample events to clear page cache events

Steven Rostedt posted 1 patch 3 months, 1 week ago
.../selftests/ftrace/test.d/filter/event-filter-function.tc   | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] selftests/tracing: Run sample events to clear page cache events
Posted by Steven Rostedt 3 months, 1 week ago
From: Steven Rostedt <rostedt@goodmis.org>

The tracing selftest "event-filter-function.tc" was failing because it
first runs the "sample_events" function that triggers the kmem_cache_free
event and it looks at what function was used during a call to "ls".

But the first time it calls this, it could trigger events that are used to
pull pages into the page cache.

The rest of the test uses the function it finds during that call to see if
it will be called in subsequent "sample_events" calls. But if there's no
need to pull pages into the page cache, it will not trigger that function
and the test will fail.

Call the "sample_events" twice to trigger all the page cache work before
it calls it to find a function to use in subsequent checks.

Cc: stable@vger.kernel.org
Fixes: eb50d0f250e96 ("selftests/ftrace: Choose target function for filter test from samples")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 .../selftests/ftrace/test.d/filter/event-filter-function.tc   | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc b/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc
index c62165fabd0c..003f612f57b0 100644
--- a/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc
+++ b/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc
@@ -20,6 +20,10 @@ sample_events() {
 echo 0 > tracing_on
 echo 0 > events/enable
 
+# Clear functions caused by page cache; run sample_events twice
+sample_events
+sample_events
+
 echo "Get the most frequently calling function"
 echo > trace
 sample_events
-- 
2.51.0
Re: [PATCH] selftests/tracing: Run sample events to clear page cache events
Posted by Masami Hiramatsu (Google) 2 months, 4 weeks ago
On Tue, 28 Oct 2025 12:27:24 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: Steven Rostedt <rostedt@goodmis.org>
> 
> The tracing selftest "event-filter-function.tc" was failing because it
> first runs the "sample_events" function that triggers the kmem_cache_free
> event and it looks at what function was used during a call to "ls".
> 
> But the first time it calls this, it could trigger events that are used to
> pull pages into the page cache.
> 
> The rest of the test uses the function it finds during that call to see if
> it will be called in subsequent "sample_events" calls. But if there's no
> need to pull pages into the page cache, it will not trigger that function
> and the test will fail.
> 
> Call the "sample_events" twice to trigger all the page cache work before
> it calls it to find a function to use in subsequent checks.
> 

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

> Cc: stable@vger.kernel.org
> Fixes: eb50d0f250e96 ("selftests/ftrace: Choose target function for filter test from samples")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  .../selftests/ftrace/test.d/filter/event-filter-function.tc   | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc b/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc
> index c62165fabd0c..003f612f57b0 100644
> --- a/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc
> +++ b/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc
> @@ -20,6 +20,10 @@ sample_events() {
>  echo 0 > tracing_on
>  echo 0 > events/enable
>  
> +# Clear functions caused by page cache; run sample_events twice
> +sample_events
> +sample_events
> +
>  echo "Get the most frequently calling function"
>  echo > trace
>  sample_events
> -- 
> 2.51.0
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>
Re: [PATCH] selftests/tracing: Run sample events to clear page cache events
Posted by Steven Rostedt 2 months, 4 weeks ago
Shuah,

Can you take this through your urgent branch?

-- Steve


On Tue, 28 Oct 2025 12:27:24 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: Steven Rostedt <rostedt@goodmis.org>
> 
> The tracing selftest "event-filter-function.tc" was failing because it
> first runs the "sample_events" function that triggers the kmem_cache_free
> event and it looks at what function was used during a call to "ls".
> 
> But the first time it calls this, it could trigger events that are used to
> pull pages into the page cache.
> 
> The rest of the test uses the function it finds during that call to see if
> it will be called in subsequent "sample_events" calls. But if there's no
> need to pull pages into the page cache, it will not trigger that function
> and the test will fail.
> 
> Call the "sample_events" twice to trigger all the page cache work before
> it calls it to find a function to use in subsequent checks.
> 
> Cc: stable@vger.kernel.org
> Fixes: eb50d0f250e96 ("selftests/ftrace: Choose target function for filter test from samples")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  .../selftests/ftrace/test.d/filter/event-filter-function.tc   | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc b/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc
> index c62165fabd0c..003f612f57b0 100644
> --- a/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc
> +++ b/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc
> @@ -20,6 +20,10 @@ sample_events() {
>  echo 0 > tracing_on
>  echo 0 > events/enable
>  
> +# Clear functions caused by page cache; run sample_events twice
> +sample_events
> +sample_events
> +
>  echo "Get the most frequently calling function"
>  echo > trace
>  sample_events
Re: [PATCH] selftests/tracing: Run sample events to clear page cache events
Posted by Shuah Khan 2 months, 4 weeks ago
On 11/10/25 15:14, Steven Rostedt wrote:
> 
> Shuah,
> 
> Can you take this through your urgent branch?

Applied to linux-kselftest fixes branch. Will send it
in an urgent pr.

thanks,
-- Shuah