modifyreg[8|32]: use small lock in modifyreg[8|32]

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-19 19:57:12 +08:00 committed by Xiang Xiao
parent c568ee7008
commit e8879f9588
26 changed files with 169 additions and 52 deletions

View file

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

View file

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

View file

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

View file

@ -33,6 +33,12 @@
#include "arm64_internal.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Public Functions
****************************************************************************/
@ -50,10 +56,10 @@ void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
irqstate_t flags;
uint8_t regval;
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg8(addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(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/arch.h>
#include <nuttx/spinlock.h>
#include "avr_internal.h"
@ -42,6 +43,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits)
irqstate_t flags;
uint32_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg32(addr);
regval &= ~clearbits;
regval |= setbits;
putreg32(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/arch.h>
#include <nuttx/spinlock.h>
#include "avr_internal.h"
@ -42,6 +43,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
irqstate_t flags;
uint8_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg8(addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(regval, addr);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_modifyreg_lock, flags);
}

View file

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

View file

@ -29,6 +29,12 @@
#include "ceva_internal.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Public Functions
****************************************************************************/
@ -46,10 +52,10 @@ void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
irqstate_t flags;
uint8_t regval;
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg8(addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(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/arch.h>
#include <nuttx/spinlock.h>
#include "hc_internal.h"
@ -42,6 +43,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits)
irqstate_t flags;
uint32_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg32(addr);
regval &= ~clearbits;
regval |= setbits;
putreg32(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/arch.h>
#include <nuttx/spinlock.h>
#include "hc_internal.h"
@ -42,6 +43,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
irqstate_t flags;
uint8_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg8(addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(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/arch.h>
#include <nuttx/spinlock.h>
#include "mips_internal.h"
@ -42,6 +43,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits)
irqstate_t flags;
uint32_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg32(addr);
regval &= ~clearbits;
regval |= setbits;
putreg32(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/arch.h>
#include <nuttx/spinlock.h>
#include "mips_internal.h"
@ -42,6 +43,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
irqstate_t flags;
uint8_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg8(addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(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/arch.h>
#include <nuttx/spinlock.h>
#include "misoc.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Public Functions
****************************************************************************/
@ -51,10 +58,10 @@ void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits)
irqstate_t flags;
uint32_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg32(addr);
regval &= ~clearbits;
regval |= setbits;
putreg32(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/arch.h>
#include <nuttx/spinlock.h>
#include "misoc.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Public Functions
****************************************************************************/
@ -51,10 +58,10 @@ void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
irqstate_t flags;
uint8_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg8(addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(regval, addr);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_modifyreg_lock, flags);
}

View file

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

View file

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

View file

@ -33,6 +33,12 @@
#include "riscv_internal.h"
/****************************************************************************
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Public Functions
****************************************************************************/
@ -50,10 +56,10 @@ void modifyreg32(uintreg_t addr, uint32_t clearbits, uint32_t setbits)
irqstate_t flags;
uint32_t regval;
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg32(addr);
regval &= ~clearbits;
regval |= setbits;
putreg32(regval, addr);
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_modifyreg_lock, flags);
}

View file

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

View file

@ -42,6 +42,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,11 +65,11 @@ void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
irqstate_t flags;
uint8_t regval;
flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg8(addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(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/arch.h>
#include <nuttx/spinlock.h>
#include "x86_internal.h"
@ -42,6 +43,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits)
irqstate_t flags;
uint32_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg32((uint16_t)addr);
regval &= ~clearbits;
regval |= setbits;
putreg32(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/arch.h>
#include <nuttx/spinlock.h>
#include "x86_internal.h"
@ -42,6 +43,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
irqstate_t flags;
uint8_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg8((uint16_t)addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(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/arch.h>
#include <nuttx/spinlock.h>
#include "x86_64_internal.h"
@ -42,6 +43,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits)
irqstate_t flags;
uint32_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg32((uint16_t)addr);
regval &= ~clearbits;
regval |= setbits;
putreg32(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/arch.h>
#include <nuttx/spinlock.h>
#include "x86_64_internal.h"
@ -42,6 +43,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -63,10 +66,10 @@ void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
irqstate_t flags;
uint8_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = getreg8((uint16_t)addr);
regval &= ~clearbits;
regval |= setbits;
putreg8(regval, (uint16_t)addr);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_modifyreg_lock, flags);
}

View file

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

View file

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

View file

@ -29,6 +29,7 @@
#include <stdint.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <arch/io.h>
/****************************************************************************
@ -39,6 +40,8 @@
* Private Data
****************************************************************************/
static spinlock_t g_modifyreg_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -60,10 +63,10 @@ void modifyreg8(uint16_t addr, uint8_t clearbits, uint8_t setbits)
irqstate_t flags;
uint8_t regval;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_modifyreg_lock);
regval = inp(addr);
regval &= ~clearbits;
regval |= setbits;
outp(regval, addr);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_modifyreg_lock, flags);
}