sched: Remove unnecessary affinity restriction & restoration over smp calls

When the task has TCB_FLAG_CPU_LOCKED it is locked to the CPU regardless
of the affinity. There is no need to switch the affinity back and forth.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
This commit is contained in:
Jukka Laitinen
2025-08-19 13:05:39 +03:00
committed by Donny(董九柱)
parent 4cc384757b
commit 0dbbce3a8f
5 changed files with 0 additions and 29 deletions
-6
View File
@@ -43,7 +43,6 @@ struct backtrace_arg_s
FAR void **buffer; FAR void **buffer;
int size; int size;
int skip; int skip;
cpu_set_t saved_affinity;
bool need_restore; bool need_restore;
}; };
@@ -72,7 +71,6 @@ static int sched_backtrace_handler(FAR void *cookie)
if (arg->need_restore) if (arg->need_restore)
{ {
tcb->affinity = arg->saved_affinity;
tcb->flags &= ~TCB_FLAG_CPU_LOCKED; tcb->flags &= ~TCB_FLAG_CPU_LOCKED;
} }
@@ -126,12 +124,8 @@ int sched_backtrace(pid_t tid, FAR void **buffer, int size, int skip)
else else
{ {
arg.pid = tcb->pid; arg.pid = tcb->pid;
arg.saved_affinity = tcb->affinity;
arg.need_restore = true; arg.need_restore = true;
tcb->flags |= TCB_FLAG_CPU_LOCKED; tcb->flags |= TCB_FLAG_CPU_LOCKED;
CPU_ZERO(&tcb->affinity);
CPU_SET(tcb->cpu, &tcb->affinity);
} }
arg.buffer = buffer; arg.buffer = buffer;
-6
View File
@@ -45,7 +45,6 @@
struct suspend_arg_s struct suspend_arg_s
{ {
pid_t pid; pid_t pid;
cpu_set_t saved_affinity;
bool need_restore; bool need_restore;
}; };
@@ -73,7 +72,6 @@ static int nxsched_suspend_handler(FAR void *cookie)
if (arg->need_restore) if (arg->need_restore)
{ {
tcb->affinity = arg->saved_affinity;
tcb->flags &= ~TCB_FLAG_CPU_LOCKED; tcb->flags &= ~TCB_FLAG_CPU_LOCKED;
} }
@@ -161,12 +159,8 @@ void nxsched_suspend(FAR struct tcb_s *tcb)
else else
{ {
arg.pid = tcb->pid; arg.pid = tcb->pid;
arg.saved_affinity = tcb->affinity;
arg.need_restore = true; arg.need_restore = true;
tcb->flags |= TCB_FLAG_CPU_LOCKED; tcb->flags |= TCB_FLAG_CPU_LOCKED;
CPU_ZERO(&tcb->affinity);
CPU_SET(tcb->cpu, &tcb->affinity);
} }
nxsched_smp_call_single(tcb->cpu, nxsched_suspend_handler, &arg); nxsched_smp_call_single(tcb->cpu, nxsched_suspend_handler, &arg);
-6
View File
@@ -53,7 +53,6 @@
struct sig_arg_s struct sig_arg_s
{ {
pid_t pid; pid_t pid;
cpu_set_t saved_affinity;
bool need_restore; bool need_restore;
}; };
@@ -82,7 +81,6 @@ static int sig_handler(FAR void *cookie)
if (arg->need_restore) if (arg->need_restore)
{ {
tcb->affinity = arg->saved_affinity;
tcb->flags &= ~TCB_FLAG_CPU_LOCKED; tcb->flags &= ~TCB_FLAG_CPU_LOCKED;
} }
@@ -175,12 +173,8 @@ static int nxsig_queue_action(FAR struct tcb_s *stcb,
} }
else else
{ {
arg.saved_affinity = stcb->affinity;
arg.need_restore = true; arg.need_restore = true;
stcb->flags |= TCB_FLAG_CPU_LOCKED; stcb->flags |= TCB_FLAG_CPU_LOCKED;
CPU_ZERO(&stcb->affinity);
CPU_SET(stcb->cpu, &stcb->affinity);
} }
arg.pid = stcb->pid; arg.pid = stcb->pid;
-6
View File
@@ -48,7 +48,6 @@
struct restart_arg_s struct restart_arg_s
{ {
pid_t pid; pid_t pid;
cpu_set_t saved_affinity;
bool need_restore; bool need_restore;
}; };
@@ -78,7 +77,6 @@ static int restart_handler(FAR void *cookie)
if (arg->need_restore) if (arg->need_restore)
{ {
tcb->affinity = arg->saved_affinity;
tcb->flags &= ~TCB_FLAG_CPU_LOCKED; tcb->flags &= ~TCB_FLAG_CPU_LOCKED;
} }
@@ -237,12 +235,8 @@ static int nxtask_restart(pid_t pid)
else else
{ {
arg.pid = tcb->pid; arg.pid = tcb->pid;
arg.saved_affinity = tcb->affinity;
arg.need_restore = true; arg.need_restore = true;
tcb->flags |= TCB_FLAG_CPU_LOCKED; tcb->flags |= TCB_FLAG_CPU_LOCKED;
CPU_ZERO(&tcb->affinity);
CPU_SET(tcb->cpu, &tcb->affinity);
} }
nxsched_smp_call_single(tcb->cpu, restart_handler, &arg); nxsched_smp_call_single(tcb->cpu, restart_handler, &arg);
-5
View File
@@ -137,15 +137,11 @@ int nxtask_terminate(pid_t pid)
if (task_state == TSTATE_TASK_RUNNING && if (task_state == TSTATE_TASK_RUNNING &&
dtcb->cpu != this_cpu()) dtcb->cpu != this_cpu())
{ {
cpu_set_t affinity;
uint16_t tcb_flags; uint16_t tcb_flags;
int ret; int ret;
tcb_flags = dtcb->flags; tcb_flags = dtcb->flags;
dtcb->flags |= TCB_FLAG_CPU_LOCKED; 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, ret = nxsched_smp_call_single(dtcb->cpu, terminat_handler,
(FAR void *)(uintptr_t)pid); (FAR void *)(uintptr_t)pid);
@@ -159,7 +155,6 @@ int nxtask_terminate(pid_t pid)
} }
dtcb->flags = tcb_flags; dtcb->flags = tcb_flags;
dtcb->affinity = affinity;
} }
else else
#endif #endif