Skip to content

Commit 1e57a56

Browse files
hujun260xiaoxiang781216
authored andcommitted
sched/sched: simplify the implementation of the function nxsched_readytorun_setpriority
Configuring NuttX and compile: $ ./tools/configure.sh -l qemu-armv8a:nsh_smp $ make Running with qemu $ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \ -machine virt,virtualization=on,gic-version=3 \ -net none -chardev stdio,id=con,mux=on -serial chardev:con \ -mon chardev=con,mode=readline -kernel ./nuttx reason: If the type of tcb is TSTATE_TASK_ASSIGNED, removing it using nxsched_remove_not_running and then putting it back into the queue may result in a context switch. Signed-off-by: hujun5 <[email protected]>
1 parent 1c5a0bf commit 1e57a56

File tree

1 file changed

+3
-73
lines changed

1 file changed

+3
-73
lines changed

sched/sched/sched_setpriority.c

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -212,83 +212,13 @@ static void nxsched_readytorun_setpriority(FAR struct tcb_s *tcb,
212212
{
213213
FAR struct tcb_s *rtcb;
214214

215-
#ifdef CONFIG_SMP
216-
int cpu;
217-
218-
/* CASE 2a. The task is ready-to-run (but not running) but not assigned to
219-
* a CPU. An increase in priority could cause a context switch may be
220-
* caused by the re-prioritization. The task is not assigned and may run
221-
* on any CPU.
222-
*/
223-
224-
if (tcb->task_state == TSTATE_TASK_READYTORUN)
225-
{
226-
cpu = nxsched_select_cpu(tcb->affinity);
227-
}
228-
229-
/* CASE 2b. The task is ready to run, and assigned to a CPU. An increase
230-
* in priority could cause this task to become running but the task can
231-
* only run on its assigned CPU.
232-
*/
233-
234-
else
235-
{
236-
cpu = tcb->cpu;
237-
}
238-
239-
/* The running task is the task at the head of the g_assignedtasks[]
240-
* associated with the selected CPU.
241-
*/
242-
243-
rtcb = current_task(cpu);
244-
245-
#else
246-
/* CASE 2. The task is ready-to-run (but not running) and a context switch
247-
* may be caused by the re-prioritization.
248-
*/
249-
250215
rtcb = this_task();
251-
#endif
252216

253-
/* A context switch will occur if the new priority of the ready-to-run
254-
* task is (strictly) greater than the current running task
255-
*/
256-
257-
if (sched_priority > rtcb->sched_priority)
258-
{
259-
/* A context switch will occur. */
260-
261-
if (nxsched_reprioritize_rtr(tcb, sched_priority))
262-
{
263-
up_switch_context(this_task(), rtcb);
264-
}
265-
}
217+
/* A context switch will occur. */
266218

267-
/* Otherwise, we can just change priority and re-schedule (since it have
268-
* no other effect).
269-
*/
270-
271-
else
219+
if (nxsched_reprioritize_rtr(tcb, sched_priority))
272220
{
273-
/* Remove the TCB from the ready-to-run task list that it resides in.
274-
* It should not be at the head of the list.
275-
*/
276-
277-
bool check = nxsched_remove_readytorun(tcb, false);
278-
DEBUGASSERT(check == false);
279-
UNUSED(check);
280-
281-
/* Change the task priority */
282-
283-
tcb->sched_priority = (uint8_t)sched_priority;
284-
285-
/* Put it back into the correct ready-to-run task list. It must not
286-
* end up at the head of the list.
287-
*/
288-
289-
check = nxsched_add_readytorun(tcb);
290-
DEBUGASSERT(check == false);
291-
UNUSED(check);
221+
up_switch_context(this_task(), rtcb);
292222
}
293223
}
294224

0 commit comments

Comments
 (0)