context-labs / mactop

mactop - Apple Silicon Monitor Top written in pure Golang! Under 1,000 lines of code.
MIT License
1.32k stars 27 forks source link

Mactop vs. Activity Monitor CPU use totally different, M2 Macbook Air #29

Open iandol opened 1 month ago

iandol commented 1 month ago

Mactop always shows ~50% P and E, even when the machine is otherwise idle. Here is what mactop and activity monitor show at the same time, note the P cores seem to be idle in AM and 50% active in mactop, the E cores are more active in AM but still not 50%:

mactop

I've tried htop, gotop, zenith and some others and they all largely agree with AM, only mactop shows this 50% CPU use...

metaspartan commented 1 month ago

Sorry for the late reply, please post your powermetrics output here if you can, that would assist in debugging this issue as we parse stats from it depending on the chip. It is possibly related to the other open issue: https://github.com/context-labs/mactop/issues/26

iandol commented 1 month ago
sudo powermetrics -i 1000 -n 20 -o pm.log

pm.log

After running this log, I immediately started mactop without anything else running and this is what it shows:

image
metaspartan commented 1 month ago

Yea, so it looks like there is no bug here, your machines E-Cluster and P-Cluster (E and P Cores) are in fact running at those percentages correctly, (cherry picking a few of what we parse out of your pm.log here):

E-Cluster HW active residency:  55.86%
P-Cluster HW active residency:  50.12%

E-Cluster HW active residency:  54.01%
P-Cluster HW active residency:  50.22%

E-Cluster HW active residency:  54.53% 
P-Cluster HW active residency:  50.27%

I recommend checking what processes you have running, seems kernel_task, com.apple.DriverKit.AppleUserECM, and WindowServer are the top three besides powermetrics utilizing a good chunk of CPU

iandol commented 1 month ago

Activity monitor shows no activity in the p-cluster at all, and it seems the cluster vs individual stats do not line up::

P-Cluster idle residency:  49.92%

CPU 4 idle residency:  99.33%

CPU 5 idle residency:  99.90%

CPU 6 idle residency:  99.96%

CPU 7 idle residency: 100.00%

How can each CPU's idle be >99% but the overall cluster is only 50% idle? Activity monitor seems to be using the CPU stats (last 4 columns are P cores I think):

image
iandol commented 1 month ago

But from your perspective, this is a powermetrics problem by the looks of it...

EDIT: an average of the CPU core values would work in my case...

metaspartan commented 1 month ago

Activity monitor shows no activity in the p-cluster at all, and it seems the cluster vs individual stats do not line up::

P-Cluster idle residency:  49.92%

CPU 4 idle residency:  99.33%

CPU 5 idle residency:  99.90%

CPU 6 idle residency:  99.96%

CPU 7 idle residency: 100.00%

How can each CPU's idle be >99% but the overall cluster is only 50% idle? Activity monitor seems to be using the CPU stats (last 4 columns are P cores I think):

image

We use HW active residency and yes possibly a powermetrics issue (Apple)

iandol commented 1 month ago

Right, powermetrics is misleading on either active or idle residency on my M2, here the active residence is 55.3% but the active residency of the CPUs is 13.1% 7.1% 4.4% & 2.9%, even if you sum them they don't make 55.3%!?!?

E-Cluster HW active frequency: 936 MHz
E-Cluster HW active residency:  55.31% (600 MHz:   0% 912 MHz:  54% 1284 MHz: .09% 1752 MHz: 1.2% 2004 MHz: .11% 2256 MHz: .11% 2424 MHz: .04%)
E-Cluster idle residency:  44.69%
CPU 0 frequency: 1036 MHz
CPU 0 active residency:  13.10% (600 MHz:   0% 912 MHz:  11% 1284 MHz: .01% 1752 MHz: 1.3% 2004 MHz: .19% 2256 MHz: .19% 2424 MHz: .04%)
CPU 0 idle residency:  86.90%
CPU 1 frequency: 982 MHz
CPU 1 active residency:   7.13% (600 MHz:   0% 912 MHz: 6.6% 1284 MHz: .01% 1752 MHz: .48% 2004 MHz: .03% 2256 MHz: .02% 2424 MHz: .03%)
CPU 1 idle residency:  92.87%
CPU 2 frequency: 949 MHz
CPU 2 active residency:   4.39% (600 MHz:   0% 912 MHz: 4.2% 1284 MHz: .00% 1752 MHz: .10% 2004 MHz: .01% 2256 MHz: .01% 2424 MHz: .04%)
CPU 2 idle residency:  95.61%
CPU 3 frequency: 1055 MHz
CPU 3 active residency:   2.87% (600 MHz:   0% 912 MHz: 2.4% 1284 MHz: .00% 1752 MHz: .44% 2004 MHz: .00% 2256 MHz: .01% 2424 MHz: .02%)
CPU 3 idle residency:  97.13%

The CPU stats seem more reliable than the cluster ones, and they also align more closely to the low power draw and activity monitor / htop etc.

Should I close this (or leave it if others hit the same issue as me)?