zyfeier opened a new pull request, #22321:
URL: https://github.com/apache/nuttx/pull/22321

   ## Summary
   
   This is the second part of the BMP series. It converts the scheduler, mm, 
irq, mqueue and signal kernel state to per-CPU data, using the infrastructure 
from part 1 (#22261).
   
   Nothing changes unless `CONFIG_BMP` is selected: every conversion goes 
through `DEFINE_PER_CPU_BMP` / `DECLARE_PER_CPU_BMP` / `this_cpu_var_bmp`, 
which collapse to a plain variable when BMP is off. The non-BMP tree is 
verified to behave exactly like master.
   
   ## What becomes per-CPU
   
   **Scheduler core** (`sched/init/nx_start.c`, `sched/sched/sched.h`, 
`sched/misc/assert.c`)
   
   - `g_readytorun`, `g_pendingtasks` and the other task lists: one list per 
CPU.
   - The task list table `g_tasklisttable[]` can no longer be a const 
initializer (its list pointers are runtime values once the lists are per-CPU), 
so it is filled at boot by `tasklist_initialize()`, which runs before the idle 
task is created. Under non-BMP it is a plain array filled the same way.
   - `g_pidhash` / `g_npidhash`, `g_lastpid`, `g_nx_initstate`, 
`g_running_tasks`, `g_idletcb`, `g_assignedtasks`, `g_delivertasks` and 
`g_cpuload_total`.
   - `g_assert_lock` and the saved panic registers become per-CPU, so a panic 
on one CPU does not fight other CPUs for the lock.
   
   **Work queues, timers and signals** (`sched/wdog`, `sched/wqueue`, 
`sched/timer`, `sched/clock`, `sched/signal`)
   
   - `g_wdactivelist` is moved to runtime initialization: a statically 
initialized list head would point into core 0's copy of the data.
   - `g_hpwork` / `g_lpwork` and the IRQ work queue thread pool and stack.
   - The clock and timer state (`g_system_ticks` in `clock_sched_ticks.c`, the 
POSIX timer pools, `g_prealloctimers`).
   - The preallocated signal action pool keeps the public `g_sigactions` symbol 
and becomes per-CPU.
   
   **mqueue / msg**
   
   - `g_msgfreelist`, `g_msgfree`, `g_msgfreeirq`, `g_msgfreelock`, `g_msgqs` 
and `g_nmsgq`.
   
   **mm** (`mm/`)
   
   - `g_mmheap` and the user heap accessor are per-CPU, so each CPU allocates 
from its own heap.
   - The free delay list moves from per-heap storage to a per-CPU global list. 
Each `mm_delaynode_s` records its heap, so a delayed free can be queued from 
any CPU without taking the heap lock; the drain invokes the node's callback 
(master's `c7408b5e648` semantics) and then force-frees through the recorded 
heap. `mm_free_delaylist()` / `mm_try_free_delaylist()` replace the per-heap 
versions.
   
   **irq**
   
   - The IRQ attach thread PID table and the IRQ work queue state.
   
   ## Impact
   
   - **Users / existing boards**: no change. No defconfig in the tree enables 
BMP, so all converted variables are plain variables and the generated code is 
unchanged.
   - **SMP**: unchanged. The SMP-only variables keep their meaning; 
`current_task()` now resolves `g_assignedtasks` through `per_cpu_var_smp()`, 
which is the same expression.
   - **BMP**: can be selected but still does not boot; the per-CPU kernel 
startup and the architecture ports come with PR-T and later parts. Until then 
BMP is a construction site: no defconfig in the tree enables it.
   - **Known issue, not CI-covered**: `stm32l476vg-disco:knsh` links 8 bytes 
over its `ksram` limit with this series. The main contributor is 
`g_tasklisttable[]` moving from `.rodata` to `.bss` (~200 bytes) because its 
contents are now runtime values. The config is not in any CI testlist and 
master itself only has ~200 bytes of slack there. The follow-up arch PRs can 
restore a const table for non-BMP builds if needed.
   
   ### Known limitations until the follow-up parts land
   
   None of these is reachable from any defconfig in the tree (none enables 
BMP); they are recorded here so the follow-up PRs know what to fix:
   
   - The per-CPU runtime initialization runs on the boot CPU only; the 
secondary-CPU bring-up comes with PR-T.
   - Selecting `PERCPU_SECTION` together with a static work-queue stack section 
(`SCHED_[HL]PWORKSTACKSECTION`, `IRQ_WORK_SECTION`) produces a duplicate 
`__attribute__((section))` conflict; the arch parts that define per-CPU 
sections will rework these definitions.
   - With `PERCPU_ARRAY`, the scalar initializers on `g_lastpid` and 
`g_oneshot_maxticks` do not compile (an array cannot take a scalar 
initializer). Bracketed initializers are unaffected.
   - `CONFIG_NCPUS` and `CONFIG_SMP_NCPUS` are independent under BMP; the 
startup loops still bound on `CONFIG_SMP_NCPUS`, so a BMP configuration must 
set both consistently until the arch parts switch the loops.
   - The mqueue pool wait (`g_msgpoolwait`) is shared while the free lists are 
per-CPU; cross-CPU wakeups need the spinlock treatment that comes with the PR-T 
runtime bring-up.
   
   ## Testing
   
   Host: Linux x86_64. Cross builds use the 
`ghcr.io/apache-nuttx/apache-nuttx-ci-linux` image. All results are on the 
final branch, on top of #22261.
   
   | Configuration | Result |
   |---|---|
   | `sim:nsh` | build OK |
   | `sim:ostest` | full suite passes: `ostest_main: Exiting with status 0` |
   | `sim:smp` | build OK |
   | `sim:nsh` + `MM_TLSF_MANAGER` | build OK (both allocators covered) |
   | `qemu-armv8a:nsh_smp` | build OK |
   | `smartl-c906:knsh` | build OK |
   | `esp32-devkitc:psram` (xtensa) | build OK |
   | `k210/maix-bit:knsh_smp` (RISC-V, `CONFIG_SMP_NCPUS=2`) | build OK |
   | `stm32l476vg-disco:knsh` | links 8 bytes over `ksram` (see Impact) |
   | `tools/checkpatch.sh -g` (per commit) | all checks pass |
   | `codespell` on all touched files | clean |
   
   `sim:ostest` (the same test list as on master):
   
   ```
   user_main: scheduler lock test
   ...
   user_main: pthread_rwlock test
   ...
   ostest_main: Exiting with status 0
   ```
   
   The series was rebased onto current master during development; the delay 
list conversion was reworked on top of master's `c7408b5e648` delay callback 
mechanism rather than against the older per-heap design.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] sched: convert kernel st... zyfeier (via GitHub) via commits

Reply via email to