Skip to content

[BUG] Round robin scheduling when SMP is enabled causes crashes #14699

@pussuw

Description

@pussuw

Description / Steps to reproduce the issue

The round robin scheduling logic causes crashes via:

bool nxsched_remove_readytorun(FAR struct tcb_s *tcb)
{
if (tcb->task_state == TSTATE_TASK_RUNNING)
{
DEBUGASSERT(tcb->cpu == this_cpu());
nxsched_remove_running(tcb);
return true;
}

The crash occurs when the task being pre-empted is running on a different CPU / core. The call tree is as follows:

_assert() at assert.c:906 0xa001f690	
__assert() at lib_assert.c:38 0xa0005d4a	
nxsched_remove_readytorun() at sched_removereadytorun.c:291 0xa0027f2c	
nxsched_reprioritize_rtr() at sched_reprioritizertr.c:67 0xa00214f2	
nxsched_process_roundrobin() at sched_roundrobin.c:141 0xa003c800	
nxsched_cpu_scheduler() at sched_processtimer.c:77 0xa003c424	
nxsched_process_scheduler() at sched_processtimer.c:134 0xa003c424	
nxsched_process_timer() at sched_processtimer.c:189 0xa003c424	

This happens when the system tick advances. An arbitrary CPU will handle the timer interrupt and advance the system ticker. It will then try to run the round robin scheduling logic for every CPU.

flags = enter_critical_section();
/* Perform scheduler operations on all CPUs */
for (i = 0; i < CONFIG_SMP_NCPUS; i++)
{
nxsched_cpu_scheduler(i);
}
leave_critical_section(flags);
}

Pre-empting a task on another CPU directly will obviously not work -> crash.

What do you think @hujun260 should this be handled by your SMP call logic, or something else ?

On which OS does this issue occur?

[OS: Linux]

What is the version of your OS?

Ubuntu

NuttX Version

master

Issue Architecture

[Arch: all]

Issue Area

[Area: Kernel]

Verification

  • I have verified before submitting the report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arch: allIssues that apply to all architecturesArea: KernelKernel issuesOS: LinuxIssues related to Linux (building system, etc)Type: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions