diff options
author | PA4WDH | 2024-08-24 16:07:11 +0200 |
---|---|---|
committer | PA4WDH | 2024-08-24 16:07:11 +0200 |
commit | 66aca8aa35bc0b07c754d9ad95c808e4d91f58f1 (patch) | |
tree | 8f051b5cc7660ff596c7ef80c69a9a485016b26c /cpufreq.c | |
parent | Add -k option to keep state on successul exit (diff) | |
download | cputemp2maxfreq-66aca8aa35bc0b07c754d9ad95c808e4d91f58f1.tar.gz cputemp2maxfreq-66aca8aa35bc0b07c754d9ad95c808e4d91f58f1.tar.bz2 cputemp2maxfreq-66aca8aa35bc0b07c754d9ad95c808e4d91f58f1.zip |
Add multi-CPU support
Diffstat (limited to 'cpufreq.c')
-rw-r--r-- | cpufreq.c | 47 |
1 files changed, 13 insertions, 34 deletions
@@ -7,62 +7,41 @@ #include <sys/types.h> #include "debug.h" #include "sysfs.h" +#include "cputemp2maxfreq.h" -// Validate if we found a file named cpu[0-9][0-9] -int cpufreq_is_cpu(char *name) -{ - if (strncmp(name,"cpu",3)!=0) return 0; - if ((name[3]<'0') || (name[3]>'9')) return 0; - if (name[4]==0) return 1; - - if ((name[4]<'0') || (name[4]>'9')) return 0; - if (name[5]==0) return 1; - - return 0; -} +extern struct s_cpudata cpudata; // Set a cpufreq parameter to a value int cpufreq_set_str(char *parameter,char *value,long int checkdelay) { - DIR *cpudir; - struct dirent *cpu_dirent; + int cpu; char sysfs_file[128]; int done=0; DEBUG1_CPUFREQ("Set %s to %s\n",parameter,value) -// Open the CPU directory in sysfs - cpudir=opendir("/sys/devices/system/cpu"); - if (cpudir==NULL) + if (cpudata.cpulist==NULL) { - DEBUG1_CPUFREQ("Unable to find CPU's\n"); + DEBUG1_CPUFREQ("No CPU list\n"); return -1; } - cpu_dirent=readdir(cpudir); - while(cpu_dirent!=NULL) + for(cpu=0;cpu<cpudata.cpulist_len;cpu++) { -// If it's a CPU, set our parameter - if (cpufreq_is_cpu(cpu_dirent->d_name)) + DEBUG2_CPUFREQ("Set CPU %s\n",cpudata.cpulist[cpu]); + snprintf(sysfs_file,128,"/sys/devices/system/cpu/%s/cpufreq/%s",cpudata.cpulist[cpu],parameter); + if (sysfs_write_str(sysfs_file,value,checkdelay)!=0) { - DEBUG2_CPUFREQ("Found CPU %s\n",cpu_dirent->d_name); - snprintf(sysfs_file,128,"/sys/devices/system/cpu/%s/cpufreq/%s",cpu_dirent->d_name,parameter); - if (sysfs_write_str(sysfs_file,value,checkdelay)!=0) - { - DEBUG1_CPUFREQ("Failed to set %s\n",cpu_dirent->d_name); - closedir(cpudir); - return -1; - } - done++; + DEBUG1_CPUFREQ("Failed to set %s\n",cpudata.cpulist[cpu]); + return -1; } - - cpu_dirent=readdir(cpudir); + done++; } - closedir(cpudir); return done; } + // This is just a wrapper around cpufreq_set_str with long int to string // conversion int cpufreq_set_long_int(char *parameter,long int value,long int checkdelay) |