28 comments

[ 5.6 ms ] story [ 58.9 ms ] thread
I don't get it. CPU graphs don't show power usage and they never have; they show how much time, percentually, a CPU was busy executing a certain type of task. You can never get a power estimate from a CPU usage graph at all. Even during normal operation purely on performance cores the clock speed will go up and down as the OS idles or new tasks get spawned. Whatever 10% is in your graph changes depending on the state of the system. This means the energy value in monitoring tools like these are bogus and should never have been trusted in the first place!

It's like trying to read the amount of gas left in the tank by looking at the odometer. Distance and fuel remaining are related, but there's no 1-to-1 connection going on there.

Different cores having different speeds is a difficult problem to solve for reporting CPU usage. The author seems to have missed the latest Intel CPUs which also have a performance/effeciency core setup, but I bet those suffer from the same "problem" as well.

Since Apple have full control over each Mac's hardware, couldn't they within a quite narrow average know how much power is consumed?

You also have hardware control chips like the T1/T2 that could help narrow this down even further.

I would get it for PC's, but here, it's quite different.

Yes.

But why would they? There's no benefit for them.

A lot of reasons to profile this if you want to advertise battery life. Internally it let's you collect metrics on apps threatening your battery life promises and externally it gives the consumers the ability to accurately blame apps when they get lower than expected battery life. For example they can notice that safari uses less power than chrome or that final cut uses way more power than they expected, etc etc
They don't want end users to have access to battery life stats. The took that out a few OS X versions ago. They don't people to say, after the last updated I get 1 hour less battery life, WTF?
Battery stats are available in the Battery System Pref pane and that has not changed. There is also some health information in the System Profiler (Apple Menu/About This Mac/System Report).
They wouldn’t need to guess. CPUs measure their own current consumption and demand specific voltage levels from their regulators. They know the instantaneous power consumption to at least three significant digits.
On Windows (or Linux) you can get power consumption numbers down to the core using tools like HWMonitor. My CPU is currently using 95W, and my GPU uses 15W. Of course then you have fans, motherboard etc. On server hardware (where software-queriable power meters in the power supply are commonplace) having as much power draw from the fans as from the CPU isn't uncommon.
Where is HWMonitor getting this data from?

> My CPU is currently using 95W

Are you currently stressing the CPU (compiling, rendering, ...)? If you are not, the 95W figure seems suspect. (FWIW, my entire system, fans and all, uses 25W at the wall when idle. The CPU is Intel 9700k, no dGPU).

It's a desktop with a 24 core Threadripper with a 250W TPD, not designed for efficiency at all. Probably something or another was using 2 to 6 cores.
> power consumption numbers down to the core using tools like HWMonitor.

