Skip to contentSkip to conversation

Is netif_tx_lock() SMP PREEMPT safe?

DISCUSSION Marin Mitov 2 participants 2 messages Feb 15, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi all,

As in: include/linux/netdevice.h (kernel-2.6.24.2) one finds:

static inline void __netif_tx_lock(struct net_device *dev, int cpu)

{
        spin_lock(&dev->_xmit_lock);
        dev->xmit_lock_owner = cpu;
}

static inline void netif_tx_lock(struct net_device *dev)

{
        __netif_tx_lock(dev, smp_processor_id());
}

Does netif_tx_lock(struct net_device *dev) expands into:

cpu = smp_processor_id();
<preempt & shift to another cpu (bogus)> spin_lock(&dev->_xmit_lock);
dev->xmit_lock_owner = cpu; /* cpu is not the lock owner */

Or to:

spin_lock(&dev->_xmit_lock);
dev->xmit_lock_owner = smp_processor_id();

which is correct?

Thanks in advance for your answer.

Regards

Marin Mitov

#1 lore raw
Quoted 21 lines · Marin Mitov

Hi all,

As in: include/linux/netdevice.h (kernel-2.6.24.2) one finds:

static inline void __netif_tx_lock(struct net_device *dev, int cpu)

{
        spin_lock(&dev->_xmit_lock);
        dev->xmit_lock_owner = cpu;
}

static inline void netif_tx_lock(struct net_device *dev)

{
        __netif_tx_lock(dev, smp_processor_id());
}

Does netif_tx_lock(struct net_device *dev) expands into:

cpu = smp_processor_id(); <preempt & shift to another cpu (bogus)> spin_lock(&dev->_xmit_lock);
dev->xmit_lock_owner = cpu; /* cpu is not the lock owner */

Quoted 8 lines

Or to:

spin_lock(&dev->_xmit_lock);
dev->xmit_lock_owner = smp_processor_id();

which is correct?

Hi Marin

This expands to the first version, but netif_tx_lock() is allways called with preemption disabled.

(Or checks in smp_processor_id() would just trigger)

Eric
(Cced netdev for network related stuff)