From: john stultz Cleans up some of the wall_time offset manipulations with a __set_wall_time_offset() helper. Also fixes some whitespaces. Signed-off-by: John Stultz Signed-off-by: Andrew Morton --- kernel/time/clocksource.c | 1 kernel/time/timeofday.c | 68 ++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 33 deletions(-) diff -puN kernel/time/clocksource.c~time-generic-timekeeping-infrastructure-wall_offset-helper-cleanup kernel/time/clocksource.c --- devel/kernel/time/clocksource.c~time-generic-timekeeping-infrastructure-wall_offset-helper-cleanup 2006-02-21 13:35:02.000000000 -0800 +++ devel-akpm/kernel/time/clocksource.c 2006-02-21 13:35:02.000000000 -0800 @@ -155,6 +155,7 @@ int register_clocksource(struct clocksou spin_unlock_irqrestore(&clocksource_lock, flags); return ret; } + EXPORT_SYMBOL(register_clocksource); /** diff -puN kernel/time/timeofday.c~time-generic-timekeeping-infrastructure-wall_offset-helper-cleanup kernel/time/timeofday.c --- devel/kernel/time/timeofday.c~time-generic-timekeeping-infrastructure-wall_offset-helper-cleanup 2006-02-21 13:35:02.000000000 -0800 +++ devel-akpm/kernel/time/timeofday.c 2006-02-21 13:35:02.000000000 -0800 @@ -338,6 +338,35 @@ void do_gettimeofday(struct timeval *tv) EXPORT_SYMBOL(do_gettimeofday); /** + * __increment_system_time - Increments system time + * @delta: nanosecond delta to add to the time variables + * + * Private helper that increments system_time and related + * timekeeping variables. + */ +static void __increment_system_time(s64 delta) +{ + system_time = ktime_add_ns(system_time, delta); + timespec_add_ns(&wall_time_ts, delta); + timespec_add_ns(&mono_time_ts, delta); +} + +/** + * __set_wall_time_offset - Sets the wall time offset + * @delta: nanosecond delta to adjust to the time variables + * + * Private helper that adjusts wall_time_offset and related + * timekeeping variables. + */ +static void __set_wall_time_offset(ktime_t val) +{ + wall_time_offset = val; + wall_time_ts = ktime_to_timespec(ktime_add(system_time, + wall_time_offset)); + monotonic_time_offset_ts = ktime_to_timespec(wall_time_offset); +} + +/** * do_settimeofday - Sets the time of day * @tv: pointer to the timespec variable containing the new time * @@ -356,12 +385,7 @@ int do_settimeofday(struct timespec *tv) write_seqlock_irqsave(&system_time_lock, flags); /* calculate the new offset from the monotonic clock */ - wall_time_offset = ktime_sub(newtime, __get_monotonic_clock()); - - /* update the internal timespec variables */ - wall_time_ts = ktime_to_timespec(ktime_add(system_time, - wall_time_offset)); - monotonic_time_offset_ts = ktime_to_timespec(wall_time_offset); + __set_wall_time_offset(ktime_sub(newtime, __get_monotonic_clock())); ntp_clear(); update_legacy_time_values(); @@ -377,20 +401,6 @@ int do_settimeofday(struct timespec *tv) EXPORT_SYMBOL(do_settimeofday); /** - * __increment_system_time - Increments system time - * @delta: nanosecond delta to add to the time variables - * - * Private helper that increments system_time and related - * timekeeping variables. - */ -static void __increment_system_time(nsec_t delta) -{ - system_time = ktime_add_ns(system_time, delta); - timespec_add_ns(&wall_time_ts, delta); - timespec_add_ns(&mono_time_ts, delta); -} - -/** * timeofday_suspend_hook - allows the timeofday subsystem to be shutdown * @dev: unused * @state: unused @@ -539,12 +549,9 @@ static void timeofday_periodic_hook(unsi if (second_check >= NSEC_PER_SEC) { /* do ntp leap second processing: */ leapsecond = ntp_leapsecond(wall_time_ts); - if (leapsecond) { - wall_time_offset = ktime_add_ns(wall_time_offset, - leapsecond * NSEC_PER_SEC); - wall_time_ts.tv_sec += leapsecond; - monotonic_time_offset_ts.tv_sec += leapsecond; - } + if (leapsecond) + __set_wall_time_offset(ktime_add_ns(wall_time_offset, + leapsecond * NSEC_PER_SEC)); second_check -= NSEC_PER_SEC; } /* sync the persistent clock: */ @@ -662,13 +669,8 @@ void __init timeofday_init(void) /* initialize wall_time_offset to now: */ /* XXX - this should be something like ns_to_ktime() */ - wall_time_offset = ktime_add_ns(wall_time_offset, - read_persistent_clock()); - - /* initialize timespec values: */ - wall_time_ts = ktime_to_timespec(ktime_add(system_time, - wall_time_offset)); - monotonic_time_offset_ts = ktime_to_timespec(wall_time_offset); + __set_wall_time_offset(ktime_add_ns(wall_time_offset, + read_persistent_clock())); /* clear NTP scaling factor & state machine: */ ntp_adj = 0; _