Re: [PATCH v3 4/6] sched/core: Pause KCOV in __schedule()
From: Alexander Potapenko
Date: Mon Sep 14 2026 - 12:10:15 EST
On Mon, Sep 14, 2026 at 7:48 AM Karl Mehltretter <kmehltretter@xxxxxxxxx> wrote:
>
> kernel/sched/ is built without KCOV instrumentation, but callees such
> as sched_clock(), architecture CPU-capacity helpers and profile_hits() are.
>
> During preemption and schedule() calls, instrumented callees can add
> nondeterministic scheduler coverage to current.
>
> With CONFIG_KCOV_SELFTEST added to x86_64 defconfig, the interrupt
> selftest fails under QEMU, detecting spurious coverage in
> arch_scale_cpu_capacity().
>
> Annotating each callee would spread exclusions across architectures.
> Pause across __schedule() instead, extending the scheduler exclusion to
> its callees.
>
> KCOV_PAUSED remains set while a task is switched out. The guard in its
> resumed __schedule() frame restores the prior state.
>
> Assisted-by: LLM
> Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
> ---
> kernel/sched/core.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index ae97c63842a4..54b5c5383fe6 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7116,6 +7116,9 @@ static void __sched notrace __schedule(int sched_mode)
> struct rq *rq;
> int cpu;
>
> + /* Instrumented callees would leak coverage into current. */
Here and in other patches, I believe Peter expected different wording.
How about "Callees instrumented with KCOV"?
> + guard(kcov_pause)();
> +
> /* Trace preemptions consistently with task switches */
> trace_sched_entry_tp(sched_mode == SM_PREEMPT);
>
> --
> 2.53.0
>
--
Alexander Potapenko
Software Engineer
Google Germany GmbH
Erika-Mann-Straße, 33
80636 München
Geschäftsführer: Paul Manicle, Liana Sebastian
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg