Skip to content

Conversation

@hujun260
Copy link
Contributor

Summary

Add spinlock synchronization to sched_note_preemption and nxsched_critmon_preemption functions. This change ensures thread-safe access to global state during preemption notification and critical section monitoring, preventing race conditions in SMP and interrupt-driven environments.

Changes

Files modified:

  • drivers/note/note_driver.c
  • sched/sched/sched_critmonitor.c

Key changes:

  • Added spinlock protection (g_note_lock) to sched_note_preemption to guard access to the global note driver list and prevent concurrent modifications.
  • Introduced a new spinlock (g_crimonitor_lock) in sched_critmonitor.c to protect global state in nxsched_critmon_preemption.
  • Wrapped all critical sections in both functions with spin_lock_irqsave_notrace/spin_unlock_irqrestore_notrace.

Synchronization pattern:

irqstate_t flags;
flags = spin_lock_irqsave_notrace(&lock);
// critical section
spin_unlock_irqrestore_notrace(&lock, flags);

@github-actions github-actions bot added Area: Drivers Drivers issues Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Jan 19, 2026
jerpelea
jerpelea previously approved these changes Jan 19, 2026
@hujun260 hujun260 dismissed stale reviews from jerpelea and xiaoxiang781216 via 199174f January 20, 2026 01:11
@hujun260 hujun260 force-pushed the apache_add_spinlock_to_sched_note_preemption branch from 199174f to 0087c65 Compare January 20, 2026 04:38
…mption

Add spinlock protection to sched_note_preemption and nxsched_critmon_preemption.
Ensures thread-safe access to global state in preemption notification and critical
monitoring, preventing race conditions in SMP and interrupt contexts.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
@hujun260 hujun260 force-pushed the apache_add_spinlock_to_sched_note_preemption branch from 0087c65 to 4980389 Compare January 21, 2026 05:16
@xiaoxiang781216 xiaoxiang781216 merged commit bb8d16f into apache:master Jan 21, 2026
39 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants