mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 07:12:54 +08:00
sched:remove g_cpu_schedlock g_cpu_irqsetlock g_cpu_locksetlock
we can use g_cpu_lockset to determine whether we are currently in the scheduling lock, and all accesses and modifications to g_cpu_lockset, g_cpu_irqlock, g_cpu_irqset are in the critical section, so we can directly operate on it. test: We can use qemu for testing. compiling make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20 running qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
committed by
Masayuki Ishikawa
parent
769e65ef8e
commit
f7843e2198
+23
-26
@@ -36,6 +36,18 @@
|
||||
#include "irq/irq.h"
|
||||
|
||||
#ifdef CONFIG_IRQCOUNT
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
# define cpu_irqlock_set(cpu) \
|
||||
do \
|
||||
{ \
|
||||
g_cpu_irqset |= (1 << cpu); \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
@@ -50,7 +62,6 @@ volatile spinlock_t g_cpu_irqlock = SP_UNLOCKED;
|
||||
|
||||
/* Used to keep track of which CPU(s) hold the IRQ lock. */
|
||||
|
||||
volatile spinlock_t g_cpu_irqsetlock;
|
||||
volatile cpu_set_t g_cpu_irqset;
|
||||
|
||||
/* Handles nested calls to enter_critical section from interrupt handlers */
|
||||
@@ -277,17 +288,7 @@ try_again_in_irq:
|
||||
DEBUGVERIFY(up_cpu_paused(cpu));
|
||||
paused = true;
|
||||
|
||||
/* NOTE: As the result of up_cpu_paused(cpu), this CPU
|
||||
* might set g_cpu_irqset in nxsched_resume_scheduler()
|
||||
* However, another CPU might hold g_cpu_irqlock.
|
||||
* To avoid this situation, releae g_cpu_irqlock first.
|
||||
*/
|
||||
|
||||
if ((g_cpu_irqset & (1 << cpu)) != 0)
|
||||
{
|
||||
spin_clrbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock,
|
||||
&g_cpu_irqlock);
|
||||
}
|
||||
DEBUGASSERT((g_cpu_irqset & (1 << cpu)) == 0);
|
||||
|
||||
/* NOTE: Here, this CPU does not hold g_cpu_irqlock,
|
||||
* so call irq_waitlock(cpu) to acquire g_cpu_irqlock.
|
||||
@@ -295,22 +296,21 @@ try_again_in_irq:
|
||||
|
||||
goto try_again_in_irq;
|
||||
}
|
||||
|
||||
cpu_irqlock_set(cpu);
|
||||
}
|
||||
|
||||
/* In any event, the nesting count is now one */
|
||||
|
||||
g_cpu_nestcount[cpu] = 1;
|
||||
|
||||
/* Also set the CPU bit so that other CPUs will be aware that
|
||||
* this CPU holds the critical section.
|
||||
*/
|
||||
|
||||
spin_setbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock,
|
||||
&g_cpu_irqlock);
|
||||
if (paused)
|
||||
{
|
||||
up_cpu_paused_restore();
|
||||
}
|
||||
|
||||
DEBUGASSERT(spin_is_locked(&g_cpu_irqlock) &&
|
||||
(g_cpu_irqset & (1 << cpu)) != 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -375,8 +375,7 @@ try_again_in_irq:
|
||||
* like lockcount: Both will disable pre-emption.
|
||||
*/
|
||||
|
||||
spin_setbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock,
|
||||
&g_cpu_irqlock);
|
||||
cpu_irqlock_set(cpu);
|
||||
rtcb->irqcount = 1;
|
||||
|
||||
/* Note that we have entered the critical section */
|
||||
@@ -482,11 +481,11 @@ void leave_critical_section(irqstate_t flags)
|
||||
|
||||
FAR struct tcb_s *rtcb = current_task(cpu);
|
||||
DEBUGASSERT(rtcb != NULL);
|
||||
DEBUGASSERT((g_cpu_irqset & (1 << cpu)) != 0);
|
||||
|
||||
if (rtcb->irqcount <= 0)
|
||||
{
|
||||
spin_clrbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock,
|
||||
&g_cpu_irqlock);
|
||||
cpu_irqlock_clear();
|
||||
}
|
||||
|
||||
g_cpu_nestcount[cpu] = 0;
|
||||
@@ -541,8 +540,7 @@ void leave_critical_section(irqstate_t flags)
|
||||
*/
|
||||
|
||||
rtcb->irqcount = 0;
|
||||
spin_clrbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock,
|
||||
&g_cpu_irqlock);
|
||||
cpu_irqlock_clear();
|
||||
|
||||
/* Have all CPUs released the lock? */
|
||||
}
|
||||
@@ -643,8 +641,7 @@ void restore_critical_section(void)
|
||||
|
||||
if ((g_cpu_irqset & (1 << me)) != 0)
|
||||
{
|
||||
spin_clrbit(&g_cpu_irqset, me, &g_cpu_irqsetlock,
|
||||
&g_cpu_irqlock);
|
||||
cpu_irqlock_clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user