3

In my CPU graph thingy, I have noticed recently that when compiling stuff I can never seem to reach 100% usage, it just keeps bobbing up and down around 60-70% max.

Example:

In contrast, this graph is completely opaque when done on my work computer.

I want to get to the bottom of this and am using the stress utility to simulate CPU usage, and vmstat to observe. I am running stress with cpu core count ranging from 1 to 15 (my CPU has 12 logical cores). Here's the result, with line 1 corresponding to 1 core running 100%, line 2 is 2 cores, etc:

procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
r  b         swpd         free         buff        cache   si   so    bi    bo   in   cs  us  sy  id  wa  st
1  0            0     24455180       465548      2862716    0    0     0    38  944 3184  11   1  88   0   0
3  0            0     24508640       465552      2862684    0    0     0   196 1112 2841  18   1  81   0   0
3  0            0     24556876       465564      2865096    0    0     0    63 1880 4569  30   1  70   0   0
4  0            0     24624764       465576      2865044    0    0     0    11 1414 1005  34   0  66   0   0
5  0            0     24625228       465580      2865068    0    0     0     9 1603 1029  42   0  58   0   0
6  0            0     24763772       465600      2864912    0    0     1   159 1973 1032  51   0  49   0   0
8  0            0     24786696       465600      2864844    0    0     0     9 2460  751  56   0  44   0   0
8  0            0     24805572       465600      2864864    0    0     0    78 2619  808  61   0  38   0   0
10  0            0     24811064       465604      2864852    0    0     0    50 2532  761  56   0  44   0   0
14  0            0     24809904       465616      2865180    0    0     0     4 2823 1049  63   0  37   0   0
13  0            0     24868936       465620      2865116    0    0     0    76 2596  709  57   0  43   0   0
19  0            0     24910408       465628      2866136    0    0     0    12 2526  738  56   0  44   0   0
16  0            0     24914768       465636      2865244    0    0     0    36 2757  720  62   0  38   0   0
18  0            0     24914332       465644      2865256    0    0     0     3 2629  862  59   0  41   0   0
19  0            0     24945952       465648      2866224    0    0     0    33 2642  678  59   0  41   0   0

The script I ran:

for corecount in $(seq 15); do
    stress -c $corecount >/dev/null&
    sleep 1
    vmstat -w 4 2 | tail -1
    pkill stress
    sleep 1
done

By looking at the us column I see that cpu usage increases linearly as expected up to 6-8 logical cores, but after that it's hitting some other bottleneck. The mouse cursor starts lagging at this point, and if I try running while a videp player is running, it will also starts to stutter at this point. (for comparison, here's the exact same test when done on my work computer: http://pastebin.com/MHPSR4E0 . Here the the cpu usage simply climbs linearly up to 99/100 and stays there (the saturation is on line 8 because it's an 8 core cpu))

