1

[Documentation/cpu-load.txt] includes an example program, smallhog.c. According to the linked thread on LKML.org it was able to hog the CPU, and the kernel only reported a few % CPU usage or less.

I tried compiling and running it on my current system. The kernel reported the program's CPU usage as about 80%. So the situation appears to have changed a bit.

Source: Documentation/cpu-load.txt says Linux cpu load *could* be misleading. Are there new (or old) mitigations that it does not mention?

But smallhog.c still has some effect. According to "task-clock" in perf stat, it really uses about 100% cpu time. But the normal CPU accounting in top thinks it only uses 80% cpu time. The same is true of "user"+"sys" in perf stat.

Why does my specific system not report 100% CPU usage for smallhog.c?

My kernel version is 5.1.15-300.fc30.x86_64.

Linux says my TSC is stable.

$ sudo perf stat ./smallhog
^C./smallhog: Interrupt

 Performance counter stats for './smallhog':

         10,072.25 msec task-clock                #    1.000 CPUs utilized          
               235      context-switches          #    0.023 K/sec                  
                65      cpu-migrations            #    0.006 K/sec                  
                44      page-faults               #    0.004 K/sec                  
    28,736,276,128      cycles                    #    2.853 GHz                       75.00%)
    18,394,555,284      instructions              #    0.64  insn per cycle           (74.99%)
     3,530,232,530      branches                  #  350.491 M/sec                    (75.01%)
        58,545,233      branch-misses             #    1.66% of all branches          (75.01%)

      10.076806251 seconds time elapsed

       3.481505000 seconds user
       4.458544000 seconds sys
$ sudo journalctl -k |grep -iE "tsc|sched_clock"
Jul 09 10:58:25 localhost kernel: tsc: Fast TSC calibration using PIT
Jul 09 10:58:25 localhost kernel: tsc: Detected 2294.623 MHz processor
Jul 09 10:58:25 localhost kernel: clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x21135dc5295, max_idle_ns: 440795305870 ns
Jul 09 10:58:25 localhost kernel: TSC deadline timer enabled
Jul 09 10:58:25 localhost kernel: clocksource: Switched to clocksource tsc-early
Jul 09 10:58:25 localhost kernel: sched_clock: Marking stable (1353126208, 521414)->(1368149024, -14501402)
Jul 09 10:58:25 localhost kernel: tsc: Refined TSC clocksource calibration: 2294.689 MHz
Jul 09 10:58:25 localhost kernel: clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x21139c00f92, max_idle_ns: 440795293667 ns
Jul 09 10:58:25 localhost kernel: clocksource: Switched to clocksource tsc
$ lscpu
...
Vendor ID:           GenuineIntel
CPU family:          6
Model:               61
Model name:          Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz
Stepping:            4
CPU MHz:             1189.926
CPU max MHz:         2900.0000
...

1 Answer 1

1

Because the other 20% of CPU time is accounted to interrupts :-D.

Run smallhog on a specific CPU, using taskset -c 0 ./smallhog. Inside top, press the 1 key. Here is the result:

%Cpu0 : 22.6 us, 56.1 sy, 0.0 ni, 0.0 id, 0.0 wa, 21.3 hi, 0.0 si, 0.0 st

hi means "hardware interrupt".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .