Skip to content

Commit

Permalink
sched/sched: change [FIRST|LAST]_ASSIGNED_STATE to [FIRST|LAST]_READY…
Browse files Browse the repository at this point in the history
…_TO_RUN_STATE in nxsched_set_affinity

reason:
In smp, It's possible that in a scenario where CONFIG_SMP_DEFAULT_CPUSET is set to 1,
when taskA is created with a relatively low priority,
it gets added to the g_readytorun queue with an affinity of 0x1.
Meanwhile, CPUs 1~n are in an idle state.
Subsequently, when we attempt to change the affinity property of taskA using nxsched_set_affinity,
the scheduling mechanism might not be triggered due to the lack of a proper condition check.
This can result in taskA remaining unscheduled and therefore unable to run.

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Nov 4, 2024
1 parent a96a4de commit 76d2a94
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sched/sched/sched_setaffinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ int nxsched_set_affinity(pid_t pid, size_t cpusetsize,
* First... is the task in an assigned task list?
*/

if (tcb->task_state >= FIRST_ASSIGNED_STATE &&
tcb->task_state <= LAST_ASSIGNED_STATE)
if (tcb->task_state >= FIRST_READY_TO_RUN_STATE &&
tcb->task_state <= LAST_READY_TO_RUN_STATE)
{
/* Yes... is the CPU associated with the assigned task in the new
* affinity mask?
Expand Down

0 comments on commit 76d2a94

Please sign in to comment.