(here's the cpu graph for the entire test run, with the choke point visible: )

General information:

Ubuntu 16.04 LTS, 32 gb memory, i7-5820K 6-core cpu.

free -h

              total        used        free      shared  buff/cache   available
Mem:            31G        4,8G         23G         90M        3,3G         26G
Swap:           15G          0B         15G

/proc/cpuinfo

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 63
model name      : Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz
stepping        : 2
microcode       : 0x2d
cpu MHz         : 1236.339
cache size      : 15360 KB
physical id     : 0
siblings        : 12
core id         : 0
cpu cores       : 6
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 15
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc
bugs            :
bogomips        : 6599.39
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

[...]

processor       : 11
vendor_id       : GenuineIntel
cpu family      : 6
model           : 63
model name      : Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz
stepping        : 2
microcode       : 0x2d
cpu MHz         : 1200.246
cache size      : 15360 KB
physical id     : 0
siblings        : 12
core id         : 5
cpu cores       : 6
apicid          : 11
initial apicid  : 11
fpu             : yes
fpu_exception   : yes
cpuid level     : 15
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc
bugs            :
bogomips        : 6599.39
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

lspci

00:00.0 Host bridge: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DMI2 (rev 02)
00:01.0 PCI bridge: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 PCI Express Root Port 1 (rev 02)
00:01.1 PCI bridge: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 PCI Express Root Port 1 (rev 02)
00:02.0 PCI bridge: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 PCI Express Root Port 2 (rev 02)
00:02.2 PCI bridge: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 PCI Express Root Port 2 (rev 02)
00:02.3 PCI bridge: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 PCI Express Root Port 2 (rev 02)
00:03.0 PCI bridge: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 PCI Express Root Port 3 (rev 02)
00:05.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Address Map, VTd_Misc, System Management (rev 02)
00:05.1 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Hot Plug (rev 02)
00:05.2 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 RAS, Control Status and Global Errors (rev 02)
00:05.4 PIC: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 I/O APIC (rev 02)
00:11.0 Unassigned class [ff00]: Intel Corporation C610/X99 series chipset SPSR (rev 05)
00:14.0 USB controller: Intel Corporation C610/X99 series chipset USB xHCI Host Controller (rev 05)
00:16.0 Communication controller: Intel Corporation C610/X99 series chipset MEI Controller #1 (rev 05)
00:19.0 Ethernet controller: Intel Corporation Ethernet Connection (2) I218-V (rev 05)
00:1a.0 USB controller: Intel Corporation C610/X99 series chipset USB Enhanced Host Controller #2 (rev 05)
00:1b.0 Audio device: Intel Corporation C610/X99 series chipset HD Audio Controller (rev 05)
00:1c.0 PCI bridge: Intel Corporation C610/X99 series chipset PCI Express Root Port #1 (rev d5)
00:1c.4 PCI bridge: Intel Corporation C610/X99 series chipset PCI Express Root Port #5 (rev d5)
00:1d.0 USB controller: Intel Corporation C610/X99 series chipset USB Enhanced Host Controller #1 (rev 05)
00:1f.0 ISA bridge: Intel Corporation C610/X99 series chipset LPC Controller (rev 05)
00:1f.2 SATA controller: Intel Corporation C610/X99 series chipset 6-Port SATA Controller [AHCI mode] (rev 05)
00:1f.3 SMBus: Intel Corporation C610/X99 series chipset SMBus Controller (rev 05)
06:00.0 VGA compatible controller: NVIDIA Corporation GF104 [GeForce GTX 460] (rev a1)
06:00.1 Audio device: NVIDIA Corporation GF104 High Definition Audio Controller (rev a1)
08:00.0 USB controller: ASMedia Technology Inc. ASM1142 USB 3.1 Host Controller
ff:0b.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 R3 QPI Link 0 & 1 Monitoring (rev 02)
ff:0b.1 Performance counters: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 R3 QPI Link 0 & 1 Monitoring (rev 02)
ff:0b.2 Performance counters: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 R3 QPI Link 0 & 1 Monitoring (rev 02)
ff:0c.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers (rev 02)
ff:0c.1 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers (rev 02)
ff:0c.2 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers (rev 02)
ff:0c.3 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers (rev 02)
ff:0c.4 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers (rev 02)
ff:0c.5 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers (rev 02)
ff:0f.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Buffered Ring Agent (rev 02)
ff:0f.1 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Buffered Ring Agent (rev 02)
ff:0f.4 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 System Address Decoder & Broadcast Registers (rev 02)
ff:0f.5 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 System Address Decoder & Broadcast Registers (rev 02)
ff:0f.6 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 System Address Decoder & Broadcast Registers (rev 02)
ff:10.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 PCIe Ring Interface (rev 02)
ff:10.1 Performance counters: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 PCIe Ring Interface (rev 02)
ff:10.5 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Scratchpad & Semaphore Registers (rev 02)
ff:10.6 Performance counters: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Scratchpad & Semaphore Registers (rev 02)
ff:10.7 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Scratchpad & Semaphore Registers (rev 02)
ff:12.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Home Agent 0 (rev 02)
ff:12.1 Performance counters: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Home Agent 0 (rev 02)
ff:13.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Target Address, Thermal & RAS Registers (rev 02)
ff:13.1 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Target Address, Thermal & RAS Registers (rev 02)
ff:13.2 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder (rev 02)
ff:13.3 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder (rev 02)
ff:13.4 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder (rev 02)
ff:13.5 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder (rev 02)
ff:13.6 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DDRIO Channel 0/1 Broadcast (rev 02)
ff:13.7 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DDRIO Global Broadcast (rev 02)
ff:14.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel 0 Thermal Control (rev 02)
ff:14.1 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel 1 Thermal Control (rev 02)
ff:14.2 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel 0 ERROR Registers (rev 02)
ff:14.3 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel 1 ERROR Registers (rev 02)
ff:14.6 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DDRIO (VMSE) 0 & 1 (rev 02)
ff:14.7 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DDRIO (VMSE) 0 & 1 (rev 02)
ff:15.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel 2 Thermal Control (rev 02)
ff:15.1 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel 3 Thermal Control (rev 02)
ff:15.2 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel 2 ERROR Registers (rev 02)
ff:15.3 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 0 Channel 3 ERROR Registers (rev 02)
ff:16.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 1 Target Address, Thermal & RAS Registers (rev 02)
ff:16.6 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DDRIO Channel 2/3 Broadcast (rev 02)
ff:16.7 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DDRIO Global Broadcast (rev 02)
ff:17.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Integrated Memory Controller 1 Channel 0 Thermal Control (rev 02)
ff:17.4 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DDRIO (VMSE) 2 & 3 (rev 02)
ff:17.5 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DDRIO (VMSE) 2 & 3 (rev 02)
ff:17.6 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DDRIO (VMSE) 2 & 3 (rev 02)
ff:17.7 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 DDRIO (VMSE) 2 & 3 (rev 02)
ff:1e.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Power Control Unit (rev 02)
ff:1e.1 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Power Control Unit (rev 02)
ff:1e.2 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Power Control Unit (rev 02)
ff:1e.3 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Power Control Unit (rev 02)
ff:1e.4 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Power Control Unit (rev 02)
ff:1f.0 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 VCU (rev 02)
ff:1f.2 System peripheral: Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 VCU (rev 02)

/proc/meminfo

MemTotal:       32841924 kB
MemFree:        24244428 kB
MemAvailable:   27418672 kB
Buffers:          478012 kB
Cached:          2622028 kB
SwapCached:            0 kB
Active:          6606180 kB
Inactive:        1240728 kB
Active(anon):    4758584 kB
Inactive(anon):    85340 kB
Active(file):    1847596 kB
Inactive(file):  1155388 kB
Unevictable:        8020 kB
Mlocked:            8020 kB
SwapTotal:      16669692 kB
SwapFree:       16669692 kB
Dirty:               284 kB
Writeback:             0 kB
AnonPages:       4754864 kB
Mapped:           780304 kB
Shmem:             93528 kB
Slab:             346300 kB
SReclaimable:     257036 kB
SUnreclaim:        89264 kB
KernelStack:       22112 kB
PageTables:       109808 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    33090652 kB
Committed_AS:   16302224 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      371016 kB
VmallocChunk:   34358945788 kB
HardwareCorrupted:     0 kB
AnonHugePages:    761856 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      537784 kB
DirectMap2M:     5648384 kB
DirectMap1G:    29360128 kB

a more detailed cpu usage screenshot from ksysguard while stress testing with 10 cores:

What is going on? What other parts of the kernel can I observe to see what's happening? Is there some cpu scheduler configuration that has been It has not always been like this, I am absolutely certain I have been able to compile before with 100% cpu utilization with no mouse lag and not really noticing it except for fans running.

  • The Linux Scheduler: a Decade of Wasted Cores -- good read even though it might not be related to your problem – Jakuje May 1 '16 at 19:32
  • @Jakue What are you suggesting by posting that? I did mention in my post that this issue has not always been there, so it's a concrete issue I'm trying to debug. – Harald H May 1 '16 at 19:40
  • 1) Linux scheduler is buggy. 2) 6 core Intel running 12 threads will saturate HT pipelines quite simply as well as the memory lanes. Depends on what is running. 3) Running the task under perf stat might give you some idea about the processor, its stalled cycles, or memory behaviour. – Jakuje May 1 '16 at 19:46
  • 1
    @Jakuje Although perhaps not in the way you thought, your answer did help me. I tried to get perf stat running but was getting error messages about the wrong kernel. So I eventually discovered I was running 4.2.0 although ubuntu 16.04 is meant to be running 4.4. So I eventually got it running 4.4.0, and now the issue is gone. – Harald H May 1 '16 at 20:29
  • What is the right way to resolve this question on Stackoverflow now? This is my first time posting a question. – Harald H May 1 '16 at 20:30
4

To debug problems with scheduling or applications performance on Linux, it is a good start to run task under perf stat. It reports statistics about the processor pipeline, its stalled cycles, or memory behaviour.

Possible problems:

  • Linux/Scheduler bug
  • Intel HT is not keeping up with your threads
  • Memory is not able to provide enough data for the program

For the sake of complexity, resolution was wrong/old kernel (4.2.0) instead of expected 4.4.0 for Ubuntu 16.04. Updating solved the problem.

  • Hardware bottlenecks like HT shared resources and memory do not limit cpu utilization, only the real world work that can be done with that cpu time. That is, when a core stalls because it needs one of these resources and they are not available, software is not aware of it and the kernel still counts it as used cpu time, not idle time. – psusi May 2 '16 at 0:19
0

I don't think this is a problem, rather this is the behaviour of the program you are running.

Your application (compiling) doesn't do 100% CPU, it might be doing quite a bit of IO. When application is doing IO, it goes in to iowait mode. It cannot use CPU until it completes IO operation.

Notice the "wait time" in top.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.