]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
timekeeping: Add percpu counter for tracking floor swap events
authorJeff Layton <jlayton@kernel.org>
Wed, 2 Oct 2024 21:27:17 +0000 (17:27 -0400)
committerChristian Brauner <brauner@kernel.org>
Thu, 10 Oct 2024 08:20:46 +0000 (10:20 +0200)
The mgtime_floor value is a global variable for tracking the latest
fine-grained timestamp handed out. Because it's a global, track the
number of times that a new floor value is assigned.

Add a new percpu counter to the timekeeping code to track the number of
floor swap events that have occurred. A later patch will add a debugfs
file to display this counter alongside other stats involving multigrain
timestamps.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Randy Dunlap <rdunlap@infradead.org> # documentation bits
Link: https://lore.kernel.org/all/20241002-mgtime-v10-2-d1c4717f5284@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/timekeeping.h
kernel/time/timekeeping.c
kernel/time/timekeeping_debug.c
kernel/time/timekeeping_internal.h

index 7aa85246c183576b039c02af4abba02b4a09ef9d..84a035e86ac811f9e7b1649246b71c9296519149 100644 (file)
@@ -48,6 +48,7 @@ extern void ktime_get_coarse_real_ts64(struct timespec64 *ts);
 /* Multigrain timestamp interfaces */
 extern void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts);
 extern void ktime_get_real_ts64_mg(struct timespec64 *ts);
+extern unsigned long timekeeping_get_mg_floor_swaps(void);
 
 void getboottime64(struct timespec64 *ts);
 
index 441792c907fadca11684b8ccabacd033c3c8a57e..962b2a31f0158627e7a0b41280a5d6f5cf7dc667 100644 (file)
@@ -2487,6 +2487,7 @@ void ktime_get_real_ts64_mg(struct timespec64 *ts)
        if (atomic64_try_cmpxchg(&mg_floor, &old, mono)) {
                ts->tv_nsec = 0;
                timespec64_add_ns(ts, nsecs);
+               timekeeping_inc_mg_floor_swaps();
        } else {
                /*
                 * Another task changed mg_floor since "old" was fetched.
index b73e8850e58d9c5b291559f475e67c7ed47c2db3..badeb222eab92a71511fa6e1dbec311be4289678 100644 (file)
@@ -17,6 +17,9 @@
 
 #define NUM_BINS 32
 
+/* Incremented every time mg_floor is updated */
+DEFINE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps);
+
 static unsigned int sleep_time_bin[NUM_BINS] = {0};
 
 static int tk_debug_sleep_time_show(struct seq_file *s, void *data)
@@ -53,3 +56,13 @@ void tk_debug_account_sleep_time(const struct timespec64 *t)
                           (s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC);
 }
 
+unsigned long timekeeping_get_mg_floor_swaps(void)
+{
+       unsigned long sum = 0;
+       int cpu;
+
+       for_each_possible_cpu(cpu)
+               sum += data_race(per_cpu(timekeeping_mg_floor_swaps, cpu));
+
+       return sum;
+}
index 4ca2787d1642e2f52bf985607ca3b03785cf9a50..0bbae825bc0226e4eed64e73fe3b454986c7573f 100644 (file)
  * timekeeping debug functions
  */
 #ifdef CONFIG_DEBUG_FS
+
+DECLARE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps);
+
+static inline void timekeeping_inc_mg_floor_swaps(void)
+{
+       this_cpu_inc(timekeeping_mg_floor_swaps);
+}
+
 extern void tk_debug_account_sleep_time(const struct timespec64 *t);
+
 #else
+
 #define tk_debug_account_sleep_time(x)
+
+static inline void timekeeping_inc_mg_floor_swaps(void)
+{
+}
+
 #endif
 
 #ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE