mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] monotonic seqlock for HPET timer
@ 2003-10-08 18:58 Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2003-10-08 18:58 UTC (permalink / raw)
  To: john stultz, Linus Torvalds, Andrew Morton; +Cc: linux-kernel

Replace read/write lock used for HPET timer monotonic_lock with seqlock.
Similar to locking used on xtime and monotonic_lock in timers/timer_tsc.c

It builds and runs, but I don't have hardware with HPET support to test.
Not a big deal (yet) since only hangcheck timer uses monotonic clock so far.

diff -urN -X dontdiff linux-2.5/arch/i386/kernel/timers/timer_hpet.c linux-2.5-net/arch/i386/kernel/timers/timer_hpet.c
--- linux-2.5/arch/i386/kernel/timers/timer_hpet.c	2003-09-30 13:53:48.000000000 -0700
+++ linux-2.5-net/arch/i386/kernel/timers/timer_hpet.c	2003-09-16 12:54:26.000000000 -0700
@@ -24,7 +24,7 @@
 static unsigned long last_tsc_low;	/* lsb 32 bits of Time Stamp Counter */
 static unsigned long last_tsc_high; 	/* msb 32 bits of Time Stamp Counter */
 static unsigned long long monotonic_base;
-static rwlock_t monotonic_lock = RW_LOCK_UNLOCKED;
+static seqlock_t monotonic_lock = SEQLOCK_UNLOCKED;
 
 /* convert from cycles(64bits) => nanoseconds (64bits)
  *  basic equation:
@@ -57,12 +57,14 @@
 static unsigned long long monotonic_clock_hpet(void)
 {
 	unsigned long long last_offset, this_offset, base;
+	unsigned seq;
 
 	/* atomically read monotonic base & last_offset */
-	read_lock_irq(&monotonic_lock);
-	last_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low;
-	base = monotonic_base;
-	read_unlock_irq(&monotonic_lock);
+	do {
+		seq = read_seqbegin(&monotonic_lock);
+		last_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low;
+		base = monotonic_base;
+	} while (read_seqretry(&monotonic_lock, seq));
 
 	/* Read the Time Stamp Counter */
 	rdtscll(this_offset);
@@ -99,7 +101,7 @@
 	unsigned long long this_offset, last_offset;
 	unsigned long offset;
 
-	write_lock(&monotonic_lock);
+	write_seqlock(&monotonic_lock);
 	last_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low;
 	rdtsc(last_tsc_low, last_tsc_high);
 
@@ -113,7 +115,7 @@
 	/* update the monotonic base value */
 	this_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low;
 	monotonic_base += cycles_2_ns(this_offset - last_offset);
-	write_unlock(&monotonic_lock);
+	write_sequnlock(&monotonic_lock);
 }
 
 void delay_hpet(unsigned long loops)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: [PATCH] monotonic seqlock for HPET timer
@ 2003-10-09  0:15 Pallipadi, Venkatesh
  0 siblings, 0 replies; 2+ messages in thread
From: Pallipadi, Venkatesh @ 2003-10-09  0:15 UTC (permalink / raw)
  To: Stephen Hemminger, john stultz, Linus Torvalds, Andrew Morton
  Cc: linux-kernel



Tested on HPET capable system. Works fine.

Thanks,
-Venkatesh

> -----Original Message-----
> From: linux-kernel-owner@vger.kernel.org 
> [mailto:linux-kernel-owner@vger.kernel.org] On Behalf Of 
> Stephen Hemminger
> Sent: Wednesday, October 08, 2003 11:58 AM
> To: john stultz; Linus Torvalds; Andrew Morton
> Cc: linux-kernel@vger.kernel.org
> Subject: [PATCH] monotonic seqlock for HPET timer
> 
> 
> Replace read/write lock used for HPET timer monotonic_lock 
> with seqlock.
> Similar to locking used on xtime and monotonic_lock in 
> timers/timer_tsc.c
> 
> It builds and runs, but I don't have hardware with HPET 
> support to test.
> Not a big deal (yet) since only hangcheck timer uses 
> monotonic clock so far.
> 
> diff -urN -X dontdiff 
> linux-2.5/arch/i386/kernel/timers/timer_hpet.c 
> linux-2.5-net/arch/i386/kernel/timers/timer_hpet.c
> --- linux-2.5/arch/i386/kernel/timers/timer_hpet.c	
> 2003-09-30 13:53:48.000000000 -0700
> +++ linux-2.5-net/arch/i386/kernel/timers/timer_hpet.c	
> 2003-09-16 12:54:26.000000000 -0700
> @@ -24,7 +24,7 @@
>  static unsigned long last_tsc_low;	/* lsb 32 bits of Time 
> Stamp Counter */
>  static unsigned long last_tsc_high; 	/* msb 32 bits of Time 
> Stamp Counter */
>  static unsigned long long monotonic_base;
> -static rwlock_t monotonic_lock = RW_LOCK_UNLOCKED;
> +static seqlock_t monotonic_lock = SEQLOCK_UNLOCKED;
>  
>  /* convert from cycles(64bits) => nanoseconds (64bits)
>   *  basic equation:
> @@ -57,12 +57,14 @@
>  static unsigned long long monotonic_clock_hpet(void)
>  {
>  	unsigned long long last_offset, this_offset, base;
> +	unsigned seq;
>  
>  	/* atomically read monotonic base & last_offset */
> -	read_lock_irq(&monotonic_lock);
> -	last_offset = ((unsigned long 
> long)last_tsc_high<<32)|last_tsc_low;
> -	base = monotonic_base;
> -	read_unlock_irq(&monotonic_lock);
> +	do {
> +		seq = read_seqbegin(&monotonic_lock);
> +		last_offset = ((unsigned long 
> long)last_tsc_high<<32)|last_tsc_low;
> +		base = monotonic_base;
> +	} while (read_seqretry(&monotonic_lock, seq));
>  
>  	/* Read the Time Stamp Counter */
>  	rdtscll(this_offset);
> @@ -99,7 +101,7 @@
>  	unsigned long long this_offset, last_offset;
>  	unsigned long offset;
>  
> -	write_lock(&monotonic_lock);
> +	write_seqlock(&monotonic_lock);
>  	last_offset = ((unsigned long 
> long)last_tsc_high<<32)|last_tsc_low;
>  	rdtsc(last_tsc_low, last_tsc_high);
>  
> @@ -113,7 +115,7 @@
>  	/* update the monotonic base value */
>  	this_offset = ((unsigned long 
> long)last_tsc_high<<32)|last_tsc_low;
>  	monotonic_base += cycles_2_ns(this_offset - last_offset);
> -	write_unlock(&monotonic_lock);
> +	write_sequnlock(&monotonic_lock);
>  }
>  
>  void delay_hpet(unsigned long loops)
> -
> To unsubscribe from this list: send the line "unsubscribe 
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-10-09  0:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-08 18:58 [PATCH] monotonic seqlock for HPET timer Stephen Hemminger
2003-10-09  0:15 Pallipadi, Venkatesh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®