public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Driver Subsystem: Replace abused semaphore
@ 2004-10-20 17:04 Thomas Gleixner
  0 siblings, 0 replies; only message in thread
From: Thomas Gleixner @ 2004-10-20 17:04 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Ingo Molnar, Patrick Mochel, LKML


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;
 
_



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-10-20 17:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-20 17:04 [PATCH] Driver Subsystem: Replace abused semaphore Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox