{"id":15,"date":"2011-07-11T12:58:43","date_gmt":"2011-07-11T12:58:43","guid":{"rendered":"http:\/\/blog.cpscotti.com\/?p=15"},"modified":"2011-07-11T21:27:35","modified_gmt":"2011-07-11T21:27:35","slug":"preventing-cpu-meltdown","status":"publish","type":"post","link":"http:\/\/cpscotti.com\/blog\/?p=15","title":{"rendered":"Preventing CPU Meltdown"},"content":{"rendered":"<p>Ok, I&#8217;ll try this.<\/p>\n<p>For real now.<\/p>\n<p>Yesterday my notebook&#8217;s fan had its last spins. The bastard was bugging me for a while but now it&#8217;s gone.. was I a bit more emotional I&#8217;d probably be crying now.<\/p>\n<p>So basically, my notebook is running on fukushima-mode. No fan.. wild and dangerous computing. The problem is that whenever I get into something serious (any long compilation or watching a 1080p snowboarding video like <a title=\"this\" href=\"http:\/\/www.youtube.com\/watch?v=kh29_SERH0Y\">this<\/a>) it grows hotter and hotter until the kernel steps in with a VERY mean attitude, killing the whole thing and shutting down the machine and interrupting whatever I was doing.<\/p>\n<p>At some point I figured I could manually <em>kill -STOP $naughtyJob<\/em> wait for the cpu to cool it&#8217;s guts and then let the naughtyjob continue whatever it was doing with -CONT. Nice idea.. I bet you can&#8217;t do that on Windows &#8211; well, probably you can but I don&#8217;t wanna know and don&#8217;t come telling me!<\/p>\n<p>The problem is that sometimes you just don&#8217;t realise the damn machine is already too hot until you see the shutdown screen and start raving about the new FAN that&#8217;s not even on the mail yet! The rational thing a Control Engineer would do is automate the -STOP\/-CONT process &#8211; behold the life-saving shell script! Wasn&#8217;t god written in awk anyway?<\/p>\n<p>The basic idea is to set a &#8220;too hot&#8221; and a &#8220;chilling&#8221; points; if it&#8217;s too hot the script STOPs the processor using more CPU at the time. If it&#8217;s chilling, the script CONTs those processes. You definitely need a quite big band in between the two points (see <a href=\"http:\/\/en.wikipedia.org\/wiki\/Hysteresis\">Hysteresis<\/a>)\u00a0 so that your script won&#8217;t run amok on you and get everything even worse.. I&#8217;m with 65\u00baC\/80\u00baC now.<\/p>\n<p>Drumroll please&#8230; (Ok.. this is just a hour-hack.. works for me, saving the day till my new fan arrives)<\/p>\n<p>[sourcecode language=&#8221;shell&#8221;]<br \/>\n#!\/bin\/bash<br \/>\nhotT=80<br \/>\ncoolT=65<\/p>\n<p>watchT=1<br \/>\ncoolDownT=3<\/p>\n<p>while true;<br \/>\ndo<br \/>\nsleep $watchT<br \/>\ntemp=`cat \/proc\/acpi\/thermal_zone\/THM\/temperature | awk &#8216;{print $2}&#8217;`<\/p>\n<p>if [ $temp -lt $coolT ]<br \/>\nthen<br \/>\necho &quot;Chilling&quot;<br \/>\ncat haltedReactors.list | while read -e tLine;<br \/>\ndo<br \/>\nfukuPid=`echo $tLine | awk &#8216;{print $2}&#8217;`<br \/>\nfukuComm=`echo $tLine | awk &#8216;{print $3}&#8217;`<br \/>\nkill -CONT $fukuPid<br \/>\nzenityLine=&quot;Restarted &quot;$fukuComm&quot;, pid: &quot;$fukuPid<br \/>\nzenity &#8211;info &#8211;text &quot;$zenityLine&quot;&amp;<br \/>\ndone<br \/>\nrm -f haltedReactors.list<br \/>\ntouch haltedReactors.list<br \/>\nfi<\/p>\n<p>if [ $temp -gt $hotT ]<br \/>\nthen<br \/>\necho &quot;Burning&quot;<\/p>\n<p>fukushimaLine=`ps -A -o pcpu,pid,comm &#8211;sort pcpu | tail -n 1`<br \/>\nfukushimaPid=`echo $fukushimaLine | awk &#8216;{print $2}&#8217;`<br \/>\nfukushimaComm=`echo $fukushimaLine | awk &#8216;{print $3}&#8217;`<\/p>\n<p>kill -STOP $fukushimaPid<br \/>\nzenityLine=&quot;Stopped &quot;$fukushimaComm&quot;, pid: &quot;$fukushimaPid<br \/>\necho $zenityLine<br \/>\nzenity &#8211;info &#8211;text &quot;$zenityLine&quot;&amp;<\/p>\n<p>echo $fukushimaLine &gt;&gt; haltedReactors.list<br \/>\nsleep $coolDownT<\/p>\n<p>fi<\/p>\n<p>done<br \/>\n[\/sourcecode]<\/p>\n<p>I&#8217;m using this for two hours now. So far firefox-bin was paused twice and spotify once. On the bright side, the <em>hot machine&#8217;s<\/em> running strong since this ungodly morning started.<\/p>\n<p>Have fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ok, I&#8217;ll try this. For real now. Yesterday my notebook&#8217;s fan had its last spins. The bastard was bugging me for a while but now it&#8217;s gone.. was I a bit more emotional I&#8217;d probably be crying now. So basically, my notebook is running on fukushima-mode. No fan.. wild and dangerous computing. The problem is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,8,7],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-hack","category-linux","category-shell"],"_links":{"self":[{"href":"http:\/\/cpscotti.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cpscotti.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cpscotti.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cpscotti.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/cpscotti.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15"}],"version-history":[{"count":10,"href":"http:\/\/cpscotti.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/15\/revisions"}],"predecessor-version":[{"id":27,"href":"http:\/\/cpscotti.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/15\/revisions\/27"}],"wp:attachment":[{"href":"http:\/\/cpscotti.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cpscotti.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cpscotti.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}