#include #include #include #include #include "cputemp2maxfreq.h" #include "cpufreq.h" #include "logger.h" #include "cpulist.h" extern struct s_cpudata cpudata; extern struct s_config config; void failsafe(int code) { // Close CSV log if used if (config.csvfile!=NULL) csvlog_close(); if (((config.keepstate==1) && (code!=0)) || config.keepstate==0) { // First try to set the CPU to it's minimum frequency if (cpufreq_set_long_int("scaling_max_freq",cpudata.min_freq,100)>0) { config.logger("Set scaling frequency to CPU's minimum frequency"); cpulist_free(); exit(code); } config.logger("Failed to set scaling frequency to CPU's minimum frequency, error: %d (%s)",errno,strerror(errno)); // If that failed, try the fallback frequency if (cpufreq_set_long_int("scaling_max_freq",config.fallback_freq,100)>0) { config.logger("Set scaling frequency to fallback frequency"); cpulist_free(); exit(code); } config.logger("Failed to set scaling frequency to fallback frequency, error: %d (%s)",errno,strerror(errno)); // Everything failed, issue a warning config.logger("All safety measures failed, watch out not to fry your hardware"); } else { // User asked for no action config.logger("Keeping current state due to -k option"); } cpulist_free(); exit(code); }