aboutsummaryrefslogtreecommitdiffstats
path: root/cputemp2maxfreq.c
diff options
context:
space:
mode:
Diffstat (limited to 'cputemp2maxfreq.c')
-rw-r--r--cputemp2maxfreq.c55
1 files changed, 50 insertions, 5 deletions
diff --git a/cputemp2maxfreq.c b/cputemp2maxfreq.c
index 6921279..cd2da9f 100644
--- a/cputemp2maxfreq.c
+++ b/cputemp2maxfreq.c
@@ -13,6 +13,7 @@
#include "argparse.h"
#include "logger.h"
#include "cputemp.h"
+#include "cpulist.h"
// Set default config
struct s_config config={
@@ -32,8 +33,19 @@ struct s_config config={
0, // Don't use unix timestamps in log outputs
-1, // Transition latency, default to autodetect
0, // Do not keep state on exit (Set CPU to lowest frequency)
+ -1, // Physical CPU to change
+};
+
+struct s_cpudata cpudata={
+ 0, // CPU's minimum frequency
+ 0, // CPU's maximum frequency
+ 0, // CPU's current frequency
+ 0, // CPU's current temperature
+ 0, // Governor's maximum scaling frequency
+ 0, // CPU's transition latency
+ NULL, // Pointer to the cpulist, set by cpulist_find_cpus
+ 0, // Number of CPU's in cpulist, set by cpulist_find_cpus
};
-struct s_cpudata cpudata;
void signal_handler(int signum)
{
@@ -61,6 +73,8 @@ int main(int argc,char **argv)
long int newfreq;
struct s_sensor sensor;
char *transition_latency_remark;
+ char sensor_string[20];
+ char sysfs_file[128];
argparse(argc,argv);
config.logger("%s version %s, buildtime %s %s",config.name,version(),__DATE__,__TIME__);
@@ -95,6 +109,12 @@ int main(int argc,char **argv)
} else {
config.logger("State on exit: Always set CPU to lowest frequency");
}
+ if (config.cpu<0)
+ {
+ config.logger("Physical CPU to change: all");
+ } else {
+ config.logger("Physical CPU to change: %d",config.cpu);
+ }
if ((config.max_temp<VALID_TEMP_MIN) || (config.max_temp>VALID_TEMP_MAX))
{
@@ -120,6 +140,12 @@ int main(int argc,char **argv)
if (strcmp(config.temp_input,"auto")==0)
{
config.logger("Starting temperature sensor autodetection");
+ if (config.cpu>=0)
+ {
+ sprintf(sensor_string,"Package id %d",config.cpu);
+ DEBUG1_MAIN("Searching for sensor \"%s\" because of -P option\n",sensor_string);
+ cputemp_find_sensor(sensor_string,&sensor);
+ }
for(count=0;autodetect_sensors[count]!=NULL;count++)
{
DEBUG1_MAIN("Searching for sensor \"%s\"\n",autodetect_sensors[count]);
@@ -143,14 +169,31 @@ int main(int argc,char **argv)
}
}
+// Find CPU's
+ cpulist_find_cpus();
+ if (cpudata.cpulist_len==0)
+ {
+ if (config.cpu>=0)
+ {
+ config.logger("No CPU's found for physical CPU %d, exiting",config.cpu);
+ } else {
+ config.logger("Failed to find any CPU, is sysfs mounted?");
+ }
+ 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");
+ sprintf(sysfs_file,"/sys/devices/system/cpu/%s/cpufreq/cpuinfo_min_freq",cpudata.cpulist[0]);
+ cpudata.min_freq=sysfs_read_long_int(sysfs_file);
+ sprintf(sysfs_file,"/sys/devices/system/cpu/%s/cpufreq/cpuinfo_max_freq",cpudata.cpulist[0]);
+ cpudata.max_freq=sysfs_read_long_int(sysfs_file);
+ sprintf(sysfs_file,"/sys/devices/system/cpu/%s/cpufreq/scaling_max_freq",cpudata.cpulist[0]);
+ cpudata.scale_max=sysfs_read_long_int(sysfs_file);
if (config.transition_latency<0)
{
transition_latency_remark=transition_latency_remarks[0];
- cpudata.transition_latency=sysfs_read_long_int("/sys/devices/system/cpu/cpufreq/policy0/cpuinfo_transition_latency");
+ sprintf(sysfs_file,"/sys/devices/system/cpu/%s/cpufreq/cpuinfo_transition_latency",cpudata.cpulist[0]);
+ cpudata.transition_latency=sysfs_read_long_int(sysfs_file);
if (cpudata.transition_latency<1000) transition_latency_remark=transition_latency_remarks[2];
} else {
transition_latency_remark=transition_latency_remarks[1];
@@ -158,6 +201,7 @@ int main(int argc,char **argv)
}
config.logger("CPU data:");
+ config.logger("Number of CPU's: %d",cpudata.cpulist_len);
config.logger("Minimum frequency: %ld",cpudata.min_freq);
config.logger("Maximum frequency: %ld",cpudata.max_freq);
config.logger("Scaling maximum frequency: %ld",cpudata.scale_max);
@@ -170,6 +214,7 @@ int main(int argc,char **argv)
{
// If we have to fail now, there's not much we can do because we have no data
config.logger("Invalid CPU data, exiting");
+ cpulist_free();
exit(1);
}