aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel/time.c
diff options
context:
space:
mode:
authorTony Breeds <tony@bakeyournoodle.com>2007-09-20 23:26:02 -0400
committerPaul Mackerras <paulus@samba.org>2007-10-02 21:48:42 -0400
commitaa3be5f32db137bc4404f32a24b36fb47d48d260 (patch)
treec1478636bf2025cf9e700c48239418836cb43fbd /arch/powerpc/kernel/time.c
parentdf174e3be88d4352bfcfe20d11adc671d2961c79 (diff)
[POWERPC] Implement {read,update}_persistent_clock
With these functions implemented we cooperate better with the generic timekeeping code. This obsoletes the need for the timer sysdev as a bonus. Signed-off-by: Tony Breeds <tony@bakeyournoodle.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/kernel/time.c')
-rw-r--r--arch/powerpc/kernel/time.c85
1 files changed, 26 insertions, 59 deletions
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index d95e68c0a6b3..b94e4dffba19 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -73,16 +73,11 @@
73#include <asm/iseries/hv_call_xm.h> 73#include <asm/iseries/hv_call_xm.h>
74#endif 74#endif
75 75
76/* keep track of when we need to update the rtc */
77time_t last_rtc_update;
78#ifdef CONFIG_PPC_ISERIES 76#ifdef CONFIG_PPC_ISERIES
79static unsigned long __initdata iSeries_recal_titan; 77static unsigned long __initdata iSeries_recal_titan;
80static signed long __initdata iSeries_recal_tb; 78static signed long __initdata iSeries_recal_tb;
81#endif 79#endif
82 80
83/* The decrementer counts down by 128 every 128ns on a 601. */
84#define DECREMENTER_COUNT_601 (1000000000 / HZ)
85
86#define XSEC_PER_SEC (1024*1024) 81#define XSEC_PER_SEC (1024*1024)
87 82
88#ifdef CONFIG_PPC64 83#ifdef CONFIG_PPC64
@@ -348,39 +343,6 @@ void udelay(unsigned long usecs)
348} 343}
349EXPORT_SYMBOL(udelay); 344EXPORT_SYMBOL(udelay);
350 345
351static __inline__ void timer_check_rtc(void)
352{
353 /*
354 * update the rtc when needed, this should be performed on the
355 * right fraction of a second. Half or full second ?
356 * Full second works on mk48t59 clocks, others need testing.
357 * Note that this update is basically only used through
358 * the adjtimex system calls. Setting the HW clock in
359 * any other way is a /dev/rtc and userland business.
360 * This is still wrong by -0.5/+1.5 jiffies because of the
361 * timer interrupt resolution and possible delay, but here we
362 * hit a quantization limit which can only be solved by higher
363 * resolution timers and decoupling time management from timer
364 * interrupts. This is also wrong on the clocks
365 * which require being written at the half second boundary.
366 * We should have an rtc call that only sets the minutes and
367 * seconds like on Intel to avoid problems with non UTC clocks.
368 */
369 if (ppc_md.set_rtc_time && ntp_synced() &&
370 xtime.tv_sec - last_rtc_update >= 659 &&
371 abs((xtime.tv_nsec/1000) - (1000000-1000000/HZ)) < 500000/HZ) {
372 struct rtc_time tm;
373 to_tm(xtime.tv_sec + 1 + timezone_offset, &tm);
374 tm.tm_year -= 1900;
375 tm.tm_mon -= 1;
376 if (ppc_md.set_rtc_time(&tm) == 0)
377 last_rtc_update = xtime.tv_sec + 1;
378 else
379 /* Try again one minute later */
380 last_rtc_update += 60;
381 }
382}
383
384/* 346/*
385 * This version of gettimeofday has microsecond resolution. 347 * This version of gettimeofday has microsecond resolution.
386 */ 348 */
@@ -689,7 +651,6 @@ void timer_interrupt(struct pt_regs * regs)
689 tb_last_jiffy = tb_next_jiffy; 651 tb_last_jiffy = tb_next_jiffy;
690 do_timer(1); 652 do_timer(1);
691 timer_recalc_offset(tb_last_jiffy); 653 timer_recalc_offset(tb_last_jiffy);
692 timer_check_rtc();
693 } 654 }
694 write_sequnlock(&xtime_lock); 655 write_sequnlock(&xtime_lock);
695 } 656 }
@@ -801,11 +762,6 @@ int do_settimeofday(struct timespec *tv)
801 set_normalized_timespec(&xtime, new_sec, new_nsec); 762 set_normalized_timespec(&xtime, new_sec, new_nsec);
802 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); 763 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
803 764
804 /* In case of a large backwards jump in time with NTP, we want the
805 * clock to be updated as soon as the PLL is again in lock.
806 */
807 last_rtc_update = new_sec - 658;
808
809 ntp_clear(); 765 ntp_clear();
810 766
811 new_xsec = xtime.tv_nsec; 767 new_xsec = xtime.tv_nsec;
@@ -881,12 +837,35 @@ void __init generic_calibrate_decr(void)
881#endif 837#endif
882} 838}
883 839
884unsigned long get_boot_time(void) 840int update_persistent_clock(struct timespec now)
841{
842 struct rtc_time tm;
843
844 if (!ppc_md.set_rtc_time)
845 return 0;
846
847 to_tm(now.tv_sec + 1 + timezone_offset, &tm);
848 tm.tm_year -= 1900;
849 tm.tm_mon -= 1;
850
851 return ppc_md.set_rtc_time(&tm);
852}
853
854unsigned long read_persistent_clock(void)
885{ 855{
886 struct rtc_time tm; 856 struct rtc_time tm;
857 static int first = 1;
858
859 /* XXX this is a litle fragile but will work okay in the short term */
860 if (first) {
861 first = 0;
862 if (ppc_md.time_init)
863 timezone_offset = ppc_md.time_init();
887 864
888 if (ppc_md.get_boot_time) 865 /* get_boot_time() isn't guaranteed to be safe to call late */
889 return ppc_md.get_boot_time(); 866 if (ppc_md.get_boot_time)
867 return ppc_md.get_boot_time() -timezone_offset;
868 }
890 if (!ppc_md.get_rtc_time) 869 if (!ppc_md.get_rtc_time)
891 return 0; 870 return 0;
892 ppc_md.get_rtc_time(&tm); 871 ppc_md.get_rtc_time(&tm);
@@ -898,14 +877,10 @@ unsigned long get_boot_time(void)
898void __init time_init(void) 877void __init time_init(void)
899{ 878{
900 unsigned long flags; 879 unsigned long flags;
901 unsigned long tm = 0;
902 struct div_result res; 880 struct div_result res;
903 u64 scale, x; 881 u64 scale, x;
904 unsigned shift; 882 unsigned shift;
905 883
906 if (ppc_md.time_init != NULL)
907 timezone_offset = ppc_md.time_init();
908
909 if (__USE_RTC()) { 884 if (__USE_RTC()) {
910 /* 601 processor: dec counts down by 128 every 128ns */ 885 /* 601 processor: dec counts down by 128 every 128ns */
911 ppc_tb_freq = 1000000000; 886 ppc_tb_freq = 1000000000;
@@ -980,19 +955,14 @@ void __init time_init(void)
980 /* Save the current timebase to pretty up CONFIG_PRINTK_TIME */ 955 /* Save the current timebase to pretty up CONFIG_PRINTK_TIME */
981 boot_tb = get_tb_or_rtc(); 956 boot_tb = get_tb_or_rtc();
982 957
983 tm = get_boot_time();
984
985 write_seqlock_irqsave(&xtime_lock, flags); 958 write_seqlock_irqsave(&xtime_lock, flags);
986 959
987 /* If platform provided a timezone (pmac), we correct the time */ 960 /* If platform provided a timezone (pmac), we correct the time */
988 if (timezone_offset) { 961 if (timezone_offset) {
989 sys_tz.tz_minuteswest = -timezone_offset / 60; 962 sys_tz.tz_minuteswest = -timezone_offset / 60;
990 sys_tz.tz_dsttime = 0; 963 sys_tz.tz_dsttime = 0;
991 tm -= timezone_offset;
992 } 964 }
993 965
994 xtime.tv_sec = tm;
995 xtime.tv_nsec = 0;
996 do_gtod.varp = &do_gtod.vars[0]; 966 do_gtod.varp = &do_gtod.vars[0];
997 do_gtod.var_idx = 0; 967 do_gtod.var_idx = 0;
998 do_gtod.varp->tb_orig_stamp = tb_last_jiffy; 968 do_gtod.varp->tb_orig_stamp = tb_last_jiffy;
@@ -1010,9 +980,6 @@ void __init time_init(void)
1010 980
1011 time_freq = 0; 981 time_freq = 0;
1012 982
1013 last_rtc_update = xtime.tv_sec;
1014 set_normalized_timespec(&wall_to_monotonic,
1015 -xtime.tv_sec, -xtime.tv_nsec);
1016 write_sequnlock_irqrestore(&xtime_lock, flags); 983 write_sequnlock_irqrestore(&xtime_lock, flags);
1017 984
1018 /* Not exact, but the timer interrupt takes care of this */ 985 /* Not exact, but the timer interrupt takes care of this */