Skip to content

Added regressions for priority changes while waiting on mutexes - #809

Merged
fdesbiens merged 3 commits into
eclipse-threadx:devfrom
howjmay:fix/mutex-inherit-waiter-priority-change
Nov 25, 2026
Merged

fdesbiens merged 3 commits into
eclipse-threadx:devfrom
howjmay:fix/mutex-inherit-waiter-priority-change

Conversation

@howjmay

@howjmay howjmay commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

The waiter priority update in #808 lacked a regression that checks acquisition order after a priority change on a mutex without inheritance.

Added API regressions that check the effective priority of suspended and ready owners after a waiter changes priority. The FIFO case checks that three waiters on a mutex without inheritance still acquire it in the order they blocked. Registered the test in the single-core, SMP, and RISC-V suites.

The regression passed on GCC 14 Linux single-core and SMP and on RISC-V QEMU with chaining on and off. Before the waiter priority update, both Linux kernels failed with ERROR #30.

A mutex owner inherits a waiter's priority only at the moment the waiter blocks in
tx_mutex_get. _tx_thread_priority_change on a thread that is not ready updated that
thread's own priority fields and nothing else, so a thread waiting on a TX_INHERIT mutex
could be raised above the owner without the owner following, and a waiter the owner had
inherited from could be lowered while the owner kept the old priority.

When the thread is suspended on a mutex, _tx_thread_priority_change now calls a new
internal function, _tx_mutex_inherit_priority_update, which recomputes the mutex's
highest waiting priority, the owner's inherited priority across every mutex it holds,
and the owner's priority. The call goes through a new function pointer,
_tx_thread_mutex_priority_update, set by tx_mutex_create in the same way as
_tx_thread_mutex_release, so the thread services still do not link the mutex services.
Applied to common and common_smp.

threadx_mutex_inherit_waiter_priority_change_test changes the priorities of two waiters
in four steps that raise the owner, lower it to the other waiter, and finally return it
to its own priority. Added to both suites. Without the fix it fails with ERROR eclipse-threadx#30 in
both; with it, the mutex tests pass in both suites' default_build_coverage
configuration, and the changed sources build cleanly under -Wall -Wextra -Werror with
TX_NOT_INTERRUPTABLE, TX_MISRA_ENABLE, TX_DISABLE_PREEMPTION_THRESHOLD and event trace.
@fdesbiens
fdesbiens self-requested a review October 16, 2026 13:30
@fdesbiens fdesbiens self-assigned this Oct 16, 2026

@fdesbiens fdesbiens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @howjmay. Thank you for this contribution. Updating inheritance when a waiter’s priority changes addresses a real gap. I left one behavior issue below. Please also add a ready-owner test, report coverage for the modified production code, and retarget the PR to dev.

Comment thread common/src/tx_thread_priority_change.c Outdated
#endif

/* Update the priority inheritance of the mutex owner. */
(_tx_thread_mutex_priority_update)(mutex_ptr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this update be limited to TX_INHERIT mutexes? For a TX_NO_INHERIT mutex with multiple waiters, the helper calls _tx_mutex_prioritize, so changing a waiter’s priority can change FIFO acquisition order. A regression checking that order would help protect this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.
Anything should I add to process this PR?

_tx_thread_priority_change called _tx_mutex_inherit_priority_update for a thread
waiting on any mutex. For a TX_NO_INHERIT mutex with several waiters, the helper's
call to _tx_mutex_prioritize moved the changed waiter to the front of the suspension
list, so changing a waiter's priority changed the FIFO order in which the waiters
obtain the mutex. The update now runs only when the mutex was created with
TX_INHERIT, and the helper's header states that requirement. Applied to common and
common_smp.

threadx_mutex_inherit_waiter_priority_change_test now also checks:
- that three waiters on a TX_NO_INHERIT mutex obtain it in the order they blocked
  after the last one is raised above the others. Without the fix it fails with
  ERROR eclipse-threadx#62 in both suites.
- a ready owner, moved 10, 15, 8 and back to 15 by changes to its waiter's
  priority, and that the owner runs before the call returns when the caller is
  below the owner's new priority.
- an owner holding two TX_INHERIT mutexes and one TX_NO_INHERIT mutex, including
  a step that leaves the owner's priority unchanged.
- two cases set up by hand: a TX_MUTEX_SUSP thread whose cleanup has already been
  cleared, and the helper run on a mutex with no waiters left.

The test passes in every tx and smp build configuration. Merged coverage of the
changed lines is 100% of lines and branches, except the TX_MISRA_ENABLE retry loop
around _tx_mutex_prioritize, which cannot iterate because _tx_misra_status_get
always returns TX_SUCCESS. The same loops in tx_mutex_put.c are also half covered.
@howjmay
howjmay requested a review from fdesbiens October 18, 2026 03:55
The production fix for priority changes while waiting on a mutex already
landed in dev. The contributor's API tests still exercise distinct cases.

Kept the suspended-owner, ready-owner, and FIFO cases and registered them
in the single-core, SMP, and RISC-V suites. Used dev's production code.

The regression passed on GCC 14 Linux single-core and SMP and on RISC-V
QEMU with chaining on and off. Before the production fix, both Linux
kernels failed with ERROR eclipse-threadx#30.

Assisted-by: Codex (GPT-6.2-Sol) <noreply@openai.com>
@fdesbiens
fdesbiens changed the base branch from master to dev November 25, 2026 00:32
@fdesbiens fdesbiens changed the title Passed a mutex waiter's priority change on to the mutex owner Added regressions for priority changes while waiting on mutexes Nov 25, 2026

@fdesbiens fdesbiens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The tests cover priority restoration for suspended and ready owners and verify that changing a waiter's priority preserves FIFO acquisition on a mutex without inheritance. The Linux and RISC-V QEMU runs passed with chaining on and off, and all CI checks that ran passed.

@fdesbiens
fdesbiens merged commit fb15fa4 into eclipse-threadx:dev Nov 25, 2026
14 checks passed
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.

2 participants