gettimeoffset() for sn2
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jes Sorensen
Jes> This patch is against 2.4.21-pre5-cset-1.1020, I will be working on a Jes> 2.5.x version later today.
Jes> Unless there are strong objections, I'd love to see this applied to the Jes> 2.4.x tree. Oh yes, I tested it on my zx1 as well.
One small comment: lose the " = NULL" initializers for the global *time_hook variables; they only increase the data size for no good reason.
The bigger issue: note that do_gettimeofday() acquires a _read_ lock. Thus, you need to be careful about updating rtc_offset atomically.
--david
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
"David" = David Mosberger <[email protected]> writes:
On Wed, 23 Apr 2003 12:19:25 -0400, Jes Sorensen <[email protected]> said:
Jes> This patch is against 2.4.21-pre5-cset-1.1020, I will be working Jes> on a 2.5.x version later today.
Jes> Unless there are strong objections, I'd love to see this applied Jes> to the 2.4.x tree. Oh yes, I tested it on my zx1 as well.
David> One small comment: lose the " = NULL" initializers for the David> global *time_hook variables; they only increase the data size David> for no good reason.
Whoops, good point, thanks.
David> The bigger issue: note that do_gettimeofday() acquires a _read_ David> lock. Thus, you need to be careful about updating rtc_offset David> atomically.
Argh, you are right, here we go again, now I think I got it all covered. However I think I will stop declaring victory on this one, everytime I do so it comes back to haunt me. This version also fixed a bug where i was scaling the RTC clock twice, not that it was lethal, but it was still a bug.
Thanks for your comments.
Cheers,
Jes
arch/ia64/kernel/time.c +16 -8
@@ -26,6 +26,9 @@extern rwlock_t xtime_lock;extern unsigned long wall_jiffies;extern unsigned long last_time_offset; +static unsigned long __ia64_gettimeoffset (void ); + +unsigned long (*gettimeoffset)(void ) = &__ia64_gettimeoffset;#ifdef CONFIG_IA64_DEBUG_IRQ
@@ -33,6 +36,8 @@#endif +#define TIME_KEEPER_ID 0/* smp_processor_id() of time-keeper */ +static void do_profile (unsigned long ip) {
@@ -58,18 +63,18 @@ }/* -* Return the number of micro-seconds that elapsed since the last update to jiffy. The -* xtime_lock must be at least read-locked when calling this routine. +* Return the number of micro-seconds that elapsed since the last update to +* jiffy. The xtime_lock must be at least read-locked when calling this +* routine. */ -static inline unsigned long -gettimeoffset (void ) +static unsigned long +__ia64_gettimeoffset (void ) {unsigned long elapsed_cycles, lost = jiffies - wall_jiffies;unsigned long now, last_tick; -# define time_keeper_id 0/* smp_processor_id() of time-keeper */ - last_tick = (cpu_data (time_keeper_id)->itm_next - - (lost +1 )*cpu_data (time_keeper_id)->itm_delta); + last_tick = (cpu_data (TIME_KEEPER_ID )->itm_next + - (lost +1 )*cpu_data (TIME_KEEPER_ID )->itm_delta); now =ia64_get_itc ();if ((long ) (now - last_tick) <0 ) {
@@ -102,6 +107,9 @@ tv->tv_sec--; } +if (update_wall_time_hook) +update_wall_time_hook (); + xtime = *tv; time_adjust =0 ;/* stop active adjtime() */ time_status |=STA_UNSYNC ;
@@ -171,7 +179,7 @@#endif new_itm += local_cpu_data->itm_delta; -if (smp_processor_id () =0 ) { +if (smp_processor_id () =TIME_KEEPER_ID ) {/* * Here we are in the timer irq handler. We have irqs locally * disabled, but we don't know if the timer_bh is running on
arch/ia64/sn/kernel/setup.c +4 -8
@@ -78,7 +78,6 @@extern void bte_init_cpu (void );unsigned long sn_rtc_cycles_per_second; -unsigned long sn_rtc_usec_per_cyc;partid_t sn_partid =-1 ;char sn_system_serial_number_string[128 ];
@@ -209,6 +208,8 @@extern nasid_t master_nasid; +extern void sn_timer_init (void ); +/** * sn_setup - SN platform setup routine * @cmdline_p: kernel command line
@@ -261,13 +262,6 @@else sn_rtc_cycles_per_second = ticks_per_sec; -#ifdef CONFIG_IA64_SGI_SN1 -/* PROM has wrong value on SN1 */ - sn_rtc_cycles_per_second =990177 ; -#endif - sn_rtc_usec_per_cyc = ((1000000UL <<IA64_USEC_PER_CYC_SHIFT ) - + sn_rtc_cycles_per_second/2 ) / sn_rtc_cycles_per_second; -for (i=0 ;i<NR_CPUS ;i++) _sn_irq_desc[i] = _irq_desc;
@@ -309,6 +303,8 @@#endif screen_info = sn_screen_info; +sn_timer_init (); +/* * Turn off "floating-point assist fault" warnings by default. */
arch/ia64/sn/kernel/sn2/Makefile +2 -1
@@ -42,6 +42,7 @@ O_TARGET = sn2.o -obj-y = cache.o iomv.o ptc_deadlock.o sn2_smp.o sn_proc_fs.o +obj-y = cache.o iomv.o ptc_deadlock.o sn2_smp.o sn_proc_fs.o \ + timer.o include $(TOPDIR)/Rules.make
arch/ia64/sn/kernel/sn2/timer.c +100 -0
100 lines not on this page · raw message
include/asm-ia64/sn/clksupport.h +2 -2
@@ -38,7 +38,7 @@extern nasid_t master_nasid; -#define RTC_MASK (0x007fffffffffffff) +#define RTC_MASK 0x007fffffffffffffUL/* clocks are not synchronized yet on SN1 - used node 0 (problem if no NASID 0) */ #define RTC_COUNTER_ADDR ((clkreg_t*)REMOTE_HUB_ADDR(master_nasid, PI_RT_COUNTER))#define RTC_COMPARE_A_ADDR ((clkreg_t*)REMOTE_HUB_ADDR(master_nasid, PI_RT_COMPARE_A))
@@ -52,7 +52,7 @@#include <asm/sn/sn2/addrs.h> #include <asm/sn/sn2/shubio.h> #include <asm/sn/sn2/shub_mmr.h> -#define RTC_MASK (SH_RTC_MASK) +#define RTC_MASK SH_RTC_MASK#define RTC_COUNTER_ADDR ((clkreg_t*)LOCAL_MMR_ADDR(SH_RTC))#define RTC_COMPARE_A_ADDR ((clkreg_t*)LOCAL_MMR_ADDR(SH_RTC))#define RTC_COMPARE_B_ADDR ((clkreg_t*)LOCAL_MMR_ADDR(SH_RTC))
include/linux/timex.h +7 -0
@@ -286,6 +286,13 @@extern long pps_errcnt;/* calibration errors */ extern long pps_stbcnt;/* stability limit exceeded */ +/* +* Call-back for high precision timer sources to snapshot every time +* wall_jiffies is updated. +*/ +extern void (*update_wall_time_hook)(void ); +extern void (*reset_wall_time_hook)(void ); +#endif /* KERNEL */ #endif /* LINUX_TIMEX_H */
kernel/time.c +3 -0
@@ -82,6 +82,9 @@return -EFAULT ;write_lock_irq (&xtime_lock);vxtime_lock (); + +if (reset_wall_time_hook) +reset_wall_time_hook (); xtime.tv_sec = value; xtime.tv_usec =0 ;vxtime_unlock ();
kernel/timer.c +14 -0
@@ -514,6 +514,15 @@ }/* +* Hook for using external high precision timers for the system clock. +* On systems where the CPU clock isn't synchronized between CPUs, +* it is necessary to use an external source such as an RTC to obtain +* precision in gettimeofday(). +*/ +void (*update_wall_time_hook)(void ); +void (*reset_wall_time_hook)(void ); + +/* * Using a loop looks inefficient, but "ticks" is * usually just one (we shouldn't be losing ticks, * we're doing this this way mainly for interrupt
@@ -525,12 +534,17 @@do { ticks--;update_wall_time_one_tick (); + +if (update_wall_time_hook) +update_wall_time_hook (); }while (ticks);if (xtime.tv_usec >=1000000 ) { xtime.tv_usec -=1000000 ; xtime.tv_sec++;second_overflow (); +if (update_wall_time_hook) +update_wall_time_hook (); } }
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jes Sorensen
Jes> Argh, you are right, here we go again, now I think I got it all Jes> covered. However I think I will stop declaring victory on this Jes> one, everytime I do so it comes back to haunt me. This version Jes> also fixed a bug where i was scaling the RTC clock twice, not Jes> that it was lethal, but it was still a bug.
The patch looks nice and clean to me (didn't try it out myself, though).
--david