9 ms·
Power, frequency, management: how M1 E cores win
- gigatexal 5y agoAmazing article, here's the synopsis at the bottom of the article: Summary of findings and conclusions drawn * macOS 12.1 manages the four E cores in the original M1 chip, and the two in the new M1 Pro, differently. * In response to a high load of low QoS processes, frequency of E cores in the original M1 chip remains about 1000 MHz. In response to a high load of low QoS processes, frequency of E cores in the M1 Pro is doubled to about 2000 MHz. * This management policy ensures that demanding background processes with low QoS can complete in similar times on the original M1 and M1 Pro chips. Had M1 Pro chips followed the same policy as the original M1, those processes could have taken twice as long. * In response to a spillover load of high QoS processes from the P cores, frequency of E cores in the M1 Pro is increased to the maximum of 2064 MHz. When running at 100% active residency and maximum frequency, the cluster of 2 E cores in the M1 Pro consumes 210 mW of power. * When running at 100% active residency and maximum frequency, each cluster of 4 P cores in the M1 Pro consumes 4 W of power. * Although there’s insufficient evidence here to conclude that all cores within a cluster are run at exactly the same frequency, their frequencies don’t appear to differ by much. Within a cluster, active residencies normally remain broadly similar but aren’t as closely correlated as frequencies. In tight loops of predominantly floating-point code, accessing only registers as used here, performance measured by timing correlates closely with that measured by powermetrics as instructions retired. * The two E cores in an M1 Pro, when at 100% active residency and maximum frequency can outperform a single P core at 100% active residency and maximum frequency, while using one fifth of the power.
- NL807 5y ago4 W of power is nuts. Less than most LED light bulbs we have in the house.
- gigatexal 5y agoImagine a laptop that was just E-Cores but 1.5x the IPC, a la some future M-revision but with defects where they only shipped it with say 8 E-Cores ... that'd be perfect for me and even better if it was in the 12-inch MacBook form factor just with an edge-to-edge screen.
- marcan_42 5y agoAnd the entire M1 SoC uses about 100 mW with the OS ~idle, screen on, writing this HN comment: ANE Power: 0 mW DRAM Power: 32 mW CPU Power: 85 mW GPU Power: 18 mW Package Power: 103 mW I've left an M1 Air powered on, screen off, WiFi connected, SSH session active and running a shell loop printing the date every minute from another machine. After 3 hours, the battery was still at 100%, and the system finally went to sleep and killed the session. Waking it up, after another 3 hours, it had dropped to 98%. That is how you do power management.
- gigatexal 5y agomarcan eh? are you by chance https://twitter.com/marcan42 https://twitter.com/marcan42 ;-)? I can not wait for proper linux -- installable by a noob like me on an m1 -- to be available. Thank you for the 100x time again for your efforts here
- marcan_42 5y agoYes, that's me :-) Easily installable Linux shouldn't take much longer, for those adventurous enough to be happy with a bunch of missing hardware support (but still a usable machine for a subset of use cases). We're pretty much tying up loose ends to get to that point now, I have a quickly shrinking list of TODOs. Of course, "proper" support for everything will take longer :-)
- Aeolos 5y agoIs there something we can do to help, short off diving into reverse engineering?
- marcan_42 5y agoReverse engineering isn't that scary! Seriously though, a big part of my role in the first year has been building tooling to make that part of the process efficient and enjoyable for everyone. We have a Python REPL for interacting with the bare metal hardware, scaffolding for building prototypes of hardware drivers in it (e.g. register and register map definitions), things like the ability to run functions on another CPU core for SMP tests, hardware exception handling so it's actually hard to crash and have to reboot, and even a hypervisor that can run full macOS and inspect all of its hardware accesses, with a rich event tracing framework that goes from raw register maps to coprocessor message passing to decoding remote procedure calls with C++ argument unmarshaling between firmware and the OS, in both directions. All controlled from any host machine running Linux or macOS, over a simple USB connection with the target.
- marcan_42 5y ago> Although there’s insufficient evidence here to conclude that all cores within a cluster are run at exactly the same frequency, their frequencies don’t appear to differ by much. They do run at the same frequency. There is one hardware register to control the frequency for the whole cluster. Any differences you see are measurement errors in powermetrics; for example, for the P-cores, it has a habit of reporting the requested frequency for a core, which may not be achievable if it is a boost frequency (only available with some cores in deep sleep) or there is throttling involved, and then those metrics are incorrect. Use the cluster frequency metric and ignore the core frequencies; the latter are not useful for anything, it's synthetic data. > The two E cores in an M1 Pro, when at 100% active residency and maximum frequency can outperform a single P core at 100% active residency and maximum frequency, while using one fifth of the power. This varies by workload. I did some basic benchmarking to come up with numbers for this, since the Linux scheduler needs them to efficiently schedule processes. The ballpark is that one E-core has about 70% of the performance of a P-core per MHz. Given that E-cores go up to 2064MHz and P-cores up to 3204MHz, that means that a maxed out E-core can perform at around 45% of a maxed out, full boost P-core (which only works if the other 3 cores are in deep sleep); without boost it's more like 48%. However, for some workloads this is way off - Dhrystone actually gives numbers for E-cores that are a mere 32% of the P-core numbers per MHz, making a maxed out P-core 5 times faster than a maxed out E-core, suggesting that that benchmark gets a huge boost out of the wider dispatch in the P-cores. It seems to be an outlier, though, since I haven't found anything else with that disparity. This is an obsolete branch that I'll have to rewrite, but here's the device tree description for the CPU clusters/cores and frequency/P-state settings for the M1 that I wrote for Asahi Linux: https://github.com/AsahiLinux/linux/commit/6b4a8c07239a4209310c967c432ebf6a5db22152 https://github.com/AsahiLinux/linux/commit/6b4a8c07239a42093... Another fun thing in there, which is replicating macOS behavior, is that when the P-core cluster frequency exceeds 2GHz it makes a change to memory controller power management settings, to increase the time-outs before it goes into lower power modes. This reduces DRAM latency under bursty/sparse load/store patterns, which slightly increases performance for some workloads. You can actually further disable DRAM PM and get even better latencies measurable in synthetic benchmarks (designed to measure this), though I wonder if it'll make any difference in any real world workload at that point; I'll have to test it one day. More random fun stuff: this is a table of the latency of switching between different CPU frequencies, as well as the worst-case pipeline stall during the switch. Better than Intel, at least from the numbers I could find :-) https://mrcn.st/p/Zyok1j0g https://mrcn.st/p/Zyok1j0g - one cool thing you might not know is that it always takes longer to go up in frequency than to go down, because going up implies raising the voltage first and that takes time; going down can happen immediately and the voltage can take its time to drop down to the new minimum to save power. That table also shows that I found that a 24MHz "pstate 0" exists, which is probably a PLL bypass (the external refclock is 24MHz) and quite useless (it is definitely below peak efficiency for the cores, below which it makes no sense to run the CPU, ever), so macOS never uses it, but just a random fun discovery. It might be that the bootloader starts out at this frequency before spinning up the PLLs and configuring the p-state machinery. It does mean these cores are very happy to run at <1% of their rated max clock, which suggests they are either a fully static design or at least have very wide clock tolerance for any dynamic logic parts.
- ChrisMarshallNY 5y agoI love this guy! This also keeps me gobsmacked by what a good job Apple has done, designing these bad boys.
- baxtr 5y agoAnd all Apple haters are like: "Apple is just a design and marketing company!" Yes, exactly. They design chips and market them. They do both things like no other company on this planet.
- leetcrew 5y agoin the consumer space, sure. but they are hardly the only company making impressive in-house archetectures for their products. aws graviton is just one example off the top of my head: https://www.anandtech.com/show/15578/cloud-clash-amazon-graviton2-arm-against-intel-and-amd/9 https://www.anandtech.com/show/15578/cloud-clash-amazon-grav...
- opencl 5y agoThe graviton chips are not an in house architecture, the cores are designed by and licenced from ARM.
- sandGorgon 5y agoApple also licenses it from the same party - it holds an "Architecture License" from ARM. https://news.ycombinator.com/item?id=10190521 https://news.ycombinator.com/item?id=10190521
- marcan_42 5y agoThat's a license for the use of the instruction set, not the design. The design is completely in-house.
- masklinn 5y agoThe point of an architecture license is that you license the ISA itself but can design your own chip from the transistor up :) There's like 15 holders of ARM architecture license. As long as Apple properly implements the ISA and passes validation, they can literally do whatever they want to the core itself (not just the SoC around it). Most ARM users have much more limited licenses, and can only buy and fab IP blocks designed by someone else (usually ARM). That is the case of Amazon, the Graviton used A72 cores, and the Graviton II uses Neoverse N1, which are derived from the A76 with more focus on server workloads. Both are designed by and licensed from ARM.
- flakiness 5y agoI wonder if opensourced darwin codebase has these hetero-core scheduling logic.
- marcan_42 5y agoSome of it is open source (search for "cluster" in XNU); some of it is implemented in the closed-source CLPC driver, which is described in this patent: https://patents.google.com/patent/US10417054B2/en?oq=US10417054B2 https://patents.google.com/patent/US10417054B2/en?oq=US10417...
- lincpa 5y agoApple M1 unified memory architecture(published on November 11, 2020.) is my "warehouse/workshop model"(hardware architecture section published on February 06, 2019), It is an architecture supported by mathematical models, unlike "von Neumann architecture". Why my "warehouse/workshop model" can achieve high performance and low power consumption (take Apple M1 chip, Intel AVX-512, Qualcomm as examples) https://github.com/linpengcheng/PurefunctionPipelineDataflow/blob/master/doc/why_wwmodel_fast_en.md https://github.com/linpengcheng/PurefunctionPipelineDataflow... The Math-based Grand Unified Programming Theory: The Pure Function Pipeline Data Flow with Principle-based Warehouse/Workshop Model https://github.com/linpengcheng/PurefunctionPipelineDataflow https://github.com/linpengcheng/PurefunctionPipelineDataflow Its mathematical prototype is the simple, classic, vivid, and widely used in social production practice, elementary school mathematics "water input/output of the pool". My theory rebuilt the theoretical foundation of the IT industry, It makes the computer theory system fully & perfectly related to mathematics in a simple and unified way: from hardware integrated circuits and computer architecture, to software programming methodology, architecture, programming language and so on. It solve the most fundamental and core major problems in the IT industry: The foundation and core of the IT theory lack mathematical support.
- Symmetry 5y agoThe general rule of thumb is that power usage tends to scale as the square of performance past a certain point so I'm surprised that the E cores are so efficient, I'd expect the two of them to draw half the power of a P core rather than a fifth!
- bullen 5y agoEffectively the M1 CPUs couple a Raspberry 2 with a Raspberry 4. Balancing what runs on what cores you can shut off the Raspberry 4 when you don't need it, which is most of the time as the GPU carries a heavy load. Try watching a MP4 movie on your iPhone 4 and you'll see that allready back then all the heavy lifting was taken off the CPU = battery barely drained at all after 1 hour of video. This is much less magic than the 5nm that basically offer very little Gflops/W benefit over the Raspberry 4 28nm.
- wdb 5y agoI hope Apple releases a M1 Pro or M2 of the MacMini so I can buy one :) This all looks really promising :D