aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/time
diff options
context:
space:
mode:
authorJohn Stultz <john.stultz@linaro.org>2012-07-13 01:21:54 -0400
committerThomas Gleixner <tglx@linutronix.de>2012-07-15 04:39:06 -0400
commit1f4f948706bcec1b51bf6492bf04057d2e21e273 (patch)
tree1677cf2f130da9ff53259fdb658fa53a4ef81b4e /kernel/time
parent1e75fa8be9fb61e1af46b5b3b176347a4c958ca1 (diff)
time: Refactor accumulation of nsecs to secs
We do the exact same logic moving nsecs to secs in the timekeeper in multiple places, so condense this into a single function. Signed-off-by: John Stultz <john.stultz@linaro.org> Reviewed-by: Ingo Molnar <mingo@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Prarit Bhargava <prarit@redhat.com> Link: http://lkml.kernel.org/r/1342156917-25092-6-git-send-email-john.stultz@linaro.org Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/time')
-rw-r--r--kernel/time/timekeeping.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index b98d9bd73e5e..cb4a433bab97 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -991,6 +991,35 @@ static void timekeeping_adjust(s64 offset)
991 991
992 992
993/** 993/**
994 * accumulate_nsecs_to_secs - Accumulates nsecs into secs
995 *
996 * Helper function that accumulates a the nsecs greater then a second
997 * from the xtime_nsec field to the xtime_secs field.
998 * It also calls into the NTP code to handle leapsecond processing.
999 *
1000 */
1001static inline void accumulate_nsecs_to_secs(struct timekeeper *tk)
1002{
1003 u64 nsecps = (u64)NSEC_PER_SEC << tk->shift;
1004
1005 while (tk->xtime_nsec >= nsecps) {
1006 int leap;
1007
1008 tk->xtime_nsec -= nsecps;
1009 tk->xtime_sec++;
1010
1011 /* Figure out if its a leap sec and apply if needed */
1012 leap = second_overflow(tk->xtime_sec);
1013 tk->xtime_sec += leap;
1014 tk->wall_to_monotonic.tv_sec -= leap;
1015 if (leap)
1016 clock_was_set_delayed();
1017
1018 }
1019}
1020
1021
1022/**
994 * logarithmic_accumulation - shifted accumulation of cycles 1023 * logarithmic_accumulation - shifted accumulation of cycles
995 * 1024 *
996 * This functions accumulates a shifted interval of cycles into 1025 * This functions accumulates a shifted interval of cycles into
@@ -1001,7 +1030,6 @@ static void timekeeping_adjust(s64 offset)
1001 */ 1030 */
1002static cycle_t logarithmic_accumulation(cycle_t offset, u32 shift) 1031static cycle_t logarithmic_accumulation(cycle_t offset, u32 shift)
1003{ 1032{
1004 u64 nsecps = (u64)NSEC_PER_SEC << timekeeper.shift;
1005 u64 raw_nsecs; 1033 u64 raw_nsecs;
1006 1034
1007 /* If the offset is smaller than a shifted interval, do nothing */ 1035 /* If the offset is smaller than a shifted interval, do nothing */
@@ -1013,16 +1041,8 @@ static cycle_t logarithmic_accumulation(cycle_t offset, u32 shift)
1013 timekeeper.clock->cycle_last += timekeeper.cycle_interval << shift; 1041 timekeeper.clock->cycle_last += timekeeper.cycle_interval << shift;
1014 1042
1015 timekeeper.xtime_nsec += timekeeper.xtime_interval << shift; 1043 timekeeper.xtime_nsec += timekeeper.xtime_interval << shift;
1016 while (timekeeper.xtime_nsec >= nsecps) { 1044
1017 int leap; 1045 accumulate_nsecs_to_secs(&timekeeper);
1018 timekeeper.xtime_nsec -= nsecps;
1019 timekeeper.xtime_sec++;
1020 leap = second_overflow(timekeeper.xtime_sec);
1021 timekeeper.xtime_sec += leap;
1022 timekeeper.wall_to_monotonic.tv_sec -= leap;
1023 if (leap)
1024 clock_was_set_delayed();
1025 }
1026 1046
1027 /* Accumulate raw time */ 1047 /* Accumulate raw time */
1028 raw_nsecs = timekeeper.raw_interval << shift; 1048 raw_nsecs = timekeeper.raw_interval << shift;
@@ -1132,17 +1152,7 @@ static void update_wall_time(void)
1132 * Finally, make sure that after the rounding 1152 * Finally, make sure that after the rounding
1133 * xtime_nsec isn't larger than NSEC_PER_SEC 1153 * xtime_nsec isn't larger than NSEC_PER_SEC
1134 */ 1154 */
1135 if (unlikely(timekeeper.xtime_nsec >= 1155 accumulate_nsecs_to_secs(&timekeeper);
1136 ((u64)NSEC_PER_SEC << timekeeper.shift))) {
1137 int leap;
1138 timekeeper.xtime_nsec -= (u64)NSEC_PER_SEC << timekeeper.shift;
1139 timekeeper.xtime_sec++;
1140 leap = second_overflow(timekeeper.xtime_sec);
1141 timekeeper.xtime_sec += leap;
1142 timekeeper.wall_to_monotonic.tv_sec -= leap;
1143 if (leap)
1144 clock_was_set_delayed();
1145 }
1146 1156
1147 timekeeping_update(false); 1157 timekeeping_update(false);
1148 1158