M2 gets really hot during compiling

When compiling source code, I observed, that my MacBook M2 Air 14 inch gets really hot.
Especially in the middle of the upper half, where I suspect the CPU sits, is affected.

When compiling on macOS, my system stays comfortably warm but never heats up like it does on Linux.

Can I solve this somehow?

There is no M2 Air 14 inch. I assume you mean 13 or 15 inch.

It’s a fanless machine, it’s supposed to get hot. There’s nowhere else for the heat to go. Chances are either the compile on macOS is less efficient at saturating the CPUs (have you checked Activity Monitor while compiling?), or it has some kind of case/chassis temperature extra throttling we don’t implement. We do have CPU thermal throttling enabled and I’ve seen it in action on the M2 Air, so I don’t think there’s any bug to be fixed here nor danger to the machine (plus there are last-resort thermal cutoffs too).

If you want to throttle things yourself manually, you could try reducing the maximum cpufreq frequency in sysfs. That will give the best improvement in perf/W (better than limiting parallelism).

Oke, thank you @marcan I‘m gonna adjust these parameters, then :slight_smile:

Is there a way to check, if throttling is enabled or just looking at CPU frequency in the beginning and when it’s hot?

Throttling is handled by the hardware (I think it’s based on clock skipping), so it isn’t visible in cpufreq information.

You can see it in action by running this in one tab:

taskset -c 0-6 stress -c 7

And this in another tab:

while true; do taskset -c 7 sysbench --threads=1 cpu run --time=1 | grep events\ per; done

On my M2 air: I get scores of around 8700-8800 at the beginning. As things warm up, it starts dropping down to 8100 or so. You can get it to throttle even more by running a GPU workload like glmark2 -s 1920x1080. This will affect the test while you run it, but if you stop it you’ll see the machine has throttled even more and climbs back up (in my case, right after stopping glmark2, the score had dropped to 7400 and then climbed up to 7900).

Note that throttling is only really visible during sustained all-core CPU usage. If you stop the workload entirely, it will instantly stop throttling, since the sensors are on the silicon die itself and the temperature instantly drops the moment the work stops. You need a combination of a warm thermal system (heatsink/etc) and a SoC actively producing heat to get the die temperature hot enough to throttle. Even though the heatsink takes longer to cool down, the die temperature drops really fast (towards the heatsink temperature) when the CPUs go idle.