Skip to content

[BACKPORT] wqueue: support custom user queues and harden queue lifecycle - #415

Open
13022591351 wants to merge 5 commits into
PX4:px4_firmware_nuttx-12.12.0+from
13022591351:backport/px4-nuttx-12.12-wqueue
Open

13022591351 wants to merge 5 commits into
PX4:px4_firmware_nuttx-12.12.0+from
13022591351:backport/px4-nuttx-12.12-wqueue

Conversation

@13022591351

Copy link
Copy Markdown

Summary

Backport five commits merged in Apache NuttX to
px4_firmware_nuttx-12.12.0+, providing the NuttX support needed for a
separate PX4 work-queue migration.

The upstream changes are from
apache/nuttx#19982 and
apache/nuttx#19983:

Apache master commit Change
b1a4d858dd24 Use the selected SRAM end for the STM32H7 Protected user heap
519c9a4b8ba0 Keep STM32H7 Protected user SRAM non-shareable
d2e01b905530 Harden custom kernel work-queue lifecycle and cancellation
7e5d05f4fdc4 Consolidate kernel work-queue submission paths
ae5997eef7c7 Support custom user work queues in libc

Each backport records the official merged Apache commit in its
cherry picked from trailer and preserves the original author and sign-off.

Impact

  • Harden custom queue creation, pending-work replacement, synchronous
    cancellation, and teardown in sched/wqueue.
  • Add handle-based custom user queues with configurable pthread worker
    pools under CONFIG_LIBC_USRWORK. The predefined Protected USRWORK
    remains usable with pthread support disabled.
  • Correct STM32H7 Protected user heap placement and MPU attributes required
    for user-space synchronization. The separately mapped shared RPTUN SRAM
    is unaffected.
  • Keep the kernel/user execution boundary: kernel queue submission can be
    used from ISR context; libc user queue operations remain task-context only.

No PX4 application, board configuration, or nuttx-apps changes are included.
The PX4 adapter is a separate change; this backport does not introduce a
PX4-specific duplicate-submission policy into NuttX.

Backport notes

  • The kernel lifecycle commit is applied against the existing stack_addr
    implementation. The later upstream static HPWORK/LPWORK stack support is
    not present in this branch and is not pulled in as a dependency.
  • Backport the functional commits without the subsequent wait-helper
    refactors. The functional commits already use nxsem_wait() / -EINTR
    retry loops, so no downstream cancellation-code changes are needed.
  • The other four backports have matching stable patch IDs with their Apache
    source commits. For the lifecycle commit, the actual added and removed
    source lines also match upstream; git range-diff shows differences only
    in the existing stack-handling context described above.

Testing

Backport preparation checks:

  • git diff --check: passed.
  • NuttX tools/checkpatch.sh over all five commits: passed.

The upstream series was tested on an STM32H7 PX4 FMUv6C with the ostest
work-queue suite in Flat, Protected kernel/user, and Protected without pthread
support; the upstream PRs contain the test records. Those results describe
the upstream validation, not a new hardware run of this backport. No
additional on-board test was performed while preparing this PR.

…heap.

up_allocate_heap() calculates the available user heap from SRAM_END but
previously placed the aligned region relative to SRAM123_END.  That mixes
the selected primary SRAM with a fixed D2 SRAM boundary and leaves
SRAM123_END undefined for dual-core M7 and M4 configurations.

Place the user heap relative to SRAM_END so its size, MPU alignment, and
location all refer to the SRAM region selected by the chip configuration.

Tested by building and booting a Protected image on an STM32H7 PX4 FMUv6C.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
(cherry picked from commit b1a4d85)
The generic ARMv7-M user SRAM helper marks memory shareable.  STM32H7
Protected user data and heaps can reside in cacheable AXI or D2 SRAM, where
userspace synchronization needs LDREX/STREX to use the CPU-local exclusive
monitor.

Map protected user SRAM as Normal, cacheable, and non-shareable.  Dual-core
RPTUN SRAM remains unaffected because it is mapped separately with explicit
shareable attributes.

Tested by booting a Protected image and running user and kernel work-queue
stress tests on an STM32H7 PX4 FMUv6C.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
(cherry picked from commit 519c9a4)
Prevent work_queue_free() from destroying predefined queues or freeing a
custom queue from one of its own callbacks.  Mark teardown under the queue
lock, reject new submissions, return pending work to its owner, and wait for
every worker before releasing queue resources.

Clean up partially created worker pools, reject invalid delays, safely
replace pending periodic work, and make synchronous cancellation wait for
every concurrent callback using the same work structure.

Tested on an STM32H7 PX4 FMUv6C with the matching ostest suite in Flat and
Protected kernel builds.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
(cherry picked from commit d2e01b9)
Factor the common queueing logic used by work_queue_wq() and
work_queue_next_wq() into a private helper.

Preserve existing timing semantics: regular work calculates its absolute
expiration before taking the queue lock, while periodic work advances the
previous expiration under the lock.

This is a code deduplication change with no public API or behavior changes.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
(cherry picked from commit 7e5d05f)
Implement the handle-based create, queue, priority, cancellation, and
teardown APIs for CONFIG_LIBC_USRWORK.  Custom queues use configurable
pthread worker pools while the predefined USRWORK queue remains available.

Match scheduler-backend delay, replacement, cancellation, and lifecycle
semantics.  Restrict the libc backend to task context because it uses
blocking synchronization.

Tested on an STM32H7 PX4 FMUv6C with ostest wqueue in Protected user space.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
(cherry picked from commit ae5997e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant