aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPA4WDH2024-08-24 12:43:34 +0200
committerPA4WDH2024-08-24 12:43:34 +0200
commita13b6a07822e9807af50bd67bfe64ccba03b5b00 (patch)
tree125b82a0e3cf114fce7522ccd1ef1ebdc936d5c3
parentAdd ebuild for version 0.5 (diff)
downloadcputemp2maxfreq-a13b6a07822e9807af50bd67bfe64ccba03b5b00.tar.gz
cputemp2maxfreq-a13b6a07822e9807af50bd67bfe64ccba03b5b00.tar.bz2
cputemp2maxfreq-a13b6a07822e9807af50bd67bfe64ccba03b5b00.zip
Add -k option to keep state on successul exit
-rw-r--r--argparse.c8
-rw-r--r--cputemp2maxfreq.c7
-rw-r--r--cputemp2maxfreq.h1
-rw-r--r--failsafe.c34
4 files changed, 36 insertions, 14 deletions
diff --git a/argparse.c b/argparse.c
index 1eae42b..e46eab7 100644
--- a/argparse.c
+++ b/argparse.c
@@ -25,6 +25,9 @@ void printhelp()
" A sensor name, for example \"Core 0\"\n"
" The word \"auto\" autodetects a valid sensor\n"
" Default: %s\n"
+ "-k Keep last state on successful exit, set CPU to lowest frequency\n"
+ " on error.\n"
+ " Default: Always set CPU to lowest frequency on exit\n"
"-p <time> Poll interval in seconds\n"
" Default: %d\n"
"-s <step> Step size in Khz when increasing/decreasing CPU speed\n"
@@ -70,7 +73,7 @@ void argparse(int argc, char **argv)
memcpy(&userconfig,&config,sizeof(struct s_config));
// Parse options
- while((opt=getopt(argc,argv,"c:C:d:f:g:hi:l:mp:s:t:u"))!=-1)
+ while((opt=getopt(argc,argv,"c:C:d:f:g:hi:kl:mp:s:t:u"))!=-1)
{
DEBUG1_ARGPARSE("Argument: %c Value: %s\n",opt,optarg);
switch(opt)
@@ -103,6 +106,9 @@ void argparse(int argc, char **argv)
case 'i':
strncpy(userconfig.temp_input,optarg,sizeof(userconfig.temp_input));
break;
+ case 'k':
+ userconfig.keepstate=1;
+ break;
case 'l':
strncpy(userconfig.logger_name,optarg,sizeof(userconfig.logger_name));
break;
diff --git a/cputemp2maxfreq.c b/cputemp2maxfreq.c
index 242969d..6921279 100644
--- a/cputemp2maxfreq.c
+++ b/cputemp2maxfreq.c
@@ -31,6 +31,7 @@ struct s_config config={
NULL, // File handler for CSV file
0, // Don't use unix timestamps in log outputs
-1, // Transition latency, default to autodetect
+ 0, // Do not keep state on exit (Set CPU to lowest frequency)
};
struct s_cpudata cpudata;
@@ -88,6 +89,12 @@ int main(int argc,char **argv)
} else {
config.logger("Transition latency: %d",config.transition_latency);
}
+ if (config.keepstate==1)
+ {
+ config.logger("State on exit: Keep last state on normal exit");
+ } else {
+ config.logger("State on exit: Always set CPU to lowest frequency");
+ }
if ((config.max_temp<VALID_TEMP_MIN) || (config.max_temp>VALID_TEMP_MAX))
{
diff --git a/cputemp2maxfreq.h b/cputemp2maxfreq.h
index ade4d58..a901e6d 100644
--- a/cputemp2maxfreq.h
+++ b/cputemp2maxfreq.h
@@ -46,6 +46,7 @@ struct s_config {
FILE *csvfile; // File handle for CSV file
char use_unixtime; // Use unixtime timestamps in logs and CSV
long int transition_latency; // User configurable transition latency, <0 for autodetect
+ int keepstate; // Keep last state on exit (0=set lowest freq)
};
#endif
diff --git a/failsafe.c b/failsafe.c
index 59d9d15..b723457 100644
--- a/failsafe.c
+++ b/failsafe.c
@@ -14,23 +14,31 @@ void failsafe(int code)
// Close CSV log if used
if (config.csvfile!=NULL) csvlog_close();
-// First try to set the CPU to it's minimum frequency
- if (cpufreq_set_long_int("scaling_max_freq",cpudata.min_freq,100)>0)
+ if (((config.keepstate==1) && (code!=0)) || config.keepstate==0)
{
- config.logger("Set scaling frequency to CPU's minimum frequency");
- exit(code);
- }
- config.logger("Failed to set scaling frequency to CPU's minimum frequency, error: %d (%s)",errno,strerror(errno));
+
+// First try to set the CPU to it's minimum frequency
+ if (cpufreq_set_long_int("scaling_max_freq",cpudata.min_freq,100)>0)
+ {
+ config.logger("Set scaling frequency to CPU's minimum frequency");
+ exit(code);
+ }
+ config.logger("Failed to set scaling frequency to CPU's minimum frequency, error: %d (%s)",errno,strerror(errno));
// If that failed, try the fallback frequency
- if (cpufreq_set_long_int("scaling_max_freq",config.fallback_freq,100)>0)
- {
- config.logger("Set scaling frequency to fallback frequency");
- exit(code);
+ if (cpufreq_set_long_int("scaling_max_freq",config.fallback_freq,100)>0)
+ {
+ config.logger("Set scaling frequency to fallback frequency");
+ exit(code);
+ }
+ config.logger("Failed to set scaling frequency to fallback frequency, error: %d (%s)",errno,strerror(errno));
+
+// Everything failed, issue a warning
+ config.logger("All safety measures failed, watch out not to fry your hardware");
+ } else {
+// User asked for no action
+ config.logger("Keeping current state due to -k option");
}
- config.logger("Failed to set scaling frequency to fallback frequency, error: %d (%s)",errno,strerror(errno));
-// Everything failed, issue a warning
- config.logger("All safety measures failed, watch out not to fry your hardware");
exit(code);
}