Skip to content

proc/threads: preserve priority inheritance for SMP#803

Draft
rmikielis wants to merge 1 commit into
masterfrom
rmikielis/proc_fix_prio_inherit
Draft

proc/threads: preserve priority inheritance for SMP#803
rmikielis wants to merge 1 commit into
masterfrom
rmikielis/proc_fix_prio_inherit

Conversation

@rmikielis

@rmikielis rmikielis commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

Potential priority inheritance race can occur on SMP when contender bumps owner priority while waiting for a lock, but owner releases another lock, before contender was added to lock waiting queue.
This solution just rips proc_threadWaitEx() so thread_common spinlock is not released before contender is added to lock waiting queue. Without some priority inheritance structures (like tree) this is the smallest amount of fixing source code I could come up with, although not very elegant. Feel free to share another ideas.

Motivation and Context

Fixes phoenix-rtos/phoenix-rtos-project#1626

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: ia32-qemu.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the lock acquisition loop in _proc_lockSet within proc/threads.c. It replaces the do-while loop and the call to proc_threadWaitEx with an infinite for loop that manually handles thread enqueuing, spinlock clearing/setting, and CPU rescheduling. It also adjusts the interruptible exit checks and spinlock management. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

Unit Test Results

9 821 tests   - 1 039   9 216 ✅  - 974   46m 52s ⏱️ - 6m 11s
  603 suites  -    67     605 💤  -  65 
    1 files   ±    0       0 ❌ ±  0 

Results for commit 141514c. ± Comparison against base commit 11a35ff.

This pull request removes 1039 tests.
flash ‑ armv7a9-zynq7000-zedboard:flash
phoenix-rtos-tests/cpp/hello-cpp ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/cpp/hello-cpp
phoenix-rtos-tests/initfini/main ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/initfini/main
phoenix-rtos-tests/ioctl/test-ioctl ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/test-ioctl.ioctl.data_in
phoenix-rtos-tests/ioctl/test-ioctl ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/test-ioctl.ioctl.data_in_big
phoenix-rtos-tests/ioctl/test-ioctl ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/test-ioctl.ioctl.data_inout
phoenix-rtos-tests/ioctl/test-ioctl ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/test-ioctl.ioctl.data_inout_big
phoenix-rtos-tests/ioctl/test-ioctl ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/test-ioctl.ioctl.data_out
phoenix-rtos-tests/ioctl/test-ioctl ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/test-ioctl.ioctl.data_out_big
phoenix-rtos-tests/ioctl/test-ioctl ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/test-ioctl.ioctl.in_val
…

♻️ This comment has been updated with latest results.

@rmikielis rmikielis force-pushed the rmikielis/proc_fix_prio_inherit branch from 70e1736 to 141514c Compare July 1, 2026 16:21
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.

potential race condition in lock priority inheritance on multi-core systems

1 participant