Gentoo Archives: gentoo-user

From: Rich Freeman <rich0@g.o>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] 100% CPU load is different to 100% CPU load?
Date: Tue, 09 Jun 2020 11:07:05
Message-Id: CAGfcS_=fX0aC54zb1VwhNbyiju2CjXXUxZhy6oGGj=1eKuf-Lw@mail.gmail.com
In Reply to: [gentoo-user] 100% CPU load is different to 100% CPU load? by tuxic@posteo.de
1 On Tue, Jun 9, 2020 at 5:17 AM <tuxic@××××××.de> wrote:
2 >
3 > What is the difference between 100% CPU load and 100% CPU load to
4 > create such an difference in temperature?
5 > How is X% load calculated?
6 >
7
8 I think a lot more detail around what you're actually running would be
9 needed to provide more insight here. I can think of a few things that
10 could cause this:
11
12 The kernel maintains a number of stats around CPU load including %
13 utilized by userspace, the kernel, IRQs, IO waiting, and truly idle
14 time. Depending on where you were getting that "100%" figure I can't
15 be sure what was included in that. If it was just 100-idle then you
16 could have had IO waiting included in the load - this is time when you
17 have a running process that wants to do something but it is blocked on
18 IO, such as reading from a disk. If you have 12 threads all doing
19 random IO from a spinning hard disk you can easily end up with the CPU
20 spending a whole lot of time doing nothing, but where it is otherwise
21 "busy." If the stat was system+user then that reflects actual CPU
22 processing activity.
23
24 Next, not all instructions are created equally, and a CPU core is a
25 fairly complex device that has many subdivisions. There are circuits
26 that do nothing but integer or floating-point math, others that
27 fetch/store data, some that do logical comparisons, and so on. While
28 the OS tries to keep all the CPU cores busy, the CPU core itself also
29 tries to keep all of its components busy (something aided by
30 optimizing compilers). However, the CPU only has so many instructions
31 in the pipeline at one time, and they often have interdependencies,
32 and so the CPU can only use out-of-order execution to a limited degree
33 to keep all its parts active. If you get a lot of cache misses the
34 CPU might spend a lot of time waiting for memory access. If you get a
35 lot of one type of instruction in a row some parts of the CPU might be
36 sitting idle. Depending on the logical flow you might get a larger or
37 smaller number of speculative execution misses that result in waiting
38 for the pipeline to be flushed. This can result in the power
39 consumption of the CPU varying even if it is "100% busy." It could be
40 100% busy executing 1 instruction per clock, or it could be 100% busy
41 executing 4 instructions per clock. Either way the processor queue is
42 100% blocked, but the instructions are being retired at different
43 rates. Modern CPUs can reduce the power consumption by idle
44 components so part of a CPU core can be using its maximum power draw
45 while another part of the same core can be using very little power.
46 The end result of this at scale is that the CPU can produce different
47 amounts of heat at 100% use depending on what it is actually doing.
48
49 I'm sure people have written about this extensively because it is very
50 important with benchmarking. When individually given a two uniform
51 set of tasks a CPU might execute a certain number of tasks per second,
52 but.when you combine the two sets of tasks and run them in parallel
53 the CPU might actually be able to perform more tasks per second
54 combined, because it is better able to utilize all of its components.
55 A lot of synthetic loads may not fully load the CPU unless it was
56 designed to balance the types of instructions generated. Natural
57 loads often fail to load a CPU fully due to the need for IO waiting.
58
59 So, I guess we can get back to your original question. Generally 100%
60 load means that from the kernel scheduler's perspective the CPU has
61 been assigned threads to execute 100% of the time. A thread could be
62 a big string of no-op instructions and from the kernel's perspective
63 that CPU core is 100% busy since it isn't available to assign other
64 threads to.
65
66 --
67 Rich

Replies