diff options
author | Pavel Tatashin <pasha.tatashin@oracle.com> | 2018-07-19 16:55:41 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2018-07-19 18:02:43 -0400 |
commit | 5d2a4e91a541cb04d20d11602f0f9340291322ac (patch) | |
tree | a73289b20244f7a057b30a71fc7fefddfa294632 | |
parent | 4763f03d3d186ce8a1125844790152d76804ad60 (diff) |
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
-rw-r--r-- | include/linux/sched_clock.h | 5 | ||||
-rw-r--r-- | init/main.c | 4 | ||||
-rw-r--r-- | kernel/sched/clock.c | 27 | ||||
-rw-r--r-- | kernel/sched/core.c | 1 | ||||
-rw-r--r-- | kernel/time/sched_clock.c | 2 |
5 files changed, 22 insertions, 17 deletions
diff --git a/include/linux/sched_clock.h b/include/linux/sched_clock.h index 411b52e424e1..abe28d5cb3f4 100644 --- a/include/linux/sched_clock.h +++ b/include/linux/sched_clock.h | |||
@@ -9,17 +9,16 @@ | |||
9 | #define LINUX_SCHED_CLOCK | 9 | #define LINUX_SCHED_CLOCK |
10 | 10 | ||
11 | #ifdef CONFIG_GENERIC_SCHED_CLOCK | 11 | #ifdef CONFIG_GENERIC_SCHED_CLOCK |
12 | extern void sched_clock_postinit(void); | 12 | extern void generic_sched_clock_init(void); |
13 | 13 | ||
14 | extern void sched_clock_register(u64 (*read)(void), int bits, | 14 | extern void sched_clock_register(u64 (*read)(void), int bits, |
15 | unsigned long rate); | 15 | unsigned long rate); |
16 | #else | 16 | #else |
17 | static inline void sched_clock_postinit(void) { } | 17 | static inline void generic_sched_clock_init(void) { } |
18 | 18 | ||
19 | static inline void sched_clock_register(u64 (*read)(void), int bits, | 19 | static inline void sched_clock_register(u64 (*read)(void), int bits, |
20 | unsigned long rate) | 20 | unsigned long rate) |
21 | { | 21 | { |
22 | ; | ||
23 | } | 22 | } |
24 | #endif | 23 | #endif |
25 | 24 | ||
diff --git a/init/main.c b/init/main.c index 3b4ada11ed52..162d931c9511 100644 --- a/init/main.c +++ b/init/main.c | |||
@@ -79,7 +79,7 @@ | |||
79 | #include <linux/pti.h> | 79 | #include <linux/pti.h> |
80 | #include <linux/blkdev.h> | 80 | #include <linux/blkdev.h> |
81 | #include <linux/elevator.h> | 81 | #include <linux/elevator.h> |
82 | #include <linux/sched_clock.h> | 82 | #include <linux/sched/clock.h> |
83 | #include <linux/sched/task.h> | 83 | #include <linux/sched/task.h> |
84 | #include <linux/sched/task_stack.h> | 84 | #include <linux/sched/task_stack.h> |
85 | #include <linux/context_tracking.h> | 85 | #include <linux/context_tracking.h> |
@@ -642,7 +642,7 @@ asmlinkage __visible void __init start_kernel(void) | |||
642 | softirq_init(); | 642 | softirq_init(); |
643 | timekeeping_init(); | 643 | timekeeping_init(); |
644 | time_init(); | 644 | time_init(); |
645 | sched_clock_postinit(); | 645 | sched_clock_init(); |
646 | printk_safe_init(); | 646 | printk_safe_init(); |
647 | perf_event_init(); | 647 | perf_event_init(); |
648 | profile_init(); | 648 | profile_init(); |
diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c index 10c83e73837a..0e9dbb2d9aea 100644 --- a/kernel/sched/clock.c +++ b/kernel/sched/clock.c | |||
@@ -53,6 +53,7 @@ | |||
53 | * | 53 | * |
54 | */ | 54 | */ |
55 | #include "sched.h" | 55 | #include "sched.h" |
56 | #include <linux/sched_clock.h> | ||
56 | 57 | ||
57 | /* | 58 | /* |
58 | * Scheduler clock - returns current time in nanosec units. | 59 | * Scheduler clock - returns current time in nanosec units. |
@@ -68,11 +69,6 @@ EXPORT_SYMBOL_GPL(sched_clock); | |||
68 | 69 | ||
69 | __read_mostly int sched_clock_running; | 70 | __read_mostly int sched_clock_running; |
70 | 71 | ||
71 | void sched_clock_init(void) | ||
72 | { | ||
73 | sched_clock_running = 1; | ||
74 | } | ||
75 | |||
76 | #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK | 72 | #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK |
77 | /* | 73 | /* |
78 | * We must start with !__sched_clock_stable because the unstable -> stable | 74 | * We must start with !__sched_clock_stable because the unstable -> stable |
@@ -199,6 +195,15 @@ void clear_sched_clock_stable(void) | |||
199 | __clear_sched_clock_stable(); | 195 | __clear_sched_clock_stable(); |
200 | } | 196 | } |
201 | 197 | ||
198 | static void __sched_clock_gtod_offset(void) | ||
199 | { | ||
200 | __gtod_offset = (sched_clock() + __sched_clock_offset) - ktime_get_ns(); | ||
201 | } | ||
202 | |||
203 | void __init sched_clock_init(void) | ||
204 | { | ||
205 | sched_clock_running = 1; | ||
206 | } | ||
202 | /* | 207 | /* |
203 | * We run this as late_initcall() such that it runs after all built-in drivers, | 208 | * We run this as late_initcall() such that it runs after all built-in drivers, |
204 | * notably: acpi_processor and intel_idle, which can mark the TSC as unstable. | 209 | * notably: acpi_processor and intel_idle, which can mark the TSC as unstable. |
@@ -385,8 +390,6 @@ void sched_clock_tick(void) | |||
385 | 390 | ||
386 | void sched_clock_tick_stable(void) | 391 | void sched_clock_tick_stable(void) |
387 | { | 392 | { |
388 | u64 gtod, clock; | ||
389 | |||
390 | if (!sched_clock_stable()) | 393 | if (!sched_clock_stable()) |
391 | return; | 394 | return; |
392 | 395 | ||
@@ -398,9 +401,7 @@ void sched_clock_tick_stable(void) | |||
398 | * TSC to be unstable, any computation will be computing crap. | 401 | * TSC to be unstable, any computation will be computing crap. |
399 | */ | 402 | */ |
400 | local_irq_disable(); | 403 | local_irq_disable(); |
401 | gtod = ktime_get_ns(); | 404 | __sched_clock_gtod_offset(); |
402 | clock = sched_clock(); | ||
403 | __gtod_offset = (clock + __sched_clock_offset) - gtod; | ||
404 | local_irq_enable(); | 405 | local_irq_enable(); |
405 | } | 406 | } |
406 | 407 | ||
@@ -434,6 +435,12 @@ EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event); | |||
434 | 435 | ||
435 | #else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */ | 436 | #else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */ |
436 | 437 | ||
438 | void __init sched_clock_init(void) | ||
439 | { | ||
440 | sched_clock_running = 1; | ||
441 | generic_sched_clock_init(); | ||
442 | } | ||
443 | |||
437 | u64 sched_clock_cpu(int cpu) | 444 | u64 sched_clock_cpu(int cpu) |
438 | { | 445 | { |
439 | if (unlikely(!sched_clock_running)) | 446 | if (unlikely(!sched_clock_running)) |
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index fe365c9a08e9..552406e9713b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -5954,7 +5954,6 @@ void __init sched_init(void) | |||
5954 | int i, j; | 5954 | int i, j; |
5955 | unsigned long alloc_size = 0, ptr; | 5955 | unsigned long alloc_size = 0, ptr; |
5956 | 5956 | ||
5957 | sched_clock_init(); | ||
5958 | wait_bit_init(); | 5957 | wait_bit_init(); |
5959 | 5958 | ||
5960 | #ifdef CONFIG_FAIR_GROUP_SCHED | 5959 | #ifdef CONFIG_FAIR_GROUP_SCHED |
diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 2d8f05aad442..cbc72c2c1fca 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c | |||
@@ -237,7 +237,7 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate) | |||
237 | pr_debug("Registered %pF as sched_clock source\n", read); | 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 | * If no sched_clock() function has been provided at that point, | 243 | * If no sched_clock() function has been provided at that point, |