lkml.org 
[lkml]   [2004]   [Oct]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH] Driver Subsystem: Replace abused semaphore
From
Date

Use completion instead of the abused semaphore. Semaphores are slower
and trigger owner conflicts during semaphore debugging.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Ingo Molnar <mingo@elte.hu>

---

2.6.9-bk-041020-thomas/drivers/base/bus.c | 2 +-
2.6.9-bk-041020-thomas/drivers/base/driver.c | 17 +++++++----------
2.6.9-bk-041020-thomas/include/linux/device.h | 2 +-
3 files changed, 9 insertions(+), 12 deletions(-)

diff -puN drivers/base/bus.c~driversbase drivers/base/bus.c
--- 2.6.9-bk-041020/drivers/base/bus.c~driversbase 2004-10-20
15:31:33.000000000 +0200
+++ 2.6.9-bk-041020-thomas/drivers/base/bus.c 2004-10-20
15:31:33.000000000 +0200
@@ -65,7 +65,7 @@ static struct sysfs_ops driver_sysfs_ops
static void driver_release(struct kobject * kobj)
{
struct device_driver * drv = to_driver(kobj);
- up(&drv->unload_sem);
+ complete(&drv->unload_done);
}

static struct kobj_type ktype_driver = {
diff -puN drivers/base/driver.c~driversbase drivers/base/driver.c
--- 2.6.9-bk-041020/drivers/base/driver.c~driversbase 2004-10-20
15:31:33.000000000 +0200
+++ 2.6.9-bk-041020-thomas/drivers/base/driver.c 2004-10-20
15:54:47.000000000 +0200
@@ -79,14 +79,13 @@ void put_driver(struct device_driver * d
* since most of the things we have to do deal with the bus
* structures.
*
- * The one interesting aspect is that we initialize @drv->unload_sem
- * to a locked state here. It will be unlocked when the driver
- * reference count reaches 0.
+ * We init the completion struct here. When the reference
+ * count reaches zero, complete() is called from bus_release().
*/
int driver_register(struct device_driver * drv)
{
INIT_LIST_HEAD(&drv->devices);
- init_MUTEX_LOCKED(&drv->unload_sem);
+ init_completion(&drv->unload_done);
return bus_add_driver(drv);
}

@@ -97,18 +96,16 @@ int driver_register(struct device_driver
*
* Again, we pass off most of the work to the bus-level call.
*
- * Though, once that is done, we attempt to take @drv->unload_sem.
- * This will block until the driver refcount reaches 0, and it is
- * released. Only modular drivers will call this function, and we
+ * Though, once that is done, we wait until the driver refcount
+ * reaches 0, and complete() is called in bus_release().
+ * Only modular drivers will call this function, and we
* have to guarantee that it won't complete, letting the driver
* unload until all references are gone.
*/
-
void driver_unregister(struct device_driver * drv)
{
bus_remove_driver(drv);
- down(&drv->unload_sem);
- up(&drv->unload_sem);
+ wait_for_completion(&drv->unload_done);
}

/**
diff -puN include/linux/device.h~driversbase include/linux/device.h
--- 2.6.9-bk-041020/include/linux/device.h~driversbase 2004-10-20
15:31:33.000000000 +0200
+++ 2.6.9-bk-041020-thomas/include/linux/device.h 2004-10-20
15:31:33.000000000 +0200
@@ -102,7 +102,7 @@ struct device_driver {
char * name;
struct bus_type * bus;

- struct semaphore unload_sem;
+ struct completion unload_done;
struct kobject kobj;
struct list_head devices;

_

-
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/

\
 
 \ /
  Last update: 2005-03-22 14:07    [W:0.608 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site