time.c (6b847d795cf4ab3e574f4fcf7193fe245908a195) | time.c (d4cfb11387ee29ba4626546c676fd25c7abbbbb2) |
---|---|
1/* 2 * Common time routines among all ppc machines. 3 * 4 * Written by Cort Dougan (cort@cs.nmt.edu) to merge 5 * Paul Mackerras' version and mine for PReP and Pmac. 6 * MPC8xx/MBX changes by Dan Malek (dmalek@jlc.net). 7 * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com) 8 * --- 827 unchanged lines hidden (view full) --- 836 return (u64)get_rtc(); 837} 838 839static notrace u64 timebase_read(struct clocksource *cs) 840{ 841 return (u64)get_tb(); 842} 843 | 1/* 2 * Common time routines among all ppc machines. 3 * 4 * Written by Cort Dougan (cort@cs.nmt.edu) to merge 5 * Paul Mackerras' version and mine for PReP and Pmac. 6 * MPC8xx/MBX changes by Dan Malek (dmalek@jlc.net). 7 * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com) 8 * --- 827 unchanged lines hidden (view full) --- 836 return (u64)get_rtc(); 837} 838 839static notrace u64 timebase_read(struct clocksource *cs) 840{ 841 return (u64)get_tb(); 842} 843 |
844void update_vsyscall_old(struct timespec *wall_time, struct timespec *wtm, 845 struct clocksource *clock, u32 mult, u64 cycle_last) | 844 845void update_vsyscall(struct timekeeper *tk) |
846{ | 846{ |
847 struct timespec xt; 848 struct clocksource *clock = tk->tkr_mono.clock; 849 u32 mult = tk->tkr_mono.mult; 850 u32 shift = tk->tkr_mono.shift; 851 u64 cycle_last = tk->tkr_mono.cycle_last; |
|
847 u64 new_tb_to_xs, new_stamp_xsec; | 852 u64 new_tb_to_xs, new_stamp_xsec; |
848 u32 frac_sec; | 853 u64 frac_sec; |
849 850 if (clock != &clocksource_timebase) 851 return; 852 | 854 855 if (clock != &clocksource_timebase) 856 return; 857 |
858 xt.tv_sec = tk->xtime_sec; 859 xt.tv_nsec = (long)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift); 860 |
|
853 /* Make userspace gettimeofday spin until we're done. */ 854 ++vdso_data->tb_update_count; 855 smp_mb(); 856 | 861 /* Make userspace gettimeofday spin until we're done. */ 862 ++vdso_data->tb_update_count; 863 smp_mb(); 864 |
857 /* 19342813113834067 ~= 2^(20+64) / 1e9 */ 858 new_tb_to_xs = (u64) mult * (19342813113834067ULL >> clock->shift); 859 new_stamp_xsec = (u64) wall_time->tv_nsec * XSEC_PER_SEC; 860 do_div(new_stamp_xsec, 1000000000); 861 new_stamp_xsec += (u64) wall_time->tv_sec * XSEC_PER_SEC; | 865 /* 866 * This computes ((2^20 / 1e9) * mult) >> shift as a 867 * 0.64 fixed-point fraction. 868 * The computation in the else clause below won't overflow 869 * (as long as the timebase frequency is >= 1.049 MHz) 870 * but loses precision because we lose the low bits of the constant 871 * in the shift. Note that 19342813113834067 ~= 2^(20+64) / 1e9. 872 * For a shift of 24 the error is about 0.5e-9, or about 0.5ns 873 * over a second. (Shift values are usually 22, 23 or 24.) 874 * For high frequency clocks such as the 512MHz timebase clock 875 * on POWER[6789], the mult value is small (e.g. 32768000) 876 * and so we can shift the constant by 16 initially 877 * (295147905179 ~= 2^(20+64-16) / 1e9) and then do the 878 * remaining shifts after the multiplication, which gives a 879 * more accurate result (e.g. with mult = 32768000, shift = 24, 880 * the error is only about 1.2e-12, or 0.7ns over 10 minutes). 881 */ 882 if (mult <= 62500000 && clock->shift >= 16) 883 new_tb_to_xs = ((u64) mult * 295147905179ULL) >> (clock->shift - 16); 884 else 885 new_tb_to_xs = (u64) mult * (19342813113834067ULL >> clock->shift); |
862 | 886 |
863 BUG_ON(wall_time->tv_nsec >= NSEC_PER_SEC); 864 /* this is tv_nsec / 1e9 as a 0.32 fraction */ 865 frac_sec = ((u64) wall_time->tv_nsec * 18446744073ULL) >> 32; | 887 /* 888 * Compute the fractional second in units of 2^-32 seconds. 889 * The fractional second is tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift 890 * in nanoseconds, so multiplying that by 2^32 / 1e9 gives 891 * it in units of 2^-32 seconds. 892 * We assume shift <= 32 because clocks_calc_mult_shift() 893 * generates shift values in the range 0 - 32. 894 */ 895 frac_sec = tk->tkr_mono.xtime_nsec << (32 - shift); 896 do_div(frac_sec, NSEC_PER_SEC); |
866 867 /* | 897 898 /* |
899 * Work out new stamp_xsec value for any legacy users of systemcfg. 900 * stamp_xsec is in units of 2^-20 seconds. 901 */ 902 new_stamp_xsec = frac_sec >> 12; 903 new_stamp_xsec += tk->xtime_sec * XSEC_PER_SEC; 904 905 /* |
|
868 * tb_update_count is used to allow the userspace gettimeofday code 869 * to assure itself that it sees a consistent view of the tb_to_xs and 870 * stamp_xsec variables. It reads the tb_update_count, then reads 871 * tb_to_xs and stamp_xsec and then reads tb_update_count again. If 872 * the two values of tb_update_count match and are even then the 873 * tb_to_xs and stamp_xsec values are consistent. If not, then it 874 * loops back and reads them again until this criteria is met. | 906 * tb_update_count is used to allow the userspace gettimeofday code 907 * to assure itself that it sees a consistent view of the tb_to_xs and 908 * stamp_xsec variables. It reads the tb_update_count, then reads 909 * tb_to_xs and stamp_xsec and then reads tb_update_count again. If 910 * the two values of tb_update_count match and are even then the 911 * tb_to_xs and stamp_xsec values are consistent. If not, then it 912 * loops back and reads them again until this criteria is met. |
875 * We expect the caller to have done the first increment of 876 * vdso_data->tb_update_count already. | |
877 */ 878 vdso_data->tb_orig_stamp = cycle_last; 879 vdso_data->stamp_xsec = new_stamp_xsec; 880 vdso_data->tb_to_xs = new_tb_to_xs; | 913 */ 914 vdso_data->tb_orig_stamp = cycle_last; 915 vdso_data->stamp_xsec = new_stamp_xsec; 916 vdso_data->tb_to_xs = new_tb_to_xs; |
881 vdso_data->wtom_clock_sec = wtm->tv_sec; 882 vdso_data->wtom_clock_nsec = wtm->tv_nsec; 883 vdso_data->stamp_xtime = *wall_time; | 917 vdso_data->wtom_clock_sec = tk->wall_to_monotonic.tv_sec; 918 vdso_data->wtom_clock_nsec = tk->wall_to_monotonic.tv_nsec; 919 vdso_data->stamp_xtime = xt; |
884 vdso_data->stamp_sec_fraction = frac_sec; 885 smp_wmb(); 886 ++(vdso_data->tb_update_count); 887} 888 889void update_vsyscall_tz(void) 890{ 891 vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; --- 342 unchanged lines hidden --- | 920 vdso_data->stamp_sec_fraction = frac_sec; 921 smp_wmb(); 922 ++(vdso_data->tb_update_count); 923} 924 925void update_vsyscall_tz(void) 926{ 927 vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; --- 342 unchanged lines hidden --- |