I understand that the official Arduino Scheduler doesn't support Uno, and there are several third-party schedulers to fill the gap, notably, Scheduler, Arduino-Scheduler and TaskScheduler. There are probably many more, though I see that many so-called "task schedulers" are actually just periodic function callers which don't handle context (i.e. they don't support yield()
).
I need to make a choice of a scheduler to use in a project (a real one, with yield
, not a periodic function caller). Is there any comparison of Arduino task schedulers? I'm specifically interested in the following aspects:
- context switching time (the most important one)
- RAM/ROM consumption estimation
- list of supported boards
-
Arduino featured this on Facebook some weeks ago hackaday.com/2021/03/17/…Juraj– Juraj ♦2021年04月04日 20:23:16 +00:00Commented Apr 4, 2021 at 20:23
-
@Juraj This seems to be yet another cyclic function runner with no context handling. You simply can't fit 57 separate stacks in 2k of RAM.Dmitry Grigoryev– Dmitry Grigoryev2021年04月05日 08:07:10 +00:00Commented Apr 5, 2021 at 8:07
1 Answer 1
I have just tested vbextreme/Scheduler
and Arduino-Scheduler
using the following code:
#include <Scheduler.h>
void setup() {
pinMode(3, OUTPUT);
Scheduler.startLoop(loop2);
}
void loop() {
digitalWrite(3, LOW);
yield();
digitalWrite(3, HIGH);
yield();
}
void loop2() {
yield();
}
Without any Scheduler
lines, the code occupies 734 bytes of ROM, 9 bytes of RAM, and the pin toggles with a period of 8.5 us (117 kHz). The numbers below represent the additional ROM/RAM/execution time:
vbextreme/Scheduler
occupies additional 1676 bytes of ROM, 70 bytes of RAM, and the context switch takes 15.5 us (toggle frequency 14.18 kHz). It seems to only support AVR/SAMD boards.vbextreme/Scheduler
withCONFIG_AVR_OPTIMIZE_COOPERATIVE
set to 1 occupies additional 1568 bytes of ROM, 70 bytes of RAM, and the context switch takes 11 us (toggle frequency 19.07 kHz).Arduino-Scheduler
occupies additional 578 bytes of ROM, 44 bytes of RAM, and the context switch takes 10.6 us (toggle frequency 19.59 kHz). It supports AVR/SAMD and some of the Teensy/STM32 boards. It seems that this scheduler is not compatible with tasks which usemalloc()
.CopyThreads
occupies an additional 2148 bytes of ROM, 41 bytes of RAM, and the context switch takes 54.5 us (toggle frequency 4.417 kHz). This scheduler claims to have the advantage of using a single stack, so as long as tasks do notyield
during peak stack usage, each task has essentially the complete stack at its disposal.
I couldn't get the equivalent code for TaskScheduler
to run, I'll be grateful if someone posts an answer featuring schedulers I didn't test.