[PATCH 2/3] timekeeping: move clocksource init to the early place

From: Lei Wen
Date: Thu Apr 03 2014 - 23:19:18 EST


So that in the very early booting place, we could call timekeeping
code, while it would not cause system panic, since clock is not
init yet.

And for system default clock is always jiffies, so that it shall be
safe to do so.

Signed-off-by: Lei Wen <leiwen@xxxxxxxxxxx>
---
include/linux/time.h | 1 +
init/main.c | 1 +
kernel/time/timekeeping.c | 22 +++++++++++++++-------
3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/include/linux/time.h b/include/linux/time.h
index a2f5079..e2d4899 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -127,6 +127,7 @@ extern void read_boot_clock(struct timespec *ts);
extern int persistent_clock_is_local;
extern int update_persistent_clock(struct timespec now);
void timekeeping_init(void);
+void timekeeping_init_early(void);
extern int timekeeping_suspended;

unsigned long get_seconds(void);
diff --git a/init/main.c b/init/main.c
index 9c7fd4c..5723933 100644
--- a/init/main.c
+++ b/init/main.c
@@ -494,6 +494,7 @@ asmlinkage void __init start_kernel(void)
*/
boot_init_stack_canary();

+ timekeeping_init_early();
cgroup_init_early();

local_irq_disable();
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index c196111..b8f850b 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -782,12 +782,25 @@ void __attribute__((weak)) read_boot_clock(struct timespec *ts)
}

/*
- * timekeeping_init - Initializes the clocksource and common timekeeping values
+ * timekeeping_init_early - setup clocksource early
*/
-void __init timekeeping_init(void)
+void __init timekeeping_init_early(void)
{
struct timekeeper *tk = &timekeeper;
struct clocksource *clock;
+
+ clock = clocksource_default_clock();
+ if (clock->enable)
+ clock->enable(clock);
+ tk_setup_internals(tk, clock);
+}
+
+/*
+ * timekeeping_init - Initializes common timekeeping values
+ */
+void __init timekeeping_init(void)
+{
+ struct timekeeper *tk = &timekeeper;
unsigned long flags;
struct timespec now, boot, tmp;

@@ -813,11 +826,6 @@ void __init timekeeping_init(void)
write_seqcount_begin(&timekeeper_seq);
ntp_init();

- clock = clocksource_default_clock();
- if (clock->enable)
- clock->enable(clock);
- tk_setup_internals(tk, clock);
-
tk_set_xtime(tk, &now);
tk->raw_time.tv_sec = 0;
tk->raw_time.tv_nsec = 0;
--
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/