Skip to content

Commit 5d2a4e9

Browse files
Pavel TatashinKAGA-KOKO
authored andcommitted
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
1 parent 4763f03 commit 5d2a4e9

5 files changed

Lines changed: 22 additions & 17 deletions

File tree

‎include/linux/sched_clock.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
#define LINUX_SCHED_CLOCK
1010

1111
#ifdef CONFIG_GENERIC_SCHED_CLOCK
12-
extern void sched_clock_postinit(void);
12+
extern void generic_sched_clock_init(void);
1313

1414
extern void sched_clock_register(u64 (*read)(void), int bits,
1515
unsigned long rate);
1616
#else
17-
static inline void sched_clock_postinit(void) { }
17+
static inline void generic_sched_clock_init(void) { }
1818

1919
static inline void sched_clock_register(u64 (*read)(void), int bits,
2020
unsigned long rate)
2121
{
22-
;
2322
}
2423
#endif
2524

‎init/main.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
#include <linux/pti.h>
8080
#include <linux/blkdev.h>
8181
#include <linux/elevator.h>
82-
#include <linux/sched_clock.h>
82+
#include <linux/sched/clock.h>
8383
#include <linux/sched/task.h>
8484
#include <linux/sched/task_stack.h>
8585
#include <linux/context_tracking.h>
@@ -642,7 +642,7 @@ asmlinkage __visible void __init start_kernel(void)
642642
softirq_init();
643643
timekeeping_init();
644644
time_init();
645-
sched_clock_postinit();
645+
sched_clock_init();
646646
printk_safe_init();
647647
perf_event_init();
648648
profile_init();

‎kernel/sched/clock.c‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
*
5454
*/
5555
#include "sched.h"
56+
#include <linux/sched_clock.h>
5657

5758
/*
5859
* Scheduler clock - returns current time in nanosec units.
@@ -68,11 +69,6 @@ EXPORT_SYMBOL_GPL(sched_clock);
6869

6970
__read_mostly int sched_clock_running;
7071

71-
void sched_clock_init(void)
72-
{
73-
sched_clock_running = 1;
74-
}
75-
7672
#ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
7773
/*
7874
* We must start with !__sched_clock_stable because the unstable -> stable
@@ -199,6 +195,15 @@ void clear_sched_clock_stable(void)
199195
__clear_sched_clock_stable();
200196
}
201197

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+
}
202207
/*
203208
* We run this as late_initcall() such that it runs after all built-in drivers,
204209
* notably: acpi_processor and intel_idle, which can mark the TSC as unstable.
@@ -385,8 +390,6 @@ void sched_clock_tick(void)
385390

386391
void sched_clock_tick_stable(void)
387392
{
388-
u64 gtod, clock;
389-
390393
if (!sched_clock_stable())
391394
return;
392395

@@ -398,9 +401,7 @@ void sched_clock_tick_stable(void)
398401
* TSC to be unstable, any computation will be computing crap.
399402
*/
400403
local_irq_disable();
401-
gtod = ktime_get_ns();
402-
clock = sched_clock();
403-
__gtod_offset = (clock + __sched_clock_offset) - gtod;
404+
__sched_clock_gtod_offset();
404405
local_irq_enable();
405406
}
406407

@@ -434,6 +435,12 @@ EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event);
434435

435436
#else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */
436437

438+
void __init sched_clock_init(void)
439+
{
440+
sched_clock_running = 1;
441+
generic_sched_clock_init();
442+
}
443+
437444
u64 sched_clock_cpu(int cpu)
438445
{
439446
if (unlikely(!sched_clock_running))

‎kernel/sched/core.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5954,7 +5954,6 @@ void __init sched_init(void)
59545954
int i, j;
59555955
unsigned long alloc_size = 0, ptr;
59565956

5957-
sched_clock_init();
59585957
wait_bit_init();
59595958

59605959
#ifdef CONFIG_FAIR_GROUP_SCHED

‎kernel/time/sched_clock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
237237
pr_debug("Registered %pF as sched_clock source\n", read);
238238
}
239239

240-
void __init sched_clock_postinit(void)
240+
void __init generic_sched_clock_init(void)
241241
{
242242
/*
243243
* If no sched_clock() function has been provided at that point,

0 commit comments

Comments
 (0)