Skip to content
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

sched: remove all spin_lock_irqsave(NULL) #15324

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hujun260
Copy link
Contributor

Summary

sched: remove all spin_lock_irqsave(NULL)

Impact

sched

Testing

ci

qemu-armv8a:nsh_smp

@github-actions github-actions bot added Area: Drivers Drivers issues Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Dec 24, 2024
@yamt
Copy link
Contributor

yamt commented Dec 24, 2024

(this comment is not specific to this PR)
do you have a plan to document which lock protects what? it isn't so obvious to me.

include/nuttx/spinlock.h Outdated Show resolved Hide resolved
sched/clock/clock_gettime.c Outdated Show resolved Hide resolved
include/nuttx/spinlock.h Outdated Show resolved Hide resolved
include/nuttx/spinlock.h Outdated Show resolved Hide resolved
sched/clock/clock_gettime.c Outdated Show resolved Hide resolved
sched/clock/clock_initialize.c Outdated Show resolved Hide resolved
sched/irq/irq_attach.c Outdated Show resolved Hide resolved
sched/mqueue/mq_msgfree.c Outdated Show resolved Hide resolved
sched/signal/sig_default.c Outdated Show resolved Hide resolved
sched/timer/timer_create.c Outdated Show resolved Hide resolved
@anchao anchao requested a review from masayuki2009 December 24, 2024 04:50
include/nuttx/clock.h Outdated Show resolved Hide resolved
@hujun260
Copy link
Contributor Author

which lock protects wha

We replace a big lock with smaller locks. Generally, it's easy to find which lock protects what through file searching.

@yamt
Copy link
Contributor

yamt commented Dec 24, 2024

which lock protects wha

We replace a big lock with smaller locks. Generally, it's easy to find which lock protects what through file searching.

sometimes it's obvious. sometimes not.

#ifdef CONFIG_RTC_HIRES
if (g_rtc_enabled)
{
up_rtc_gettime(&ts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

race condition may in lower half

#ifdef CONFIG_RTC_HIRES
if (g_rtc_enabled)
{
up_rtc_gettime(&bias);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if (g_rtc_enabled)
{
irqstate_t flags;

up_rtc_gettime(ts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

g_basetime_lock is just use for protect g_basetime

Copy link
Contributor Author

@hujun260 hujun260 Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added c_section protection to up_rtc_gettime in driver code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the global lock is to improve performance, but adding c_section will make the performance worse, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This critical section is temporarily added. To avoid potential issues, it will be gradually removed entirely in the future. The goal is to replace the critical section with a spinlock.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what's the point of removing the global lock? Make the code more complicated and make the performance worse?We are not robots. If it is just a simple replacement of the lock, why not let AI do it? Any changes need to think about how to make the code better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just only one opinion "We can't let the performance get worse after any change" right?

spin_lock_irqsave(NULL) ->
spin_lock_irqsave(lock) + enter_critical_section()

up_rtc_gettime() is called very frequently. If the timer driver needs enter_critical_section() protection, it means that the spinlock global lock is not really removed yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire replacement process needs to be carried out step by step. We can quickly submit a patch to replace the critical sections in the up_rtc_gettime driver as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please

  1. Resolve the lower half resource exclusive problem first
  2. Then delete the global spinlock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added spinlock to protect up_rtc_gettime

@github-actions github-actions bot added Arch: arm Issues related to ARM (32-bit) architecture Arch: renesas Issues related to the Renesas chips Arch: x86_64 Issues related to the x86_64 architecture labels Dec 25, 2024
@hujun260 hujun260 force-pushed the apache_53 branch 3 times, most recently from 00ee1d0 to 68b83f3 Compare December 25, 2024 07:23
reason:
We have removed the critical section protection
for the up_rtc_gettime function in common code.

Signed-off-by: hujun5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: arm Issues related to ARM (32-bit) architecture Arch: renesas Issues related to the Renesas chips Arch: x86_64 Issues related to the x86_64 architecture Area: Drivers Drivers issues Area: OS Components OS Components issues Size: M The size of the change in this PR is medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants