Skip to content

Commit

Permalink
remove big lock in arch_phy_irq
Browse files Browse the repository at this point in the history
reason:
We would like to replace the big lock with a small lock.

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Dec 18, 2024
1 parent c1b665c commit 5d68ab6
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 40 deletions.
12 changes: 8 additions & 4 deletions arch/arm/src/tiva/tm4c/tm4c_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <nuttx/net/mii.h>
#include <nuttx/net/ip.h>
#include <nuttx/net/netdev.h>
#include <nuttx/spinlock.h>

#ifdef CONFIG_TIVA_PHY_INTERRUPTS
# include <nuttx/net/phy.h>
Expand Down Expand Up @@ -628,6 +629,7 @@ struct tiva_ethmac_s
struct wdog_s txtimeout; /* TX timeout timer */
struct work_s irqwork; /* For deferring interrupt work to the work queue */
struct work_s pollwork; /* For deferring poll work to the work queue */
spinlock_t lock; /* Spinlock */

#ifdef CONFIG_TIVA_PHY_INTERRUPTS
xcpt_t handler; /* Attached PHY interrupt handler */
Expand Down Expand Up @@ -2250,7 +2252,7 @@ static int tiva_ifdown(struct net_driver_s *dev)

/* Disable the Ethernet interrupt */

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
up_disable_irq(TIVA_IRQ_ETHCON);

/* Cancel the TX timeout timers */
Expand All @@ -2267,7 +2269,7 @@ static int tiva_ifdown(struct net_driver_s *dev)
/* Mark the device "down" */

priv->ifup = false;
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return OK;
}

Expand Down Expand Up @@ -3180,6 +3182,8 @@ static int tiva_phyinit(struct tiva_ethmac_s *priv)
#endif
#endif

spin_lock_init(&priv->lock);

ninfo("Duplex: %s Speed: %d MBps\n",
priv->fduplex ? "FULL" : "HALF",
priv->mbps100 ? 100 : 10);
Expand Down Expand Up @@ -4035,7 +4039,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
* following operations are atomic.
*/

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);

/* Save the new interrupt handler information */

Expand All @@ -4053,7 +4057,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
*enable = handler ? tiva_phy_intenable : NULL;
}

leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return OK;
}
#endif /* CONFIG_TIVA_PHY_INTERRUPTS */
Expand Down
12 changes: 8 additions & 4 deletions arch/renesas/src/rx65n/rx65n_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <nuttx/net/mii.h>
#include <nuttx/net/ip.h>
#include <nuttx/net/netdev.h>
#include <nuttx/spinlock.h>

#if defined(CONFIG_ARCH_PHY_INTERRUPT)
# include <nuttx/net/phy.h>
Expand Down Expand Up @@ -410,6 +411,7 @@ struct rx65n_ethmac_s

uint32_t prevlinkstatus; /* Previous link status to ignore multiple link change interrupt (specific to GR-Rose) */
uint8_t mc_filter_flag; /* Multicast filter */
spinlock_t lock; /* SpinLock */
};

/****************************************************************************
Expand Down Expand Up @@ -2097,7 +2099,7 @@ static int rx65n_ifdown(struct net_driver_s *dev)
irqstate_t flags;
int ret = OK;
ninfo("Taking the network down\n");
flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);

/* Disable the Ethernet interrupt */

Expand Down Expand Up @@ -2125,7 +2127,7 @@ static int rx65n_ifdown(struct net_driver_s *dev)

priv->prevlinkstatus = ETHER_LINKDOWN;

leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return ret;
}

Expand Down Expand Up @@ -2648,7 +2650,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
return -ENODEV;
}

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_rx65nethmac[0].lock);
rx65n_phyintenable(false);

/* Configure the interrupt */
Expand Down Expand Up @@ -2677,7 +2679,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,

/* Return the old handler (so that it can be restored) */

leave_critical_section(flags);
spin_unlock_irqrestore(&g_rx65nethmac[0].lock, flags);
return OK;
}
#endif
Expand Down Expand Up @@ -3891,6 +3893,8 @@ int rx65n_ethinitialize(int intf)
rx65n_cmtw0_create(RX65N_CMTW0_COUNT_VALUE_FOR_TXPOLL ,
RX65N_CMTW0_COUNT_VALUE_FOR_TXTIMEOUT);

spin_lock_init(&priv->lock);

/* Attach the IRQ to the driver */

if (irq_attach(RX65N_ETH_IRQ, rx65n_interrupt, NULL))
Expand Down
7 changes: 5 additions & 2 deletions boards/arm/at32/at32f437-mini/src/at32_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/spinlock.h>

#include "at32_gpio.h"
#include "at32_eth.h"
Expand Down Expand Up @@ -80,6 +81,8 @@
* Private Data
****************************************************************************/

