diff options
Diffstat (limited to 'cputemp2maxfreq.c')
-rw-r--r-- | cputemp2maxfreq.c | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/cputemp2maxfreq.c b/cputemp2maxfreq.c index ebf5026..b023b79 100644 --- a/cputemp2maxfreq.c +++ b/cputemp2maxfreq.c @@ -10,17 +10,11 @@ #include "cputemp2maxfreq.h" #include "failsafe.h" #include "version.h" +#include "argparse.h" -// Valid frequencies are between 100MHz and 10GHz -#define VALID_FREQ_MIN 100000 -#define VALID_FREQ_MAX 10000000 - -// Valid temperatures are between 10 and 150 degrees -#define VALID_TEMP_MIN 10000 -#define VALID_TEMP_MAX 150000 - -struct s_cpudata cpudata; +// Set default config struct s_config config={"conservative",70000,"/sys/devices/virtual/thermal/thermal_zone0/temp",100000,2000000,10}; +struct s_cpudata cpudata; void signal_handler(int signum) { @@ -28,12 +22,13 @@ void signal_handler(int signum) failsafe(0); } -int main() +int main(int argc,char **argv) { long int diff; long int newfreq; printf("Version %s, buildtime %s %s\n",version(),__DATE__,__TIME__); + argparse(argc,argv); // Print configuration printf("Configuration:\n"); @@ -43,16 +38,37 @@ int main() printf("Frequency step: %ld\n",config.freq_step); printf("Fallback frquency: %ld\n",config.fallback_freq); printf("Interval: %d\n",config.interval); + printf("\n"); + + if ((config.max_temp<VALID_TEMP_MIN) || (config.max_temp>VALID_TEMP_MAX)) + { + printf("Invalid temperature, range is %d-%d\n",VALID_TEMP_MIN,VALID_TEMP_MAX); + exit(1); + } + + if ((config.freq_step<VALID_STEP_MIN) || (config.freq_step>VALID_STEP_MAX)) + { + printf("Invalid frequency step, range is %d-%d\n",VALID_STEP_MIN,VALID_STEP_MAX); + exit(1); + } + + if ((config.interval<VALID_INTERVAL_MIN) || (config.interval>VALID_INTERVAL_MAX)) + { + printf("Invalid poll interval, range is %d-%d\n",VALID_INTERVAL_MIN,VALID_INTERVAL_MAX); + exit(1); + + } // Get and validate CPU data cpudata.min_freq=sysfs_read_long_int("/sys/devices/system/cpu/cpufreq/policy0/cpuinfo_min_freq"); cpudata.max_freq=sysfs_read_long_int("/sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq"); cpudata.scale_max=sysfs_read_long_int("/sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq"); - printf("\nCPU data:\n"); + printf("CPU data:\n"); printf("Minimum frequency: %ld\n",cpudata.min_freq); printf("Maximum frequency: %ld\n",cpudata.max_freq); printf("Scaling maximum frequency: %ld\n",cpudata.scale_max); + printf("\n"); if ((cpudata.min_freq<VALID_FREQ_MIN) || (cpudata.min_freq>VALID_FREQ_MAX) || (cpudata.max_freq<VALID_FREQ_MIN) || (cpudata.max_freq>VALID_FREQ_MAX) || @@ -63,6 +79,18 @@ int main() exit(1); } +// Modify fallback frequency is needed + if (config.fallback_freq<cpudata.min_freq) + { + printf("Fallback frequency is lower than CPU's minimum frequency, setting to %ld.\n",cpudata.min_freq); + config.fallback_freq=cpudata.min_freq; + } + if (config.fallback_freq>cpudata.max_freq) + { + printf("Fallback frequency is higher than CPU's maximum frequency, setting to %ld.\n",cpudata.max_freq); + config.fallback_freq=cpudata.max_freq; + } + // Set the governor if (cpufreq_set_str("scaling_governor",config.governor,0)<0) { |