From: Yinghai Lu <yinghai@kernel.org>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Thomas Gleixner <tglx@linutronix.de>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>, "H. Peter Anvin" <hpa@zytor.com>,
Greg KH <greg@kroah.com>, Jesse Barnes <jbarnes@virtuousgeek.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Christoph Lameter <cl@linux.com>, Tejun Heo <tj@kernel.org>
Subject: Re: [RFC PATCH] x86: Add safe_udelay() and safe_msleep()
Date: Thu, 13 Jan 2011 14:21:29 -0800 [thread overview]
Message-ID: <4D2F7AE9.2000809@kernel.org> (raw)
In-Reply-To: <1294799565.9586.13.camel@pasglop>
On 01/11/2011 06:32 PM, Benjamin Herrenschmidt wrote:
> On Tue, 2011-01-11 at 17:06 -0800, Yinghai Lu wrote:
>> We need to use those function in early-quirk stage with code that is shared with
>> later stage.
>>
>> for x86, normal udelay() will need to wait per_cpu(cpu_info) is allocated... that i
>> after smp_prepare_cpus(), because it need to use percpu.loops_per_jiffy.
>>
>> Also msleep() will need to wait schedular is ready.
>>
>> Try to have one early version udelay that use loops_per_jiffy directly.
>> and early msleep is just early delay.
>>
>> This patch will set safe_udelay to early in x86 early arch code, and then init/main.c
>> will set them back.
>
> I still think it's better to just make msleep() work with and without
> scheduler and avoid having to bother with a new API
please check if you are happy with this one.
[PATCH] x86: Make udelay() and msleep() can be used early
We need to use those functions in early-quirk stage with code that is shared with
later stage.
For x86, normal udelay need to use percpu.loops_per_jiffy
will need to wait per_cpu(cpu_info) is allocated and copied
from boot_cpu_data, after it is in smp_prepare_cpus()
boot_cpu_data.loops_per_jiffy get set in identify_boot_cpu from check_bugs.
Also msleep() will need to wait schedular is ready.
Try to have one early version udelay that use loops_per_jiffy directly.
and early msleep is just early delay.
-v2: use function pointer and keep old udelay() and msleep() API as requested from BenH
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
arch/x86/lib/delay.c | 28 +++++++++++++++++++++++++++-
include/linux/delay.h | 2 ++
init/main.c | 3 +++
kernel/timer.c | 28 +++++++++++++++++++++++-----
4 files changed, 55 insertions(+), 6 deletions(-)
Index: linux-2.6/arch/x86/lib/delay.c
===================================================================
--- linux-2.6.orig/arch/x86/lib/delay.c
+++ linux-2.6/arch/x86/lib/delay.c
@@ -113,7 +113,7 @@ void __delay(unsigned long loops)
}
EXPORT_SYMBOL(__delay);
-inline void __const_udelay(unsigned long xloops)
+static void __normal_const_udelay(unsigned long xloops)
{
int d0;
@@ -125,8 +125,34 @@ inline void __const_udelay(unsigned long
__delay(++xloops);
}
+
+/* before percpu cpu_info.loops_per_jiffy is set */
+static void __init __early_const_udelay(unsigned long xloops)
+{
+ int d0;
+
+ xloops *= 4;
+ asm("mull %%edx"
+ : "=d" (xloops), "=&a" (d0)
+ : "1" (xloops), "0"
+ (loops_per_jiffy * (HZ/4)));
+
+ delay_loop(++xloops);
+}
+
+static void (*__const_udelay_fn)(unsigned long) = __early_const_udelay;
+
+void __const_udelay(unsigned long usecs)
+{
+ __const_udelay_fn(usecs);
+}
EXPORT_SYMBOL(__const_udelay);
+void __init use_normal_delay(void)
+{
+ __const_udelay_fn = __normal_const_udelay;
+}
+
void __udelay(unsigned long usecs)
{
__const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
Index: linux-2.6/include/linux/delay.h
===================================================================
--- linux-2.6.orig/include/linux/delay.h
+++ linux-2.6/include/linux/delay.h
@@ -52,4 +52,6 @@ static inline void ssleep(unsigned int s
msleep(seconds * 1000);
}
+extern void use_normal_delay(void);
+extern void use_normal_sleep(void);
#endif /* defined(_LINUX_DELAY_H) */
Index: linux-2.6/init/main.c
===================================================================
--- linux-2.6.orig/init/main.c
+++ linux-2.6/init/main.c
@@ -879,6 +879,9 @@ static int __init kernel_init(void * unu
cad_pid = task_pid(current);
smp_prepare_cpus(setup_max_cpus);
+ /* set them back, x86 use it for early delay*/
+ use_normal_delay();
+ use_normal_sleep();
do_pre_smp_initcalls();
lockup_detector_init();
Index: linux-2.6/kernel/timer.c
===================================================================
--- linux-2.6.orig/kernel/timer.c
+++ linux-2.6/kernel/timer.c
@@ -1723,11 +1723,7 @@ void __init init_timers(void)
open_softirq(TIMER_SOFTIRQ, run_timer_softirq);
}
-/**
- * msleep - sleep safely even with waitqueue interruptions
- * @msecs: Time in milliseconds to sleep for
- */
-void msleep(unsigned int msecs)
+static void __normal_msleep(unsigned int msecs)
{
unsigned long timeout = msecs_to_jiffies(msecs) + 1;
@@ -1735,6 +1731,28 @@ void msleep(unsigned int msecs)
timeout = schedule_timeout_uninterruptible(timeout);
}
+static void __init __early_msleep(unsigned int msecs)
+{
+ mdelay(msecs);
+}
+
+static void (*msleep_fn)(unsigned int) = __early_msleep;
+
+void __init use_normal_sleep(void)
+{
+ msleep_fn = __normal_msleep;
+}
+
+void __init __weak use_normal_delay(void) { }
+
+/**
+ * msleep - sleep safely even with waitqueue interruptions
+ * @msecs: Time in milliseconds to sleep for
+ */
+void msleep(unsigned int msecs)
+{
+ msleep_fn(msecs);
+}
EXPORT_SYMBOL(msleep);
/**
next prev parent reply other threads:[~2011-01-13 22:23 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-09 19:58 [PATCH 0/3] x86, usb, pci: Disable usb legacy support early Yinghai Lu
2011-01-10 8:43 ` [PATCH -v2 0/4] " Yinghai Lu
2011-01-11 0:49 ` [PATCH -v3 " Yinghai Lu
2011-01-11 0:55 ` [PATCH -v3 1/4] pci, usb: Make usb handoff func all take base remapping Yinghai Lu
2011-01-11 1:07 ` Greg KH
2011-01-11 1:20 ` Yinghai Lu
2011-01-11 3:37 ` Greg KH
2011-01-11 5:21 ` Benjamin Herrenschmidt
2011-01-11 6:34 ` Yinghai Lu
2011-01-11 7:37 ` Benjamin Herrenschmidt
2011-01-11 9:21 ` Yinghai Lu
2011-01-11 13:56 ` Greg KH
2011-01-11 17:39 ` Konrad Rzeszutek Wilk
2011-01-12 1:06 ` [RFC PATCH] x86: Add safe_udelay() and safe_msleep() Yinghai Lu
2011-01-12 2:32 ` Benjamin Herrenschmidt
2011-01-12 5:07 ` Greg KH
2011-01-13 22:21 ` Yinghai Lu [this message]
2011-01-13 22:44 ` Greg KH
2011-01-13 22:52 ` Thomas Gleixner
2011-01-13 23:02 ` Greg KH
2011-01-13 23:04 ` Yinghai Lu
2011-01-13 23:31 ` Thomas Gleixner
2011-01-14 22:42 ` Yinghai Lu
2011-01-13 23:48 ` Greg KH
2011-01-14 0:31 ` Yinghai Lu
2011-01-14 0:40 ` Benjamin Herrenschmidt
2011-01-14 1:00 ` Yinghai Lu
2011-01-14 14:46 ` Christoph Lameter
2011-01-14 0:44 ` Greg KH
2011-01-14 1:12 ` Yinghai Lu
2011-01-14 14:50 ` Christoph Lameter
2011-01-14 21:22 ` [PATCH] x86: set percpu cpu0 lpj to default Yinghai Lu
2011-01-14 21:28 ` Christoph Lameter
2011-01-15 13:09 ` Tejun Heo
2011-01-16 2:32 ` Yinghai Lu
2011-01-14 22:16 ` Greg KH
2011-01-14 22:29 ` Yinghai Lu
2011-01-11 5:18 ` [PATCH -v3 1/4] pci, usb: Make usb handoff func all take base remapping Benjamin Herrenschmidt
2011-01-11 0:55 ` [PATCH 2/4] x86: early_quirk check all dev/func in domain 0 Yinghai Lu
2011-01-11 1:09 ` Greg KH
2011-01-11 1:46 ` Yinghai Lu
2011-01-11 3:38 ` Greg KH
2011-01-11 3:39 ` Greg KH
2011-01-11 0:55 ` [PATCH 3/4] x86, pci: add dummy pci device for early stage Yinghai Lu
2011-01-11 0:55 ` [PATCH -v3 4/4] x86: usb handoff in early_quirk Yinghai Lu
2011-01-11 1:08 ` Greg KH
2011-01-11 1:41 ` Yinghai Lu
2011-01-11 1:07 ` [PATCH -v3 0/4] x86, usb, pci: Disable usb legacy support early Greg KH
2011-01-11 1:25 ` Yinghai Lu
2011-01-11 3:35 ` Greg KH
[not found] ` <4D2AC584.6010004@kernel.org>
2011-01-10 8:43 ` [PATCH -v2 1/4] pci, usb: Seperate usb handoff func to another file Yinghai Lu
2011-01-10 8:44 ` [PATCH 2/4] x86: early_quirk check all dev/func in domain 0 Yinghai Lu
2011-01-10 8:44 ` [PATCH 3/4] x86, pci: add dummy pci device for early stage Yinghai Lu
2011-01-10 8:44 ` [PATCH v2 4/4] x86: usb handoff in early_quirk Yinghai Lu
2011-01-10 15:57 ` [PATCH 0/3] x86, usb, pci: Disable usb legacy support early Greg KH
2011-01-10 18:27 ` Jesse Barnes
2011-01-10 20:10 ` Yinghai Lu
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=4D2F7AE9.2000809@kernel.org \
--to=yinghai@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=benh@kernel.crashing.org \
--cc=cl@linux.com \
--cc=greg@kroah.com \
--cc=hpa@zytor.com \
--cc=jbarnes@virtuousgeek.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
--cc=tj@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.