6 ms·
How macOS manages M1 CPU cores
- Tsiklon 5y agoThis is a cool exploration of these new systems. I wonder is some of this scheduling functionality exposed in the Apache licensed Linux version of Grand Central Dispatch? Or is this architecturally incompatible with how tasks and processes are scheduled on Linux? Additionally I wonder why Apple chose to change the number of efficiency cores between M1 and M1-P, M1-M and M1-U?
- saagarjha 5y agoI believe libdispatch delegates to pthread priorities, so it's up to the kernel scheduler to figure out what to do with it.
- smoldesu 5y agoI use big.LITTLE on Linux, I might be able to shed some light on the situation here: Technology like Thread Director is simply not ready on Linux yet. Period. You're not going to get intelligent process management a-la M1 or MacOS quite yet, mostly because Intel hasn't quite finished rolling out Alder Lake to the server market. It'll take some time, but I fully expect us to get there. The flip side of that coin, however, is that the core management is already quite good. Intel had previously merged some basic code for managing heterogeneous systems during the Rocket Lake rollout (iirc), and it does a pretty good job of keeping you on the E-cores most of the time. As far as I can tell, it's original intention was to get the kernel to run processes on lower-binned cores until it needed to turbo, at which point it would heavily prioritize the faster ones. This helped distribute the workload and save some power, but it also came in clutch for Linux users with Alder Lake. So long as the same code works on ARM, I can image the situation will be quite good. Most people would probably never notice the difference.
- saagarjha 5y ago> This also applies to compression and decompression performed by Archive Utility: for example, if you download a copy of Xcode in xip format, decompressing that takes a long time as the code is constrained to the E cores, and there’s no way to change that. This is actually not correct. If you decompress something with Archive Utility, you'll see that it does spend some time on all the cores, although it's definitely not using them equally. It's just that it doesn't spend very much time on them, because it does not parallelize tasks very well, so most of the time it will be effectively running on 1-2 threads with the other cores idle, which macOS will split over the efficiency cores and perhaps bring in one of the P-core clusters if it likes. For the very limited portions of the process that Archive Utility is actually computationally bottlenecked, AppleFSCompression will farm out the work to all the cores. When writing unxip (https://github.com/saagarjha/unxip https://github.com/saagarjha/unxip) I found that you will actually lose to Archive Utility if you don't use all the cores at least part of the way. > There are two situations in which code appears to run exclusively on a single P core, though: during the boot process, before the kernel initialises and runs the other cores, code runs on just a single active P core. I'm not 100% sure on this, but I believe the processor comes out of reset on an Icestorm core?
- jandrese 5y agoIt's very annoying that of all of the commonly used compression formats in use today it seems like only BZip2 parallelizes nicely. Some will use all of the cores on compression but only one for decompression and others do all of the math on a single core. For plain old zip this is excusable since it comes from the 80s, but for modern compression utilities they really should do better.
- paulmd 5y agoEasy to say, hard to do. Particularly since most threading optimizations will trade some bandwidth - and people generally prefer smaller file sizes as their first-order preference.
- jandrese 5y agoThe files are typically within a few bytes, there's really no practical difference in size.
- andrelaszlo 5y agoSwitching from gzip->pigz really sped things up in one of our CI steps recently. It seemed like the output files were identical as well. What are the drawbacks?
- duskwuff 5y ago> it seems like only BZip2 parallelizes nicely Which is really unfortunate, because bzip2 is not a very good compressor otherwise. It outperforms gzip on compression ratio, but is beat out by anything modern, and is extremely slow, even when parallelized. A lot of modern compressors can be made parallelizable (and, as a bonus seekable!) by breaking the input/output into chunks and compressing each chunk independently. This loses a bit of compression efficiency, but surprisingly little for sufficiently large blocks. (This isn't what pigz does, by the way. pigz keeps state between each compressed block, which prevents parallel decoding.) > For plain old zip this is excusable Do you mean gzip? PKZIP decompression is actually somewhat parallelizable, because each file is compressed independently of the other files in the archive -- I'm not sure anyone actually does this, though.
- deleted 5y ago[deleted]
- galogon 5y agoApple is the undisputed king of performance per watt but they need to keep up in single core performance. Sure, Intel draws a ton of power but most tasks we do day to day are single core and the Intel i9-12900K is already 15-20% faster than the M1. The M2 will have a modest single core boost (10%) but the next i9-13900K will be 15-20% faster than the 12900K and increase Intel's lead even further.
- dimillian 5y agoWell, unless you get throttled down and run at 20% of your capacity because the temps is around 100 celcius ;)
- GeekyBear 5y agoOr it throttles down because you unplug your laptop from the wall.
- mciancia 5y agoWe still didn't see Apple desktop m-series cpu And you know, maybe 12900k is 15-20% faster in single core, but cmon - it's 250W tdp cpu vs something that doesn't even need active cooling
- qwytw 5y ago> something that doesn't even need active cooling Only M1 Ultra seems to be comparable to the 12900k so that's not completely fair. It still seems to be ~2-3 times more power efficient though.
- deleted 5y ago[deleted]
- howinteresting 5y agoM1 Ultra is a desktop CPU, and it has a huge cooler on top of it.
- uuyi 5y ago
- dfox 5y ago> M1 Ultra has one cluster of 4 E cores (E0) This seems weird or wrong. Given that M1 Ultra are two M1 Max bolted together (apparently in a way that is somewhat unconventional, but in effect neat) I don't see how that would be done in hardware or even why the authors would want to it work like that (it is my understanding that the whole reason for clusters is that whole cluster has same clock, which is somewhat hard and pointless to do when half of it resides on different die). Maybe it is only an software abstraction and in HW there are two 2xIcestorm clusters?
- zamadatix 5y agoFrom watching the Asahi IRC over time this sounds right, 6 clusters total. Like you say I wouldn't be surprised if macOS lumps them together from a scheduling perspective to keep low performance scheduling (where going across the interconnect doesn't matter as much anyways) simpler.
- dfox 5y agoI somehow assume that the interconnect between the M1 Ultra dies boils down to bunch of AHB ports more or less directly connected together through the interposer (with only minimal pad logic). This seems consistent with both the performance profile of the thing and with macOS mostly ignoring the topology for scheduling purposes.
- nyanpasu64 5y agoI ran into issues with M1 core scheduling recently in one of my applications: https://github.com/corrscope/corrscope/#m1-slowdown= https://github.com/corrscope/corrscope/#m1-slowdown= corrscope is a PyQt app with a background thread which streams video frames to a ffplay process, which shows these frames in a video player window along with synchronized audio. During playback, ffplay is focused and corrscope lies in the background generating video frames. > On M1 processors, if you open preview, after 40 or so seconds, the preview may suddenly slow down and audio will stop playing. This is because macOS thinks ffplay is the active app, and Corrscope is a background job burning CPU, so it moves Corrscope to an Efficiency core, slowing it down. > There is no fix for this issue at the moment. As a workaround, you can click on Corrscope's window to avoid the slowdown, and drag it aside so it doesn't obstruct the preview. Setting the background worker thread to QOS_CLASS_USER_INTERACTIVE does not prevent it from being moved to E-cores. This is a rather severe issue which damages the user experience, and I haven't found a workaround yet (outside of moving video playback in-process). How do Chrome and Firefox (and Safari I suppose) give their worker processes P-cores while users are interacting with the browser window process?
- saagarjha 5y agoPerhaps you are running into App Nap?
- deleted 5y ago[deleted]
- nyanpasu64 5y agoNot sure why you're downvoted; you seem to be right! In Activity Monitor's Energy tab, I have to expand Terminal > login > zsh > python, but my python process is shown as App Nap: Yes. How would I opt a program out of App Nap? Should I trust https://pypi.org/project/appnope/ https://pypi.org/project/appnope/?
- dave78 5y agoI've used AppNope with success, though I've never tested on an M1.
- grahamlee 5y agoApple's documentation for the XNU kernel describes the scheduler implementation. https://github.com/apple-oss-distributions/xnu/blob/xnu-8019.80.24/doc/sched_clutch_edge.md https://github.com/apple-oss-distributions/xnu/blob/xnu-8019...
- dt2m 5y ago> Counterintuitively, it seems that under very light load, things work well, and under very heavy load, things work well, but for medium loads, there is failure. Also counterintuitively, the newer M1 Pro and M1 Max CPUs, with more performance cores (6-8) and fewer efficiency cores (2), seem to have a larger "medium load" range where things don't work well. Source (https://1014.org/?article=854 https://1014.org/?article=854) This explains Justin Frankel's observations in the article above. It's a bit annoying there seems to be no way to force a process to only run on the P cores with no throttling. Having mostly bought a M1 Mac for music production, I keep running into this exact issue. Light workloads invoke more processing glitches than running loads of tracks and plugins at the same time. Hopefully developers will eventually get more granular control of this for high-performance apps, battery life be damned.
- officeplant 5y ago>It's a bit annoying there seems to be no way to force a process to only run on the P cores with no throttling. I'm not sure about the throttling side of things as I've mostly worked with M1 Mac Mini, but Logic Pro has CPU thread settings to limit things to just P cores. My guess is that it will take time for other DAW's to implement similar features. Can't say I've had many issues performance wise in Logic, but I've had some crashing with newer plugins like Korg's recent plugin version of the OP-Six. Especially when memory use ramps up. Reported my findings back to Korg's tech support, but no solutions yet.
- dt2m 5y agoAnecdotally, Logic has consistently been the worst DAW in my testing, performance-wise, when it comes to hosting plugins. Maybe it's due to the AU format, but the de facto result is the same. I run Ableton, FL, Pro Tools and Logic (mainly working in Ableton) and my goal is to record at 48k with a buffer length of 32 samples, with very light use of plugins. In my testing with the exact same plugins, Logic would consistently have buffer overflows every minute or so. Ableton ran far more stable (especially in Rosetta), but PT was the only DAW to do it without hiccups. My initial guess is that the AAX plugin format is more tightly coupled to its internal processing, improving performance. But I was quite shocked to find out that Logic (Apple's own software) performed the worst. Plugin development in general is a shitshow where most devs seemingly only do enough to get them barely working, so I'm not surprised most of them misbehave on ARM. It's a bit sad that we're two years into the Apple Silicon transition and performance still is so rocky.
- lincpa 5y ago
- rbanffy 5y agoIn my observations, macOS has a very different behavior with nice than my Linux machines. On my Linux laptop, I can run processor-heavy tasks with `nice -n 19` and browse the web as if the machine was doing nothing else. On my (x86) Mac, if I do that, the machine crawls to a halt, as if the OS were ignoring the nice setting. Maybe there is some connection to this and this elaborate scheduling model - on Linux I'd expect processes with lower nice levels get assigned beefier cores and bump out nicer ones to smaller cores and that would take care of everything.
- zozbot234 5y ago> if I do that, the machine crawls to a halt Most likely some unsolved priority inversion bug doing that. Linux actually bumps up the priority of "nice" tasks when something else is waiting on them, which goes a long way to address this issue.
- rbanffy 5y agoIt's not the nice task that halts - on the Mac, it's everything else, as if the task I started with nice is allowed to hog all resources and isn't bumped out of the CPUs when, say, the browser needs them.