From a3804657076ff5f2bb65575ee630609a8d2e94dc Mon Sep 17 00:00:00 2001 From: celso Date: Thu, 10 Nov 2022 08:55:01 -0300 Subject: [PATCH] added current governor check --- src/homemade_speedstep.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/homemade_speedstep.c b/src/homemade_speedstep.c index 38f42e0..d28ad30 100644 --- a/src/homemade_speedstep.c +++ b/src/homemade_speedstep.c @@ -5,7 +5,18 @@ #define SETSPDPATH "/sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed" #define CURTEMPPATH "/sys/devices/virtual/thermal/thermal_zone0/temp" -void getfilec(FILE *file, char arr[]){ +int comparestrings(char *a, char *b){ + int c = 0; + while(a[c]!='\0' && b[c]!='\0'){ + if(a[c] != b[c]){ + return 1; + } + c++; + } + return 0; +} + +int getfilec(FILE *file, char arr[]){ int c, i; i=0; while((c=fgetc(file)) != EOF){ @@ -13,10 +24,17 @@ void getfilec(FILE *file, char arr[]){ i++; } arr[i]='\0'; + return i; } int main(){ + char gov[20]; FILE *govfile = fopen(CURGOV, "r"); + getfilec(govfile, gov); + if (comparestrings(gov, "userspace\n") != 0){ + printf("error: userspace governor not set\n"); + return 1; + } FILE *freqsfile = fopen(FREQS, "r"); FILE *curmaxfile = fopen(MAXSPDPATH, "r"); FILE *setspeedfile = fopen(SETSPDPATH, "r");