3 ms·
Does anyone have any insight into the MacOS scheduler and the algorithm it uses to place threads on E vs. P cores? Is it as simple as noting whether a thread wa
by drob518 9mo ago
Does anyone have any insight into the MacOS scheduler and the algorithm it uses to place threads on E vs. P cores? Is it as simple as noting whether a thread was last suspended blocking on I/O or for a time slice timeout and mapping I/O blockers to E cores and time slice blockers to P cores? Or does the programmer indicate a static mapping at thread creation? I write code on a Mac all the time, but I use Clojure and all the low level OS decisions are opaque to me.
- sys_64738 9mo agoThe article mentions P or E is generally decided by if it's a "background" process (whatever than means). Possible some (undocumented) designation in code or directive to the compiler of the binary decides this at compile time.
- masklinn 9mo ago> whatever than means It’s a QoS level: https://developer.apple.com/documentation/dispatch/dispatchqos https://developer.apple.com/documentation/dispatch/dispatchq...
- detourdog 9mo agohttps://developer.apple.com/videos/play/tech-talks/110147/ https://developer.apple.com/videos/play/tech-talks/110147/
- drob518 9mo agoExcellent, thanks!
- masklinn 9mo agoThe baseline is static: low QoS tasks are dispatched to the E cores, while high QoS tasks are dispatched to P cores. IIRC high QoS cores can migrate to the E cores if all P cores are loaded, but my understanding is that the lowest QoS tasks (background) never get promoted to P cores.
- drob518 9mo agoHow is the QoS communicated to the scheduler? Is there a mark on the binary or does the code do it at thread startup?
- dcrazy 9mo agoThe Apple software stack makes heavy use of thread pools via libdispatch. Individual work items are tagged with QoS, which influences which thread picks up the work item from the queue.
- astrange 9mo agoThere's also priority inheritance (two different systems for it) so that requests originating from users/apps are more important. Swift concurrency is more about structured concurrency than thread pools. A lot of other systems seem to use futures, which aren't good at priority inheritance.
- saagarjha 9mo agoIt’s done in code.
- macshome 9mo agoCheck out the scheduler documentation that Apple has in the xnu repo. https://github.com/apple-oss-distributions/xnu/blob/main/doc/scheduler/sched_clutch_edge.md https://github.com/apple-oss-distributions/xnu/blob/main/doc...
- drob518 9mo agoThis is exactly what I was looking for. Thanks. Lots of technical details here for those interested.
- deleted 9mo ago[deleted]