CPU frequency scaling (Italiano)

From ArchWiki
Revision as of 18:21, 10 October 2011 by Veleno77 (Talk | contribs) (parte del wiki tradotto)

Jump to: navigation, search

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:CPU frequency scaling (Italiano)#)
Warning: Questa pagina è in fase di revisione e potrebbe non essere aggiornata. Seguite per ora le istruzioni della versione inglese.

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

La variazionde della frequenza della CPU è una tecnologia rivolta principalmente ai notebook che consente al sistema operativo di variare la velocità di funzionamento della CPU in base al sistema ed al consumo di energia. Per esempio, rallentando la CPU quando un notebook è alimentato dalla batteria, preserva la durata della batteria stessa. Intel definisce questa tecnologia SpeedStep. L'equivalente tecnologia di AMD è detta PowerNow! o Cool'n'Quiet.


cpufreq si riferisce l'infrastruttura del kernel che implementa la variazione della frequenza della CPU. Questa tecnologia consente al sistema operativo di scalare la velocità della CPU verso l'alto o verso il basso in modo da risparmiare energia. Le frequenze della CPU possono essere scalati automaticamente a seconda del carico del sistema, in risposta agli eventi ACPI, o manualmente da programmi userspace.

Come minimo, i moduli del kernel necessari devono essere caricati e poi deve essere impostato un governatore . Configurazioni più avanzate possono includere una combinazione di cpufrequtils, acpid , laptop-mode-tools e strumenti grafici forniti per l'ambiente desktop.

cpufrequtils

Template:Package Official è un insieme di utility in userspace progettate per supportare la variazione di frequenza della CPU. Il pacchetto non è necessario per effettuare il ridimensionamento, ma è altamente consigliato in quanto fornisce strumenti a riga di comando e uno script per impostare il demone governatore all'avvio (si veda demone ).

Il pacchetto Template:Package Official è reperibile nel repository [extra]:

# pacman -S cpufrequtils

Configurazione

Il processo di configurazione della variazione di frequenza della CPU è suddivisa in tre fasi:

  1. Caricare il driver appropriato in grado di gestire la frequenza della CPU
  2. Caricare il governatore/i desiderati per lo scaling CPU
  3. Selezionare un metodo per gestire il cambiamento e la messa a punti dei governatori:
    • Manualmente attraverso l'interfaccia /sys o cpufreq-set (da cpufrequtils),
    • Tramite il demone cpufrequtils ,
    • Laptop Mode Tools,
    • Eventiacpid,
    • Applets/utility del proprio ambiente desktop,
    • o una combinazione dei questi.

Driver per la frequenza della CPU

Al fine che la variazione di frequenza funzioni correttamente, il sistema operativo deve prima conoscere i limiti della/e CPU. Per fare questo, un modulo del kernel è caricato in grado di leggere e gestire le specifiche della/e CPU. Si noti che questi moduli possono esigere di funzioni correlate abilitate nel BIOS, che possono essere etichettati come: Speedstep, Cool and Quiet, PowerNow!, o ACPI. Se avete un processore a 64 bit, è molto probabile che il driver appropriato sia Template:Codeline per processori Intel o Template:Codeline per processori AMD K8/K10 (Athlon 64, Opteron e Phenom). Questi moduli sono costruiti per il kernel 32 e 64-bit kernel, anche se si esegue un kernel a 32 bit sul proprio hardware a 64 bit sono probabilmente ancora quelli i driver necessari. Per vedere una lista completa dei driver disponibili, eseguire il seguente comando:

$ ls /lib/modules/$(uname -r)/kernel/drivers/cpufreq/

La seguente tabella contiene una lista parzioale dei driver disponibili per la gestione della frequenza (Adapted from kernel source file Template:Filename).

