Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
translations translations
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Thank You for your continued support and contributions!

+  Rockbox Technical Forums
|-+  Rockbox General
| |-+  Rockbox General Discussion
| | |-+  Cooperative multitasking?
« previous next »
  • Print
Pages: [1]

Author Topic: Cooperative multitasking?  (Read 274 times)

Offline bigpilot

  • Member
  • *
  • Posts: 16
Cooperative multitasking?
« on: May 10, 2025, 07:05:38 PM »
Does the Rockbox kernel use cooperative multitasking? Or is it preemptive?
Logged

Offline speachy

  • Administrator
  • Member
  • *
  • Posts: 665
Re: Cooperative multitasking?
« Reply #1 on: May 10, 2025, 10:11:41 PM »
Quote from: bigpilot on May 10, 2025, 07:05:38 PM
Does the Rockbox kernel use cooperative multitasking? Or is it preemptive?

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.
« Last Edit: May 11, 2025, 07:27:37 AM by speachy »
Logged

Offline amachronic

  • Developer
  • Member
  • *
  • Posts: 306
Re: Cooperative multitasking?
« Reply #2 on: May 11, 2025, 06:09:33 AM »
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.
Logged

Offline speachy

  • Administrator
  • Member
  • *
  • Posts: 665
Re: Cooperative multitasking?
« Reply #3 on: May 11, 2025, 07:27:04 AM »
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..)
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 1194
Re: Cooperative multitasking?
« Reply #4 on: May 11, 2025, 08:49:51 AM »
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.

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

Offline amachronic

  • Developer
  • Member
  • *
  • Posts: 306
Re: Cooperative multitasking?
« Reply #5 on: May 11, 2025, 09:03:04 AM »
Ouch. I forgot about that nasty side-effect on hosted platforms. But yeah, we could catch a lot by testing hosted & sim builds with pthreads if we wanted to go fully preemptive. The biggest chunk of core code that isn't testable that way is the filesystem layer. I think being able to test the FS code in sim would be great for many other reasons too, but it's a PITA to implement.

Realistically even if some platforms could go preemptive, we would still need to support cooperative threading for the foreseeable future, to avoid breaking platform-specific code that we can't update for whatever reason (lack of hardware, time, etc).
Logged

Offline bigpilot

  • Member
  • *
  • Posts: 16
Re: Cooperative multitasking?
« Reply #6 on: May 23, 2025, 03:07:20 AM »
What would you use a tick_taks for? And what does HZ stand for?
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox General
| |-+  Rockbox General Discussion
| | |-+  Cooperative multitasking?
 

  • SMF 2.0.19 | SMF © 2021, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.068 seconds with 17 queries.