Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
2cd005ca
Commit
2cd005ca
authored
Apr 19, 2011
by
Dominik Brodowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cpupowerutils: helpers - ConfigStyle bugfixes
Signed-off-by:
Dominik Brodowski
<
linux@dominikbrodowski.net
>
parent
b510b541
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
100 additions
and
86 deletions
+100
-86
tools/power/cpupower/utils/helpers/amd.c
tools/power/cpupower/utils/helpers/amd.c
+4
-4
tools/power/cpupower/utils/helpers/bitmask.c
tools/power/cpupower/utils/helpers/bitmask.c
+7
-5
tools/power/cpupower/utils/helpers/cpuid.c
tools/power/cpupower/utils/helpers/cpuid.c
+6
-8
tools/power/cpupower/utils/helpers/helpers.h
tools/power/cpupower/utils/helpers/helpers.h
+3
-3
tools/power/cpupower/utils/helpers/misc.c
tools/power/cpupower/utils/helpers/misc.c
+2
-1
tools/power/cpupower/utils/helpers/pci.c
tools/power/cpupower/utils/helpers/pci.c
+1
-1
tools/power/cpupower/utils/helpers/sysfs.c
tools/power/cpupower/utils/helpers/sysfs.c
+60
-52
tools/power/cpupower/utils/helpers/sysfs.h
tools/power/cpupower/utils/helpers/sysfs.h
+14
-9
tools/power/cpupower/utils/helpers/topology.c
tools/power/cpupower/utils/helpers/topology.c
+3
-3
No files found.
tools/power/cpupower/utils/helpers/amd.c
View file @
2cd005ca
...
@@ -53,8 +53,8 @@ static int get_cof(int family, union msr_pstate pstate)
...
@@ -53,8 +53,8 @@ static int get_cof(int family, union msr_pstate pstate)
if
(
family
==
0x11
)
if
(
family
==
0x11
)
t
=
0x8
;
t
=
0x8
;
return
(
(
100
*
(
fid
+
t
))
>>
did
)
;
return
(
100
*
(
fid
+
t
))
>>
did
;
}
}
/* Needs:
/* Needs:
* cpu -> the cpu that gets evaluated
* cpu -> the cpu that gets evaluated
...
@@ -74,7 +74,7 @@ int decode_pstates(unsigned int cpu, unsigned int cpu_family,
...
@@ -74,7 +74,7 @@ int decode_pstates(unsigned int cpu, unsigned int cpu_family,
{
{
int
i
,
psmax
,
pscur
;
int
i
,
psmax
,
pscur
;
union
msr_pstate
pstate
;
union
msr_pstate
pstate
;
unsigned
long
long
val
;
unsigned
long
long
val
;
/* Only read out frequencies from HW when CPU might be boostable
/* Only read out frequencies from HW when CPU might be boostable
to keep the code as short and clean as possible.
to keep the code as short and clean as possible.
...
@@ -95,7 +95,7 @@ int decode_pstates(unsigned int cpu, unsigned int cpu_family,
...
@@ -95,7 +95,7 @@ int decode_pstates(unsigned int cpu, unsigned int cpu_family,
pscur
+=
boost_states
;
pscur
+=
boost_states
;
psmax
+=
boost_states
;
psmax
+=
boost_states
;
for
(
i
=
0
;
i
<=
psmax
;
i
++
)
{
for
(
i
=
0
;
i
<=
psmax
;
i
++
)
{
if
(
i
>=
MAX_HW_PSTATES
)
{
if
(
i
>=
MAX_HW_PSTATES
)
{
fprintf
(
stderr
,
"HW pstates [%d] exceeding max [%d]
\n
"
,
fprintf
(
stderr
,
"HW pstates [%d] exceeding max [%d]
\n
"
,
psmax
,
MAX_HW_PSTATES
);
psmax
,
MAX_HW_PSTATES
);
...
...
tools/power/cpupower/utils/helpers/bitmask.c
View file @
2cd005ca
...
@@ -8,12 +8,12 @@
...
@@ -8,12 +8,12 @@
#define bitsperlong (8 * sizeof(unsigned long))
#define bitsperlong (8 * sizeof(unsigned long))
/* howmany(a,b) : how many elements of size b needed to hold all of a */
/* howmany(a,b) : how many elements of size b needed to hold all of a */
#define howmany(x,y) (((x)+((y)-1))/(y))
#define howmany(x,
y) (((x)+((y)-1))/(y))
/* How many longs in mask of n bits */
/* How many longs in mask of n bits */
#define longsperbits(n) howmany(n, bitsperlong)
#define longsperbits(n) howmany(n, bitsperlong)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define max(a,
b) ((a) > (b) ? (a) : (b))
/*
/*
* Allocate and free `struct bitmask *`
* Allocate and free `struct bitmask *`
...
@@ -73,7 +73,8 @@ static void _setbit(struct bitmask *bmp, unsigned int n, unsigned int v)
...
@@ -73,7 +73,8 @@ static void _setbit(struct bitmask *bmp, unsigned int n, unsigned int v)
if
(
v
)
if
(
v
)
bmp
->
maskp
[
n
/
bitsperlong
]
|=
1UL
<<
(
n
%
bitsperlong
);
bmp
->
maskp
[
n
/
bitsperlong
]
|=
1UL
<<
(
n
%
bitsperlong
);
else
else
bmp
->
maskp
[
n
/
bitsperlong
]
&=
~
(
1UL
<<
(
n
%
bitsperlong
));
bmp
->
maskp
[
n
/
bitsperlong
]
&=
~
(
1UL
<<
(
n
%
bitsperlong
));
}
}
}
}
...
@@ -185,7 +186,7 @@ unsigned int bitmask_next(const struct bitmask *bmp, unsigned int i)
...
@@ -185,7 +186,7 @@ unsigned int bitmask_next(const struct bitmask *bmp, unsigned int i)
* 0-3 0,1,2,3
* 0-3 0,1,2,3
* 0-7:2 0,2,4,6
* 0-7:2 0,2,4,6
* 1,3,5-7 1,3,5,6,7
* 1,3,5-7 1,3,5,6,7
* 0-3:2,8-15:4 0,2,8,12
* 0-3:2,8-15:4 0,2,8,12
*/
*/
int
bitmask_parselist
(
const
char
*
buf
,
struct
bitmask
*
bmp
)
int
bitmask_parselist
(
const
char
*
buf
,
struct
bitmask
*
bmp
)
{
{
...
@@ -251,7 +252,8 @@ static inline int emit(char *buf, int buflen, int rbot, int rtop, int len)
...
@@ -251,7 +252,8 @@ static inline int emit(char *buf, int buflen, int rbot, int rtop, int len)
if
(
rbot
==
rtop
)
if
(
rbot
==
rtop
)
len
+=
snprintf
(
buf
+
len
,
max
(
buflen
-
len
,
0
),
"%d"
,
rbot
);
len
+=
snprintf
(
buf
+
len
,
max
(
buflen
-
len
,
0
),
"%d"
,
rbot
);
else
else
len
+=
snprintf
(
buf
+
len
,
max
(
buflen
-
len
,
0
),
"%d-%d"
,
rbot
,
rtop
);
len
+=
snprintf
(
buf
+
len
,
max
(
buflen
-
len
,
0
),
"%d-%d"
,
rbot
,
rtop
);
return
len
;
return
len
;
}
}
...
...
tools/power/cpupower/utils/helpers/cpuid.c
View file @
2cd005ca
...
@@ -67,28 +67,26 @@ int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info)
...
@@ -67,28 +67,26 @@ int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info)
continue
;
continue
;
value
[
63
-
1
]
=
'\0'
;
value
[
63
-
1
]
=
'\0'
;
if
(
!
strncmp
(
value
,
"processor
\t
: "
,
12
))
{
if
(
!
strncmp
(
value
,
"processor
\t
: "
,
12
))
sscanf
(
value
,
"processor
\t
: %u"
,
&
proc
);
sscanf
(
value
,
"processor
\t
: %u"
,
&
proc
);
}
if
(
proc
!=
cpu
)
if
(
proc
!=
cpu
)
continue
;
continue
;
/* Get CPU vendor */
/* Get CPU vendor */
if
(
!
strncmp
(
value
,
"vendor_id"
,
9
))
if
(
!
strncmp
(
value
,
"vendor_id"
,
9
))
{
for
(
x
=
1
;
x
<
X86_VENDOR_MAX
;
x
++
)
{
for
(
x
=
1
;
x
<
X86_VENDOR_MAX
;
x
++
)
{
if
(
strstr
(
value
,
cpu_vendor_table
[
x
]))
if
(
strstr
(
value
,
cpu_vendor_table
[
x
]))
cpu_info
->
vendor
=
x
;
cpu_info
->
vendor
=
x
;
}
}
/* Get CPU family, etc. */
/* Get CPU family, etc. */
else
if
(
!
strncmp
(
value
,
"cpu family
\t
: "
,
13
))
{
}
else
if
(
!
strncmp
(
value
,
"cpu family
\t
: "
,
13
))
{
sscanf
(
value
,
"cpu family
\t
: %u"
,
sscanf
(
value
,
"cpu family
\t
: %u"
,
&
cpu_info
->
family
);
&
cpu_info
->
family
);
}
}
else
if
(
!
strncmp
(
value
,
"model
\t\t
: "
,
9
))
{
else
if
(
!
strncmp
(
value
,
"model
\t\t
: "
,
9
))
{
sscanf
(
value
,
"model
\t\t
: %u"
,
sscanf
(
value
,
"model
\t\t
: %u"
,
&
cpu_info
->
model
);
&
cpu_info
->
model
);
}
}
else
if
(
!
strncmp
(
value
,
"stepping
\t
: "
,
10
))
{
else
if
(
!
strncmp
(
value
,
"stepping
\t
: "
,
10
))
{
sscanf
(
value
,
"stepping
\t
: %u"
,
sscanf
(
value
,
"stepping
\t
: %u"
,
&
cpu_info
->
stepping
);
&
cpu_info
->
stepping
);
...
...
tools/power/cpupower/utils/helpers/helpers.h
View file @
2cd005ca
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#ifndef gettext_noop
#ifndef gettext_noop
#define gettext_noop(String) String
#define gettext_noop(String) String
#endif
#endif
#define N_(String) gettext_noop
(String)
#define N_(String) gettext_noop(String)
/* Internationalization ****************************/
/* Internationalization ****************************/
extern
int
run_as_root
;
extern
int
run_as_root
;
...
@@ -39,11 +39,11 @@ extern int be_verbose;
...
@@ -39,11 +39,11 @@ extern int be_verbose;
#define dprint(fmt, ...) { \
#define dprint(fmt, ...) { \
if (be_verbose) { \
if (be_verbose) { \
fprintf(stderr, "%s: " fmt, \
fprintf(stderr, "%s: " fmt, \
__
FUNCTION
__, ##__VA_ARGS__); \
__
func
__, ##__VA_ARGS__); \
} \
} \
}
}
#else
#else
static
inline
void
dprint
(
const
char
*
fmt
,
...)
{
}
static
inline
void
dprint
(
const
char
*
fmt
,
...)
{
}
#endif
#endif
extern
int
be_verbose
;
extern
int
be_verbose
;
/* Global verbose (-v) stuff *********************************/
/* Global verbose (-v) stuff *********************************/
...
...
tools/power/cpupower/utils/helpers/misc.c
View file @
2cd005ca
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
#include "helpers/helpers.h"
#include "helpers/helpers.h"
int
cpufreq_has_boost_support
(
unsigned
int
cpu
,
int
*
support
,
int
*
active
,
int
*
states
)
int
cpufreq_has_boost_support
(
unsigned
int
cpu
,
int
*
support
,
int
*
active
,
int
*
states
)
{
{
struct
cpupower_cpu_info
cpu_info
;
struct
cpupower_cpu_info
cpu_info
;
int
ret
;
int
ret
;
...
...
tools/power/cpupower/utils/helpers/pci.c
View file @
2cd005ca
...
@@ -33,7 +33,7 @@ struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id,
...
@@ -33,7 +33,7 @@ struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id,
for
(
i
=
0
;
dev_ids
[
i
]
!=
0
;
i
++
)
{
for
(
i
=
0
;
dev_ids
[
i
]
!=
0
;
i
++
)
{
filter_nb_link
.
device
=
dev_ids
[
i
];
filter_nb_link
.
device
=
dev_ids
[
i
];
for
(
device
=
(
*
pacc
)
->
devices
;
device
;
device
=
device
->
next
)
{
for
(
device
=
(
*
pacc
)
->
devices
;
device
;
device
=
device
->
next
)
{
if
(
pci_filter_match
(
&
filter_nb_link
,
device
))
if
(
pci_filter_match
(
&
filter_nb_link
,
device
))
return
device
;
return
device
;
}
}
...
...
tools/power/cpupower/utils/helpers/sysfs.c
View file @
2cd005ca
...
@@ -19,14 +19,14 @@
...
@@ -19,14 +19,14 @@
unsigned
int
sysfs_read_file
(
const
char
*
path
,
char
*
buf
,
size_t
buflen
)
unsigned
int
sysfs_read_file
(
const
char
*
path
,
char
*
buf
,
size_t
buflen
)
{
{
int
fd
;
int
fd
;
size_t
numread
;
s
s
ize_t
numread
;
if
(
(
fd
=
open
(
path
,
O_RDONLY
)
)
==
-
1
)
fd
=
open
(
path
,
O_RDONLY
);
if
(
fd
==
-
1
)
return
0
;
return
0
;
numread
=
read
(
fd
,
buf
,
buflen
-
1
);
numread
=
read
(
fd
,
buf
,
buflen
-
1
);
if
(
numread
<
1
)
if
(
numread
<
1
)
{
{
close
(
fd
);
close
(
fd
);
return
0
;
return
0
;
}
}
...
@@ -34,26 +34,26 @@ unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen)
...
@@ -34,26 +34,26 @@ unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen)
buf
[
numread
]
=
'\0'
;
buf
[
numread
]
=
'\0'
;
close
(
fd
);
close
(
fd
);
return
numread
;
return
(
unsigned
int
)
numread
;
}
}
static
unsigned
int
sysfs_write_file
(
const
char
*
path
,
static
unsigned
int
sysfs_write_file
(
const
char
*
path
,
const
char
*
value
,
size_t
len
)
const
char
*
value
,
size_t
len
)
{
{
int
fd
;
int
fd
;
size_t
numwrite
;
s
s
ize_t
numwrite
;
if
(
(
fd
=
open
(
path
,
O_WRONLY
)
)
==
-
1
)
fd
=
open
(
path
,
O_WRONLY
);
if
(
fd
==
-
1
)
return
0
;
return
0
;
numwrite
=
write
(
fd
,
value
,
len
);
numwrite
=
write
(
fd
,
value
,
len
);
if
(
numwrite
<
1
)
if
(
numwrite
<
1
)
{
{
close
(
fd
);
close
(
fd
);
return
0
;
return
0
;
}
}
close
(
fd
);
close
(
fd
);
return
numwrite
;
return
(
unsigned
int
)
numwrite
;
}
}
/* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */
/* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */
...
@@ -69,17 +69,17 @@ unsigned int sysfs_idlestate_read_file(unsigned int cpu, unsigned int idlestate,
...
@@ -69,17 +69,17 @@ unsigned int sysfs_idlestate_read_file(unsigned int cpu, unsigned int idlestate,
{
{
char
path
[
SYSFS_PATH_MAX
];
char
path
[
SYSFS_PATH_MAX
];
int
fd
;
int
fd
;
size_t
numread
;
s
s
ize_t
numread
;
snprintf
(
path
,
sizeof
(
path
),
PATH_TO_CPU
"cpu%u/cpuidle/state%u/%s"
,
snprintf
(
path
,
sizeof
(
path
),
PATH_TO_CPU
"cpu%u/cpuidle/state%u/%s"
,
cpu
,
idlestate
,
fname
);
cpu
,
idlestate
,
fname
);
if
(
(
fd
=
open
(
path
,
O_RDONLY
)
)
==
-
1
)
fd
=
open
(
path
,
O_RDONLY
);
if
(
fd
==
-
1
)
return
0
;
return
0
;
numread
=
read
(
fd
,
buf
,
buflen
-
1
);
numread
=
read
(
fd
,
buf
,
buflen
-
1
);
if
(
numread
<
1
)
if
(
numread
<
1
)
{
{
close
(
fd
);
close
(
fd
);
return
0
;
return
0
;
}
}
...
@@ -87,7 +87,7 @@ unsigned int sysfs_idlestate_read_file(unsigned int cpu, unsigned int idlestate,
...
@@ -87,7 +87,7 @@ unsigned int sysfs_idlestate_read_file(unsigned int cpu, unsigned int idlestate,
buf
[
numread
]
=
'\0'
;
buf
[
numread
]
=
'\0'
;
close
(
fd
);
close
(
fd
);
return
numread
;
return
(
unsigned
int
)
numread
;
}
}
/* read access to files which contain one numeric value */
/* read access to files which contain one numeric value */
...
@@ -116,19 +116,18 @@ static unsigned long long sysfs_idlestate_get_one_value(unsigned int cpu,
...
@@ -116,19 +116,18 @@ static unsigned long long sysfs_idlestate_get_one_value(unsigned int cpu,
char
linebuf
[
MAX_LINE_LEN
];
char
linebuf
[
MAX_LINE_LEN
];
char
*
endp
;
char
*
endp
;
if
(
which
>=
MAX_IDLESTATE_VALUE_FILES
)
if
(
which
>=
MAX_IDLESTATE_VALUE_FILES
)
return
0
;
return
0
;
if
(
(
len
=
sysfs_idlestate_read_file
(
cpu
,
idlestate
,
len
=
sysfs_idlestate_read_file
(
cpu
,
idlestate
,
idlestate_value_files
[
which
],
idlestate_value_files
[
which
],
linebuf
,
sizeof
(
linebuf
)))
==
0
)
linebuf
,
sizeof
(
linebuf
));
{
if
(
len
==
0
)
return
0
;
return
0
;
}
value
=
strtoull
(
linebuf
,
&
endp
,
0
);
value
=
strtoull
(
linebuf
,
&
endp
,
0
);
if
(
endp
==
linebuf
||
errno
==
ERANGE
)
if
(
endp
==
linebuf
||
errno
==
ERANGE
)
return
0
;
return
0
;
return
value
;
return
value
;
...
@@ -148,9 +147,9 @@ static const char *idlestate_string_files[MAX_IDLESTATE_STRING_FILES] = {
...
@@ -148,9 +147,9 @@ static const char *idlestate_string_files[MAX_IDLESTATE_STRING_FILES] = {
};
};
static
char
*
sysfs_idlestate_get_one_string
(
unsigned
int
cpu
,
static
char
*
sysfs_idlestate_get_one_string
(
unsigned
int
cpu
,
unsigned
int
idlestate
,
unsigned
int
idlestate
,
enum
idlestate_string
which
)
enum
idlestate_string
which
)
{
{
char
linebuf
[
MAX_LINE_LEN
];
char
linebuf
[
MAX_LINE_LEN
];
char
*
result
;
char
*
result
;
...
@@ -159,12 +158,14 @@ static char * sysfs_idlestate_get_one_string(unsigned int cpu,
...
@@ -159,12 +158,14 @@ static char * sysfs_idlestate_get_one_string(unsigned int cpu,
if
(
which
>=
MAX_IDLESTATE_STRING_FILES
)
if
(
which
>=
MAX_IDLESTATE_STRING_FILES
)
return
NULL
;
return
NULL
;
if
(
(
len
=
sysfs_idlestate_read_file
(
cpu
,
idlestate
,
len
=
sysfs_idlestate_read_file
(
cpu
,
idlestate
,
idlestate_string_files
[
which
],
idlestate_string_files
[
which
],
linebuf
,
sizeof
(
linebuf
)))
==
0
)
linebuf
,
sizeof
(
linebuf
));
if
(
len
==
0
)
return
NULL
;
return
NULL
;
if
(
(
result
=
strdup
(
linebuf
)
)
==
NULL
)
result
=
strdup
(
linebuf
);
if
(
result
==
NULL
)
return
NULL
;
return
NULL
;
if
(
result
[
strlen
(
result
)
-
1
]
==
'\n'
)
if
(
result
[
strlen
(
result
)
-
1
]
==
'\n'
)
...
@@ -173,27 +174,30 @@ static char * sysfs_idlestate_get_one_string(unsigned int cpu,
...
@@ -173,27 +174,30 @@ static char * sysfs_idlestate_get_one_string(unsigned int cpu,
return
result
;
return
result
;
}
}
unsigned
long
sysfs_get_idlestate_latency
(
unsigned
int
cpu
,
unsigned
int
idlestate
)
unsigned
long
sysfs_get_idlestate_latency
(
unsigned
int
cpu
,
unsigned
int
idlestate
)
{
{
return
sysfs_idlestate_get_one_value
(
cpu
,
idlestate
,
IDLESTATE_LATENCY
);
return
sysfs_idlestate_get_one_value
(
cpu
,
idlestate
,
IDLESTATE_LATENCY
);
}
}
unsigned
long
sysfs_get_idlestate_usage
(
unsigned
int
cpu
,
unsigned
int
idlestate
)
unsigned
long
sysfs_get_idlestate_usage
(
unsigned
int
cpu
,
unsigned
int
idlestate
)
{
{
return
sysfs_idlestate_get_one_value
(
cpu
,
idlestate
,
IDLESTATE_USAGE
);
return
sysfs_idlestate_get_one_value
(
cpu
,
idlestate
,
IDLESTATE_USAGE
);
}
}
unsigned
long
long
sysfs_get_idlestate_time
(
unsigned
int
cpu
,
unsigned
int
idlestate
)
unsigned
long
long
sysfs_get_idlestate_time
(
unsigned
int
cpu
,
unsigned
int
idlestate
)
{
{
return
sysfs_idlestate_get_one_value
(
cpu
,
idlestate
,
IDLESTATE_TIME
);
return
sysfs_idlestate_get_one_value
(
cpu
,
idlestate
,
IDLESTATE_TIME
);
}
}
char
*
sysfs_get_idlestate_name
(
unsigned
int
cpu
,
unsigned
int
idlestate
)
char
*
sysfs_get_idlestate_name
(
unsigned
int
cpu
,
unsigned
int
idlestate
)
{
{
return
sysfs_idlestate_get_one_string
(
cpu
,
idlestate
,
IDLESTATE_NAME
);
return
sysfs_idlestate_get_one_string
(
cpu
,
idlestate
,
IDLESTATE_NAME
);
}
}
char
*
sysfs_get_idlestate_desc
(
unsigned
int
cpu
,
unsigned
int
idlestate
)
char
*
sysfs_get_idlestate_desc
(
unsigned
int
cpu
,
unsigned
int
idlestate
)
{
{
return
sysfs_idlestate_get_one_string
(
cpu
,
idlestate
,
IDLESTATE_DESC
);
return
sysfs_idlestate_get_one_string
(
cpu
,
idlestate
,
IDLESTATE_DESC
);
}
}
...
@@ -211,14 +215,14 @@ int sysfs_get_idlestate_count(unsigned int cpu)
...
@@ -211,14 +215,14 @@ int sysfs_get_idlestate_count(unsigned int cpu)
snprintf
(
file
,
SYSFS_PATH_MAX
,
PATH_TO_CPU
"cpuidle"
);
snprintf
(
file
,
SYSFS_PATH_MAX
,
PATH_TO_CPU
"cpuidle"
);
if
(
stat
(
file
,
&
statbuf
)
!=
0
||
!
S_ISDIR
(
statbuf
.
st_mode
))
if
(
stat
(
file
,
&
statbuf
)
!=
0
||
!
S_ISDIR
(
statbuf
.
st_mode
))
return
-
ENODEV
;
return
-
ENODEV
;
snprintf
(
file
,
SYSFS_PATH_MAX
,
PATH_TO_CPU
"cpu%u/cpuidle/state0"
,
cpu
);
snprintf
(
file
,
SYSFS_PATH_MAX
,
PATH_TO_CPU
"cpu%u/cpuidle/state0"
,
cpu
);
if
(
stat
(
file
,
&
statbuf
)
!=
0
||
!
S_ISDIR
(
statbuf
.
st_mode
))
if
(
stat
(
file
,
&
statbuf
)
!=
0
||
!
S_ISDIR
(
statbuf
.
st_mode
))
return
0
;
return
0
;
while
(
stat
(
file
,
&
statbuf
)
==
0
&&
S_ISDIR
(
statbuf
.
st_mode
))
{
while
(
stat
(
file
,
&
statbuf
)
==
0
&&
S_ISDIR
(
statbuf
.
st_mode
))
{
snprintf
(
file
,
SYSFS_PATH_MAX
,
PATH_TO_CPU
snprintf
(
file
,
SYSFS_PATH_MAX
,
PATH_TO_CPU
"cpu%u/cpuidle/state%d"
,
cpu
,
idlestates
);
"cpu%u/cpuidle/state%d"
,
cpu
,
idlestates
);
idlestates
++
;
idlestates
++
;
...
@@ -261,7 +265,7 @@ static const char *cpuidle_string_files[MAX_CPUIDLE_STRING_FILES] = {
...
@@ -261,7 +265,7 @@ static const char *cpuidle_string_files[MAX_CPUIDLE_STRING_FILES] = {
};
};
static
char
*
sysfs_cpuidle_get_one_string
(
enum
cpuidle_string
which
)
static
char
*
sysfs_cpuidle_get_one_string
(
enum
cpuidle_string
which
)
{
{
char
linebuf
[
MAX_LINE_LEN
];
char
linebuf
[
MAX_LINE_LEN
];
char
*
result
;
char
*
result
;
...
@@ -270,11 +274,13 @@ static char * sysfs_cpuidle_get_one_string(enum cpuidle_string which)
...
@@ -270,11 +274,13 @@ static char * sysfs_cpuidle_get_one_string(enum cpuidle_string which)
if
(
which
>=
MAX_CPUIDLE_STRING_FILES
)
if
(
which
>=
MAX_CPUIDLE_STRING_FILES
)
return
NULL
;
return
NULL
;
if
(
(
len
=
sysfs_cpuidle_read_file
(
cpuidle_string_files
[
which
],
len
=
sysfs_cpuidle_read_file
(
cpuidle_string_files
[
which
],
linebuf
,
sizeof
(
linebuf
)))
==
0
)
linebuf
,
sizeof
(
linebuf
));
if
(
len
==
0
)
return
NULL
;
return
NULL
;
if
(
(
result
=
strdup
(
linebuf
)
)
==
NULL
)
result
=
strdup
(
linebuf
);
if
(
result
==
NULL
)
return
NULL
;
return
NULL
;
if
(
result
[
strlen
(
result
)
-
1
]
==
'\n'
)
if
(
result
[
strlen
(
result
)
-
1
]
==
'\n'
)
...
@@ -283,7 +289,7 @@ static char * sysfs_cpuidle_get_one_string(enum cpuidle_string which)
...
@@ -283,7 +289,7 @@ static char * sysfs_cpuidle_get_one_string(enum cpuidle_string which)
return
result
;
return
result
;
}
}
char
*
sysfs_get_cpuidle_governor
(
void
)
char
*
sysfs_get_cpuidle_governor
(
void
)
{
{
char
*
tmp
=
sysfs_cpuidle_get_one_string
(
CPUIDLE_GOVERNOR_RO
);
char
*
tmp
=
sysfs_cpuidle_get_one_string
(
CPUIDLE_GOVERNOR_RO
);
if
(
!
tmp
)
if
(
!
tmp
)
...
@@ -292,7 +298,7 @@ char * sysfs_get_cpuidle_governor(void)
...
@@ -292,7 +298,7 @@ char * sysfs_get_cpuidle_governor(void)
return
tmp
;
return
tmp
;
}
}
char
*
sysfs_get_cpuidle_driver
(
void
)
char
*
sysfs_get_cpuidle_driver
(
void
)
{
{
return
sysfs_cpuidle_get_one_string
(
CPUIDLE_DRIVER
);
return
sysfs_cpuidle_get_one_string
(
CPUIDLE_DRIVER
);
}
}
...
@@ -304,9 +310,9 @@ char * sysfs_get_cpuidle_driver(void)
...
@@ -304,9 +310,9 @@ char * sysfs_get_cpuidle_driver(void)
*
*
* Returns negative value on failure
* Returns negative value on failure
*/
*/
int
sysfs_get_sched
(
const
char
*
smt_mc
)
int
sysfs_get_sched
(
const
char
*
smt_mc
)
{
{
unsigned
long
value
;
unsigned
long
value
;
char
linebuf
[
MAX_LINE_LEN
];
char
linebuf
[
MAX_LINE_LEN
];
char
*
endp
;
char
*
endp
;
char
path
[
SYSFS_PATH_MAX
];
char
path
[
SYSFS_PATH_MAX
];
...
@@ -314,11 +320,12 @@ int sysfs_get_sched(const char* smt_mc)
...
@@ -314,11 +320,12 @@ int sysfs_get_sched(const char* smt_mc)
if
(
strcmp
(
"mc"
,
smt_mc
)
&&
strcmp
(
"smt"
,
smt_mc
))
if
(
strcmp
(
"mc"
,
smt_mc
)
&&
strcmp
(
"smt"
,
smt_mc
))
return
-
EINVAL
;
return
-
EINVAL
;
snprintf
(
path
,
sizeof
(
path
),
PATH_TO_CPU
"sched_%s_power_savings"
,
smt_mc
);
snprintf
(
path
,
sizeof
(
path
),
if
(
sysfs_read_file
(
path
,
linebuf
,
MAX_LINE_LEN
)
==
0
)
PATH_TO_CPU
"sched_%s_power_savings"
,
smt_mc
);
if
(
sysfs_read_file
(
path
,
linebuf
,
MAX_LINE_LEN
)
==
0
)
return
-
1
;
return
-
1
;
value
=
strtoul
(
linebuf
,
&
endp
,
0
);
value
=
strtoul
(
linebuf
,
&
endp
,
0
);
if
(
endp
==
linebuf
||
errno
==
ERANGE
)
if
(
endp
==
linebuf
||
errno
==
ERANGE
)
return
-
1
;
return
-
1
;
return
value
;
return
value
;
}
}
...
@@ -329,7 +336,7 @@ int sysfs_get_sched(const char* smt_mc)
...
@@ -329,7 +336,7 @@ int sysfs_get_sched(const char* smt_mc)
*
*
* Returns negative value on failure
* Returns negative value on failure
*/
*/
int
sysfs_set_sched
(
const
char
*
smt_mc
,
int
val
)
int
sysfs_set_sched
(
const
char
*
smt_mc
,
int
val
)
{
{
char
linebuf
[
MAX_LINE_LEN
];
char
linebuf
[
MAX_LINE_LEN
];
char
path
[
SYSFS_PATH_MAX
];
char
path
[
SYSFS_PATH_MAX
];
...
@@ -338,13 +345,14 @@ int sysfs_set_sched(const char* smt_mc, int val)
...
@@ -338,13 +345,14 @@ int sysfs_set_sched(const char* smt_mc, int val)
if
(
strcmp
(
"mc"
,
smt_mc
)
&&
strcmp
(
"smt"
,
smt_mc
))
if
(
strcmp
(
"mc"
,
smt_mc
)
&&
strcmp
(
"smt"
,
smt_mc
))
return
-
EINVAL
;
return
-
EINVAL
;
snprintf
(
path
,
sizeof
(
path
),
PATH_TO_CPU
"sched_%s_power_savings"
,
smt_mc
);
snprintf
(
path
,
sizeof
(
path
),
PATH_TO_CPU
"sched_%s_power_savings"
,
smt_mc
);
sprintf
(
linebuf
,
"%d"
,
val
);
sprintf
(
linebuf
,
"%d"
,
val
);
if
(
stat
(
path
,
&
statbuf
)
!=
0
)
if
(
stat
(
path
,
&
statbuf
)
!=
0
)
return
-
ENODEV
;
return
-
ENODEV
;
if
(
sysfs_write_file
(
path
,
linebuf
,
MAX_LINE_LEN
)
==
0
)
if
(
sysfs_write_file
(
path
,
linebuf
,
MAX_LINE_LEN
)
==
0
)
return
-
1
;
return
-
1
;
return
0
;
return
0
;
}
}
tools/power/cpupower/utils/helpers/sysfs.h
View file @
2cd005ca
...
@@ -7,17 +7,22 @@
...
@@ -7,17 +7,22 @@
extern
unsigned
int
sysfs_read_file
(
const
char
*
path
,
char
*
buf
,
size_t
buflen
);
extern
unsigned
int
sysfs_read_file
(
const
char
*
path
,
char
*
buf
,
size_t
buflen
);
extern
unsigned
long
sysfs_get_idlestate_latency
(
unsigned
int
cpu
,
unsigned
int
idlestate
);
extern
unsigned
long
sysfs_get_idlestate_latency
(
unsigned
int
cpu
,
extern
unsigned
long
sysfs_get_idlestate_usage
(
unsigned
int
cpu
,
unsigned
int
idlestate
);
unsigned
int
idlestate
);
extern
unsigned
long
long
sysfs_get_idlestate_time
(
unsigned
int
cpu
,
unsigned
int
idlestate
);
extern
unsigned
long
sysfs_get_idlestate_usage
(
unsigned
int
cpu
,
extern
char
*
sysfs_get_idlestate_name
(
unsigned
int
cpu
,
unsigned
int
idlestate
);
unsigned
int
idlestate
);
extern
char
*
sysfs_get_idlestate_desc
(
unsigned
int
cpu
,
unsigned
int
idlestate
);
extern
unsigned
long
long
sysfs_get_idlestate_time
(
unsigned
int
cpu
,
unsigned
int
idlestate
);
extern
char
*
sysfs_get_idlestate_name
(
unsigned
int
cpu
,
unsigned
int
idlestate
);
extern
char
*
sysfs_get_idlestate_desc
(
unsigned
int
cpu
,
unsigned
int
idlestate
);
extern
int
sysfs_get_idlestate_count
(
unsigned
int
cpu
);
extern
int
sysfs_get_idlestate_count
(
unsigned
int
cpu
);
extern
char
*
sysfs_get_cpuidle_governor
(
void
);
extern
char
*
sysfs_get_cpuidle_governor
(
void
);
extern
char
*
sysfs_get_cpuidle_driver
(
void
);
extern
char
*
sysfs_get_cpuidle_driver
(
void
);
extern
int
sysfs_get_sched
(
const
char
*
smt_mc
);
extern
int
sysfs_get_sched
(
const
char
*
smt_mc
);
extern
int
sysfs_set_sched
(
const
char
*
smt_mc
,
int
val
);
extern
int
sysfs_set_sched
(
const
char
*
smt_mc
,
int
val
);
#endif
/* __CPUPOWER_HELPERS_SYSFS_H__ */
#endif
/* __CPUPOWER_HELPERS_SYSFS_H__ */
tools/power/cpupower/utils/helpers/topology.c
View file @
2cd005ca
...
@@ -22,17 +22,17 @@
...
@@ -22,17 +22,17 @@
/* returns -1 on failure, 0 on success */
/* returns -1 on failure, 0 on success */
int
sysfs_topology_read_file
(
unsigned
int
cpu
,
const
char
*
fname
)
int
sysfs_topology_read_file
(
unsigned
int
cpu
,
const
char
*
fname
)
{
{
unsigned
long
value
;
unsigned
long
value
;
char
linebuf
[
MAX_LINE_LEN
];
char
linebuf
[
MAX_LINE_LEN
];
char
*
endp
;
char
*
endp
;
char
path
[
SYSFS_PATH_MAX
];
char
path
[
SYSFS_PATH_MAX
];
snprintf
(
path
,
sizeof
(
path
),
PATH_TO_CPU
"cpu%u/topology/%s"
,
snprintf
(
path
,
sizeof
(
path
),
PATH_TO_CPU
"cpu%u/topology/%s"
,
cpu
,
fname
);
cpu
,
fname
);
if
(
sysfs_read_file
(
path
,
linebuf
,
MAX_LINE_LEN
)
==
0
)
if
(
sysfs_read_file
(
path
,
linebuf
,
MAX_LINE_LEN
)
==
0
)
return
-
1
;
return
-
1
;
value
=
strtoul
(
linebuf
,
&
endp
,
0
);
value
=
strtoul
(
linebuf
,
&
endp
,
0
);
if
(
endp
==
linebuf
||
errno
==
ERANGE
)
if
(
endp
==
linebuf
||
errno
==
ERANGE
)
return
-
1
;
return
-
1
;
return
value
;
return
value
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment