-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spinlock+sched_lock #14578
base: master
Are you sure you want to change the base?
spinlock+sched_lock #14578
Conversation
157736b
to
175819e
Compare
@patacongo please review this patch which fix the long issue about sched lock. |
87f9b88
to
cde599d
Compare
please fix conflict |
…ed_[un]lock reason: 1 Accelerated the implementation of sched_lock, remove enter_critical_section in sched_lock and only enter_critical_section when task scheduling is required. 2 we add sched_lock_wo_note/sched_unlock_wo_note and it does not perform instrumentation logic Signed-off-by: hujun5 <[email protected]>
reason: allow the spin_lock_irqsave_wo_note to respond interrupts during the test set loop and improve RT performance Signed-off-by: hujun5 <[email protected]>
reason: We aim to replace big locks with smaller ones. So we will use spin_lock_irqsave extensively to replace enter_critical_section in the subsequent process. We imitate the implementation of Linux by adding sched_lock to spin_lock_irqsave in order to address scenarios where sem_post occurs within spin_lock_irqsave, which can lead to spinlock failures and deadlocks. Signed-off-by: hujun5 <[email protected]>
done |
@@ -232,7 +232,7 @@ irqstate_t enter_critical_section(void) | |||
|
|||
DEBUGASSERT((g_cpu_irqset & (1 << cpu)) == 0); | |||
|
|||
spin_lock(&g_cpu_irqlock); | |||
spin_lock_wo_note(&g_cpu_irqlock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need change leave_critical_section too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drivers/note/noterpmsg_driver.c
Outdated
@@ -85,6 +86,8 @@ struct noterpmsg_driver_s g_noterpmsg_driver = | |||
}, | |||
}; | |||
|
|||
volatile spinlock_t g_note_driver_lock = SP_UNLOCKED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove volatile and add static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/note/noterpmsg_driver.c
Outdated
@@ -178,15 +181,15 @@ static bool noterpmsg_transfer(FAR struct noterpmsg_driver_s *drv, | |||
static void noterpmsg_work(FAR void *priv) | |||
{ | |||
FAR struct noterpmsg_driver_s *drv = priv; | |||
irqstate_t flags = enter_critical_section(); | |||
irqstate_t flags = spin_lock_irqsave(&g_note_driver_lock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need call wo_note version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/note/noterpmsg_driver.c
Outdated
|
||
if (!noterpmsg_transfer(drv, false)) | ||
{ | ||
work_queue(HPWORK, &drv->work, noterpmsg_work, drv, | ||
NOTE_RPMSG_WORK_DELAY); | ||
} | ||
|
||
leave_critical_section(flags); | ||
spin_unlock_irqrestore(&g_note_driver_lock, flags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
include/nuttx/spinlock.h
Outdated
|
||
#ifdef CONFIG_SPINLOCK | ||
# define spin_trylock_irqsave_wo_note(l, f) \ | ||
({ \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could.we.avoid.use gcc express statement extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -528,22 +567,29 @@ static inline_function | |||
irqstate_t spin_lock_irqsave_wo_note(FAR volatile spinlock_t *lock) | |||
{ | |||
irqstate_t ret; | |||
ret = up_irq_save(); | |||
int me; | |||
|
|||
if (NULL == lock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove NULL support in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
…id recursive calls. Signed-off-by: hujun5 <[email protected]>
reason: spin_lock_wo_note/spin_unlock_wo_note should be called in matching pairs. Signed-off-by: hujun5 <[email protected]>
reason: 1: spin_lock_init and spin_initialize have similar functionalities. 2: spin_lock and spin_unlock should be called in matching pairs. Signed-off-by: hujun5 <[email protected]>
reason: we.avoid.use gcc express statement extension in spinlock, to enhance compatibility Signed-off-by: hujun5 <[email protected]>
Summary
1 Accelerated the implementation of sched_lock, remove enter_critical_section in sched_lock and
only enter_critical_section when task scheduling is required.
2 we add sched_lock_wo_note/sched_unlock_wo_note and it does not perform instrumentation logic
3 We aim to replace big locks with smaller ones. So we will use spin_lock_irqsave extensively to
replace enter_critical_section in the subsequent process. We imitate the implementation of Linux
by adding sched_lock to spin_lock_irqsave in order to address scenarios where sem_post occurs
within spin_lock_irqsave, which can lead to spinlock failures and deadlocks.
Impact
spinlock and sched_lock
Testing
Build Host:
Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ 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