2009-01-29 15:15:30

by Ming Lei

[permalink] [raw]
Subject: [PATCH] driver core: remove polling for driver_probe_done

From: Ming Lei <[email protected]>

This patch renames driver_probe_done to driver_probe_wait_done,
and make it wait on condition variable of probe done to remove
polling for it in fs initialization.

Removing polling in fs initialization may lead to a faster boot.

Signed-off-by: Ming Lei <[email protected]>
---
drivers/base/dd.c | 12 +++++-------
include/linux/device.h | 2 +-
init/do_mounts.c | 10 +++++-----
init/do_mounts_md.c | 5 +++--
4 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 9b721d3..ee998ca 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -153,18 +153,16 @@ done:
}

/**
- * driver_probe_done
- * Determine if the probe sequence is finished or not.
+ * driver_probe_wait_done
+ * wait the probe sequence to be finished.
*
- * Should somehow figure out how to use a semaphore, not an atomic variable...
*/
-int driver_probe_done(void)
+void driver_probe_wait_done(void)
{
pr_debug("%s: probe_count = %d\n", __func__,
atomic_read(&probe_count));
- if (atomic_read(&probe_count))
- return -EBUSY;
- return 0;
+
+ wait_event(probe_waitqueue, atomic_read(&probe_count) == 0);
}

/**
diff --git a/include/linux/device.h b/include/linux/device.h
index 45e5b19..20b50c4 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -146,7 +146,7 @@ extern struct device_driver *get_driver(struct device_driver *drv);
extern void put_driver(struct device_driver *drv);
extern struct device_driver *driver_find(const char *name,
struct bus_type *bus);
-extern int driver_probe_done(void);
+extern void driver_probe_wait_done(void);

/* sysfs interface for exporting driver attributes */

diff --git a/init/do_mounts.c b/init/do_mounts.c
index 708105e..ce46c38 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -371,8 +371,8 @@ void __init prepare_namespace(void)
}

/* wait for the known devices to complete their probing */
- while (driver_probe_done() != 0)
- msleep(100);
+ driver_probe_wait_done();
+
async_synchronize_full();

md_run_setup();
@@ -396,9 +396,9 @@ void __init prepare_namespace(void)
if ((ROOT_DEV == 0) && root_wait) {
printk(KERN_INFO "Waiting for root device %s...\n",
saved_root_name);
- while (driver_probe_done() != 0 ||
- (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0)
- msleep(100);
+ ROOT_DEV = name_to_dev_t(saved_root_name);
+ if (ROOT_DEV)
+ driver_probe_wait_done();
}

is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
index ff95e31..e9a4e54 100644
--- a/init/do_mounts_md.c
+++ b/init/do_mounts_md.c
@@ -281,8 +281,9 @@ static void __init autodetect_raid(void)
*/
printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n");
printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n");
- while (driver_probe_done() < 0)
- msleep(100);
+
+ driver_probe_wait_done();
+
fd = sys_open("/dev/md0", 0, 0);
if (fd >= 0) {
sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
--
1.6.0


2009-01-29 15:25:53

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [PATCH] driver core: remove polling for driver_probe_done

On Thu, 29 Jan 2009 23:15:10 +0800
[email protected] wrote:

> From: Ming Lei <[email protected]>
>
> This patch renames driver_probe_done to driver_probe_wait_done,
> and make it wait on condition variable of probe done to remove
> polling for it in fs initialization.
>

I do not see where you add the wake_up() for waking up the wait queue...
.... are you sure this is going to work ?

--
Arjan van de Ven Intel Open Source Technology Centre
For development, discussion and tips for power savings,
visit http://www.lesswatts.org

2009-01-29 15:35:46

by Ming Lei

[permalink] [raw]
Subject: Re: [PATCH] driver core: remove polling for driver_probe_done

2009/1/29 Arjan van de Ven <[email protected]>:
> On Thu, 29 Jan 2009 23:15:10 +0800
> [email protected] wrote:
>
>> From: Ming Lei <[email protected]>
>>
>> This patch renames driver_probe_done to driver_probe_wait_done,
>> and make it wait on condition variable of probe done to remove
>> polling for it in fs initialization.
>>
>
> I do not see where you add the wake_up() for waking up the wait queue...
> .... are you sure this is going to work ?

really_probe always wake up the queue of probe_waitqueue,
but no one pend on it. This patch adds the waitting on the queue.

static int really_probe(struct device *dev, struct device_driver *drv)
{
...
done:
atomic_dec(&probe_count);
wake_up(&probe_waitqueue);
return ret;
??

>
> --
> Arjan van de Ven Intel Open Source Technology Centre
> For development, discussion and tips for power savings,
> visit http://www.lesswatts.org
>



--
Lei Ming

2009-01-29 15:36:05

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [PATCH] driver core: remove polling for driver_probe_done

> @@ -396,9 +396,9 @@ void __init prepare_namespace(void)
> if ((ROOT_DEV == 0) && root_wait) {
> printk(KERN_INFO "Waiting for root device %s...\n",
> saved_root_name);
> - while (driver_probe_done() != 0 ||
> - (ROOT_DEV = name_to_dev_t(saved_root_name))
> == 0)
> - msleep(100);
> + ROOT_DEV = name_to_dev_t(saved_root_name);
> + if (ROOT_DEV)
> + driver_probe_wait_done();
> }
>

Hi,

another comment:

this is not equivalent

you turned "wait until all probing is done OR until the device exists"
into "wait until all probing is done"... which might be several seconds
longer!

2009-01-29 15:46:24

by Ming Lei

[permalink] [raw]
Subject: Re: [PATCH] driver core: remove polling for driver_probe_done

2009/1/29 Arjan van de Ven <[email protected]>:
>> @@ -396,9 +396,9 @@ void __init prepare_namespace(void)
>> if ((ROOT_DEV == 0) && root_wait) {
>> printk(KERN_INFO "Waiting for root device %s...\n",
>> saved_root_name);
>> - while (driver_probe_done() != 0 ||
>> - (ROOT_DEV = name_to_dev_t(saved_root_name))
>> == 0)
>> - msleep(100);
>> + ROOT_DEV = name_to_dev_t(saved_root_name);
>> + if (ROOT_DEV)
>> + driver_probe_wait_done();
>> }
>>
>
> Hi,
>
> another comment:
>
> this is not equivalent
>
> you turned "wait until all probing is done OR until the device exists"
> into "wait until all probing is done"... which might be several seconds
> longer!

Yes, you are right. I will consider how to fix the problem.
Thanks.

>



--
Lei Ming