aboutsummaryrefslogtreecommitdiffstats
path: root/cputemp2maxfreq.c
diff options
context:
space:
mode:
Diffstat (limited to 'cputemp2maxfreq.c')
-rw-r--r--cputemp2maxfreq.c29
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");