arch, boards, drivers, include, sched, wireless: Change spinlock APIs.

Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
  g_irq_spin for backword compatibility (In this case, NULL must be specified)

Impact:
- None

Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
This commit is contained in:
Masayuki Ishikawa
2021-02-08 09:21:26 +09:00
committed by Xiang Xiao
parent f63c189a17
commit d87f350831
70 changed files with 452 additions and 406 deletions
+29 -13
View File
@@ -32,6 +32,7 @@
# include <assert.h>
# ifdef CONFIG_SMP
# include <stdbool.h>
# include <nuttx/spinlock.h>
# endif
#endif
@@ -274,30 +275,38 @@ void leave_critical_section(irqstate_t flags);
*
* Description:
* If SMP is are enabled:
* Disable local interrupts and take the global spinlock (g_irq_spin)
* If the argument lock is not specified (i.e. NULL),
* disable local interrupts and take the global spinlock (g_irq_spin)
* if the call counter (g_irq_spin_count[cpu]) equals to 0. Then the
* counter on the CPU is increment to allow nested call.
* counter on the CPU is increment to allow nested call and return
* the interrupt state.
*
* If the argument lock is specified,
* disable local interrupts and take the lock spinlock and return
* the interrupt state.
*
* NOTE: This API is very simple to protect data (e.g. H/W register
* or internal data structure) in SMP mode. But do not use this API
* with kernel APIs which suspend a caller thread. (e.g. nxsem_wait)
*
* If SMP is not enabled:
* This function is equivalent to enter_critical_section().
* This function is equivalent to up_irq_save().
*
* Input Parameters:
* None
* lock - Caller specific spinlock. If specified NULL, g_irq_spin is used
* and can be nested. Otherwise, nested call for the same lock
* would cause a deadlock
*
* Returned Value:
* An opaque, architecture-specific value that represents the state of
* the interrupts prior to the call to spin_lock_irqsave();
* the interrupts prior to the call to spin_lock_irqsave(lock);
*
****************************************************************************/
#if defined(CONFIG_SMP)
irqstate_t spin_lock_irqsave(void);
irqstate_t spin_lock_irqsave(spinlock_t *lock);
#else
# define spin_lock_irqsave() enter_critical_section()
# define spin_lock_irqsave(l) up_irq_save()
#endif
/****************************************************************************
@@ -305,17 +314,24 @@ irqstate_t spin_lock_irqsave(void);
*
* Description:
* If SMP is enabled:
* Decrement the call counter (g_irq_spin_count[cpu]) and if it
* If the argument lock is not specified (i.e. NULL),
* decrement the call counter (g_irq_spin_count[cpu]) and if it
* decrements to zero then release the spinlock (g_irq_spin) and
* restore the interrupt state as it was prior to the previous call to
* spin_lock_irqsave().
* spin_lock_irqsave(NULL).
*
* If the argument lock is specified, release the the lock and
* restore the interrupt state as it was prior to the previous call to
* spin_lock_irqsave(lock).
*
* If SMP is not enabled:
* This function is equivalent to leave_critical_section().
* This function is equivalent to up_irq_restore().
*
* Input Parameters:
* lock - Caller specific spinlock. If specified NULL, g_irq_spin is used.
*
* flags - The architecture-specific value that represents the state of
* the interrupts prior to the call to spin_lock_irqsave();
* the interrupts prior to the call to spin_lock_irqsave(lock);
*
* Returned Value:
* None
@@ -323,9 +339,9 @@ irqstate_t spin_lock_irqsave(void);
****************************************************************************/
#if defined(CONFIG_SMP)
void spin_unlock_irqrestore(irqstate_t flags);
void spin_unlock_irqrestore(spinlock_t *lock, irqstate_t flags);
#else
# define spin_unlock_irqrestore(f) leave_critical_section(f)
# define spin_unlock_irqrestore(l, f) up_irq_restore(f)
#endif
#undef EXTERN