modifyreg16: use small lock in modifyreg16

reason:
We would like to replace the big lock with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2024-12-18 16:08:01 +08:00 committed by Xiang Xiao
parent d48583604c
commit 15c80e68a0
12 changed files with 78 additions and 24 deletions

View file

@ -33,6 +33,12 @@
#include "arm_internal.h" #include "arm_internal.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -50,10 +56,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16(addr); regval = getreg16(addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, addr); putreg16(regval, addr);
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -33,6 +33,12 @@
#include "arm64_internal.h" #include "arm64_internal.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -50,10 +56,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16(addr); regval = getreg16(addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, addr); putreg16(regval, addr);
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -31,6 +31,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/spinlock.h>
#include "avr_internal.h" #include "avr_internal.h"
@ -42,6 +43,8 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16(addr); regval = getreg16(addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, addr); putreg16(regval, addr);
leave_critical_section(flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -29,6 +29,12 @@
#include "ceva_internal.h" #include "ceva_internal.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -46,10 +52,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16(addr); regval = getreg16(addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, addr); putreg16(regval, addr);
spin_unlock_irqrestore(flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -31,6 +31,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/spinlock.h>
#include "hc_internal.h" #include "hc_internal.h"
@ -42,6 +43,8 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16(addr); regval = getreg16(addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, addr); putreg16(regval, addr);
leave_critical_section(flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -31,6 +31,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/spinlock.h>
#include "mips_internal.h" #include "mips_internal.h"
@ -42,6 +43,8 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16(addr); regval = getreg16(addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, addr); putreg16(regval, addr);
leave_critical_section(flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -31,9 +31,16 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/spinlock.h>
#include "misoc.h" #include "misoc.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -51,10 +58,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16(addr); regval = getreg16(addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, addr); putreg16(regval, addr);
leave_critical_section(flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -33,6 +33,12 @@
#include "or1k_internal.h" #include "or1k_internal.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -50,10 +56,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16(addr); regval = getreg16(addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, addr); putreg16(regval, addr);
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -42,6 +42,8 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -63,11 +65,11 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16(addr); regval = getreg16(addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, addr); putreg16(regval, addr);
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -31,6 +31,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/spinlock.h>
#include "x86_internal.h" #include "x86_internal.h"
@ -42,6 +43,8 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16((uint16_t)addr); regval = getreg16((uint16_t)addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, (uint16_t)addr); putreg16(regval, (uint16_t)addr);
leave_critical_section(flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -31,6 +31,7 @@
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/spinlock.h>
#include "x86_64_internal.h" #include "x86_64_internal.h"
@ -42,6 +43,8 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16((uint16_t)addr); regval = getreg16((uint16_t)addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, (uint16_t)addr); putreg16(regval, (uint16_t)addr);
leave_critical_section(flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }

View file

@ -35,6 +35,12 @@
#include "xtensa.h" #include "xtensa.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -52,10 +58,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
irqstate_t flags; irqstate_t flags;
uint16_t regval; uint16_t regval;
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg16(addr); regval = getreg16(addr);
regval &= ~clearbits; regval &= ~clearbits;
regval |= setbits; regval |= setbits;
putreg16(regval, addr); putreg16(regval, addr);
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&g_modifyreg_lock, flags);
} }