threshold default value is now relative to the CPU number

obsdfreqd uses hw.ncpuonline to calculate a threshold
matching 80% of a single core usage. This helps the
default value to work fine with computer from 1 to many cores.
This commit is contained in:
Solène Rapenne 2023-08-22 16:33:00 +02:00
parent 18eaf38df8
commit c851c1cc80
3 changed files with 26 additions and 2 deletions

View File

@ -52,7 +52,7 @@ Parameters are applied when both plugged on the wall or on battery, parameters c
- `-i inertia` sets the number of cycles after which the frequency will decay, 0 is the default
- `-m maxfrequency` sets the maximum frequency the CPU can reach in percent, 100% is default
- `-l minfrequency` sets the minimum frequency the CPU must be lowered to, 0% is default
- `-r threshold` sets the CPU usage in % that will trigger the frequency increase, 30% is the default
- `-r threshold` sets the CPU usage in % that will trigger the frequency increase, defaults to 80% of a single core.
- `-s stepfrequency` sets the percent of frequency added every cycle when increasing, 10% is default
- `-t timefreq` sets the milliseconds between each poll, 300 is the default
- `-T maxtemperature` sets the temperature threshold under which the maximum frequency will be temporary lowered until the CPU cools down

24
main.c
View File

@ -52,6 +52,7 @@ int temperature_sensor_found;
void try_to_find_default_temperature_sensor(void);
int get_temp(void);
int get_cpu_online(void);
void set_policy(const char*);
void quit_gracefully(int signum);
void usage(void);
@ -159,6 +160,21 @@ int get_temp() {
return(value);
}
/* get the number of online CPUs */
int get_cpu_online(void) {
int mib_cpu[2] = { CTL_HW, HW_NCPUONLINE };
int ncpu = 1;
size_t len_ncpu = sizeof(len_ncpu);
if (sysctl(mib_cpu, 2, &ncpu, &len_ncpu, NULL, 0) == -1)
err(1, "sysctl");
if (ncpu <= 0)
err(1, "cpuonline detection");
return(ncpu);
}
/* define the policy to auto or manual */
void set_policy(const char* policy) {
int mib[2] = { CTL_HW, HW_PERFPOLICY };
@ -425,11 +441,17 @@ int main(int argc, char *argv[]) {
int cpu_usage_percent = 0, cpu_usage;
float temp;
size_t len, len_cpu;
int ncpu;
ncpu = get_cpu_online();
// battery defaults
hard_min_freq = batt_min= 0;
hard_max_freq = batt_max= 100;
threshold = batt_threshold= 30;
// threshold defaults to 80% usage of one CPU
threshold = batt_threshold= floor(100/ncpu*0.8);
down_step = batt_down_step= 100;
inertia = batt_inertia= 5;
step = batt_step= 100;

View File

@ -44,6 +44,8 @@ Defines the maximum frequency in percent the CPU can be increased to.
Defines the minimum frequency in percent the CPU can be reduced to.
.It Fl r Ar threshold
Defines the CPU usage in percent above which the frequency is increased.
The default is to use a value that match the usage of 80% of a single core.
Example: for a 4 CPU system, the threshold will be 100/4*0.8 = 20%
.It Fl s Ar stepfrequency
Defines the frequency increase step in percent.
.It Fl t Ar timefrequency