Ceci est une ancienne révision du document !
1
By way of introduction, I should say that my PC doesn't encounter overheating problems for virtually all programs. However, I do quite a lot of video transcoding (altering an audio-video file from one format to another). It is highly CPU intensive, uses 100% of all CPU cores and runs for long periods. As a result, my CPU gets excessively hot. So I have a requirement to prevent this program from killing my CPU. It is true that the CPU is continuously monitoring temperature and that, when a critical temperature is reached, it would take certain actions (for example, drastically reducing the clock speed in order to reduce the power consumption), until the temperature falls to a sub-critical value. This is all very well as it prevents an actual meltdown event, but running components at high temperatures on a continuous basis will seriously shorten their life. I use an excellent GUI program called HandBrake for my transcoding – a Command Line version is also available. Because this is not a time-critical application (for me), I want to, somehow, suspend/resume it based on the temperature of the CPU. The motherboard and CPU contain a number of sensors of various kinds, which provide information to the Linux Kernel. However, this is of no help to me as I just need a simple, standard way to monitor the temperature.
En introduction, je dois dire que, pour presque tous les programmes, mon PC ne connait pas de problèmes de surchauffe. Cependant, je fais beaucoup de transcodage vidéo (en changeant le format du fichier audio-vidéo). Cela utilise le processeur de façon très intensive, se sert de 100 % de tous ses cœurs et tourne pendant de longues périodes. Par conséquent, mon processeur devient beaucoup trop chaud. Ainsi, je dois empêcher ce programmer de tuer mon CPU.
Il est vrai que le processeur surveille la température continuellement et que, quand une température critique est atteinte, il ferait le nécessaire (par exemple réduire de façon draconienne la vitesse de l'horloge pour pouvoir réduire la consommation d'électricité), jusqu'à ce que la température baisse pour atteindre un niveau inférieur au seuil critique. C'est bien en soit, car cela empêche la fusion complète du processeur, mais faire tourner des composants à de hautes températures continuellement, réduira sérieusement leur durée de vie.
Pour le transcodage, j'utilise un excellent programme à interface graphique, appelé HandBrake - une version en ligne de commande est disponible aussi. Puisque ce n'est pas une application où le temps est un facteur très important (pour moi), je veux pouvoir, d'une façon ou d'une autre, la suspendre/reprendre, selon la température du processeur. Il y a de nombreux capteurs de diverses sortes sur la carte-mère et dans le processeur qui fournissent des renseignements au Noyau Linux. Mais cela ne m'aide pas du tout, car je n'ai besoin que d'une façon simple et standard de surveiller la température.
2
So my programme is:- • Get the CPU temperature. • Find out how to suspend multiple processes. • Find out how to resume these multiple processes. • Write a simple script to maintain the CPU at an acceptable temperature. It turns out that the first step is the most interesting. A set of scripts has been maintained for a number of years for most distros to access hardware related information. By default, the latest Ubuntu (16.04) doesn't include the inxi package from the Universe repository (Community-maintained free and open-source software). You may need to select this repository – if it is not already selected. To install inxi, possibly with a few dependencies: sudo apt install inxi We don't need any special authorities to run the inxi command in a Terminal window; it has a very large number of possible options. For example, inxi with no options gives the result shown in the image at the top of this page.
Je prévois donc de : • Récupérer la température du processeur. • Apprendre comment suspendre de multiples processus. • Apprendre comment reprendre ces multiples processus. • Écrire un simple script qui maintiendra le CPU à une température acceptable.
Il s'avère que la première étape est la plus intéressante. Pour la plupart des distributions, un ensemble de scripts donnant accès aux informations concernant le matériel, est maintenu depuis de nombreuses années. Par défaut, la plus récente Ubuntu (la 16.04) ne contient pas le paquet inxi du dépôt Universe (logiciels gratuits et Open Source maintenus par la communauté). Vous pourriez avoir besoin de sélectionner de dépôt, s'il n'est pas déjà sélectionné. Pour installer inxi, avec quelques dépendances, sans doute :
sudo apt install inxi
Nous n'avons pas besoin de droits spéciaux pour exécuter la commande inxi dans un Terminal ; il comporte de très nombreuses options possibles. Par exemple, inxi, sans aucune option donne le résultat montré dans l'image en haut de cette page.
3
Which looks promising, however when coloured characters are shown on the terminal, this is done by transmitting non-text characters to the screen – in a text editor this looks like:- #[1;34mCPU#[0;37m~Dual core Intel Core i3-3110M (-HT-MCP-)#[1;34mspeed/max#[0;37m~1239/2400 MHz…. Where the # represents some non-printable character. A good way of preparing a short description of your computer to send elsewhere would be to run: inxi -c0 > summary-file (the -c0 option specifies text-only output). and then email that summary-file. The summary-file looks like CPU~Quad core AMD FX-4350 (-MCP-) clocked at 1400 Mhz Kernel~3.16.0-4-amd64 x86_64 Up~8:08 Mem~1564.9/7905.2MB HDD~2000.4GB(37.0% used) Procs~196 Client~Shell inxi~2.1.28
Ce qui semble prometteur, cependant, quand des caractères de couleur s'affichent sur le terminal, ce qui est fait en transmettant des caractères qui ne sont pas du text à l'écran. Dans un éditeur de texte, cela ressemble à ceci :
#[1;34mCPU#[0;37m~Dual core Intel Core i3-3110M (-HT-MCP-)#[1;34mspeed/max#[0;37m~1239/2400 MHz….
où le # représente un caractère qui ne s'imprimera pas.
Une bonne façon de préparer un court descriptif de votre ordinateur à envoyer ailleurs, serait de lancer :
inxi -c0 > summary-file (l'option -c spécifie une sortie composée uniquement de text).
et puis d'envoyer ce fichier-résumé par mail.
Le fichier-résumé ressemble à
CPU~Quad core AMD FX-4350 (-MCP-) clocked at 1400 Mhz Kernel~3.16.0-4-amd64 x86_64 Up~8:08 Mem~1564.9/7905.2MB HDD~2000.4GB(37.0% used) Procs~196 Client~Shell inxi~2.1.28
4
Two points: • You may notice I've switched to a different machine (for convenience) and that the output is now an ordinary text file, although it is not quite as easy to read as the coloured, formatted version. • I won't go through all the options, since the full documentation can be viewed with the man inxi command. We shall be mainly interested in the inxi -s command, as this shows the state of the sensors. This should work on all laptops, but might require some work on some older desktops. If inxi -s does not show any CPU temperature, then consider running the procedures detailed in https://help.ubuntu.com/community/SensorInstallHowto My inxi -s looks like this, but the amount of information you get will depend on your PC. I won't worry about the presence of those non-text characters as I just want to pick up the first two digits of the first number on the first line. For us this is a fixed layout. We can therefore bolt a couple of standard programs together: inxi -s | grep 'System Temperatures' | cut -b 66-67
5
The grep statement outputs all lines that have 'System Temperatures' in them (just the first line). This line is then piped into a cut command where we specify that we just want bytes 66 & 67 of the line. So running the above command should output 33. Note that other tools, such as 'sed', could do the same job, only with more flexibility. Moving on to the problem of suspending/resuming active processes, it turns out to be ridiculously easy! If we were to issue a “normal” killall 'program name' command, then all matching processes are sent a TERM signal, causing the processes to terminate themselves. However, we can send less destructive signals. killall -s STOP 'progam name' will cause all the relevant processes to pause themselves. killall -s CONT 'progam name' will cause all the relevant processes to resume themselves. I've written a short monitoring script (called schedule.sh) which can be run from a Terminal window. It contains an infinite loop, so that when it is no longer wanted it has to be terminated by CTRL+C. Normally, I use it for HandBrake, which runs a program called 'ghb', but it could be used for any CPU-greedy program. So ./schedule.sh 'program name' should work for any program.
6
In choosing the hard-coded values for temperature, 59°C was really as hot as I wanted to go, but 45°C was chosen as a lower limit because the rate of cooling is proportional to the difference between the temperature of the hot object and the temperature of its surroundings. So there isn't any point in aiming for anything much lower. The range of 45° - 59° still gives a few minutes run-time between pauses, especially as the usual cooling methods are continuously removing some of the heat during the run phase. If I run any other programs concurrently, then they are unaffected; any excessive CPU usage would simply cause the monitored program to get suspended slightly more often. I don't claim that this is anything other than a sticking plaster solution to my problem. However, I've discovered useful new features of inxi and killall. I've included a Bash script for schedule.sh which may not be beautiful, but it works. It can also be found at http://pastebin.com/yiDfJ4iF So, to run my heavyweight transcoding program, protected against high temperatures:- • Run ./schedule.sh in a Terminal Window and leave it running • Run Handbrake in a GUI Window • Go and do something else. As an example of what inxi is capable of, I'll round off with a quick way of obtaining a display of some quite detailed information about my graphics card, using the -G parameter and adding a 'xx' parameter asks for extra, extra details.