sched/affinity: Fix CPU_LOCKED functionality for some SMP calls

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.
This commit is contained in:
Ville Juven 2025-04-25 11:51:36 +03:00 committed by Xiang Xiao
parent 8832136b69
commit c12aa5663d
6 changed files with 6 additions and 0 deletions

View File

@ -130,6 +130,7 @@ int sched_backtrace(pid_t tid, FAR void **buffer, int size, int skip)
arg.need_restore = true;
tcb->flags |= TCB_FLAG_CPU_LOCKED;
CPU_ZERO(&tcb->affinity);
CPU_SET(tcb->cpu, &tcb->affinity);
}

View File

@ -240,6 +240,7 @@ static inline void nxsched_running_setpriority(FAR struct tcb_s *tcb,
arg.need_restore = true;
tcb->flags |= TCB_FLAG_CPU_LOCKED;
CPU_ZERO(&tcb->affinity);
CPU_SET(tcb->cpu, &tcb->affinity);
}

View File

@ -161,6 +161,7 @@ void nxsched_suspend(FAR struct tcb_s *tcb)
arg.need_restore = true;
tcb->flags |= TCB_FLAG_CPU_LOCKED;
CPU_ZERO(&tcb->affinity);
CPU_SET(tcb->cpu, &tcb->affinity);
}

View File

@ -181,6 +181,7 @@ static int nxsig_queue_action(FAR struct tcb_s *stcb, siginfo_t *info)
arg.need_restore = true;
stcb->flags |= TCB_FLAG_CPU_LOCKED;
CPU_ZERO(&stcb->affinity);
CPU_SET(stcb->cpu, &stcb->affinity);
}

View File

@ -241,6 +241,7 @@ static int nxtask_restart(pid_t pid)
arg.need_restore = true;
tcb->flags |= TCB_FLAG_CPU_LOCKED;
CPU_ZERO(&tcb->affinity);
CPU_SET(tcb->cpu, &tcb->affinity);
}

View File

@ -144,6 +144,7 @@ int nxtask_terminate(pid_t pid)
tcb_flags = dtcb->flags;
dtcb->flags |= TCB_FLAG_CPU_LOCKED;
affinity = dtcb->affinity;
CPU_ZERO(&dtcb->affinity);
CPU_SET(dtcb->cpu, &dtcb->affinity);
ret = nxsched_smp_call_single(dtcb->cpu, terminat_handler,