10 ms·
How does macOS manage virtual cores on Apple Silicon?
- miohtama 3y agoSounds like this explains why Docker eats thru Mac battery so fast
- jbverschoor 3y agoTry orbstack
- mhrmsn 3y agoDoes it make use of the E cores on Apple Silicon?
- sgerenser 3y agoSince all docker implementations use a VM on Mac, and according to this article VMs only use P-Cores, I have to assume it only uses the P cores.
- astrange 3y agoThis article is based on an M1 Max but I think M2 Max behaves differently here since it has more E-cores. Don't quote me though.
- kdrag0n 3y ago(dev here) Yes. I've spent quite a bit of time on scheduling. It's more nuanced than what this article says and there are ways to influence it (but sorry, can't share too many details). OrbStack tends to use E cores more than other virtualization-based apps do on Apple Silicon, especially for heavy workloads.
- miohtama 3y agoThank you! This is really interesting, will give OrbStack a test drive.
- MrRolleyes 3y agoOrbstack still seems to rely on docker's virtualization. We need something better than docker to improve on this.
- piperswe 3y agoOrbstack runs Docker inside its own lightweight VM. It doesn't use any of Docker Desktop's virtualization. I'm not sure if it handles scheduling any better though.
- deleted 3y ago[deleted]
- MrRolleyes 3y ago[dead]
- amazingman 3y agoI get 6h or so running quite a few workloads in Kubernetes on Docker For Mac on Apple Silicon. Intel was < 2h. The rest of my team has similar experiences. Are you sure it's Docker causing your battery issues?
- bmurphy1976 3y agoDocker is definitely a problem, although newer versions have implemented new functionality that may have significantly reduced this. I can't really tell however, as I'm stuck on too many Zoom calls all day long and Zoom absolutely murders my battery life.
- jwells89 3y agoI haven’t tested it personally but you may be able to get some of that battery life back by using the web version of Zoom in Safari. That tends to force video chat services to use hardware accelerated video codecs which are considerably easier on battery.
- c0balt 3y agoAnd that's not just for Mac's, the same can help on Linux devices. It's somewhat hilarious that running a non-native app gets you better hardware accel but here we are.
- doubled112 3y agoMaybe the web browser is the OS now. Does that make the OS just a hardware abstraction layer?
- dijit 3y agoI think that's generally accepted as true for some classification of people. That's why chromebooks are an idea that was perhaps too early (and hardware too anaemic)
- 3y ago
- wutwutwat 3y agoCheckout App Tamer[1] to control the priority of processes as well as core assignment on the M series chips: > App Tamer can take special advantage of Apple Silicon powered Macs, which have two different types of processor cores. Use it to automatically run busy background apps on the M1 or M2's efficiency cores to save power, leaving the performance cores for the apps you want to run fastest. 1. https://www.stclairsoft.com/AppTamer/ https://www.stclairsoft.com/AppTamer/
- caycep 3y agoa bit OT, but has anyone had the opportunity to compare how Vimy feels vs. UTM?
- Angostura 3y ago> With the introduction of Game Mode in Sonoma, CPU scheduling can now work differently, with E cores being reserved for the use of games. - shouldn't that be 'P cores'?
- samtheprogram 3y agoThat was my first impression too, but it actually makes sense. According to a linked article by the same author: > it’s apparent that during Game Mode, the game was given exclusive use of the two E cores, and threads from other processes fixed at low QoS, which would require them to be run on the E cores, were kept waiting. The game’s threads were run on a combination of E and P cores, with much of their load being concentrated on the E cores. This appears to be energy-efficient, and ideal for use on notebooks running on battery power. So: the E cores are resevered for the use of games, but the game still makes use of some P cores. https://eclecticlight.co/2023/10/18/how-game-mode-manages-cpu-and-gpu/ https://eclecticlight.co/2023/10/18/how-game-mode-manages-cp...
- Angostura 3y agoAh excellent. Thaks for correcting my erroneous correction attempt
- chongli 3y agoI like the sound of this! I play a lot of older games on my MacBook Air and one of my biggest annoyances is when the game gets the machine to heat up (and in previous iterations spin up the fan) despite being a very graphically undemanding game. I think there are a lot of otherwise graphically simple games that poll or sit there in busy wait loops or render more frames than the display can show. It’s like they’ve been built for a resource starved environment and don’t know how to properly handle abundance. It’s really frustrating!
- withinboredom 3y agoOn my PC, I limit my FPS to 24 (via graphics card settings). It uses far less power, and runs considerably cooler.
- infamouscow 3y agoI don't think macOS allows a userspace program to set thread affinities. Not only are the functions commented out, there's this note THREAD_AFFINITY_POLICY: This policy is experimental. This may be used to express affinity relationships between threads in the task. Threads with the same affinity tag will be scheduled to share an L2 cache if possible. That is, affinity tags are a hint to the scheduler for thread placement. The namespace of affinity tags is generally local to one task. However, a child task created after the assignment of affinity tags by its parent will share that namespace. In particular, a family of forked processes may be created with a shared affinity namespace. https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/thread_policy.h https://github.com/apple-oss-distributions/xnu/blob/main/osf...
- wutwutwat 3y agoHere's one example of userspace programs assigning affinity to specific cores > Use it to automatically run busy background apps on the M1 or M2's efficiency cores to save power, leaving the performance cores for the apps you want to run fastest. https://www.stclairsoft.com/AppTamer/ https://www.stclairsoft.com/AppTamer/
- krackers 3y agoUnfortunately you can't do the reverse, pin to p core
- wutwutwat 3y agoYou can in a way, if you tie up the E cores by pinning work to them exclusively, the scheduler will send other stuff to the P cores due to resource constraint avoidance attempts. It's not power efficient to sit and wait for an efficient core when you can buzz it through a P core super quick and get back to idle, I would imagine haha
- Waterluvian 3y agoWas the industry ready for this concept of a computer having a number of meaningfully different kinds of cores? Has this happened before? Or did application developers just get cores as an integer count and that was it?
- bombcar 3y agoI mean ever since very early on the GPU was a "separate CPU with different kinds of cores" compared to the main CPU.
- xcv123 3y agoIt's been around since 2011 on Android. Nothing new. https://en.wikipedia.org/wiki/ARM_big.LITTLE https://en.wikipedia.org/wiki/ARM_big.LITTLE
- wmf 3y agoYet nobody in the Windows/Mac world was ready (if you think they should have to care which maybe they shouldn't).
- xcv123 3y agoOn Mac they have used the Grand Central Dispatch library since 2009. So if developers already used that, they were ready for M1 https://en.wikipedia.org/wiki/Grand_Central_Dispatch https://en.wikipedia.org/wiki/Grand_Central_Dispatch
- astrange 3y agoGCD was actually not designed for this scenario and it's easy to mess up with it. It was designed for a large number of equal cores (aka SMP), meaning people did dispatch_async to the default concurrent queues all over the place, which is a bad pattern when you have to shrink down to phone size. Also, dispatch_semaphore has priority inversions and a lot of other features (like dispatch_group) are semaphores in disguise. It does work if you use it carefully, but Swift concurrency is a different design for a reason.
- 1-6 3y agoI read virtual cores on a Processor, got excited for a bit but realized it’s not the same as a soft core processor. I hope FPGAs take off one day and software can compile hyper-optimized processors that do very specialized tasks.
- ta988 3y agoFPGAs are pretty slow clockwise compared to a cpu, their main advantages is that they can work with many different kind of clocks and somewhat massively parallel. Do you have any specialized task you are thinking about?
- deleted 3y ago[deleted]
- ge96 3y agoI'm not a "hater" of Apple, I think they were just too expensive for me long time ago. I will say since I use them for work, their ability to keep running despite opening so much crap is amazing. Browser tab wise. Not just limited to a specific silicon either as I use both intel/m2.
- hypercube33 3y agoHow so? I usually have 200-600 browser tabs open for weeks on Windows/ryzen 5000
- vGPU 3y agoI have one specific TradingView tab that will crash the browser if I try to interact with it. Been that way for weeks.
- deleted 3y ago[deleted]
- theGnuMe 3y agoWeird, chrome freezes daily for me.
- NavinF 3y agoOn what machine? As I mentioned up thread, if a machine with similar specs can't handle that many tabs, something is misconfigured. Eg maybe memory timings are way too conservative or the wrong power profile is in use. If you open Resource Monitor before the freeze, you can usually see what happened on the graphs. If you're fast enough, you can also click "analyze wait chain" to see something that looks like a stack trace. The graphs and trace should make it pretty obvious why an app is frozen. Eg maybe it's trying to save the history sqlite database and your SSD ran out of SLC cache.
- ge96 3y agoYeah my comment is more on memory management in this case 16GB range. edit: I'm gonna get dinged for OT comment again ha
- MBCook 3y agoSince we’re talking the scheduler, has it gotten better at not ping-ponging processors around? I seem to remember years ago I could open activity monitor and watch processes migrate back-and-forth between cores for seemingly no reason instead of just sticking in places. I haven’t watched to see what happens recently. Is that still an issue?
- 3cats-in-a-coat 3y agoAside from cosmetics, is it really an issue? And why?
- MBCook 3y agoDepending on which cores it’s moving between it could be a performance issue if they don’t share a cache. I don’t know if it actually is or was.
- serf 3y agoIt causes latency issues on SMP machines with multiple processors for sure; I don't know whether or not that same issue translates to a similar scheduling problem across the same die, although I imagine it would, the context switch and scheduler itself isn't costless. gamers have been binding to single processors/cores for years for that reason, it's a huge cause of microstutter type behaviors -- but who knows if its perceivable with all the magic going on with processors nowadays.
- aeadio 3y agoProcesses get interrupted and rescheduled between tens and hundreds of times per second (depending on OS, the scheduler may take over somewhere between 100 and 2000 Hz, although it doesn't necessarily deschedule every time). This is how SMP works at its most fundamental level. Every time that happens, it involves a full flush from the hardware perspective. It's always context switching, savings the registers, clearing the buffers, etc. When a process gets descheduled and then later rescheduled, there is no particular reason to reschedule it on the same core it was on previously. Desktop class hardware doesn't have NUMA. Last level caches might have locality-dependent performance characteristics, but this is usually pretty nuanced, wildly variable between hardware microarchitectures, and not accounted for / not worth accounting for in the OS's scheduler, since there's a good chance that data won't be around next timeslice anyway. Binding a processor to a single core affinity-wise is not changing any of this. If you really have a throughput-bound process that needs to squeeze every single microsecond of compute and/or you're super latency bound for some reason, you schedule a process with what's called realtime priority, which changes the scheduling decision of WHEN to deschedule it. Not every operating system has equivalent mechanisms for this, but that's more in line with the phenomena that you're describing. But a process may well cause itself to be descheduled anyway by doing something that puts it to sleep. You have no control over this. In reality, looking at which core a process is on is mostly the wrong way to be thinking. You're looking at this on a 1-2 second window (the amount of time it takes for Activity Monitor / Task Manager to update its UI). A full second of time is an absolute eternity to a process. Large amounts of work happen on the order of microseconds and quicker. And in that 1-2 second snapshot that Activity Monitor or Task Manager gave you, the process probably spent time on EVERY core -- and you're just seeing wherever it was in the brief moment when Activity Monitor / Task Manager updated its UI. > gamers have been binding to single processors/cores for years for that reason, it's a huge cause of microstutter type behaviors It wouldn't be the first time gamers prescribed placebo tweaks because of magical type thinking.
- mef 3y ago> QoS is a control set and changed in the code launching a process, and can only be altered by the user if the app exposes a control, a feature which remains exceptionally uncommon. Neither is there any easy way for a user to know the QoS of any given process unless the app reveals that. That... sucks
- brianpan 3y agoDoes it? I buy my MacBook to use it, not manage process performance. When I launch a game, I get a popup that tells me that it will be prioritized while it is fullscreen. And there's a menu icon to turn off "game mode". Ok, fine, but I don't really care and I doubt I'll ever touch the setting. It's there to be exposed if the developer thinks it should. That seems like the right balance to me.
- deleted 3y ago[deleted]
- samjord0n 3y agoBig.Little is a good architectural innovation, although I don't think MacOS and Android have been making good use of it. It is tricky hw feature to manage in software overall. Virtualization adds even more complexity.
- aurareturn 3y agoDo you have a reason for why macOS doesn't make good use of big.Little? As far as I know, it allocates background/low priority tasks to little cores such as OS housekeeping tasks. When you're on low powered mode or low battery mode, it automatically switches to little cores to save energy. When you need extra multithread power, it uses all cores.
- a-dub 3y agowhat's the difference between a P-core and an E-core? special machinery for caching, branch prediction and speculative execution? i still have the antiquated view that performance and efficiency are essentially the same metric and these are the only kinds of ideas i can come up with that would separate them..
- MBCook 3y agoE-cores are physically smaller and have fewer execution units and what they do have are more likely to be shared, I think. So they simply can’t process as much clock for clock.
- monocasa 3y agoThey also have smaller resources like reorder buffers so they can't speculatively keep nearly as much in progress work around, leading to more stalls.
- zamadatix 3y agoSpeculative architecture is one thing but plain ol' superscalar architecture can make things run faster by simply executing more instructions per cycle, given you dedicated the die space to additional execution units to do more things at the same time.
- ip26 3y agoA semi truck is a very efficient way to move a lot of packages across the country very quickly. It is a terribly inefficient way to move a single envelope. Deeper speculation, larger out of order window, more accurate branch prediction, larger caches, more execution pipes, larger register files…
- ta8645 3y agoIt's interesting to see AMD's take on big-little. The only difference between their Zen 4 core (big) and Zen 4c (little) cores is the speed and thermal characteristics. Owing to the same architecture (RTL) being implemented by both, with only the layout and cell density differing. https://youtu.be/h80TB8K-Rfo?t=260 https://youtu.be/h80TB8K-Rfo?t=260
- pohl 3y agoIs that meaningfully different from Apple’s take?
- MBCook 3y agoI don’t think so. But it is different from some Intel CPUs where the efficiency cores didn’t support all the vector ops the performance cores did, causing issues with some software.
- kfreds 3y agoGreat video! Thanks for the link. By the way, I was confused by how you equated architecture and RTL. In this context I use "architecture" to mean ISA. I use "microarchitecture" to refer to how e.g. its performance characteristics are realized, like IPC. You seem to know more than I do and would love you to comment. Thanks!
- Aardwolf 3y agoI like this approach (especially because it supports AVX-512), however even not counting the Zen 4c, AMD 3D v-cache CPU's have cores that are sufficiently heterogeneous (those with and without 3D cache) that some special scheduling is desired for some use cases (gaming on Windows)
- publicmail 3y agoSort of related, are there any posix API extensions planned to allow a program to set thread hints in terms of whether it should run on e core or p core? Or maybe even a scale like 0-255?