-
Notifications
You must be signed in to change notification settings - Fork 423
Description
I noticed that the default scheduler (FIFO scheduler) in ArceOS does not effectively utilize available idle cores in an SMP environment. When one processor is occupied, pending tasks do not seem to be scheduled on the other idle processor(s). This may cause the multitasking performance issue.
Reproducible Example
Here is the PoC I found:
// enable features: ["alloc", "smp", "multitask"]
#![no_std]
#![no_main]
use axstd::println;
use axstd::thread;
use axstd::time;
#[unsafe(no_mangle)]
fn main() {
// create many tasks
for i in 0..10 {
thread::spawn(move || {
println!("thread running: {i}");
});
}
println!("main: running!");
// Since we do not enable "irq" feature,
// thread::sleep use a busy wait here.
thread::sleep(time::Duration::from_secs(5));
}I run the above code with make A=/path/to/poc SMP=2 run, and the output is like this:
main: running!
thread running: 1
thread running: 3
thread running: 5
thread running: 7
thread running: 9
In this PoC, a processor is occupied by the main thread, since the main thread is trapped in a busy wait by thread::sleep(time::Duration::from_secs(5)). Since I set SMP=2, the rest of the threads (2, 4, 6, 8) are expected to run on another processor. However, the rest of the threads do not run until the main thread ends.
Based on the current behavior, I suspect that threads are pinned to a specific CPU upon creation, rather than being dynamically scheduled. This may limit the efficiency of FIFO scheduler.
Could you clarify if this is a bug or expected behavior?