diff options
author | PA4WDH | 2024-09-12 13:34:54 +0200 |
---|---|---|
committer | PA4WDH | 2024-09-12 13:34:54 +0200 |
commit | 03d8eb4eaf05e5f9929a765e04600dbcace8015f (patch) | |
tree | 41dda2ceef729a9b16f453c2c0741d84919263b3 | |
parent | Fix copyright headers (diff) | |
download | cputemp2maxfreq-03d8eb4eaf05e5f9929a765e04600dbcace8015f.tar.gz cputemp2maxfreq-03d8eb4eaf05e5f9929a765e04600dbcace8015f.tar.bz2 cputemp2maxfreq-03d8eb4eaf05e5f9929a765e04600dbcace8015f.zip |
Add cpufreq_get_long_int as generic function to get cpufreq data
-rw-r--r-- | cpufreq.c | 8 | ||||
-rw-r--r-- | cpufreq.h | 1 | ||||
-rw-r--r-- | cputemp2maxfreq.c | 15 |
3 files changed, 14 insertions, 10 deletions
@@ -69,3 +69,11 @@ int cpufreq_set_long_int(char *parameter,long int value,long int checkdelay) snprintf(buf,255,"%ld",value); return cpufreq_set_str(parameter,buf,checkdelay); } + +long int cpufreq_get_long_int(char *parameter) +{ + char sysfs_file[128]; + sprintf(sysfs_file,"/sys/devices/system/cpu/%s/cpufreq/%s",cpudata.cpulist[0],parameter); + return sysfs_read_long_int(sysfs_file); +} + @@ -21,5 +21,6 @@ int cpufreq_set_str(char *parameter,char *value,long int checkdelay); int cpufreq_set_long_int(char *parameter,long int value,long int checkdelay); +long int cpufreq_get_long_int(char *parameter); #endif diff --git a/cputemp2maxfreq.c b/cputemp2maxfreq.c index 434fb70..d146158 100644 --- a/cputemp2maxfreq.c +++ b/cputemp2maxfreq.c @@ -92,7 +92,6 @@ int main(int argc,char **argv) 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__); @@ -205,17 +204,13 @@ int main(int argc,char **argv) } // Get and validate CPU data - 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); + cpudata.min_freq=cpufreq_get_long_int("cpuinfo_min_freq"); + cpudata.max_freq=cpufreq_get_long_int("cpuinfo_max_freq"); + cpudata.scale_max=cpufreq_get_long_int("scaling_max_freq"); if (config.transition_latency<0) { transition_latency_remark=transition_latency_remarks[0]; - sprintf(sysfs_file,"/sys/devices/system/cpu/%s/cpufreq/cpuinfo_transition_latency",cpudata.cpulist[0]); - cpudata.transition_latency=sysfs_read_long_int(sysfs_file); + cpudata.transition_latency=cpufreq_get_long_int("cpuinfo_transition_latency"); if (cpudata.transition_latency<1000) transition_latency_remark=transition_latency_remarks[2]; } else { transition_latency_remark=transition_latency_remarks[1]; @@ -275,7 +270,7 @@ int main(int argc,char **argv) while(1) { // Get new measurements - cpudata.cur_freq=sysfs_read_long_int("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq"); + cpudata.cur_freq=cpufreq_get_long_int("scaling_cur_freq"); if ((cpudata.cur_freq<VALID_FREQ_MIN) || (cpudata.cur_freq>VALID_FREQ_MAX)) { config.logger("Invalid current frequency reported by CPU, exiting"); |