2
* Copyright (C) 2002,2003,2004 Mattia Dongili<dongili@supereva.it>
3
* George Staikos <staikos@0wned.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include "sys_check.h"
23
/* int select_pm_plugin
25
* Check the existance of power interfaces trying
26
* to call the check function for each plugin
31
/* int find_cpufreq_interface(general *configuration)
33
* Checks whether we need to use the 2.4 or 2.5/2.6
34
* cpufreq interface and sets the has_sysfs bit
37
* Returns 0 on success, -1 otherwise
39
int find_cpufreq_interface(general *configuration) {
43
/* try first with the 2.6 series */
44
rc = stat(CPUFREQ_SYSFS_INTERFACE, &sb);
49
cp_log(LOG_DEBUG, "find_cpufreq_interface(): found %s interface.\n", CPUFREQ_SYSFS_INTERFACE);
50
configuration->has_sysfs = 1;
52
/* Read min freq to translate frequencies */
53
fp = fopen(CPUFREQ_SYSFS_INTERFACE_CPUMIN, "r");
54
if (!fp || !fgets(buf, 255, fp)) {
55
cp_log(LOG_ERR, "find_cpufreq_interface(): %s: %s\n",
56
CPUFREQ_SYSFS_INTERFACE_CPUMIN, strerror(errno));
59
configuration->cpu_min_freq = atoi(buf);
60
cp_log(LOG_DEBUG, "find_cpufreq_interface(): minimum available frequency %d\n", configuration->cpu_min_freq);
63
/* Read max freq to translate frequencies */
64
fp = fopen(CPUFREQ_SYSFS_INTERFACE_CPUMAX, "r");
65
if (!fp || !fgets(buf, 255, fp)) {
66
cp_log(LOG_ERR, "find_cpufreq_interface(): %s: %s\n",
67
CPUFREQ_SYSFS_INTERFACE_CPUMAX, strerror(errno));
70
configuration->cpu_max_freq = atoi(buf);
71
cp_log(LOG_DEBUG, "find_cpufreq_interface(): maximum available frequency %d\n", configuration->cpu_max_freq);
77
/* try with the 2.4 series or the deprecated /prco/cpufreq interface also */
78
rc = stat(CPUFREQ_PROC_INTERFACE, &sb);
80
cp_log(LOG_DEBUG, "find_cpufreq_interface(): found %s interface.\n", CPUFREQ_PROC_INTERFACE);
81
configuration->has_sysfs = 0;
85
cp_log(LOG_ERR, "find_cpufreq_interface(): no cpufreq interface found.\n");
91
/* int get_cpu_num(general *configuration)
93
* Gets the number of installed CPUs from procfs
94
* and sets cpu_num appropriately.
96
* Returns 0 on success, -1 on error
98
int get_cpu_num(general *configuration)
104
fp = fopen(CPUINFO_PROC, "r");
106
cp_log(LOG_ERR, "get_cpu_num(): %s: %s\n", CPUINFO_PROC, strerror(errno));
112
fgets(line, 255, fp);
113
if(!strncmp(line, "processor", 9))
118
cp_log(LOG_DEBUG, "get_cpu_num(): found %i CPUs\n", n);
119
configuration->cpu_num = n;