From a88d3fc7f89e628686ce18c290f5eca403a3b598 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sat, 17 Apr 2010 21:43:32 +0200 Subject: [PATCH] Speed names can now be given, allowing the use of "full-speed". --- breezed.1 | 16 +++++++----- breezed.c | 53 +++++++++++++++++++++++++++++++--------- breezed_Lenovo_X61s.conf | 2 +- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/breezed.1 b/breezed.1 index af84fd9..3fa2e9e 100644 --- a/breezed.1 +++ b/breezed.1 @@ -1,4 +1,4 @@ -.TH "BREEZED" "1" +.TH "BREEZED" "1.4" "Mar 2010" "Francois Fleuret" "System Deamons" .SH "NAME" breezed - Fan control daemon .SH "SYNOPSIS" @@ -19,7 +19,9 @@ whose temperature threshold is two degrees above T, and sets the fan speed one level below. This two degree gap avoids too many oscillations. Also, the daemon waits for at least 30s after any change of the fan speed before reducing it. The fan speed is set by writing -"level " into the specified fan file. +"level " into the specified fan file. The speed name is +the leve itself if no alternative is provided with the temperature +threshold. Options can not be specified twice, neither on the command line nor in the configuration file. @@ -39,7 +41,7 @@ prevent the reading of a configuration file set the files to spool for temperatures. .IP "\fB-ff | --fan-file \fP" 10 set the file to control the fan speed. -.IP "\fB-tt | --temperature-thresholds [,temp2]...\fP" 10 +.IP "\fB-tt | --temperature-thresholds [:][,temp2[:speed_name_2]]...\fP" 10 set the temperature thresholds. .SH "CONFIGURATION FILE" @@ -61,12 +63,14 @@ for instance with breezed --no-configuration-file \ --thermal-files /proc/acpi/thermal_zone/THM0/temperature,/proc/acpi/thermal_zone/THM1/temperature \ --fan-file /proc/acpi/ibm/fan \ - --temperature-thresholds 52,54,56,58,60,62,64 + --temperature-thresholds 52,54,56,58,60,62,64,68:full-speed which specifies that when the temperature raises above 52C, the fan level should be 1, when the temperature raises above 54C it should be -2, etc. The maximum speed level 7 should be chosen for temperatures -above 64C. +2, etc. The maximum speed level 8 should be chosen for temperatures +above 68C, and its name is "full-speed" (since no other speed name is +provided, the other ones are the default level names, hence their +numerical value). Due to the two degrees gap between the thresholds to increase and the thresholds to decrease the temperature, it will for instance remains diff --git a/breezed.c b/breezed.c index 5d57861..e8043df 100644 --- a/breezed.c +++ b/breezed.c @@ -3,7 +3,7 @@ breezed is a fan speed control daemon for Linux computers. - Copyright (c) 2008, 2009 Francois Fleuret + Copyright (c) 2008, 2009, 2010 Francois Fleuret Written by Francois Fleuret This file is part of breezed. @@ -30,7 +30,7 @@ #include const int major_version_number = 1; -const int minor_version_number = 3; +const int minor_version_number = 4; const int buffer_size = 1024; @@ -56,6 +56,7 @@ int file_fan_fd; int nb_temperature_thresholds; int *temperature_thresholds = 0; +char **speed_names = 0; int nb_file_thermal = 0; char **file_thermal = 0; @@ -63,6 +64,19 @@ int *file_thermal_fd = 0; char *configuration_file; +/********************************************************************/ + +/* malloc with error checking. */ + +void *safe_malloc(size_t n) { + void *p = malloc(n); + if (!p && n != 0) { + fprintf(stderr, "Can not allocate memory: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + return p; +} + /******************************************************************/ char *next_word(char *buffer, char *r, int buffer_size) { @@ -99,7 +113,7 @@ char *next_word(char *buffer, char *r, int buffer_size) { void set_fan_level(int fan_fd, int f, int max_fan_level) { char buffer[buffer_size]; if(f < 0 || f > max_fan_level) f = max_fan_level; - sprintf(buffer, "level %d\n", f); + sprintf(buffer, "level %s\n", speed_names[f]); if(write(fan_fd, buffer, strlen(buffer)) < 0) { fprintf(stderr, "Error in setting the fan level (%s).\n", strerror(errno)); @@ -122,8 +136,8 @@ void define_thermal_files(char *definition) { nb_file_thermal++; } - file_thermal = (char **) malloc(nb_file_thermal * sizeof(char *)); - file_thermal_fd = (int *) malloc(nb_file_thermal * sizeof(int)); + file_thermal = safe_malloc(nb_file_thermal * sizeof(char *)); + file_thermal_fd = safe_malloc(nb_file_thermal * sizeof(int)); s = definition; int k = 0; while(s) { @@ -143,7 +157,8 @@ void define_temperature_thresholds(char *definition) { nb_temperature_thresholds = 1; - char *s; + char *s, *u; + s = definition; while(s) { s = next_word(token, s, buffer_size); @@ -151,7 +166,10 @@ void define_temperature_thresholds(char *definition) { } temperature_thresholds = - (int *) malloc(nb_temperature_thresholds * sizeof(int)); + safe_malloc(nb_temperature_thresholds * sizeof(int)); + + speed_names = + safe_malloc(nb_temperature_thresholds * sizeof(char *)); temperature_thresholds[0] = -1; @@ -159,7 +177,19 @@ void define_temperature_thresholds(char *definition) { int k = 1; while(s) { s = next_word(token, s, buffer_size); - temperature_thresholds[k] = atoi(token); + u = token; + while(*u && *u != ':') u++; + if(*u) { + *u = '\0'; + temperature_thresholds[k] = atoi(token); + u++; + speed_names[k] = strdup(u); + } else { + temperature_thresholds[k] = atoi(token); + snprintf(token, buffer_size, "%d", k); + speed_names[k] = strdup(token); + } + if(k > 0 && temperature_thresholds[k] < temperature_thresholds[k-1]) { fprintf(stderr, "The temperature thresholds have to be increasing.\n"); @@ -472,8 +502,9 @@ Written by Francois Fleuret (francois@fleuret.org).\n", printf("file_fan %s\n", file_fan); for(t = 0; t < nb_temperature_thresholds; t++) { - printf("temperature_thresholds[%d] %d", - t, temperature_thresholds[t]); + printf("temperature_thresholds[%d] = %d speed_names[%d] = \"%s\"\n", + t, temperature_thresholds[t], + t, speed_names[t]); } } @@ -584,7 +615,7 @@ Written by Francois Fleuret (francois@fleuret.org).\n", nb_rounds_since_last_change = 0; last_level = new_level; if(debug) { - printf("Temperature is %dC setting the fan level to %d.", + printf("Temperature is %dC setting the fan level to %d.\n", temperature, new_level); } } diff --git a/breezed_Lenovo_X61s.conf b/breezed_Lenovo_X61s.conf index 959978e..a5978c8 100644 --- a/breezed_Lenovo_X61s.conf +++ b/breezed_Lenovo_X61s.conf @@ -10,4 +10,4 @@ thermal_files /proc/acpi/thermal_zone/THM0/temperature /proc/acpi/thermal_zone/THM1/temperature fan_file /proc/acpi/ibm/fan -temperature_thresholds 52,54,56,58,60,62,64 +temperature_thresholds 52,54,56,58,60,62,64,68:full-speed -- 2.39.5