apache / nuttx

Apache NuttX is a mature, real-time embedded operating system (RTOS)
https://nuttx.apache.org/
Apache License 2.0
2.81k stars 1.16k forks source link

[BUG] the semantics of enter_critical_section is unclear #14593

Open yamt opened 19 hours ago

yamt commented 19 hours ago

Description / Steps to reproduce the issue

https://github.com/apache/nuttx/blob/master/Documentation/implementation/critical_sections.rst

Without going into the details of the implementation of enter_critical_section() suffice it to say that it (1) disables interrupts on the local CPU and (2) uses spinlocks to assure exclusive access to a code sequence across all CPUs.

as users of enter_critical_section don't seem to have a way to limit the scope, i guess it implies enter_critical_section works as the single global lock covering the whole system. is it right?

also, to me it isn't clear if enter_critical_section is supposed to disable interrupts on the remote CPUs. the comment in irq_csection.c says

Take the CPU IRQ lock and disable interrupts on all CPUs.

on the other hand, other comment in the file says

NOTE 1: Ideally this should disable interrupts on all CPUs, but most architectures only support disabling interrupts on the local CPU.`

they seem contradicting each other.

On which OS does this issue occur?

[OS: Mac]

What is the version of your OS?

macOS 14.7

NuttX Version

master

Issue Architecture

[Arch: all]

Issue Area

[Area: Api], [Area: Kernel]

Verification

acassis commented 15 hours ago

@anchao could you please help to shed some light here?