Skip to content

Commit

Permalink
time/sched_clock: Broaden sched_clock()'s instrumentation coverage
Browse files Browse the repository at this point in the history
Most of sched_clock()'s implementation is ineligible for instrumentation
due to relying on sched_clock_noinstr().

Split the implementation off into an __always_inline function
__sched_clock(), which is then used by the noinstr and instrumentable
version, to allow more of sched_clock() to be covered by various
instrumentation.

This will allow instrumentation with the various sanitizers (KASAN,
KCSAN, KMSAN, UBSAN). For KCSAN, we know that raw seqcount_latch usage
without annotations will result in false positive reports: tell it that
all of __sched_clock() is "atomic" for the latch reader; later changes
in this series will take care of the writers.

Co-developed-by: "Peter Zijlstra (Intel)" <[email protected]>
Signed-off-by: "Peter Zijlstra (Intel)" <[email protected]>
Signed-off-by: Marco Elver <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
melver authored and Peter Zijlstra committed Nov 5, 2024
1 parent 1139c71 commit 8ab40fc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions kernel/time/sched_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ notrace int sched_clock_read_retry(unsigned int seq)
return raw_read_seqcount_latch_retry(&cd.seq, seq);
}

unsigned long long noinstr sched_clock_noinstr(void)
static __always_inline unsigned long long __sched_clock(void)
{
struct clock_read_data *rd;
unsigned int seq;
Expand All @@ -98,11 +98,23 @@ unsigned long long noinstr sched_clock_noinstr(void)
return res;
}

unsigned long long noinstr sched_clock_noinstr(void)
{
return __sched_clock();
}

unsigned long long notrace sched_clock(void)
{
unsigned long long ns;
preempt_disable_notrace();
ns = sched_clock_noinstr();
/*
* All of __sched_clock() is a seqcount_latch reader critical section,
* but relies on the raw helpers which are uninstrumented. For KCSAN,
* mark all accesses in __sched_clock() as atomic.
*/
kcsan_nestable_atomic_begin();
ns = __sched_clock();
kcsan_nestable_atomic_end();
preempt_enable_notrace();
return ns;
}
Expand Down

0 comments on commit 8ab40fc

Please sign in to comment.