#!/usr/bin/python # # tempwatchd.py - temperature watching daemon # licensed under... well, do whatever you want. I do not care. # No warranty. Any kind of warranty. Use at your own risk. # Romano Giannetti import syslog import sys import time import os # # file frm where we read the temp and to which we do the throtthling # they will change in 2.6/2.7 cycle, but I think t should't be a big # deal to adapt it # tempfile="/proc/acpi/thermal_zone/THRM/temperature" throttfile="/proc/acpi/processor/CPU0/throttling" # # This are the temperature thresholds. CPU will be "throttled own" # to the T level specified in status_low if temperature reach upper_t, # and going back to full speed when it cools down to lower_t. # If your system does not cool down, try using an higher T-level # upper_t=74 lower_t=72 status_low=4 # # you shouldn't need to change anything here. If yes, please tell me # def read_temp(): fin=open(tempfile,"r") a=float(fin.readline().split()[1]) fin.close() return a def set_state(num): os.system("echo -n %d > %s" % (num, throttfile)) syslog.syslog(syslog.LOG_WARNING, "Processor state set to %d" % num) return syslog.openlog("test.py",syslog.LOG_PID) status=0 #normal run T0 syslog.syslog(syslog.LOG_WARNING, "Thermal control starting, temp=%f" % read_temp()) while 1: t=read_temp() if (status==0) and (t >= upper_t): syslog.syslog(syslog.LOG_WARNING, "Too hot: temp=%f" % t) set_state(status_low) status=status_low if (status==status_low) and (t>upper_t): syslog.syslog(syslog.LOG_CRIT, "WARNING, temperature running up: temp=%f" % t) if (status==status_low) and (t<=lower_t): syslog.syslog(syslog.LOG_WARNING, "Cooled down, temp=%f" % t) set_state(0) status=0 time.sleep(2) # never exit