-
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 |
done |
…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 <hujun5@xiaomi.com>
reason: allow the spin_lock_irqsave_wo_note to respond interrupts during the test set loop and improve RT performance Signed-off-by: hujun5 <hujun5@xiaomi.com>
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 <hujun5@xiaomi.com>
…id recursive calls. Signed-off-by: hujun5 <hujun5@xiaomi.com>
reason: spin_lock_wo_note/spin_unlock_wo_note should be called in matching pairs. Signed-off-by: hujun5 <hujun5@xiaomi.com>
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 <hujun5@xiaomi.com>
reason: we.avoid.use gcc express statement extension in spinlock, to enhance compatibility Signed-off-by: hujun5 <hujun5@xiaomi.com>
@@ -85,6 +86,8 @@ struct noterpmsg_driver_s g_noterpmsg_driver = | |||
}, | |||
}; | |||
|
|||
static 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.
move into noterpmsg_driver_s
@@ -291,6 +291,7 @@ static inline_function void spin_lock(FAR volatile spinlock_t *lock) | |||
/* Lock without trace note */ | |||
|
|||
spin_lock_wo_note(lock); | |||
sched_lock_wo_note(); |
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.
spin_lock_wo_note need schedlock too
@@ -353,6 +354,8 @@ spin_trylock_wo_note(FAR volatile spinlock_t *lock) | |||
} | |||
|
|||
SP_DMB(); | |||
sched_lock_wo_note(); |
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.
lose sched lock note in spin_trylock
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.
spin_trylock will call spin_trylock_wo_note
spin_trylock_wo_note will call sched_lock_wo_note
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.
spin_trylock should call sched_lock to trace the preemption state.
@@ -721,6 +725,7 @@ void spin_unlock_irqrestore_wo_note(FAR volatile spinlock_t *lock, | |||
} | |||
|
|||
up_irq_restore(flags); | |||
sched_unlock_wo_note(); |
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.
rwlock need update too
@@ -721,6 +725,7 @@ void spin_unlock_irqrestore_wo_note(FAR volatile spinlock_t *lock, | |||
} | |||
|
|||
up_irq_restore(flags); | |||
sched_unlock_wo_note(); | |||
} | |||
#else | |||
# define spin_unlock_irqrestore_wo_note(l, f) ((void)(l), up_irq_restore(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.
up case need lock/unlock sched lock too
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