Module Description
acpi-cpufreq CPUFreq driver che utilizza le ACPI Processor Performance States. Questo driver supporta anche i processori Intel Enhanced Speedstep (precedentemente supportato dal deprecato modulo speedstep-centrino).
speedstep-ich CPUFreq driver per alcuni processori per laptop Intel Pentium III (Coppermine), tutti i processori Intel mobile Pentium III-M (Tualatin), Pentium 4 P4-M su sistemi che hanno un southbridge Intel ICH2, ICH3 or ICH4 .
speedstep-smi CPUFreq driver per alcuni processori per laptop Intel Pentium III (Coppermine), tutti i processori Intel mobile Pentium III-M (Tualatin) su sistemi che hanno un southbridge Intel 440BX/ZX/MX .
powernow-k8 CPUFreq driver processori K8/K10 Athlon64/Opteron/Phenom.
powernow-k7 CPUFreq driver processori AMD K7 mobile.
cpufreq-nforce2 CPUFreq driver per il cambiamento dell' FSB su piattaforme nForce2. (AMD K7, Socket A)
pcc-cpufreq Questo driver supporta l'interfaccia di controllo della frequenza di Clock dei processori da Hewlett-Packard e Microsoft Corporation, che è utile in alcuni server Proliant.
p4-clockmod CPUFreq driver processori Intel Pentium 4/XEON. Quando è abilitato lo abbasserà soltanto la temperatura della CPU saltando la frequenza di clocks.
Probabilmente si preferisce usare un driver Speedstep al suo posto.


Aper caricare un dricer per la gestione della CPU manualmente eseguire:

# modprobe acpi-cpufreq

Note that if you attempt to load the wrong module you will get get an error such as

FATAL: Error inserting acpi_cpufreq ([...]/acpi-cpufreq.ko): No such device

Once the appropriate cpufreq driver is loaded, detailed information about the CPU(s) can be displayed by running: Template:Command

To load the driver automatically at startup, add the appropriate driver to the MODULES array within Template:Filename. For example:

MODULES=(acpi-cpufreq)

Scaling governors

Governors can be thought of as pre-configured power schemes for the CPU. These governors must be loaded as kernel modules in order to be seen by user space programs. One may load as many governors as desired (only one will be active on a CPU at any given time).

Available governors:

Template:Codeline (default)
The performance governor is built into the kernel and runs the CPU(s) at maximum clock speed
Template:Codeline (recommended)
Dynamically switches between the CPU(s) available clock speeds based on system load
Template:Codeline
Similar to Template:Codeline, but the CPU(S) clock speed switches gradually through all its available frequencies based on system load
Template:Codeline
Runs the CPU(s) at minimum speed
Template:Codeline
Manually configured clock speeds by user

For Desktops and most systems, the ondemand governor can provide the best compromise between heat emission, power consumption, performance, and manageability. For Laptops or other mobile systems, the conservative governor can possibly provide significant savings in power consumption.

Load the desired governor(s) with Template:Codeline. For example:

# modprobe cpufreq_ondemand
# modprobe cpufreq_userspace

Or, add the desired governor(s) to the MODULES array in Template:Filename and reboot.

MODULES=(acpi-cpufreq cpufreq_ondemand cpufreq_powersave)

To see which governors have been loaded:

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

Manually set the governor by running the Template:Codeline command (as root). For example:

# cpufreq-set -c 0 -g ondemand

Note that the previous command only sets the governor for the first processor! Multicore or multiprocessor systems require the -c flag to set the governor for a specific core and to repeat for each remaining. Numbering starts from 0 not 1!

For a quad core chip:

# for i in 0 1 2 3; do cpufreq-set -c $i -g ondemand; done

For a dual core chip:

# for i in 0 1; do cpufreq-set -c $i -g ondemand; done

Note: These settings will not be preserved after a reboot/shutdown. See the #Daemon section below for configuring cpufreq governors at boot.

Additional options such as upper and lower frequency bounds used by the governor can optionally be set by using the -u and -d options. A processors valid frequencies can be seen by calling cpufreq-info. For example, to set the second core's upper frequency bound as 2.00Ghz and its lower bound as 1.00Ghz:

