aboutsummaryrefslogtreecommitdiffstats
path: root/failsafe.c
diff options
context:
space:
mode:
authorPA4WDH2023-05-20 19:27:47 +0200
committerPA4WDH2023-05-20 19:27:47 +0200
commit48ec55bd19362c5b8f7d06f7678321c3535672f4 (patch)
tree7a8ec313dd0aea97a56697e844aa99cd6c25cf03 /failsafe.c
parentTranslate POC to C code (diff)
downloadcputemp2maxfreq-48ec55bd19362c5b8f7d06f7678321c3535672f4.tar.gz
cputemp2maxfreq-48ec55bd19362c5b8f7d06f7678321c3535672f4.tar.bz2
cputemp2maxfreq-48ec55bd19362c5b8f7d06f7678321c3535672f4.zip
Add validation and fallback to startup
Diffstat (limited to 'failsafe.c')
-rw-r--r--failsafe.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/failsafe.c b/failsafe.c
new file mode 100644
index 0000000..5b3e7d3
--- /dev/null
+++ b/failsafe.c
@@ -0,0 +1,33 @@
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "cputemp2maxfreq.h"
+#include "cpufreq.h"
+
+extern struct s_cpudata cpudata;
+extern struct s_config config;
+
+void failsafe()
+{
+ printf("Failed to set governor, error %d (%s).\n",errno,strerror(errno));
+
+// We failed to set the governor, try to fail safe. First try the CPU minimum
+// frequency, if that doesn't work out try the fallback frequency
+ if (cpufreq_set_long_int("scaling_max_freq",cpudata.min_freq,100)==0)
+ {
+ printf("Set scaling frequency to CPU's minimum frequency.");
+ exit(1);
+ }
+ printf("Failed to set scaling frequency to CPU's minimum frequency, error: %d (%s).\n",errno,strerror(errno));
+
+ if (cpufreq_set_long_int("scaling_max_freq",config.fallback_freq,100)==0)
+ {
+ printf("Set scaling frequency to fallback frequency.");
+ exit(1);
+ }
+ printf("Failed to set scaling frequency to fallback frequency, error: %d (%s).\n",errno,strerror(errno));
+
+ printf("All safety measures failed, watch out not to fry your hardware.\n");
+ exit(1);
+}