Rockbox General > Rockbox General Discussion

Cooperative multitasking?

(1/2) > >>

bigpilot:
Does the Rockbox kernel use cooperative multitasking? Or is it preemptive?

speachy:

--- Quote from: bigpilot on May 10, 2025, 07:05:38 PM ---Does the Rockbox kernel use cooperative multitasking? Or is it preemptive?

--- End quote ---

It's preemptive, but given that there's no memory or process protection/isolation, it's pretty easy for a task (or interrupt) to block everything else if it misbehaves.

...It would be an interesting exercise to replace our kernel with something like FreeRTOS but 2/3 of our major processor architectures (much less minor variations within a given family) aren't supported, so IMO it's really not worth the effort.

EDIT:  See later replies.

amachronic:
No, Rockbox uses cooperative scheduling. It's the reason that hosted ports use a custom threading implementation based around sigaltstack rather than using pthreads. Interrupts can still interrupt the running thread, but they can't swap it out and return back to a different thread. The running thread needs to explicitly yield to the next one (ultimately, by calling the kernel's switch_thread() function). Much as I would prefer to have preemptive threading, there's a decent amount of code that relies on the fact that it can't be arbitrarily preempted by another thread -- including some I've written myself, unfortunately -- so switching the threading model would be pretty painful.

speachy:
Hah, I stand corrected!

.. I'd actually written a "mostly cooperative" reply before I second-guessed myself after finding out that we do indeed turn on a systick (or equivalent). I guess we only use that for setting timers, not full scheduling.

Our use of sigalstack threading on hosted platforms is responsible for a lot of problems, primarily from system calls blocking the entire application instead of just a single task.  Converting that to pthreads (and/or SDL threads) would be quite beneficial, and provide a low-risk way to shaking loose the things that can't be arbitrarily preempted.

(There's a decent amount of overhead from running a task scheduler every tick; I suspect our more underpowered platforms (eg m68k or PP500x) would suffer..)

Bilgus:
AFAIK this page is still relevant


--- Quote --- The Rockbox kernel is an advanced priority aware cooperative kernel. It consists of thin threads with some means of passing messages and locking data structures.
--- End quote ---

https://www.rockbox.org/wiki/RockboxKernel.html#General

Navigation

[0] Message Index

[#] Next page

Go to full version