From: Thomas Gleixner <tglx@linutronix.de>
To: Andrew Morton <akpm@osdl.org>
Cc: Ingo Molnar <mingo@elte.hu>,
Patrick Mochel <mochel@digitalimplant.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] Driver Subsystem: Replace abused semaphore
Date: Wed, 20 Oct 2004 19:04:30 +0200 [thread overview]
Message-ID: <1098291870.12223.1618.camel@thomas> (raw)
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;
_
reply other threads:[~2004-10-20 17:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1098291870.12223.1618.camel@thomas \
--to=tglx@linutronix.de \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mochel@digitalimplant.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox