From: john stultz <johnstul@us.ibm.com>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: lkml <linux-kernel@vger.kernel.org>
Subject: [patch] linux-2.5.45_delay-cleanup_A0.patch
Date: 04 Nov 2002 14:58:58 -0800 [thread overview]
Message-ID: <1036450738.5089.232.camel@cog> (raw)
Linus, All,
This patch moves __delay into the timer_ops infrastructure. This makes
it simple to use alternate time sources for the __delay function.
Please consider for inclusion.
-john
diff -Nru a/arch/i386/kernel/timers/timer_cyclone.c b/arch/i386/kernel/timers/timer_cyclone.c
--- a/arch/i386/kernel/timers/timer_cyclone.c Mon Nov 4 14:58:18 2002
+++ b/arch/i386/kernel/timers/timer_cyclone.c Mon Nov 4 14:58:18 2002
@@ -150,7 +150,6 @@
}
-#if 0 /* XXX future work */
static void delay_cyclone(unsigned long loops)
{
unsigned long bclock, now;
@@ -162,12 +161,12 @@
now = cyclone_timer[0];
} while ((now-bclock) < loops);
}
-#endif
/************************************************************/
/* cyclone timer_opts struct */
struct timer_opts timer_cyclone = {
.init = init_cyclone,
.mark_offset = mark_offset_cyclone,
- .get_offset = get_offset_cyclone
+ .get_offset = get_offset_cyclone,
+ .delay = delay_cyclone,
};
diff -Nru a/arch/i386/kernel/timers/timer_pit.c b/arch/i386/kernel/timers/timer_pit.c
--- a/arch/i386/kernel/timers/timer_pit.c Mon Nov 4 14:58:18 2002
+++ b/arch/i386/kernel/timers/timer_pit.c Mon Nov 4 14:58:18 2002
@@ -25,6 +25,19 @@
/* nothing needed */
}
+static void delay_pit(unsigned long loops)
+{
+ int d0;
+ __asm__ __volatile__(
+ "\tjmp 1f\n"
+ ".align 16\n"
+ "1:\tjmp 2f\n"
+ ".align 16\n"
+ "2:\tdecl %0\n\tjns 2b"
+ :"=&a" (d0)
+ :"0" (loops));
+}
+
/* This function must be called with interrupts disabled
* It was inspired by Steve McCanne's microtime-i386 for BSD. -- jrs
@@ -127,4 +140,5 @@
.init = init_pit,
.mark_offset = mark_offset_pit,
.get_offset = get_offset_pit,
+ .delay = delay_pit,
};
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 Nov 4 14:58:18 2002
+++ b/arch/i386/kernel/timers/timer_tsc.c Mon Nov 4 14:58:18 2002
@@ -12,7 +12,6 @@
#include <asm/timer.h>
#include <asm/io.h>
-extern int x86_udelay_tsc;
extern spinlock_t i8253_lock;
static int use_tsc;
@@ -87,6 +86,17 @@
delay_at_last_interrupt = (count + LATCH/2) / LATCH;
}
+static void delay_tsc(unsigned long loops)
+{
+ unsigned long bclock, now;
+
+ rdtscl(bclock);
+ do
+ {
+ rep_nop();
+ rdtscl(now);
+ } while ((now-bclock) < loops);
+}
/* ------ Calibrate the TSC -------
* Return 2^32 * (1 / (TSC clocks per usec)) for do_fast_gettimeoffset().
@@ -249,8 +259,6 @@
* We could be more selective here I suspect
* and just enable this for the next intel chips ?
*/
- x86_udelay_tsc = 1;
-
/* report CPU clock rate in Hz.
* The formula is (10^6 * 2^32) / (2^32 * 1 / (clocks/us)) =
* clock/second. Our precision is about 100 ppm.
@@ -278,4 +286,5 @@
.init = init_tsc,
.mark_offset = mark_offset_tsc,
.get_offset = get_offset_tsc,
+ .delay = delay_tsc,
};
diff -Nru a/arch/i386/lib/delay.c b/arch/i386/lib/delay.c
--- a/arch/i386/lib/delay.c Mon Nov 4 14:58:18 2002
+++ b/arch/i386/lib/delay.c Mon Nov 4 14:58:18 2002
@@ -15,35 +15,18 @@
#include <linux/delay.h>
#include <asm/processor.h>
#include <asm/delay.h>
+#include <asm/timer.h>
#ifdef CONFIG_SMP
#include <asm/smp.h>
#endif
-int x86_udelay_tsc = 0; /* Delay via TSC */
+extern struct timer_opts* timer;
-
/*
- * Do a udelay using the TSC for any CPU that happens
- * to have one that we trust.
+ * Backup non-TSC based delay loop.
+ * Used until a timer is chosen.
*/
-
-static void __rdtsc_delay(unsigned long loops)
-{
- unsigned long bclock, now;
-
- rdtscl(bclock);
- do
- {
- rep_nop();
- rdtscl(now);
- } while ((now-bclock) < loops);
-}
-
-/*
- * Non TSC based delay loop for 386, 486, MediaGX
- */
-
static void __loop_delay(unsigned long loops)
{
int d0;
@@ -59,8 +42,8 @@
void __delay(unsigned long loops)
{
- if (x86_udelay_tsc)
- __rdtsc_delay(loops);
+ if(timer)
+ timer->delay(loops);
else
__loop_delay(loops);
}
diff -Nru a/include/asm-i386/timer.h b/include/asm-i386/timer.h
--- a/include/asm-i386/timer.h Mon Nov 4 14:58:18 2002
+++ b/include/asm-i386/timer.h Mon Nov 4 14:58:18 2002
@@ -14,6 +14,7 @@
int (*init)(void);
void (*mark_offset)(void);
unsigned long (*get_offset)(void);
+ void (*delay)(unsigned long);
};
#define TICK_SIZE (tick_nsec / 1000)
next reply other threads:[~2002-11-04 22:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-04 22:58 john stultz [this message]
2002-11-04 23:08 ` [patch] linux-2.5.45_delay-cleanup_A0.patch 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=1036450738.5089.232.camel@cog \
--to=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/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