From: Stephen Hemminger <shemminger@osdl.org>
To: Linus Torvalds <torvalds@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] use seq_lock for monotonic time
Date: Tue, 16 Sep 2003 10:27:06 -0700 [thread overview]
Message-ID: <20030916102706.26bc4516.shemminger@osdl.org> (raw)
Monotonic clock code uses reader/writer lock which is prone to same
starvation problems as we saw with xtime. This patch changes it to seq_lock
which is faster and won't starve writers in face of lots of readers.
diff -Nru a/arch/i386/kernel/timers/timer_tsc.c b/arch/i386/kernel/timers/timer_tsc.c
--- a/arch/i386/kernel/timers/timer_tsc.c Mon Sep 15 15:48:01 2003
+++ b/arch/i386/kernel/timers/timer_tsc.c Mon Sep 15 15:48:01 2003
@@ -39,7 +39,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:
@@ -111,12 +111,14 @@
static unsigned long long monotonic_clock_tsc(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);
@@ -135,7 +137,7 @@
unsigned long long this_offset, last_offset;
static int lost_count = 0;
- write_lock(&monotonic_lock);
+ write_seqlock(&monotonic_lock);
last_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low;
/*
* It is important that these two operations happen almost at
@@ -204,7 +206,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);
/* calculate delay_at_last_interrupt */
count = ((LATCH-1) - count) * TICK_SIZE;
@@ -236,7 +238,7 @@
unsigned long long this_offset, last_offset;
unsigned long offset, temp, hpet_current;
- write_lock(&monotonic_lock);
+ write_seqlock(&monotonic_lock);
last_offset = ((unsigned long long)last_tsc_high<<32)|last_tsc_low;
/*
* It is important that these two operations happen almost at
@@ -264,7 +266,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);
/* calculate delay_at_last_interrupt */
/*
next reply other threads:[~2003-09-16 17:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-16 17:27 Stephen Hemminger [this message]
[not found] ` <20030916115935.64ebce3d.akpm@osdl.org>
2003-09-16 21:00 ` [PATCH] use seq_lock for monotonic time Stephen Hemminger
2003-09-16 21:17 ` john stultz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030916102706.26bc4516.shemminger@osdl.org \
--to=shemminger@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).