2
* Copyright (C) 2006 Victor de la Fuente Castillo <vniebla@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
* Based upon the pmu version:
19
* Copyright (C) 2003,2004 Rene Rebe <rene@rocklinux.org>
20
* 2005 Mattia Dongili <malattia@linux.it>
29
#include "cpufreqd_plugin.h"
31
# define CPU_INFO_FILE "/proc/cpuinfo"
33
struct temperature_interval {
37
struct temperature_interval tau_temperature;
42
static int tokenize (FILE *fp, char *t, char *v) {
48
if (fgets(str, 255, fp) == NULL)
51
if ((s1 = strtok(str, ":")) == NULL)
54
s2 = s1 + strlen (s1) - 1;
55
/* remove trailing spaces */
56
for ( ; s1 != s2 ; --s2) {
67
if ((s1 = strtok(NULL, ":")) == NULL)
70
for ( ; *s1 != 0 ; ++s1) {
75
s2 = s1 + strlen (s1) - 1;
76
/* remove trailing spaces */
77
for ( ; s1 != s2 ; --s2) {
91
static int tau_init(void) {
94
fp = fopen(CPU_INFO_FILE, "r");
96
clog(LOG_ERR, "%s: %s\n", CPU_INFO_FILE, strerror(errno));
102
clog(LOG_NOTICE, "/proc/cpuinfo file found\n");
107
static int tau_update(void) {
111
fp = fopen(CPU_INFO_FILE, "r");
113
clog(LOG_ERR, "%s: %s\n", CPU_INFO_FILE, strerror(errno));
119
if (fgets(str, 255, fp) == NULL){
120
clog(LOG_INFO,"%s",str);
125
while (tokenize(fp, tag, val) != EOF) {
126
if (strcmp(tag, "temperature") == 0) {
128
if (((readed=sscanf(val, "%d-%d", &(tau_temperature.min), &(tau_temperature.max))) < 1)
130
clog(LOG_ERR, "wrong temperature value %s\n", val);
133
} else if (readed == 1) {
134
//Temperature is not an interval
135
tau_temperature.max = tau_temperature.min;
137
clog(LOG_INFO,"TAU temperature = %d-%d",tau_temperature.min, tau_temperature.max);
138
break; //Reading more is a waste of time
146
static int tau_parse(const char *ev, void **obj) {
147
struct temperature_interval *tau_temperature_interval = malloc(sizeof(struct temperature_interval));
148
if (tau_temperature_interval == NULL) {
149
clog(LOG_ERR, "couldn't make enough room for tau_temperature_interval (%s)\n",
153
tau_temperature_interval->min = tau_temperature_interval->max = 0;
154
clog(LOG_DEBUG, "called with %s\n", ev);
156
if (sscanf(ev, "%d-%d", &(tau_temperature_interval->min), &(tau_temperature_interval->max)) != 2) {
157
clog(LOG_ERR, "wrong parameter %s\n", ev);
158
free(tau_temperature_interval);
162
clog(LOG_INFO, "parsed %d-%d\n", tau_temperature_interval->min, tau_temperature_interval->max);
164
*obj = tau_temperature_interval;
168
static int tau_evaluate(const void *s) {
169
const struct temperature_interval *ti = (const struct temperature_interval *)s;
171
clog(LOG_DEBUG, "called %d-%d , actual temperature: %d-%d\n", ti->min, ti->max, tau_temperature.min, tau_temperature.max);
173
return ((tau_temperature.min<=ti->min && tau_temperature.max>=ti->min)
174
|| (tau_temperature.min<=ti->max && tau_temperature.max>=ti->max)
175
|| (ti->max >= tau_temperature.max && ti->min<=tau_temperature.min))? MATCH : DONT_MATCH;
178
static struct cpufreqd_keyword kw[] = {
179
{ .word = "tau_temperature", .parse = &tau_parse, .evaluate = &tau_evaluate },
180
{ .word = NULL, .parse = NULL, .evaluate = NULL }
183
static struct cpufreqd_plugin tau = {
184
.plugin_name = "tau_plugin", /* plugin_name */
185
.keywords = kw, /* config_keywords */
186
.plugin_init = &tau_init, /* plugin_init */
187
.plugin_update = &tau_update /* plugin_update */
190
struct cpufreqd_plugin *create_plugin (void) {