diff options
author | PA4WDH | 2024-07-28 14:45:59 +0200 |
---|---|---|
committer | PA4WDH | 2024-07-28 14:45:59 +0200 |
commit | 36162d6931aaaf56c60c2e1c77cd3cdc2eba8363 (patch) | |
tree | 6bb22ce09315d14a5b7fb4ba2e5178d1b5dd9450 /cputemp2maxfreq.c | |
parent | FLush after writes to CSV file (diff) | |
download | cputemp2maxfreq-36162d6931aaaf56c60c2e1c77cd3cdc2eba8363.tar.gz cputemp2maxfreq-36162d6931aaaf56c60c2e1c77cd3cdc2eba8363.tar.bz2 cputemp2maxfreq-36162d6931aaaf56c60c2e1c77cd3cdc2eba8363.zip |
Add autodetection for temperature input
Diffstat (limited to 'cputemp2maxfreq.c')
-rw-r--r-- | cputemp2maxfreq.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/cputemp2maxfreq.c b/cputemp2maxfreq.c index 47b1f53..d3242b6 100644 --- a/cputemp2maxfreq.c +++ b/cputemp2maxfreq.c @@ -12,13 +12,14 @@ #include "version.h" #include "argparse.h" #include "logger.h" +#include "cputemp.h" // Set default config struct s_config config={ "", // Name of this program, set by argparse "conservative", // Governor 70000, // Temperature - "/sys/devices/virtual/thermal/thermal_zone0/temp", // Temperature input + "auto", // Temperature input 100000, // Frequency step 2000000, // Fallback frequency 10, // Interval @@ -49,7 +50,7 @@ int main(int argc,char **argv) { long int diff; long int newfreq; - + struct s_sensor sensor; char *transition_latency_remark; argparse(argc,argv); @@ -98,6 +99,30 @@ int main(int argc,char **argv) exit(1); } +// Autodetect temperature input if needed + if (config.temp_input[0]!='/') + { + if (strcmp(config.temp_input,"auto")==0) + { + DEBUG1_MAIN("Starting temperature sensor detection with name \"Package id 0\"\n"); + cputemp_find_sensor("Package id 0",&sensor); + } else { + DEBUG1_MAIN("Starting temperature sensor detection with name \"%s\"\n",config.temp_input); + cputemp_find_sensor(config.temp_input,&sensor); + } + if (sensor.valid==1) + { + DEBUG1_MAIN("Found sensor \"%s\"\n",sensor.name); + DEBUG1_MAIN("Sensor file: %s\n",sensor.filename); + strncpy(config.temp_input,sensor.filename,sizeof(config.temp_input)); + config.logger("Detection returned temperature input: %s",config.temp_input); + config.logger("Temperature input name: %s",sensor.name); + } else { + config.logger("Detection failed to return a valid sensor, set it using -i"); + 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"); |