# cpufreq-set -c 1 -g ondemand -u 2.00Ghz -d 1.00Ghz

To manually set a processor to a specific frequency the userspace governor is used. For example, to set core 0 to 2.50Ghz and core 1 to 800Mhz:

# cpufreq-set -c 0 -g userspace -f 2.50Ghz
# cpufreq-set -c 1 -g userspace -f 800Mhz

Run Template:Codeline or Template:Codeline for more information.

For those who would like a GUI for setting governors or frequency there is trayfreq, a GTK+ application that sits in the system tray.

The monitoring of CPU clock in real-time is accomplished by running:

$ watch grep \"cpu MHz\" /proc/cpuinfo

Improving ondemand performance

With the out-of-the-box configuration, the ondemand governor will result in a slight but measurable and noticeable loss of performance. It will not clock up the CPU when it is at lower than 95% usage, and will sample the usage at the fastest possible frequency when at full clock speeds in order to clock back down as soon as possible.

Tuning the governor for your needs can reduce the performance loss to the point where it is negligible/non-existent if you are willing to lose a lot of the power savings. If you just want to save power while idle, lowering the up_threshold to 11% and raising the sample_down_factor by an order of magnitude can accomplish this.

Tunables are available in Template:Filename once the governor is loaded and selected and can be preserved at reboot using Template:Filename.

Starting the cpufreq daemon in the background (i.e. with an '@' in Template:Filename) will likely cause Template:Filename to be processed before the cpufreq daemon has a chance to change the governor. Make sure that the cpufreq daemon script will have finished running before the tunables are set. Example:

Template:File

Changing the Template:Codeline governor's threshold

To change when the Template:Codeline governor switches to a higher multiplier, one can manipulate Template:Filename. Determine the current setting by issuing the following command as root:

# cat /sys/devices/system/cpu/cpufreq/ondemand/up_threshold

The value returned should be Template:Codeline, the default setting as of kernel version 3.0. This means that the Template:Codeline governor currently increases the clock rate if a core reaches 95% utilization. This can be changed, for example:

# echo -n 15 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
ondemand governor sampling-down-factor

sampling_down_factor is another global ondemand global tunable.

Set to 1 it makes no changes from existing behavior, but set to greater than 1 (e.g. 100) it acts as a multiplier for the scheduling interval for reevaluating load when the CPU is at its top speed due to high load. This improves performance by reducing the overhead of load evaluation and helping the CPU stay at its top speed when truly busy, rather than shifting back and forth in speed. This tunable has no effect on behavior at lower speeds/lower CPU loads.

Read the value (default: 1):

# cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor

Set the value:

# echo -n 10 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor

Tuning conservative governor

While the conservative governor switches smoothly and utilizes all of the available frequencies, users may want to tune it further. Out-of-the-box it will clock the CPU up when load reaches 75% and clock down when load drops to 20%. As with the ondemand governor, decreasing the Template:Codeline may improve performance and responsiveness.

Tunables are available in Template:Filename. Refer to the #Improving ondemand performance section for important advice regarding making this changes permanent, and potential daemon loading issues.

Changing the Template:Codeline governor's thresholds

Determine the current Template:Codeline setting by issuing the following command as root:

# cat /sys/devices/system/cpu/cpufreq/conservative/up_threshold

The value returned should be Template:Codeline, the default setting as of kernel version 3.0. This means that the Template:Codeline governor currently increases the clock rate to the next highest speed if a core reaches 75% utilization. The can be changed, for example:

# echo -n 40 > /sys/devices/system/cpu/cpufreq/conservative/up_threshold
Note: The minimum value one can enter must be above the one in Template:Codeline; entering a value under that results in the error, "bash: echo: write error: Invalid argument"

Similarly the Template:Codeline value can be read and modified via Template:Filename. The default value should be Template:Codeline as of kernel version 3.0. This means that the Template:Codeline governor decreases the clock rate to the next lowest speed if a core falls to 20% utilization, which is a sensible default.

