apache / apache/nuttx

[BUG] the semantics of enter_critical_section is unclear

Open
#14,593 9 comments 0 reactions 1 assignee Claimed by @xiaoxiang781216 View on GitHub
Arch: all Area: Api Area: Kernel OS: Mac Type: Bug
Dominant language
C
Stars
4k
Forks
1.7k
Avg merge
1d 17h
Merged PRs (30d)
237

Description

### 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

- [X] I have verified before submitting the report.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.