Outils pour utilisateurs

Outils du site


tech:gerer_le_cpu_sous_gnu_linux

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
tech:gerer_le_cpu_sous_gnu_linux [2025/11/11 16:34] Jean-Baptistetech:gerer_le_cpu_sous_gnu_linux [2026/06/29 16:12] (Version actuelle) Jean-Baptiste
Ligne 1: Ligne 1:
 +<!DOCTYPE markdown>
 +{{tag>Brouillon CPU Matériel Kernel Linux}}
 +
 +# Gérer les CPUs sous GNU/Linux
 +
 +Voir 
 +* [[temperature_materiel_cpu_carte_mere_debian_lm-sensors|Température CPU]]
 +* <https://www.grid5000.fr/w/CPU_parameters>
 +* https://www.deltasight.fr/processeurs-gestion-energie-frequence/
 +
 +
 +## Notes
 +
 +Outils :
 +  * lscpu
 +  * chcpu
 +  * cpufreq-info
 +  * CoreCtrl
 +  * turbostat
 +  * cpupower
 +  * powertop
 +  * rdmsr / wrmsr (msr-tools)
 +  * kvm-ok / check-bios-nx (cpu-checker)
 +
 +Notions :
 +  * Systèmes multi-processeurs (NUMA SMP)
 +  * Systèmes multi-cœurs (SMP) 
 +  * Systèmes multi-threads (SMT)
 +
 +
 +Params Kernel :
 +* nr_cpus
 +
 +
 +
 +## Infos nombre de cores threads CPU
 +
 +Nombre de threads
 +~~~bash
 +grep ^processor /proc/cpuinfo
 +~~~
 +
 +Nous avons une valeurs par thread.
 +C'est donc la derniere valeur +1 qui donne le nombre de threads (si un seul CPU physique)
 +
 +Nombre de cores
 +~~~bash
 +grep '^cpu cores' /proc/cpuinfo
 +~~~
 +
 +Toutes les valeurs sont identiques si un seul CPU physique
 +
 +
 +
 +
 +## CPUFrequtils
 +
 +Voir aussi : [intel_p-state](https://doc.ubuntu-fr.org/intel_p-state|)
 +
 +Gérer la fréquence cpu
 +
 +~~~bash
 +service cpufrequtils stop
 +~~~
 +
 +~~~bash
 +#!/bin/sh -e
 +#
 +# rc.local
 +echo "conservative" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
 +echo "conservative" >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
 +echo "conservative" >/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
 +#echo "conservative" >/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
 +# echo "performance" >  /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
 +exit 0
 +~~~
 +
 +Fichier à exécuter en root pour changer le gouverneur. Choix possible selon la configuration du noyau : conservative, ondemand, powersave, performance.
 +
 +    Avec cpufrequtils : (en root)
 +
 +~~~bash
 +cp /usr/share/doc/cpufrequtils/examples/cpufrequtils.sample /etc/default/cpufrequtils
 +
 +cpufreq-set -c 0 -d 2100000 -u 3300000
 +
 +service cpufrequtils reload
 +~~~
 +    -c : numéro processeur
 +    -d : freq min
 +    -u : freq max
 +    -f : freq exact voulu
 +
 +
 +## Notes cpufreq
 +
 +Voir : 
 +* https://www.kernel.org/doc/html/v4.14/admin-guide/pm/cpufreq.html
 +* https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt
 +* https://doc.ubuntu-fr.org/cpu-frequtils
 +* https://wiki.debian.org/HowTo/CpuFrequencyScaling
 +* https://wiki.archlinux.org/index.php/CPU_frequency_scaling
 +* https://www.linuxquestions.org/questions/slackware-14/locking-all-cpu%27s-to-their-maximum-frequency-4175607506/
 +* https://www.thomas-krenn.com/en/wiki/Disable_CPU_Power_Saving_Management_in_BIOS
 +* https://bbs.archlinux.org/viewtopic.php?id=163253
 +* https://doc.ubuntu-fr.org/intel_p-state
 +
 +~~~bash
 +grep MHz /proc/cpuinfo
 +~~~
 +
 +
 +~~~bash
 +apt-get install linux-cpupower
 +cpupower
 +~~~
 +
 +~~~
 +$ cpupower frequency-info -g
 +analyzing CPU 0:
 +  available cpufreq governors: Not Available
 +
 +$ cpupower frequency-info
 +analyzing CPU 0:
 +  no or unknown cpufreq driver is active on this CPU
 +  CPUs which run at the same hardware frequency: Not Available
 +  CPUs which need to have their frequency coordinated by software: Not Available
 +  maximum transition latency:  Cannot determine or is not supported.
 +  hardware limits: Not Available
 +  available cpufreq governors: Not Available
 +  Unable to determine current Policy
 +  current CPU frequency: Unable to call hardware
 +  current CPU frequency:  Unable to call to kernel
 +  boost state support:
 +    Supported: yes
 +    Active: yes
 +~~~
 +
 +
 +If you have Turbo Boost enabled in the UEFI/BIOS, you can turn boost on (1) or off (0) by running
 +~~~bash
 +echo 1 > /sys/devices/system/cpu/cpufreq/boost
 +~~~
 +
 +Limite d'utilisation du CPU en %
 +~~~
 +# cat /sys/devices/system/cpu/intel_pstate/max_perf_pct 
 +100
 +~~~
 +
 +~~~bash
 +cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
 +~~~
 +
 +Exemble de "gorvernors" possible
 +* performance
 +* powersave
 +* userspace
 +* ondemand
 +* conservative
 +
 +~~~bash
 +cpufreq-set -r -u 2.24Ghz
 +#cpufreq-set --cpu 0 --governor conservative
 +cpufreq-set -r -g performance
 +
 +cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors 
 +echo "performance" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 
 +
 +#echo "3900000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
 +~~~
 +
 +`/etc/default/grub`
 +~~~bash
 +CMDLINE_LINUX_DEFAULT="quiet splash intel_pstate=disable processor.ignore_ppc=1"
 +~~~
 +
 +~~~bash
 +update-grub
 +~~~
 +
 +Pour remplacer `intel_pstate` par `acpi-cpufreq`
 +~~~bash
 +cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_driver
 +~~~
 +
 +La liste des drivers ici :
 +~~~bash
 +ls -1 /lib/modules/`uname -r`/kernel/drivers/cpufreq/
 +~~~
 +
 +
 +## BIOS frequency limitation
 +
 +Source : https://wiki.archlinux.org/index.php/CPU_frequency_scaling
 +
 +~~~bash
 +cat /sys/devices/system/cpu/cpu0/cpufreq/bios_limit
 +~~~
 +
 +
 +For trying this temporarily change the value in /sys/module/processor/parameters/ignore_ppc from 0 to 1. 
 +
 +~~~bash
 +echo 1 > /sys/module/processor/parameters/ignore_ppc
 +~~~
 +
 +For setting it permanent refer to Kernel modules or just read on. Add processor.ignore_ppc=1 to your kernel boot line or create
 +
 +`/etc/modprobe.d/ignore_ppc.conf`
 +~~~bash
 +
 +# If the frequency of your machine gets wrongly limited by BIOS, this should help
 +options processor ignore_ppc=1
 +~~~
 +
 +----
 +Avec cpulimit
 +
 +~~~bash
 +sudo apt-get install cpulimit
 +~~~
 +
 +http://www.linuxscrew.com/2012/07/03/limit-cpu-usage-of-linux-process/
 +
 +
 +## Perf 
 +
 +
 +perf
 +
 +~~~bash
 +apt-get install linux-base linux-tools
 +~~~
 +
 +https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4b715d24f4f14731c7b553cbb8604fe865cb8d3c
 +
 +Voir :
 +* https://developers.redhat.com/articles/2023/09/29/how-we-solved-hotspot-performance-puzzle
 +
 +~~~bash
 +# Disable SMP
 +echo off > /sys/devices/system/cpu/smt/control
 +
 +# Disable THP
 +echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
 +
 +# Disable turbo boost
 +echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo
 +~~~
 +
 +
 +### commande perf
 +
 +Voir :
 +  * https://developers.redhat.com/articles/2023/07/31/frame-pointers-untangling-unwinding?sc_cid=7013a000003Sm66AAC
 +  * https://www.brendangregg.com/perf.html
 +  * https://elinux.org/images/d/d0/Moll--cycle_accurate_profiling_with_perf.pdf
 +
 +
 +## Nombre de core / CPU
 +
 +/usr/bin/nproc (coreutils)
 +
 +getconf _NPROCESSORS_ONLN
 +
 +## Notes
 +
 +service cpufrequtils stop
 +
 +echo "performance" >  /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
 +
 +noatime
 +
 +Swap config
 +
 +Blacklist module
 +
 +## irqbalance
 +/proc/interrupts
 +cat /proc/irq/3/smp_affinity
 +
 +cpupower
 +
 +## Hotplug 
 +
 +http://www.linux-kvm.org/page/CPUHotPlug
 +
 +* switch to the monitor
 +* type `cpu_set <n+1> online`
 +* A new cpu should appear on /sys/devices/system/cpu
 +* bring it online by writting 1 to the "online" file inside that directory on guest
 +* Try adding as many cpus as possible, and make sure we at least do not crash.
 +
 +##  Monitoring
 +
 +pcp
 +http://www.pcp.io/docs/guide.html
 +https://www.youtube.com/watch?v=zrAjevr8_Ds
 +
 +## Kernel
 +
 +Real-time kernel ?
 +
 +http://www.tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap7sec80.html
 +
 +https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/pdf/Performance_Tuning_Guide/Red_Hat_Enterprise_Linux-6-Performance_Tuning_Guide-en-US.pdf
 +
 +https://wiki.archlinux.org/index.php/maximizing_performance
 +
 +https://tweaked.io/guide/kernel/
 +
 +http://www.redhat.com/promo/summit/2008/downloads/pdf/Wednesday_1015am_John_Shakshober_and_Larry_Woodman_Decoding_the_Code.pdf
 +
 +http://www.brendangregg.com/blog/2015-03-03/performance-tuning-linux-instances-on-ec2.html
 +
 +https://oracle-base.com/articles/linux/configuring-huge-pages-for-oracle-on-linux-64
 +
 +
 +## Autres
 +
 +~~~
 +root# dmidecode | grep HTT
 +HTT (Hyper-Threading Technology)
 +HTT (Hyper-Threading Technology)
 +
 +root# egrep 'siblings|cpu cores' /proc/cpuinfo | head -2
 +siblings : 2
 +cpu cores : 1
 +
 +root# grep '^flags\b' /proc/cpuinfo | tail -1
 +flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx
 +fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc pni
 +pclmulqdq est ssse3 cx16 sse4_1 sse4_2 popcnt aes f16c rdrand hypervisor lahf_lm ida
 +arat epb pln pts dts fsgsbase erms
 +
 +root# dmidecode | grep Count # tests that HTT is available *and* enabled
 +Core Count: 1
 +Thread Count: 2
 +Core Count: 1
 +Thread Count: 2
 +~~~
 +Source : https://www.oracle.com/docs/tech/ovm-performance.pdf
 +
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki