Skip to content

fix(kernel): restore transitive priority inheritance and green build - #97

Merged
srpatcha merged 2 commits into
embeddedos-org:masterfrom
furqan72672:fix/kernel-priority-inheritance-build
Sep 1, 2026
Merged

srpatcha merged 2 commits into
embeddedos-org:masterfrom
furqan72672:fix/kernel-priority-inheritance-build

Conversation

@furqan72672

Copy link
Copy Markdown
Contributor

Summary

The kernel does not compile on master. Commit 2c490a ("restore mutex owner priority after waiter timeout", PR #55) rewrote the mutex priority-inheritance logic and left the code in an inconsistent state, so the latest "restore a green build" commit (#71) is not actually green.

This PR restores a compiling kernel and the transitive priority-inheritance behavior that the regression silently removed.

Issue being addressed

kernel/src/sync.c referenced four symbols that the commit had deleted, producing 9 compile errors:

  • m->original_prio — field is not present in mtx_t
  • ask_valid(), g_blocked_on, pi_propagate() — removed helper functions/state

kernel/src/task.c gained a duplicate eos_task_set_current_internal definition (a second one was appended while an existing, more complete one remained), producing a further compile error.

Two secondary regressions from the same commit are also fixed:

  • ests/test_kernel.c silently stopped running est_task_stats() and est_tick_overflow() from main() (it reported "10/10" while 12 test functions exist).
  • CHANGELOG.md described a fix that never landed (original_prio) and clobbered the existing device-tree parser entries.

Approach and implementation

  1. kernel/src/sync.c — restored the complete transitive priority-inheritance machinery from the immediately preceding commit 9a61678 ("Correct and transitive mutex priority inheritance"):
    • g_blocked_on[] — records, per task, which mutex it is blocked on
    • pi_recompute() — recomputes a task's effective priority as min(base_priority, priorities of all waiters on every mutex it owns)
    • pi_propagate() — walks the blocking chain (bounded by PI_MAX_CHAIN_DEPTH) so a boost reaches the head of a chain
    • mtx_remove_waiter() — returns success so callers can react
  2. kernel/src/task.c — removed the duplicate eos_task_set_current_internal, keeping the documented version that also marks the task RUNNING.
  3. ** ests/test_kernel.c** — re-registered est_task_stats() and est_tick_overflow(); the summary now reports 12/12. The new est_mutex_pi_timeout_restores_priority() test from fix(kernel): restore mutex owner priority after waiter timeout #55 is kept and passes against the restored implementation.
  4. CHANGELOG.md — corrected the mutex entry and restored the clobbered device-tree entries.
  5. TASKS.md — recorded the work as T-009.

Testing / validation

The machine this was developed on has no system C toolchain (no cmake/gcc/clang), so verification was done with Zig's bundled clang (zig cc, installed via pip install ziglang):

  • zig cc -std=c11 -Wall -Wextra -c kernel/src/sync.c → passes, no warnings
  • zig cc -std=c11 -Wall -Wextra -c kernel/src/task.c → passes, no warnings
  • Built and ran ests/test_priority_inherit.c against all kernel sources → 6/6 pass, including ransitive chained inheritance
  • Built and ran ests/test_kernel.c against all kernel sources → 12/12 pass, including the restored ask runtime stats and ick overflow wraparound, and mutex PI timeout restores owner priority

Full cmake/ctest run: not performed on this machine (no CMake toolchain available).

Type of change

  • fix — Bug fix
  • test — Add or fix tests
  • docs — Documentation only (changelog)

Additional considerations / limitations

  • Verification used Zig's clang rather than the project's GCC/Clang CI; the changed files were compiled with -Wall -Wextra to approximate the CI's stricter flags, but the cross-compile job's -Werror has not been run.
  • The restored design intentionally keeps the global-min recompute (pi_recompute over all mutexes a task owns) rather than the per-mutex original_prio approach from fix(kernel): restore mutex owner priority after waiter timeout #55, because the per-mutex approach cannot express transitive inheritance (the ransitive chained inheritance test fails under it).
  • This PR does not touch the pre-existing open items in TASKS.md (T-005–T-008).

Commit 02c490a ("restore mutex owner priority after waiter timeout")
left the kernel unable to compile and silently dropped transitive
priority inheritance:

- kernel/src/sync.c referenced m->original_prio (no such field in
  mtx_t), task_valid(), g_blocked_on, and pi_propagate() - all of
  which the commit removed, producing 9 compile errors.
- kernel/src/task.c gained a duplicate eos_task_set_current_internal
  definition - a further compile error.
- tests/test_kernel.c silently stopped running test_task_stats() and
  test_tick_overflow(), reporting "10/10" while 12 tests exist.
- CHANGELOG.md described a fix that never landed and clobbered the
  device-tree parser entries.

Restore the transitive priority-inheritance machinery from 9a61678
(pi_recompute/pi_propagate over a g_blocked_on chain), remove the
duplicate definition, re-register the dropped tests, and repair the
changelog.

Verified with zig cc (clang): kernel sources compile clean under
-Wall -Wextra; test_priority_inherit passes 6/6 and test_kernel
passes 12/12.
Copilot AI lite review requested due to automatic review settings August 30, 2026 22:33

Copilot AI 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.

🟡 Changes recommended

The new g_blocked_on[] PI state is not reset by eos_kernel_init(), so repeated init (used by tests and possible re-init scenarios) can propagate stale blocking chains and yield incorrect PI behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Restores the kernel’s ability to compile on master and reintroduces transitive mutex priority inheritance (PI) that was regressed by the prior PI rewrite, while also re-enabling missing kernel tests and correcting release notes/task tracking.

Changes:

  • Reintroduce transitive PI machinery in kernel/src/sync.c (blocked-on tracking, recompute + chain propagation) and adjust lock/unlock paths accordingly.
  • Remove the duplicate eos_task_set_current_internal definition in kernel/src/task.c, keeping the version that sets the RUNNING state.
  • Re-enable test_task_stats() and test_tick_overflow() execution in tests/test_kernel.c, and repair related documentation in CHANGELOG.md and TASKS.md.
File summaries
File Description
tests/test_kernel.c Re-adds two previously-defined tests to main() and updates the pass summary count.
TASKS.md Records the work as T-009 with a summary of the build breakage and the restoration steps.
kernel/src/task.c Removes the appended duplicate eos_task_set_current_internal implementation.
kernel/src/sync.c Restores transitive priority inheritance logic and integrates it into mutex lock/unlock/timeout/delete flows.
CHANGELOG.md Updates the mutex PI entry and restores the device-tree parser changelog entries that were clobbered.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread kernel/src/sync.c
Comment on lines +61 to +63
/* Mutex each task is blocked on, as handle + 1 so that 0 means "none". */
static uint8_t g_blocked_on[EOS_MAX_TASKS];

srpatcha
srpatcha previously approved these changes Sep 1, 2026
Copilot AI review requested due to automatic review settings September 1, 2026 10:52

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

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.

3 participants