From: "Carlos Martín" <carlos@cmartin.tk>
To: acx100-devel@lists.sourceforge.net
Cc: netdev@vger.kernel.org
Subject: [PATCH] acx: Transform semaphore to mutex
Date: Sun, 5 Feb 2006 16:56:52 +0100 [thread overview]
Message-ID: <200602051656.57214.carlos@cmartin.tk> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 699 bytes --]
Hi,
The attached patch transform the semaphore to a mutex. That's how we use it,
it's faster and makes the binary smaller. It also deletes the semaphore debug
functions because I the kernel takes care of that now. Just yell if I've
misunderstood.
text data bss dec hex filename
113475 1520 20 115015 1c147 acx.ko-sem
111033 1520 20 112573 1b7bd acx.ko
This only works for newer kernels, so I suppose it could be kept as an
into-mainline patch. People with newer kernels probably want this patch.
cmn
--
Carlos Martín http://www.cmartin.tk
"Erdbeben? Sicherlich etwas, das mit Erdberen zu tun hat." -- me, paraphrased
[-- Attachment #1.2: acx-sem-to-mutex.patch --]
[-- Type: text/x-diff, Size: 4615 bytes --]
diff --git a/acx_func.h b/acx_func.h
index a8e2482..239698b 100644
--- a/acx_func.h
+++ b/acx_func.h
@@ -307,27 +307,18 @@ acx_unlock_helper(acx_device_t *adev, un
acx_unlock_debug(adev, where);
spin_unlock_irqrestore(&adev->lock, *fp);
}
-static inline void
-acx_down_helper(acx_device_t *adev, const char* where)
-{
- acx_down_debug(adev, where);
-}
-static inline void
-acx_up_helper(acx_device_t *adev, const char* where)
-{
- acx_up_debug(adev, where);
-}
+
#define acx_lock(adev, flags) acx_lock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__))
#define acx_unlock(adev, flags) acx_unlock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__))
-#define acx_sem_lock(adev) acx_down_helper(adev, __FILE__ ":" STRING(__LINE__))
-#define acx_sem_unlock(adev) acx_up_helper(adev, __FILE__ ":" STRING(__LINE__))
+#define acx_sem_lock(adev) mutex_lock(&(adev)->mutex)
+#define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex)
#elif defined(DO_LOCKING)
#define acx_lock(adev, flags) spin_lock_irqsave(&adev->lock, flags)
#define acx_unlock(adev, flags) spin_unlock_irqrestore(&adev->lock, flags)
-#define acx_sem_lock(adev) down(&adev->sem)
-#define acx_sem_unlock(adev) up(&adev->sem)
+#define acx_sem_lock(adev) mutex_lock(&(adev)->mutex)
+#define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex)
#define acx_lock_unhold() ((void)0)
#define acx_sem_unhold() ((void)0)
diff --git a/acx_struct.h b/acx_struct.h
index 0bd18c4..65d6cf5 100644
--- a/acx_struct.h
+++ b/acx_struct.h
@@ -1142,7 +1142,7 @@ struct acx_device {
/* FIXME: try to convert semaphore to more efficient mutex according
to Ingo Molnar's docs (but not before driver is in mainline or
pre-mutex Linux 2.6.10 is very outdated). */
- struct semaphore sem;
+ struct mutex mutex;
spinlock_t lock;
#if defined(PARANOID_LOCKING) /* Lock debugging */
const char *last_sem;
diff --git a/common.c b/common.c
index 70e8afc..c019cef 100644
--- a/common.c
+++ b/common.c
@@ -189,59 +189,7 @@ acx_unlock_debug(acx_device_t *adev, con
}
}
}
-void
-acx_down_debug(acx_device_t *adev, const char* where)
-{
- int sem_count;
- unsigned long timeout = jiffies + 5*HZ;
-
- where = sanitize_str(where);
- for (;;) {
- sem_count = atomic_read(&adev->sem.count);
- if (sem_count) break;
- if (time_after(jiffies, timeout))
- break;
- msleep(5);
- }
- if (!sem_count) {
- printk(KERN_EMERG "D STATE at %s! last sem at %s\n",
- where, adev->last_sem);
- dump_stack();
- }
- adev->last_sem = where;
- adev->sem_time = jiffies;
- down(&adev->sem);
- if (acx_debug & L_LOCK) {
- printk("%s: sem_down %d -> %d\n",
- where, sem_count, atomic_read(&adev->sem.count));
- }
-}
-void
-acx_up_debug(acx_device_t *adev, const char* where)
-{
- int sem_count = atomic_read(&adev->sem.count);
- if (sem_count) {
- where = sanitize_str(where);
- printk(KERN_EMERG "STRAY UP at %s! sem.count=%d\n", where, sem_count);
- dump_stack();
- }
- if (acx_debug & L_LOCK) {
- unsigned long diff = jiffies - adev->sem_time;
- if (diff > max_sem_time) {
- where = sanitize_str(where);
- printk("max sem hold time %ld jiffies from %s "
- "to %s\n", diff, adev->last_sem, where);
- max_sem_time = diff;
- }
- }
- up(&adev->sem);
- if (acx_debug & L_LOCK) {
- where = sanitize_str(where);
- printk("%s: sem_up %d -> %d\n",
- where, sem_count, atomic_read(&adev->sem.count));
- }
-}
#endif /* PARANOID_LOCKING */
diff --git a/pci.c b/pci.c
index 910155f..a390606 100644
--- a/pci.c
+++ b/pci.c
@@ -1617,7 +1617,7 @@ acxpci_e_probe(struct pci_dev *pdev, con
adev = ndev2adev(ndev);
spin_lock_init(&adev->lock); /* initial state: unlocked */
/* We do not start with downed sem: we want PARANOID_LOCKING to work */
- sema_init(&adev->sem, 1); /* initial state: 1 (upped) */
+ mutex_init(&adev->mutex); /* initial state: 1 (upped) */
/* since nobody can see new netdev yet, we can as well
** just _presume_ that we're under sem (instead of actually taking it): */
/* acx_sem_lock(adev); */
diff --git a/usb.c b/usb.c
index 3183743..cd610e4 100644
--- a/usb.c
+++ b/usb.c
@@ -869,7 +869,7 @@ acxusb_e_probe(struct usb_interface *int
adev->usbdev = usbdev;
spin_lock_init(&adev->lock); /* initial state: unlocked */
- sema_init(&adev->sem, 1); /* initial state: 1 (upped) */
+ mutex_init(&adev->mutex); /* initial state: 1 (upped) */
/* Check that this is really the hardware we know about.
** If not sure, at least notify the user that he
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next reply other threads:[~2006-02-05 15:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-05 15:56 Carlos Martín [this message]
2006-02-06 7:04 ` [PATCH] acx: Transform semaphore to mutex Denis Vlasenko
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=200602051656.57214.carlos@cmartin.tk \
--to=carlos@cmartin.tk \
--cc=acx100-devel@lists.sourceforge.net \
--cc=netdev@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).