htop icon indicating copy to clipboard operation
htop copied to clipboard

Htop 3.4.0-dev not showing CPU percentage on apple silicon

Open Korrd opened this issue 9 months ago • 10 comments

Since upgrading to 3.4.0-dev, htop won't show CPU percentages on the processes' list.

sudo htop Image

I'm running macOS Sequoia 15.3.2 (24D81) on an M4 Pro Macbook

This issue had been reported and fixed before, here https://github.com/htop-dev/htop/issues/622. Maybe a resurgence?

Korrd avatar Mar 13 '25 20:03 Korrd

Can you take a look with git bisect if you can locate where this issue got introduced? TIA.

BenBE avatar Mar 13 '25 21:03 BenBE

Didn't see precisely where the error is through the screenshot. I have a M2 MacBook Pro with macOS Sequoia and didn't observe error on my side.

Explorer09 avatar Mar 13 '25 23:03 Explorer09

If you compare the CPU Usage bars to the CPU usage on the process list, you'll notice there are no processes reflecting the amount of CPU usage shown on the bars themselves.

Here's a better screenshot showing the disparity between CPU graph and reported CPU usage on process' list.

Image

Korrd avatar Mar 14 '25 15:03 Korrd

This is an actual problem on Apple silicon. I checked all the commits that touched DarwinProcess.c from the 3.3.0 tag on. It turned out that the problem is in this commit. In particular, this behavior seems caused by having removed the #else block in Platform_calculateNanosecondsPerMachTick. Between tonight and tomorrow morning I'll do some more investigations, because the running time seems to be correct (before it wasn't).

aestriplex avatar Mar 17 '25 19:03 aestriplex

I reverted my previous commit. Now it shows a more reliable cpu percentage at a process level (or at least consistent with 3.3.0). @BenBE @fasterit I wait to open a pr, because I wish to further investigate the Platform_calculateNanosecondsPerMachTick function. In the case of a program compiled directly for silicon, it should not run in compatibility mode (i.e. without rosetta); here's the compiler binary from my M2:

% file htop
htop: Mach-O 64-bit executable arm64

so perhaps it should be enough

...
else {
      // No workarounds needed, use the OS-provided value.
      mach_timebase_info(&info);
}
...

aestriplex avatar Mar 18 '25 14:03 aestriplex

The mach_timebase_info on Apple Silicon sets the structure correctly (125/3). Everything seems ok, both the cpu percentage and the running time (compared to top). Even if isRunningUnderRosetta2 should always be false, because the program is compiled for the right architecture each time, probably we can leave those controls there, just in case. I'll open a pr with the commit reverted

aestriplex avatar Mar 18 '25 23:03 aestriplex

The title of this issue wasn't quite intuitive to me so I didn't spot that what I reported in #1664 is likely a duplicate of this issue here.

In my case I do see percentages for CPU, it's just that they are way too small since version 3.4.0 and on Apple silicon. Is that what this issue here is about? Why does it say "not showing percentage" when it is showing?

@Explorer09: Didn't see precisely where the error is through the screenshot.

That was also my issue, took me a while to identify the duplicate. I've got a GIF showing top vs htop showing that CPU reported by htop is ~40x too small:

Image

@BenBE The question label should be removed, I have the exact same issue, with homebrew and source compiled 3.4.0.

corneliusroemer avatar Apr 08 '25 13:04 corneliusroemer

Is there a release date for this fix?

Korrd avatar Apr 18 '25 07:04 Korrd

Details are in #1643, which won't be merged as is, as it reverts from one broken state to another broken state instead of providing an actual improvement …

BenBE avatar Apr 18 '25 10:04 BenBE

@BenBE Any updates on this ...?

chenzhuoyu avatar Jun 20 '25 14:06 chenzhuoyu

I see that its associated PR is ready for merge. Is there anything else blocking it?

Korrd avatar Jun 27 '25 11:06 Korrd

There are two PRs associated with this issue: #1643 & #1691

Explorer09 avatar Jun 27 '25 13:06 Explorer09