netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] acx: Transform semaphore to mutex
@ 2006-02-05 15:56 Carlos Martín
  2006-02-06  7:04 ` Denis Vlasenko
  0 siblings, 1 reply; 2+ messages in thread
From: Carlos Martín @ 2006-02-05 15:56 UTC (permalink / raw)
  To: acx100-devel; +Cc: netdev


[-- 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 --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] acx: Transform semaphore to mutex
  2006-02-05 15:56 [PATCH] acx: Transform semaphore to mutex Carlos Martín
@ 2006-02-06  7:04 ` Denis Vlasenko
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Vlasenko @ 2006-02-06  7:04 UTC (permalink / raw)
  To: acx100-devel; +Cc: Carlos Martín, netdev

On Sunday 05 February 2006 17:56, Carlos Martín wrote:
> 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.

http://195.66.192.167/linux/acx_patches/acx-sem-to-mutex.patch

Thanks!
--
vda


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x103432&bid#0486&dat\x121642

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-02-06  7:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-05 15:56 [PATCH] acx: Transform semaphore to mutex Carlos Martín
2006-02-06  7:04 ` Denis Vlasenko

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).