aboutsummaryrefslogtreecommitdiffstats
path: root/cputemp2maxfreq.c
diff options
context:
space:
mode:
authorPA4WDH2023-05-24 09:09:23 +0200
committerPA4WDH2023-05-24 09:09:23 +0200
commit33bd1b7c488e935f247407e191811a7539a12375 (patch)
treef60c23d07933afbfc36363b742945b62c93732cf /cputemp2maxfreq.c
parentAdd logging functions (diff)
downloadcputemp2maxfreq-33bd1b7c488e935f247407e191811a7539a12375.tar.gz
cputemp2maxfreq-33bd1b7c488e935f247407e191811a7539a12375.tar.bz2
cputemp2maxfreq-33bd1b7c488e935f247407e191811a7539a12375.zip
Redirect all output to logging functions
Diffstat (limited to 'cputemp2maxfreq.c')
-rw-r--r--cputemp2maxfreq.c65
1 files changed, 31 insertions, 34 deletions
diff --git a/cputemp2maxfreq.c b/cputemp2maxfreq.c
index 9e20848..88d9a5d 100644
--- a/cputemp2maxfreq.c
+++ b/cputemp2maxfreq.c
@@ -28,7 +28,7 @@ struct s_cpudata cpudata;
void signal_handler(int signum)
{
- printf("Received signal %d, exiting.\n",signum);
+ config.logger("Received signal %d, exiting.",signum);
failsafe(0);
}
@@ -37,38 +37,34 @@ int main(int argc,char **argv)
long int diff;
long int newfreq;
- printf("Version %s, buildtime %s %s\n",version(),__DATE__,__TIME__);
argparse(argc,argv);
-
-// Print configuration
- printf("Configuration:\n");
- printf("Governor: %s\n",config.governor);
- printf("Temperature: %ld\n",config.max_temp);
- printf("Temp input: %s\n",config.temp_input);
- printf("Frequency step: %ld\n",config.freq_step);
- printf("Fallback frquency: %ld\n",config.fallback_freq);
- printf("Interval: %d\n",config.interval);
- printf("Logger: %s (%p)\n",config.logger_name,config.logger);
- printf("\n");
-
- config.logger("Log test1");
- config.logger("Log test2");
+ config.logger("Version %s, buildtime %s %s",version(),__DATE__,__TIME__);
+
+// Log configuration
+ config.logger("Configuration:");
+ config.logger("Governor: %s",config.governor);
+ config.logger("Temperature: %ld",config.max_temp);
+ config.logger("Temp input: %s",config.temp_input);
+ config.logger("Frequency step: %ld",config.freq_step);
+ config.logger("Fallback frquency: %ld",config.fallback_freq);
+ config.logger("Interval: %d",config.interval);
+ config.logger("Logger: %s (%p)",config.logger_name,config.logger);
if ((config.max_temp<VALID_TEMP_MIN) || (config.max_temp>VALID_TEMP_MAX))
{
- printf("Invalid temperature, range is %d-%d\n",VALID_TEMP_MIN,VALID_TEMP_MAX);
+ config.logger("Invalid temperature, range is %d-%d",VALID_TEMP_MIN,VALID_TEMP_MAX);
exit(1);
}
if ((config.freq_step<VALID_STEP_MIN) || (config.freq_step>VALID_STEP_MAX))
{
- printf("Invalid frequency step, range is %d-%d\n",VALID_STEP_MIN,VALID_STEP_MAX);
+ config.logger("Invalid frequency step, range is %d-%d",VALID_STEP_MIN,VALID_STEP_MAX);
exit(1);
}
if ((config.interval<VALID_INTERVAL_MIN) || (config.interval>VALID_INTERVAL_MAX))
{
- printf("Invalid poll interval, range is %d-%d\n",VALID_INTERVAL_MIN,VALID_INTERVAL_MAX);
+ config.logger("Invalid poll interval, range is %d-%d",VALID_INTERVAL_MIN,VALID_INTERVAL_MAX);
exit(1);
}
@@ -77,30 +73,29 @@ int main(int argc,char **argv)
cpudata.max_freq=sysfs_read_long_int("/sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq");
cpudata.scale_max=sysfs_read_long_int("/sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq");
- printf("CPU data:\n");
- printf("Minimum frequency: %ld\n",cpudata.min_freq);
- printf("Maximum frequency: %ld\n",cpudata.max_freq);
- printf("Scaling maximum frequency: %ld\n",cpudata.scale_max);
- printf("\n");
+ config.logger("CPU data:");
+ config.logger("Minimum frequency: %ld",cpudata.min_freq);
+ config.logger("Maximum frequency: %ld",cpudata.max_freq);
+ config.logger("Scaling maximum frequency: %ld",cpudata.scale_max);
if ((cpudata.min_freq<VALID_FREQ_MIN) || (cpudata.min_freq>VALID_FREQ_MAX) ||
(cpudata.max_freq<VALID_FREQ_MIN) || (cpudata.max_freq>VALID_FREQ_MAX) ||
(cpudata.scale_max<VALID_FREQ_MIN) || (cpudata.scale_max>VALID_FREQ_MAX))
{
// If we have to fail now, there's not much we can do because we have no data
- printf("Invalid CPU data, exiting.\n");
+ config.logger("Invalid CPU data, exiting");
exit(1);
}
// Modify fallback frequency if needed
if (config.fallback_freq<cpudata.min_freq)
{
- printf("Fallback frequency is lower than CPU's minimum frequency, setting to %ld.\n",cpudata.min_freq);
+ config.logger("Fallback frequency is lower than CPU's minimum frequency, setting to %ld",cpudata.min_freq);
config.fallback_freq=cpudata.min_freq;
}
if (config.fallback_freq>cpudata.max_freq)
{
- printf("Fallback frequency is higher than CPU's maximum frequency, setting to %ld.\n",cpudata.max_freq);
+ config.logger("Fallback frequency is higher than CPU's maximum frequency, setting to %ld",cpudata.max_freq);
config.fallback_freq=cpudata.max_freq;
}
@@ -109,7 +104,7 @@ int main(int argc,char **argv)
{
if (cpufreq_set_str("scaling_governor",config.governor,0)<0)
{
- printf("Failed to set governor, error %d (%s).\n",errno,strerror(errno));
+ config.logger("Failed to set governor, error %d (%s)",errno,strerror(errno));
// We failed to set the governor, call the failsafe
failsafe(1);
@@ -127,14 +122,14 @@ int main(int argc,char **argv)
cpudata.cur_freq=sysfs_read_long_int("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq");
if ((cpudata.cur_freq<VALID_FREQ_MIN) || (cpudata.cur_freq>VALID_FREQ_MAX))
{
- printf("Invalid current frequency reported by CPU, exiting.\n");
+ config.logger("Invalid current frequency reported by CPU, exiting");
failsafe(1);
}
cpudata.cur_temp=sysfs_read_long_int(config.temp_input);
if ((cpudata.cur_temp<VALID_TEMP_MIN) || (cpudata.cur_temp>VALID_TEMP_MAX))
{
- printf("Invalid current tempature reported by CPU, exiting.\n");
+ config.logger("Invalid current tempature reported by CPU, exiting");
failsafe(1);
}
@@ -147,17 +142,18 @@ int main(int argc,char **argv)
newfreq=cpudata.scale_max+(config.freq_step*diff);
if (newfreq>cpudata.max_freq) newfreq=cpudata.max_freq;
DEBUG1_MAIN("Increase to %ld\n",newfreq);
+ config.logger("Increase scaling_max_freq to %ld",newfreq);
// Set new value and validate
if (cpufreq_set_long_int("scaling_max_freq",newfreq,100)<0)
{
- printf("Failed to set scaling_max_freq, exiting.\n");
+ config.logger("Failed to set scaling_max_freq, exiting");
failsafe(1);
}
cpudata.scale_max=sysfs_read_long_int("/sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq");
if ((cpudata.scale_max<VALID_FREQ_MIN) || (cpudata.scale_max>VALID_FREQ_MAX))
{
- printf("Invalid scale_max_freq reported, exiting,\n");
+ config.logger("Invalid scale_max_freq reported, exiting");
failsafe(1);
}
}
@@ -169,17 +165,18 @@ int main(int argc,char **argv)
newfreq=cpudata.scale_max-(config.freq_step*diff);
if (newfreq<cpudata.min_freq) newfreq=cpudata.min_freq;
DEBUG1_MAIN("Decrease to %ld\n",newfreq);
+ config.logger("Decrease scaling_max_freq to %ld",newfreq);
// Set new value and validate
if (cpufreq_set_long_int("scaling_max_freq",newfreq,100)<0)
{
- printf("Failed to set scaling_max_freq, exiting.\n");
+ config.logger("Failed to set scaling_max_freq, exiting");
failsafe(1);
}
cpudata.scale_max=sysfs_read_long_int("/sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq");
if ((cpudata.scale_max<VALID_FREQ_MIN) || (cpudata.scale_max>VALID_FREQ_MAX))
{
- printf("Invalid scale_max_freq reported, exiting,\n");
+ config.logger("Invalid scale_max_freq reported, exiting");
failsafe(1);
}
}