Skip to content

sched/affinity: Fix CPU_LOCKED functionality for some SMP calls#16262

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
tiiuae:fix_smp_call
Apr 26, 2025
Merged

sched/affinity: Fix CPU_LOCKED functionality for some SMP calls#16262
xiaoxiang781216 merged 1 commit into
apache:masterfrom
tiiuae:fix_smp_call

Conversation

@pussuw

@pussuw pussuw commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

Summary

For some SMP calls it is necessary to lock the current CPU for the process receiving the SMP call. This is done by setting the CPU affinity to the current CPU and preventing the CPU selection algorithm from switching CPUs.

dtcb->flags |= TCB_FLAG_CPU_LOCKED;
CPU_SET(dtcb->cpu, &dtcb->affinity);

However, this logic is currently broken, as CPU_SET is defined as:

#define CPU_SET(c,s) do { *(s) |= (1u << (c)); } while (0)

In order to assign tcb->cpu (the current CPU) to the affinity mask, the mask must be cleared first by calling CPU_ZERO.

Impact

This fixes a bug in SMP mode where the kernel attempts to lock CPU for a process, but the CPU can still change. Impact
is a bug fix in the kernel. No user / documentation / API changes and so forth.

Testing

Testing and bug hunting was done by @jlaitine by running ostest with SMP enabled. The crash occurs in signest test.

Issues related:
#16193
#16133

For some SMP calls it is necessary to lock the current CPU for the process
receiving the SMP call. This is done by setting the CPU affinity to the
current CPU and preventing the CPU selection algorithm from switching
CPUs.

  dtcb->flags |= TCB_FLAG_CPU_LOCKED;
  CPU_SET(dtcb->cpu, &dtcb->affinity);

However, this logic is currently broken, as CPU_SET is defined as:

  #define CPU_SET(c,s) do { *(s) |= (1u << (c)); } while (0)

In order to assign tcb->cpu (the current CPU) to the affinity mask, the
mask must be cleared first by calling CPU_ZERO.
@github-actions github-actions Bot added Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small labels Apr 25, 2025
@xiaoxiang781216 xiaoxiang781216 merged commit c12aa56 into apache:master Apr 26, 2025
@pussuw pussuw deleted the fix_smp_call branch April 26, 2025 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] RP2350 ostest stuck when SMP enabled [BUG] esp32-devkitc:smp fails on ostest after #16030

3 participants