diff options
-rw-r--r-- | include/linux/timex.h | 3 | ||||
-rw-r--r-- | kernel/timer.c | 39 |
2 files changed, 37 insertions, 5 deletions
diff --git a/include/linux/timex.h b/include/linux/timex.h index 04a4a8cb4ed3..b7ca1204e42a 100644 --- a/include/linux/timex.h +++ b/include/linux/timex.h | |||
@@ -345,6 +345,9 @@ time_interpolator_reset(void) | |||
345 | 345 | ||
346 | #endif /* !CONFIG_TIME_INTERPOLATION */ | 346 | #endif /* !CONFIG_TIME_INTERPOLATION */ |
347 | 347 | ||
348 | /* Returns how long ticks are at present, in ns / 2^(SHIFT_SCALE-10). */ | ||
349 | extern u64 current_tick_length(void); | ||
350 | |||
348 | #endif /* KERNEL */ | 351 | #endif /* KERNEL */ |
349 | 352 | ||
350 | #endif /* LINUX_TIMEX_H */ | 353 | #endif /* LINUX_TIMEX_H */ |
diff --git a/kernel/timer.c b/kernel/timer.c index b9dad3994676..fe3a9a9f8328 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
@@ -717,12 +717,16 @@ static void second_overflow(void) | |||
717 | #endif | 717 | #endif |
718 | } | 718 | } |
719 | 719 | ||
720 | /* in the NTP reference this is called "hardclock()" */ | 720 | /* |
721 | static void update_wall_time_one_tick(void) | 721 | * Returns how many microseconds we need to add to xtime this tick |
722 | * in doing an adjustment requested with adjtime. | ||
723 | */ | ||
724 | static long adjtime_adjustment(void) | ||
722 | { | 725 | { |
723 | long time_adjust_step, delta_nsec; | 726 | long time_adjust_step; |
724 | 727 | ||
725 | if ((time_adjust_step = time_adjust) != 0 ) { | 728 | time_adjust_step = time_adjust; |
729 | if (time_adjust_step) { | ||
726 | /* | 730 | /* |
727 | * We are doing an adjtime thing. Prepare time_adjust_step to | 731 | * We are doing an adjtime thing. Prepare time_adjust_step to |
728 | * be within bounds. Note that a positive time_adjust means we | 732 | * be within bounds. Note that a positive time_adjust means we |
@@ -733,10 +737,19 @@ static void update_wall_time_one_tick(void) | |||
733 | */ | 737 | */ |
734 | time_adjust_step = min(time_adjust_step, (long)tickadj); | 738 | time_adjust_step = min(time_adjust_step, (long)tickadj); |
735 | time_adjust_step = max(time_adjust_step, (long)-tickadj); | 739 | time_adjust_step = max(time_adjust_step, (long)-tickadj); |
740 | } | ||
741 | return time_adjust_step; | ||
742 | } | ||
736 | 743 | ||
744 | /* in the NTP reference this is called "hardclock()" */ | ||
745 | static void update_wall_time_one_tick(void) | ||
746 | { | ||
747 | long time_adjust_step, delta_nsec; | ||
748 | |||
749 | time_adjust_step = adjtime_adjustment(); | ||
750 | if (time_adjust_step) | ||
737 | /* Reduce by this step the amount of time left */ | 751 | /* Reduce by this step the amount of time left */ |
738 | time_adjust -= time_adjust_step; | 752 | time_adjust -= time_adjust_step; |
739 | } | ||
740 | delta_nsec = tick_nsec + time_adjust_step * 1000; | 753 | delta_nsec = tick_nsec + time_adjust_step * 1000; |
741 | /* | 754 | /* |
742 | * Advance the phase, once it gets to one microsecond, then | 755 | * Advance the phase, once it gets to one microsecond, then |
@@ -759,6 +772,22 @@ static void update_wall_time_one_tick(void) | |||
759 | } | 772 | } |
760 | 773 | ||
761 | /* | 774 | /* |
775 | * Return how long ticks are at the moment, that is, how much time | ||
776 | * update_wall_time_one_tick will add to xtime next time we call it | ||
777 | * (assuming no calls to do_adjtimex in the meantime). | ||
778 | * The return value is in fixed-point nanoseconds with SHIFT_SCALE-10 | ||
779 | * bits to the right of the binary point. | ||
780 | * This function has no side-effects. | ||
781 | */ | ||
782 | u64 current_tick_length(void) | ||
783 | { | ||
784 | long delta_nsec; | ||
785 | |||
786 | delta_nsec = tick_nsec + adjtime_adjustment() * 1000; | ||
787 | return ((u64) delta_nsec << (SHIFT_SCALE - 10)) + time_adj; | ||
788 | } | ||
789 | |||
790 | /* | ||
762 | * Using a loop looks inefficient, but "ticks" is | 791 | * Using a loop looks inefficient, but "ticks" is |
763 | * usually just one (we shouldn't be losing ticks, | 792 | * usually just one (we shouldn't be losing ticks, |
764 | * we're doing this this way mainly for interrupt | 793 | * we're doing this this way mainly for interrupt |