From 38fd93cc43eb74bb044969b355ad52bdd1f5956e Mon Sep 17 00:00:00 2001 From: celso Date: Tue, 22 Nov 2022 18:53:43 -0300 Subject: [PATCH] simplified some lines of code and updated README --- README.md | 2 +- src/homemade_speedstep.c | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e5944b8..fc0a99b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Run `make clean` to remove the compiled binary (note: only from `bin`, to remove ## How it works The program checks the available frequency steps supported by your CPU and uses them to set the maximum frequency your cpufreq governor may choose for it to run at. -Every second, the program reads the temperature of the CPU and two thresholds, a minimum and maximum temperature you provide it with, to set this maximum frequency. +Every n ammount of seconds, set by the user at build time, the program reads the temperature of the CPU and two thresholds, a minimum and maximum temperature you provide it with, to set this maximum frequency. Any time the temperature hits the upper threshold, the maximum frequency will be lowered by one step, until the temperature is below the threshold or the minimum step is reached. diff --git a/src/homemade_speedstep.c b/src/homemade_speedstep.c index 4bdb366..4e0eebd 100644 --- a/src/homemade_speedstep.c +++ b/src/homemade_speedstep.c @@ -14,8 +14,7 @@ void changespeed(int threads, char* step){ FILE* file; for (i=0; i < threads; i++){ sprintf(filename, MAXSPDPREFIX"%d"MAXSPDSUFFIX, i); - file = fopen(filename, "w"); - if (file != NULL){ + if ((file = fopen(filename, "w")) != NULL){ fprintf(file, "%s\n", step); fclose(file); } @@ -145,8 +144,8 @@ int main(int argc, char** argv){ return 2; } /* try to open scaling_available_frequencies, exit on fail */ - FILE *freqsfile = fopen(FREQS, "r"); - if (freqsfile == NULL){ + FILE *freqsfile; + if ((freqsfile = fopen(FREQS, "r")) == NULL){ fprintf(stderr, "error: couldn't open scaling_available_frequencies\n"); fprintf(stderr, " check that you have support for cpufreq\n"); fprintf(stderr, " in your kernel and that the program is\n"); @@ -170,8 +169,8 @@ int main(int argc, char** argv){ free(freqsfilec); fclose(freqsfile); /* try to open scaling_maximum_frequency, exit on fail */ - FILE* curmaxfile = fopen(MAXSPDPREFIX"0"MAXSPDSUFFIX, "r"); - if (curmaxfile == NULL){ + FILE* curmaxfile; + if ((curmaxfile = fopen(MAXSPDPREFIX"0"MAXSPDSUFFIX, "r")) == NULL){ fprintf(stderr, "error: couldn't open scaling_maximum_frequency\n"); fprintf(stderr, " check that you have support for cpufreq\n"); fprintf(stderr, " in your kernel and that the program is\n");