While the down sampling rate can also be adjusted for the Template:Codeline governor, increasing it may only help with occasional low usage CPU spikes during high usage applications, as the Template:Codeline is a much more direct control for down scaling which does not exist on the Template:Codeline governor.

Be aware that setting Template:Codeline too close to Template:Codeline may result in constant CPU switching, which might be something desirable for certain users and not for others. Setting Template:Codeline or Template:Codeline too low may result in the CPU being clocked higher than it needs sacrificing power saving for performance, and setting Template:Codeline too high may result in decreased performance, but reduced power consumption. Experiment to find the optimal values for your system and your needs.

Interaction with ACPI events

Users may configure scaling governors to switch automatically based on different ACPI events such as connecting the AC adapter or closing a laptop lid. A quick example is given below, however it may be worth reading full article on acpid.

Events are defined in Template:Filename. If the Template:Package Official package is installed, the file should already exist and be executable. For example, to change the scaling governor from Template:Codeline to Template:Codeline when the AC adapter is disconnected and change it back if reconnected:

Template:File

Daemon

Template:Codeline includes a daemon which allows users to set the desired scaling governor and min/max clock speeds for all processor cores at boot-time.

Before starting the daemon, edit Template:Filename as root, selecting the desired governor and setting the min/max speed for your CPU(s), for example:

Template:File

Note: The exact min/max values of the CPU(s) can be determined by running Template:Codeline after loading the CPU driver (e.g. Template:Codeline). However, these values are optional. Users may omit them entirely by deleting or commenting out the min/max_freq lines; scaling will work automatically.

With the appropriate configuration, start the daemon with the following command: Template:Cli

To start the daemon automatically at startup, add Template:Codeline to the DAEMONS array in Template:Filename, for example:

DAEMONS=(syslog-ng networkmanager @alsa @crond @cupsd @cpufreq)

Privilege Granting Under Gnome

Gnome has a nice applet to change the governor on the fly. To use it without the need to enter the root password, simply create Template:Filename and populate it with the following:

[org.gnome.cpufreqselector]
Identity=unix-user:USER
Action=org.gnome.cpufreqselector
ResultAny=no
ResultInactive=no
ResultActive=yes

Where the word USER is replaced with the username of interest.

The Template:Package AUR package in the AUR contains a similar .pkla file for authorizing all users of the power group to change the governor.

Laptop Mode Tools

