Skip to content

Commit 2a15385

Browse files
jtlaytonbrauner
authored andcommitted
timekeeping: Add percpu counter for tracking floor swap events
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Randy Dunlap <[email protected]> # documentation bits Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent ee3283c commit 2a15385

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

include/linux/timekeeping.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extern void ktime_get_coarse_real_ts64(struct timespec64 *ts);
4848
/* Multigrain timestamp interfaces */
4949
extern void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts);
5050
extern void ktime_get_real_ts64_mg(struct timespec64 *ts);
51+
extern unsigned long timekeeping_get_mg_floor_swaps(void);
5152

5253
void getboottime64(struct timespec64 *ts);
5354

kernel/time/timekeeping.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,7 @@ void ktime_get_real_ts64_mg(struct timespec64 *ts)
24872487
if (atomic64_try_cmpxchg(&mg_floor, &old, mono)) {
24882488
ts->tv_nsec = 0;
24892489
timespec64_add_ns(ts, nsecs);
2490+
timekeeping_inc_mg_floor_swaps();
24902491
} else {
24912492
/*
24922493
* Another task changed mg_floor since "old" was fetched.

kernel/time/timekeeping_debug.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#define NUM_BINS 32
1919

20+
/* Incremented every time mg_floor is updated */
21+
DEFINE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps);
22+
2023
static unsigned int sleep_time_bin[NUM_BINS] = {0};
2124

2225
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)
5356
(s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC);
5457
}
5558

59+
unsigned long timekeeping_get_mg_floor_swaps(void)
60+
{
61+
unsigned long sum = 0;
62+
int cpu;
63+
64+
for_each_possible_cpu(cpu)
65+
sum += data_race(per_cpu(timekeeping_mg_floor_swaps, cpu));
66+
67+
return sum;
68+
}

kernel/time/timekeeping_internal.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,24 @@
1010
* timekeeping debug functions
1111
*/
1212
#ifdef CONFIG_DEBUG_FS
13+
14+
DECLARE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps);
15+
16+
static inline void timekeeping_inc_mg_floor_swaps(void)
17+
{
18+
this_cpu_inc(timekeeping_mg_floor_swaps);
19+
}
20+
1321
extern void tk_debug_account_sleep_time(const struct timespec64 *t);
22+
1423
#else
24+
1525
#define tk_debug_account_sleep_time(x)
26+
27+
static inline void timekeeping_inc_mg_floor_swaps(void)
28+
{
29+
}
30+
1631
#endif
1732

1833
#ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE

0 commit comments

Comments
 (0)