* [RFC net-next-2.6] can: replace spinlocks with mutexes
@ 2011-04-20 15:31 Oliver Hartkopp
2011-04-20 15:39 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: Oliver Hartkopp @ 2011-04-20 15:31 UTC (permalink / raw)
To: David Miller, Eric Dumazet
Cc: Linux Netdev List, Kurt Van Dijck, Urs Thuermann
This patch removes spinlocks for the CAN netdevice specific receive lists.
The RCU-based receive lists can be modified from process context or from the
netdevice notifier call. As both might sleep we can safely replace the
spinlocks with mutexes.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
diff --git a/net/can/af_can.c b/net/can/af_can.c
index a8dcaa4..e52ed358 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -47,7 +47,7 @@
#include <linux/kmod.h>
#include <linux/slab.h>
#include <linux/list.h>
-#include <linux/spinlock.h>
+#include <linux/mutex.h>
#include <linux/rcupdate.h>
#include <linux/uaccess.h>
#include <linux/net.h>
@@ -79,7 +79,7 @@ MODULE_PARM_DESC(stats_timer, "enable timer for statistics (default:on)");
/* receive filters subscribed for 'all' CAN devices */
struct dev_rcv_lists can_rx_alldev_list;
-static DEFINE_SPINLOCK(can_rcvlists_lock);
+static DEFINE_MUTEX(can_rcvlists_lock);
static struct kmem_cache *rcv_cache __read_mostly;
@@ -435,7 +435,7 @@ int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
if (!r)
return -ENOMEM;
- spin_lock(&can_rcvlists_lock);
+ mutex_lock(&can_rcvlists_lock);
d = find_dev_rcv_lists(dev);
if (d) {
@@ -459,7 +459,7 @@ int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
err = -ENODEV;
}
- spin_unlock(&can_rcvlists_lock);
+ mutex_unlock(&can_rcvlists_lock);
return err;
}
@@ -497,7 +497,7 @@ void can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
if (dev && dev->type != ARPHRD_CAN)
return;
- spin_lock(&can_rcvlists_lock);
+ mutex_lock(&can_rcvlists_lock);
d = find_dev_rcv_lists(dev);
if (!d) {
@@ -548,7 +548,7 @@ void can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
}
out:
- spin_unlock(&can_rcvlists_lock);
+ mutex_unlock(&can_rcvlists_lock);
/* schedule the receiver item for deletion */
if (r)
@@ -775,7 +775,7 @@ static int can_notifier(struct notifier_block *nb, unsigned long msg,
break;
case NETDEV_UNREGISTER:
- spin_lock(&can_rcvlists_lock);
+ mutex_lock(&can_rcvlists_lock);
d = dev->ml_priv;
if (d) {
@@ -789,7 +789,7 @@ static int can_notifier(struct notifier_block *nb, unsigned long msg,
printk(KERN_ERR "can: notifier: receive list not "
"found for dev %s\n", dev->name);
- spin_unlock(&can_rcvlists_lock);
+ mutex_unlock(&can_rcvlists_lock);
break;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC net-next-2.6] can: replace spinlocks with mutexes
2011-04-20 15:31 [RFC net-next-2.6] can: replace spinlocks with mutexes Oliver Hartkopp
@ 2011-04-20 15:39 ` Eric Dumazet
2011-04-20 16:18 ` Oliver Hartkopp
2011-04-21 13:00 ` Oliver Hartkopp
0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2011-04-20 15:39 UTC (permalink / raw)
To: Oliver Hartkopp
Cc: David Miller, Linux Netdev List, Kurt Van Dijck, Urs Thuermann
Le mercredi 20 avril 2011 à 17:31 +0200, Oliver Hartkopp a écrit :
> This patch removes spinlocks for the CAN netdevice specific receive lists.
> The RCU-based receive lists can be modified from process context or from the
> netdevice notifier call. As both might sleep we can safely replace the
> spinlocks with mutexes.
>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
>
> ---
But... why ?
A spinlock is faster/smaller than a mutex.
Maybe you wanted to _remove_ spinlock, since/if writer hold RTNL and
doesnt need to exclude another writer(s) ?
Note : I did not check the RTNL assertion, you might add appropriate
ASSERT_RTNL() calls just to be 100% safe.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC net-next-2.6] can: replace spinlocks with mutexes
2011-04-20 15:39 ` Eric Dumazet
@ 2011-04-20 16:18 ` Oliver Hartkopp
2011-04-21 13:00 ` Oliver Hartkopp
1 sibling, 0 replies; 4+ messages in thread
From: Oliver Hartkopp @ 2011-04-20 16:18 UTC (permalink / raw)
To: Eric Dumazet
Cc: David Miller, Linux Netdev List, Kurt Van Dijck, Urs Thuermann
On 20.04.2011 17:39, Eric Dumazet wrote:
> Le mercredi 20 avril 2011 à 17:31 +0200, Oliver Hartkopp a écrit :
>> This patch removes spinlocks for the CAN netdevice specific receive lists.
>> The RCU-based receive lists can be modified from process context or from the
>> netdevice notifier call. As both might sleep we can safely replace the
>> spinlocks with mutexes.
>>
>> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
>>
>> ---
>
> But... why ?
>
> A spinlock is faster/smaller than a mutex.
Hm, i expected the mutex to have some advantages especially in multicore
systems ...
But if it doesn't has any vital advantage, we can leave it as-is.
> Maybe you wanted to _remove_ spinlock, since/if writer hold RTNL and
> doesnt need to exclude another writer(s) ?
That's an interesting idea. The filters are modified at socket
creation/removal time and can also be modified in between using sockopts by
_ordinary_ users. Could that be a problem?
> Note : I did not check the RTNL assertion, you might add appropriate
> ASSERT_RTNL() calls just to be 100% safe.
I'll investigate some similar places in the networking code and then replace
the spinlocks with rtnl_locks for some testing.
Thanks for the feedback,
Oliver
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC net-next-2.6] can: replace spinlocks with mutexes
2011-04-20 15:39 ` Eric Dumazet
2011-04-20 16:18 ` Oliver Hartkopp
@ 2011-04-21 13:00 ` Oliver Hartkopp
1 sibling, 0 replies; 4+ messages in thread
From: Oliver Hartkopp @ 2011-04-21 13:00 UTC (permalink / raw)
To: Eric Dumazet
Cc: David Miller, Linux Netdev List, Kurt Van Dijck, Urs Thuermann
On 20.04.2011 17:39, Eric Dumazet wrote:
> Le mercredi 20 avril 2011 à 17:31 +0200, Oliver Hartkopp a écrit :
>> This patch removes spinlocks for the CAN netdevice specific receive lists.
>> The RCU-based receive lists can be modified from process context or from the
>> netdevice notifier call. As both might sleep we can safely replace the
>> spinlocks with mutexes.
>>
>> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
>>
>> ---
>
> But... why ?
>
> A spinlock is faster/smaller than a mutex.
>
> Maybe you wanted to _remove_ spinlock, since/if writer hold RTNL and
> doesnt need to exclude another writer(s) ?
>
> Note : I did not check the RTNL assertion, you might add appropriate
> ASSERT_RTNL() calls just to be 100% safe.
>
I played a bit with rtnl locks but ran into problems with a lock sock when
enabling all locking debug techniques. Therefore i pull back my RFC for now
and leave the locking using spinlocks as-is.
Thanks,
Oliver
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-04-21 13:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-20 15:31 [RFC net-next-2.6] can: replace spinlocks with mutexes Oliver Hartkopp
2011-04-20 15:39 ` Eric Dumazet
2011-04-20 16:18 ` Oliver Hartkopp
2011-04-21 13:00 ` Oliver Hartkopp
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.