If you are already using or plan to use Laptop Mode Tools for other power saving solutions, then you may want to let it also manage CPU frequency scaling. To do so, you just have to insert the appropriate frequency driver to the MODULES array in Template:Filename (see #CPU frequency driver above) and then go through the Template:Filename file to define governors, frequencies and policies. You will not need to load other modules and daemons or to set up scaling governors and interaction with ACPI events. Please refer to Laptop Mode Tools for more details.

Troubleshooting

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:CPU frequency scaling (Italiano)#)
  • Some applications, like ntop, do not respond well to automatic frequency scaling. In the case of ntop it can result in segmentation faults and lots of lost information as even the Template:Codeline governor cannot change the frequency quickly enough when a lot of packets suddenly arrive at the monitored network interface that cannot be handled by the current processor speed.
  • Some CPU's may suffer from poor performance with the default settings of the Template:Codeline governor (e.g. flash videos not playing smoothly or stuttering window animations). Instead of completely disabling frequency scaling to resolve these issues, the aggressiveness of frequency scaling can be increased by lowering the up_threshold sysctl variable for each CPU. See #Changing the ondemand governor's threshold.
  • Sometimes the ondemand governor may not throttle to the maximum frequency but one step below. This can be solved by setting max_freq value slightly higher than the real maximum. For example, if frequency range of the CPU is from 2.00 GHz to 3.00 GHz, setting max_freq to 3.01 GHz can be a good idea.
  • Some CPU/BIOS configurations may have difficulties to scale to the maximum frequencies or scale to higher frequencies at all. Sadly there is only a workaround right now. Add "processor.ignore_ppc=1" to your kernel boot line and/or edit the value in Template:Filename from 0 to 1. (It seems to be fixed at least since kernel 3.0, for Toshiba NB-100)
  • Some combinations of ALSA drivers and sound chips may cause audio skipping as the governor changes between frequencies, switching back to a non-changing governor seems to stop the audio skipping.




La variazionde della frequenza della CPU è una tecnologia rivolta principalmente ai notebook che consente al sistema operativo di variare la velocità di funzionamento della CPU in base al sistema ed al consumo di energia. Per esempio, rallentando la CPU quando un notebook è alimentato dalla batteria, preserva la durata della batteria stessa. Intel definisce questa tecnologia SpeedStep. L'equivalente tecnologia di AMD è detta PowerNow! o Cool'n'Quiet.

cpufrequtils

Procedura

1. Installare cpufrequtils

# pacman -S cpufrequtils

2.Caricare i moduli del kernel

Intel:

# modprobe acpi-cpufreq

Alcune vecchie CPU potrebbero restituire un errore simile al seguente:

FATAL: Error inserting acpi_cpufreq ([...]/acpi-cpufreq.ko): No such device

In questo caso occorre sostituire acpi-cpufreq con uno dei seguenti moduli: speedstep-centrino, p4-clockmod, speedstep-ich. È comunque da notare che speedstep-centrino è deprecato, mentre p4-clockmod supporta solo i governor performance e powersave.

AMD:

# modprobe powernow-k{6,7,8}

3. Caricare i gestori della variazione

# modprobe cpufreq_ondemand
# modprobe cpufreq_powersave

Questi moduli possono essere aggiunti all'elenco MODULES all'interno di/etc/rc.conf, così da mantenere la configurazione ad ogni riavvio. Per esempio:

 MODULES=( acpi-cpufreq cpufreq_ondemand cpufreq_powersave vboxdrv fuse fglrx iwl3945 ... )

o, se si ha un processore AMD:

 MODULES=( powernow-k8 cpufreq_ondemand cpufreq_powersave vboxdrv fuse fglrx iwl3945 ... )

4. Modificare /etc/conf.d/cpufreq come root, selezionando i gestori desiderati:

#configuration for cpufreq control
# valid governors:
#  ondemand, performance, powersave,
#  conservative, userspace
governor="ondemand"

# valid suffixes: Hz, kHz (default), MHz, GHz, THz
min_freq="1GHz"
max_freq="2GHz"

Nota: le linee min_freq e max_freq dovrebbero essere commentate, dato che i driver presenti nel kernel possono rilevare questi valori automaticamente. Per esserne certi, lanciare:

# cpufreq-info

e controllarne l'output.

Demone cpufreq

Opzionalmente, si può lanciare cpufreqd come demone

# /etc/rc.d/cpufreq start

Aggiungere cpufreq alla lista DAEMONS in /etc/rc.conf.

GUI

Installare e configurare un'interfaccia grafica nel proprio Ambiente Desktop. Per KDE si può scegliere tra KLaptop e KPowersave. Quest'ultimo è reperibile tramite AUR ed è più completo. La versione in sviluppo (devel-version) è raccomandata, visto che non dipende più da powersave.

Ulteriori informazioni sono disponibili alla pagina cpufrequtils.

Nota per processori MultiCore:

1. La variazione sarà applicata solo al primo core cpu0. Aggiungere queste linee al proprio /etc/rc.local per applicare la variazione ad ogni core.

  1. echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
  2. echo "ondemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor

...e così via fin a quando necessario, in base al numero di core.

2. Se il secondo core non segue le regole di variazione impostate dopo un "suspend to ram" (Stand by), modificare /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux ed aggiungere le linee necessarie, per esempio:

# echo "ondemand">/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor

prima della riga finale ("exit$RET").

Altre risorse

cpufrequtils - informazioni per utenti esperti