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

sched/clock: Move sched clock initialization and merge with generic clock

sched_clock_postinit() initializes a generic clock on systems where no
other clock is provided. This function may be called only after
timekeeping_init().

Rename sched_clock_postinit to generic_clock_inti() and call it from
sched_clock_init(). Move the call for sched_clock_init() until after
time_init().

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: steven.sistare@oracle.com
Cc: daniel.m.jordan@oracle.com
Cc: linux@armlinux.org.uk
Cc: schwidefsky@de.ibm.com
Cc: heiko.carstens@de.ibm.com
Cc: john.stultz@linaro.org
Cc: sboyd@codeaurora.org
Cc: hpa@zytor.com
Cc: douly.fnst@cn.fujitsu.com
Cc: prarit@redhat.com
Cc: feng.tang@intel.com
Cc: pmladek@suse.com
Cc: gnomes@lxorguk.ukuu.org.uk
Cc: linux-s390@vger.kernel.org
Cc: boris.ostrovsky@oracle.com
Cc: jgross@suse.com
Cc: pbonzini@redhat.com
Link: https://lkml.kernel.org/r/20180719205545.16512-23-pasha.tatashin@oracle.com

authored by

Pavel Tatashin and committed by
Thomas Gleixner
5d2a4e91 4763f03d

+22 -17
+2 -3
include/linux/sched_clock.h
··· 9 9 #define LINUX_SCHED_CLOCK 10 10 11 11 #ifdef CONFIG_GENERIC_SCHED_CLOCK 12 - extern void sched_clock_postinit(void); 12 + extern void generic_sched_clock_init(void); 13 13 14 14 extern void sched_clock_register(u64 (*read)(void), int bits, 15 15 unsigned long rate); 16 16 #else 17 - static inline void sched_clock_postinit(void) { } 17 + static inline void generic_sched_clock_init(void) { } 18 18 19 19 static inline void sched_clock_register(u64 (*read)(void), int bits, 20 20 unsigned long rate) 21 21 { 22 - ; 23 22 } 24 23 #endif 25 24
+2 -2
init/main.c
··· 79 79 #include <linux/pti.h> 80 80 #include <linux/blkdev.h> 81 81 #include <linux/elevator.h> 82 - #include <linux/sched_clock.h> 82 + #include <linux/sched/clock.h> 83 83 #include <linux/sched/task.h> 84 84 #include <linux/sched/task_stack.h> 85 85 #include <linux/context_tracking.h> ··· 642 642 softirq_init(); 643 643 timekeeping_init(); 644 644 time_init(); 645 - sched_clock_postinit(); 645 + sched_clock_init(); 646 646 printk_safe_init(); 647 647 perf_event_init(); 648 648 profile_init();
+17 -10
kernel/sched/clock.c
··· 53 53 * 54 54 */ 55 55 #include "sched.h" 56 + #include <linux/sched_clock.h> 56 57 57 58 /* 58 59 * Scheduler clock - returns current time in nanosec units. ··· 68 67 EXPORT_SYMBOL_GPL(sched_clock); 69 68 70 69 __read_mostly int sched_clock_running; 71 - 72 - void sched_clock_init(void) 73 - { 74 - sched_clock_running = 1; 75 - } 76 70 77 71 #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK 78 72 /* ··· 195 199 __clear_sched_clock_stable(); 196 200 } 197 201 202 + static void __sched_clock_gtod_offset(void) 203 + { 204 + __gtod_offset = (sched_clock() + __sched_clock_offset) - ktime_get_ns(); 205 + } 206 + 207 + void __init sched_clock_init(void) 208 + { 209 + sched_clock_running = 1; 210 + } 198 211 /* 199 212 * We run this as late_initcall() such that it runs after all built-in drivers, 200 213 * notably: acpi_processor and intel_idle, which can mark the TSC as unstable. ··· 390 385 391 386 void sched_clock_tick_stable(void) 392 387 { 393 - u64 gtod, clock; 394 - 395 388 if (!sched_clock_stable()) 396 389 return; 397 390 ··· 401 398 * TSC to be unstable, any computation will be computing crap. 402 399 */ 403 400 local_irq_disable(); 404 - gtod = ktime_get_ns(); 405 - clock = sched_clock(); 406 - __gtod_offset = (clock + __sched_clock_offset) - gtod; 401 + __sched_clock_gtod_offset(); 407 402 local_irq_enable(); 408 403 } 409 404 ··· 434 433 EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event); 435 434 436 435 #else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */ 436 + 437 + void __init sched_clock_init(void) 438 + { 439 + sched_clock_running = 1; 440 + generic_sched_clock_init(); 441 + } 437 442 438 443 u64 sched_clock_cpu(int cpu) 439 444 {
-1
kernel/sched/core.c
··· 5954 5954 int i, j; 5955 5955 unsigned long alloc_size = 0, ptr; 5956 5956 5957 - sched_clock_init(); 5958 5957 wait_bit_init(); 5959 5958 5960 5959 #ifdef CONFIG_FAIR_GROUP_SCHED
+1 -1
kernel/time/sched_clock.c
··· 237 237 pr_debug("Registered %pF as sched_clock source\n", read); 238 238 } 239 239 240 - void __init sched_clock_postinit(void) 240 + void __init generic_sched_clock_init(void) 241 241 { 242 242 /* 243 243 * If no sched_clock() function has been provided at that point,