2
* Copyright 2008, Intel Corporation
4
* This file is part of PowerTOP
6
* This program file is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
* You should have received a copy of the GNU General Public License
16
* along with this program in a file named COPYING; if not, write to the
17
* Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301 USA
22
* Arjan van de Ven <arjan@linux.intel.com>
30
#include <sys/types.h>
40
* Perform a CPU ID operation; with various registers set
42
static void cpuid( unsigned int *eax,
47
/* call the cpuid instruction with the registers as input and output
48
* modification by Dwokfur based on Sam Hocevar's discussion on
49
* how to make Assemly code PIC compatible:
50
* http://sam.zoy.org/blog/2007-04-13-shlib-with-non-pic-code-have-inline-assembly-and-pic-mix-well
52
__asm__("pushl %%ebx \n\t" /* save %ebx */
54
"movl %%ebx, %1 \n\t" /* save what cpuid just put in %ebx */
55
"popl %%ebx \n\t" /* restore the old %ebx */
70
void print_intel_cstates(void)
81
char filename[128], *f;
83
unsigned int eax, ebx, ecx, edx;
85
memset(bios_table, 0, sizeof(bios_table));
88
cpudir = opendir("/sys/devices/system/cpu");
92
/* Loop over cpuN entries */
93
while ((entry = readdir(cpudir))) {
94
if (strlen(entry->d_name) < 3)
97
if (!isdigit(entry->d_name[3]))
100
len = sprintf(filename, "/sys/devices/system/cpu/%s/cpuidle",
103
dir = opendir(filename);
107
/* For each C-state, there is a stateX directory which
108
* contains a 'usage' and a 'time' (duration) file */
109
while ((entry = readdir(dir))) {
110
if (strlen(entry->d_name) < 3)
112
sprintf(filename + len, "/%s/desc", entry->d_name);
113
file = fopen(filename, "r");
116
memset(line, 0, 4096);
117
f = fgets(line, 4096, file);
122
f = strstr(line, "MWAIT ");
125
bios_table[(strtoull(f, NULL, 16)>>4) + 1]++;
138
ebx = 0; ecx = 0; edx = 0;
139
cpuid(&eax, &ebx, &ecx, &edx);
140
if (!edx || ((ecx&1) == 0))
143
printf(_("Your CPU supports the following C-states : "));
152
printf(_("Your BIOS reports the following C-states : "));
153
for (i = 0; i < 8; i++)