Tuning sous Debian

Par défaut, le governor de changement de fréquence du CPU optimise la consommation d'énergie. C'est intéressant mais pour un serveur avec une fréquence si petite, cela fait la différence. Ici, la taille compte ;).

Pour commencer, vérifions le governor utilisé :

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
powersave
powersave
powersave
powersave

Et de manière cohérente, la fréquence de la CPU est loin d'être à son maximum :

grep -E '^model name|^cpu MHz' /proc/cpuinfo
model name      : Intel(R) Celeron(R) CPU  N3150  @ 1.60GHz
cpu MHz         : 479.980
model name      : Intel(R) Celeron(R) CPU  N3150  @ 1.60GHz
cpu MHz         : 479.980
model name      : Intel(R) Celeron(R) CPU  N3150  @ 1.60GHz
cpu MHz         : 479.980
model name      : Intel(R) Celeron(R) CPU  N3150  @ 1.60GHz
cpu MHz         : 482.226

Le paquet cpufrequtils contient le programme cpufreq-info offrant peu plus de détails :

sudo cpufreq-info
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.         
analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 0.97 ms.
  hardware limits: 480 MHz - 2.08 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 480 MHz and 2.08 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 894 GHz (asserted by call to hardware).
[...]
analyzing CPU 3:                      
  driver: intel_pstate               
  CPUs which run at the same hardware frequency: 3   
  CPUs which need to have their frequency coordinated by software: 3
  maximum transition latency: 0.97 ms.                                    
  hardware limits: 480 MHz - 2.08 GHz
  available cpufreq governors: performance, powersave             
  current policy: frequency should be within 480 MHz and 2.08 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.              
  current CPU frequency is 716 MHz (asserted by call to hardware). 

Pour changer le governor en performance (fréquence CPU montant plus facilement au maximum), il suffit de passer la commande suivante :

for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do [ -f $CPUFREQ ] || continue; echo -n performance > $CPUFREQ; done

Par contre, après un redémarrage, cela est perdu. Pour charger les governors au boot, activer le script d'init suivant :

sudo systemctl enable cpufrequtils.service

Créer un fichier de configuration /etc/default/cpufrequtils avec :

/etc/default/cpufrequtils
ENABLE="true"
GOVERNOR="performance"
MIN_SPEED="1000"

et lancer le service :

sudo systemctl start cpufrequtils.service

verifier son statut :

sudo systemctl status cpufrequtils.service
● cpufrequtils.service - LSB: set CPUFreq kernel parameters
   Loaded: loaded (/etc/init.d/cpufrequtils; generated; vendor preset: enabled)
   Active: active (exited) since Sun 2017-08-13 22:11:38 CEST; 12min ago
     Docs: man:systemd-sysv-generator(8)
 
Aug 13 22:11:38 popeye systemd[1]: Starting LSB: set CPUFreq kernel parameters...
Aug 13 22:11:38 popeye cpufrequtils[25261]: CPUFreq Utilities: Setting performance CPUFreq governor...CPU0...CPU1...CPU2...CPU3...done.
Aug 13 22:11:38 popeye systemd[1]: Started LSB: set CPUFreq kernel parameters.

Vérifions rapidement le governors :

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
powersave
powersave
powersave
powersave

La fréquence CPU n'est pas encore au max mais monte beaucoup plus facilement qu'avant :

grep -E '^model name|^cpu MHz' /proc/cpuinfo
model name      : Intel(R) Celeron(R) CPU  N3150  @ 1.60GHz
cpu MHz         : 617.382
model name      : Intel(R) Celeron(R) CPU  N3150  @ 1.60GHz
cpu MHz         : 1028.808
model name      : Intel(R) Celeron(R) CPU  N3150  @ 1.60GHz
cpu MHz         : 1467.968
model name      : Intel(R) Celeron(R) CPU  N3150  @ 1.60GHz
cpu MHz         : 699.414
cat /proc/interrupts  | grep enp            
 120:   22305151   22323261   22299110   22328592   PCI-MSI 524288-edge      enp1s0
 123:   11380352   11314317   11383781   11314080   PCI-MSI 1048576-edge      enp2s0

Bibliographie