Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

clocksource: Make clocksource watchdog test safe for slow-HZ systems

The clocksource watchdog test sets a local JIFFIES_SHIFT macro and assumes
that HZ is >= 100. For smaller HZ values this shift value is too large and
causes undefined behaviour.

Move the HZ-based definitions of JIFFIES_SHIFT from kernel/time/jiffies.c
to kernel/time/tick-internal.h so the clocksource watchdog test can utilize
them, which makes it work correctly with all HZ values.

[ tglx: Resolved conflicts and massaged changelog ]

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/lkml/20210812000133.GA402890@paulmck-ThinkPad-P17-Gen-1/

authored by

Paul E. McKenney and committed by
Thomas Gleixner
d25a0252 127c92fe

+23 -23
+2 -3
kernel/time/clocksource-wdtest.c
··· 19 19 #include <linux/prandom.h> 20 20 #include <linux/cpu.h> 21 21 22 + #include "tick-internal.h" 23 + 22 24 MODULE_LICENSE("GPL"); 23 25 MODULE_AUTHOR("Paul E. McKenney <paulmck@kernel.org>"); 24 26 ··· 35 33 { 36 34 return (u64)jiffies; 37 35 } 38 - 39 - /* Assume HZ > 100. */ 40 - #define JIFFIES_SHIFT 8 41 36 42 37 static struct clocksource clocksource_wdtest_jiffies = { 43 38 .name = "wdtest-jiffies",
+1 -20
kernel/time/jiffies.c
··· 10 10 #include <linux/init.h> 11 11 12 12 #include "timekeeping.h" 13 + #include "tick-internal.h" 13 14 14 - 15 - /* Since jiffies uses a simple TICK_NSEC multiplier 16 - * conversion, the .shift value could be zero. However 17 - * this would make NTP adjustments impossible as they are 18 - * in units of 1/2^.shift. Thus we use JIFFIES_SHIFT to 19 - * shift both the nominator and denominator the same 20 - * amount, and give ntp adjustments in units of 1/2^8 21 - * 22 - * The value 8 is somewhat carefully chosen, as anything 23 - * larger can result in overflows. TICK_NSEC grows as HZ 24 - * shrinks, so values greater than 8 overflow 32bits when 25 - * HZ=100. 26 - */ 27 - #if HZ < 34 28 - #define JIFFIES_SHIFT 6 29 - #elif HZ < 67 30 - #define JIFFIES_SHIFT 7 31 - #else 32 - #define JIFFIES_SHIFT 8 33 - #endif 34 15 35 16 static u64 jiffies_read(struct clocksource *cs) 36 17 {
+20
kernel/time/tick-internal.h
··· 177 177 void clock_was_set_delayed(void); 178 178 179 179 void hrtimers_resume_local(void); 180 + 181 + /* Since jiffies uses a simple TICK_NSEC multiplier 182 + * conversion, the .shift value could be zero. However 183 + * this would make NTP adjustments impossible as they are 184 + * in units of 1/2^.shift. Thus we use JIFFIES_SHIFT to 185 + * shift both the nominator and denominator the same 186 + * amount, and give ntp adjustments in units of 1/2^8 187 + * 188 + * The value 8 is somewhat carefully chosen, as anything 189 + * larger can result in overflows. TICK_NSEC grows as HZ 190 + * shrinks, so values greater than 8 overflow 32bits when 191 + * HZ=100. 192 + */ 193 + #if HZ < 34 194 + #define JIFFIES_SHIFT 6 195 + #elif HZ < 67 196 + #define JIFFIES_SHIFT 7 197 + #else 198 + #define JIFFIES_SHIFT 8 199 + #endif