These are just rough estimates and can be wildly inaccurate (just like in the OSX post we're discussing). AFAIK there's no facility for actual measurement.

> On server hardware (where software-queriable power meters in the power supply are commonplace)

Are you certain these are actual meters and not just estimates done in software?

Any modern computer has facilities for actual measurements.

All motherboards contain sensor chips that can measure the voltages of all power supplies that are used on that board.

All modern CPUs (i.e. all CPUs with variable clock frequency) have internal sensors that measure the currents and the voltages provided by their power supplies. From the currents and the voltages the power consumption is computed. The current and voltage values, together with the temperatures provided by one or more temperature sensors, are used by the algorithms that control the turbo clock frequencies. (The reason why power consumption values are needed by the turbo algorithms is because the chip temperature has a too large inertia, if the clock frequency would be reduced only after the temperature is already too high it would be too late; using the power consumption the future temperature raise can be predicted and the clock frequency can be reduced in advance, avoiding the overshooting of the maximum temperature.)

Some of the values provided by the internal CPU sensors are available in model-specific registers, so the monitoring programs can read them and display the CPU power consumption.

The discrete GPUs from NVIDIA and AMD also have internal sensors that can be read by programs to display the GPU power consumption. The GPUs also use their internal sensors to control their clock frequencies.

Most inaccuracies in reporting the power consumption are due to poor or non-existent documentation of the sensors, which affects especially the AMD CPUs and some of the motherboard sensors. The Intel sensors are usually well documented.

How to read and display the power consumption values provided by the internal CPU sensors can be seen e.g. in the source code of the utility turbostat, which can be found in the source tree of the Linux kernel. (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...)

Apple should have good internal documentation, which should enable accurate power consumption reporting. They cannot blame an external company which refused to provide adequate documentation for the sensors.

I don't believe this is correct. My understanding is that these tools all use RAPL, and RAPL data is calculated as I suggested (estimates from activity counters) rather than metering amps and volts.

Turbostat uses RAPL data, as you can see by reading the source code you linked.

I mention this because as far as I'm aware it's impractical to actually measure energy directly. I'm fairly certain that all of these types of systems use estimate models - whether it's in software or firmware.

Most (all?) recently made graphics cards have shunt resistors specifically for measuring power (current) consumption and it is actually real time consumption. One of the ways that extreme overclockers (think, liquid nitrogen cooling) push cards harder is by 'power modding' them, by switching out the shunt resistors for smaller value resistors to trick the graphics card into thinking it is using less current than it actually is.

It's similar on CPUs, but the monitoring circuitry is internal, I think.

They do, and their software knows as well. It’s just Activity Monitor that isn’t currently using the data for some reason.
Can't the CPU just measure how much power it's drawing?
> CPU graphs don't show power usage and they never have

Sure, but Activity Monitor has separate CPU and Energy graphs, and the author here appears to be talking specifically about the Energy graph ("According to Activity Monitor’s Energy pane") rather than the CPU one.

I don’t think the article only looked at CPU graphs (FTA: “According to Activity Monitor’s Energy pane”)

https://support.apple.com/en-gb/guide/activity-monitor/actmn...:

- In the Activity Monitor app on your Mac, click Energy (or use the Touch Bar).

To display more columns, choose View > Columns, then choose the columns you want to show.

The energy use of individual apps and their processes is displayed in the upper part of the Activity Monitor window.

- Energy Impact: A relative measure of the current energy consumption of the app (lower is better).

>You can never get a power estimate from a CPU usage graph at all.

Yes, but you could (or should) get one from Activity Monitor's energy usage graph (under the "Energy" tab).

I'm torn, or maybe I misunderstood, from what I know about energy efficiency of CPU's, it has always been: Spend less time on the CPU.

If your task is short lived, or constrained by I/O, affining it to E cores is going to be better so that you don't have to "race to a stop-light".

But, to take an extreme example: having a 10w CPU awake for 24hrs vs a 30w one for 7 hours is going to be less energy efficient.

Race-to-idle is a good strategy in homogenous CPU setups.

But chips like the M1 with its E and P cores (or ARMs BIG.little designs) significantly change the playing field, and race-to-idle makes less sense.

Two of the places you can look to understand why running on an E core for longer is better than running on a P core for shorter, is power consumption as frequency increases, and number of computational units in each core.

Power consumption in CPU generally increases exponentially with clock frequency. So double the frequency, if 4x the power (as a very rough guiding principle), so going slow and steady can be more power efficient.

Additionally E cores will have fewer computational units (ALUs and other basic computing blocks) compared to a P core. Running a core generally means you’re powering all of it computational units, regardless of if they’re actually doing any work (modern CPU have very good power gating, but there’s a limit). So running a core with less silicon is more efficient, because portion of powered silicon doing useful work is larger.

Put all of the above together, throw in sophisticated power gating, CPU clock scaling, various on die peripherals (like media engines, crypto engines etc) and all of a sudden, simple strategies like race-to-idle stop being a good approach.

> 100% active residency of an E core running at maximum frequency uses around 100 mW, and the same active residency of a P core running at its higher maximum frequency uses ten times that amount, 1000 mW.

Damn, that's a lot more efficient!

> just as they would on an Intel processor with its identical cores.

Whilst its true that all intel macs have identical cores, the latest intel architecture also has Efficiency cores that are different from the performance cores.

This is good to know.

I wonder if Xcode Instruments could be used to profile energy usage instead?

(Well, actually, for the stuff I do I almost certainly want to leave it to the OS to decide when to use which core.)

There's an argument that says to prefer performance cores, because once a non-looping task completes, the cores can idle again.

This allows the system to more quickly reach a very power efficient state, compared to leaving a weak stove on to cook a large pot of chili.

I always thought that part of the reason that Apple measured energy impact in arbitrary units was because they're trying to take into account the energy used by the rest of the system. So, for example, if a task takes half the energy when running on E cores, but causes the screen, wifi, disk, etc. to stay on longer, then perhaps it really is causing more total power to be used.

But, OTOH, if it's happening in the background while you're already using the computer, then those parts were probably going to be on anyways, so I suppose it's fairly context-dependent.