static spinlock_t g_ethmac_lock = SP_UNLOCKED;

#ifdef HAVE_NETMONITOR
static xcpt_t g_ethmac_handler;
static void *g_ethmac_arg;
Expand Down Expand Up @@ -214,7 +217,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,

DEBUGASSERT(intf);

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_ethmac_lock);

if (strcmp(intf, AT32_ETHMAC_DEVNAME) == 0)
{
Expand All @@ -234,7 +237,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
*enable = enabler;
}

leave_critical_section(flags);
spin_unlock_irqrestore(&g_ethmac_lock, flags);
return OK;
}
#endif
Expand Down
10 changes: 8 additions & 2 deletions boards/arm/imxrt/imxrt1020-evk/src/imxrt_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
# define phyinfo(x...)
#endif

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_phy_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -235,7 +241,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
* following operations are atomic.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_phy_lock);

/* Configure the interrupt */

Expand Down Expand Up @@ -270,7 +276,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,

/* Return the old handler (so that it can be restored) */

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_phy_lock, flags);
return OK;
}
#endif /* GPIO_ENET_IRQ */
Expand Down
10 changes: 8 additions & 2 deletions boards/arm/imxrt/imxrt1050-evk/src/imxrt_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
# define phyinfo(x...)
#endif

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_phy_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -243,7 +249,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
* following operations are atomic.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_phy_lock);

/* Configure the interrupt */

Expand Down Expand Up @@ -278,7 +284,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,

/* Return the old handler (so that it can be restored) */

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_phy_lock, flags);
return OK;
}
#endif /* CONFIG_IMXRT_GPIO1_0_15_IRQ */
Expand Down
10 changes: 8 additions & 2 deletions boards/arm/imxrt/imxrt1060-evk/src/imxrt_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
# define phyinfo(x...)
#endif

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_phy_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -235,7 +241,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
* following operations are atomic.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_phy_lock);

/* Configure the interrupt */

Expand Down Expand Up @@ -270,7 +276,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,

/* Return the old handler (so that it can be restored) */

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_phy_lock, flags);
return OK;
}
#endif /* CONFIG_IMXRT_GPIO1_0_15_IRQ */
Expand Down
10 changes: 8 additions & 2 deletions boards/arm/imxrt/imxrt1064-evk/src/imxrt_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
# define phyinfo(x...)
#endif

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_phy_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -235,7 +241,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
* following operations are atomic.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_phy_lock);

/* Configure the interrupt */

Expand Down Expand Up @@ -270,7 +276,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,

/* Return the old handler (so that it can be restored) */

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_phy_lock, flags);
return OK;
}
#endif /* CONFIG_IMXRT_GPIO1_0_15_IRQ */
Expand Down
10 changes: 8 additions & 2 deletions boards/arm/imxrt/imxrt1170-evk/src/imxrt_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
# define phyinfo(x...)
#endif

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_phy_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -254,7 +260,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
* following operations are atomic.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_phy_lock);

/* Configure the interrupt */

Expand Down Expand Up @@ -289,7 +295,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,

/* Return the old handler (so that it can be restored) */

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_phy_lock, flags);
return OK;
}
#endif /* CONFIG_IMXRT_GPIO1_0_15_IRQ */
Expand Down
10 changes: 8 additions & 2 deletions boards/arm/imxrt/teensy-4.x/src/imxrt_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
# define phyinfo(x...)
#endif

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_phy_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -235,7 +241,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
* following operations are atomic.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_phy_lock);

/* Configure the interrupt */

Expand Down Expand Up @@ -270,7 +276,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,

/* Return the old handler (so that it can be restored) */

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_phy_lock, flags);
return OK;
}
#endif /* CONFIG_IMXRT_GPIO1_0_15_IRQ */
Expand Down
13 changes: 11 additions & 2 deletions boards/arm/sam34/sam4e-ek/src/sam_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/spinlock.h>

#include "sam_gpio.h"
#include "sam_emac.h"
Expand Down Expand Up @@ -71,6 +72,14 @@
# define phyinfo(x...)
#endif

/****************************************************************************
* Private Data
****************************************************************************/

#ifdef CONFIG_SAM34_GPIOD_IRQ
static spinlock_t g_phy_lock = SP_UNLOCKED;
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -205,7 +214,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,
* following operations are atomic.
*/

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_phy_lock);

/* Configure the interrupt */

Expand Down Expand Up @@ -237,7 +246,7 @@ int arch_phy_irq(const char *intf, xcpt_t handler, void *arg,

/* Return the old handler (so that it can be restored) */

leave_critical_section(flags);
spin_unlock_irqrestore(&g_phy_lock, flags);
return OK;
}
#endif /* CONFIG_SAM34_GPIOD_IRQ */
Expand Down
Loading

0 comments on commit 5d68ab6

Please sign in to comment.