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
nexedi
linux
Commits
6c2b8185
Commit
6c2b8185
authored
Apr 19, 2011
by
Dominik Brodowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cpupowerutils: lib - ConfigStyle bugfixes
Signed-off-by:
Dominik Brodowski
<
linux@dominikbrodowski.net
>
parent
02af3cb5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
209 additions
and
172 deletions
+209
-172
tools/power/cpupower/lib/cpufreq.c
tools/power/cpupower/lib/cpufreq.c
+45
-27
tools/power/cpupower/lib/cpufreq.h
tools/power/cpupower/lib/cpufreq.h
+31
-23
tools/power/cpupower/lib/sysfs.c
tools/power/cpupower/lib/sysfs.c
+111
-110
tools/power/cpupower/lib/sysfs.h
tools/power/cpupower/lib/sysfs.h
+22
-12
No files found.
tools/power/cpupower/lib/cpufreq.c
View file @
6c2b8185
...
...
@@ -42,21 +42,25 @@ int cpufreq_get_hardware_limits(unsigned int cpu,
return
sysfs_get_freq_hardware_limits
(
cpu
,
min
,
max
);
}
char
*
cpufreq_get_driver
(
unsigned
int
cpu
)
{
char
*
cpufreq_get_driver
(
unsigned
int
cpu
)
{
return
sysfs_get_freq_driver
(
cpu
);
}
void
cpufreq_put_driver
(
char
*
ptr
)
{
void
cpufreq_put_driver
(
char
*
ptr
)
{
if
(
!
ptr
)
return
;
free
(
ptr
);
}
struct
cpufreq_policy
*
cpufreq_get_policy
(
unsigned
int
cpu
)
{
struct
cpufreq_policy
*
cpufreq_get_policy
(
unsigned
int
cpu
)
{
return
sysfs_get_freq_policy
(
cpu
);
}
void
cpufreq_put_policy
(
struct
cpufreq_policy
*
policy
)
{
void
cpufreq_put_policy
(
struct
cpufreq_policy
*
policy
)
{
if
((
!
policy
)
||
(
!
policy
->
governor
))
return
;
...
...
@@ -65,11 +69,14 @@ void cpufreq_put_policy(struct cpufreq_policy *policy) {
free
(
policy
);
}
struct
cpufreq_available_governors
*
cpufreq_get_available_governors
(
unsigned
int
cpu
)
{
struct
cpufreq_available_governors
*
cpufreq_get_available_governors
(
unsigned
int
cpu
)
{
return
sysfs_get_freq_available_governors
(
cpu
);
}
void
cpufreq_put_available_governors
(
struct
cpufreq_available_governors
*
any
)
{
void
cpufreq_put_available_governors
(
struct
cpufreq_available_governors
*
any
)
{
struct
cpufreq_available_governors
*
tmp
,
*
next
;
if
(
!
any
)
...
...
@@ -86,11 +93,14 @@ void cpufreq_put_available_governors(struct cpufreq_available_governors *any) {
}
struct
cpufreq_available_frequencies
*
cpufreq_get_available_frequencies
(
unsigned
int
cpu
)
{
struct
cpufreq_available_frequencies
*
cpufreq_get_available_frequencies
(
unsigned
int
cpu
)
{
return
sysfs_get_available_frequencies
(
cpu
);
}
void
cpufreq_put_available_frequencies
(
struct
cpufreq_available_frequencies
*
any
)
{
void
cpufreq_put_available_frequencies
(
struct
cpufreq_available_frequencies
*
any
)
{
struct
cpufreq_available_frequencies
*
tmp
,
*
next
;
if
(
!
any
)
...
...
@@ -105,11 +115,13 @@ void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies *any
}
struct
cpufreq_affected_cpus
*
cpufreq_get_affected_cpus
(
unsigned
int
cpu
)
{
struct
cpufreq_affected_cpus
*
cpufreq_get_affected_cpus
(
unsigned
int
cpu
)
{
return
sysfs_get_freq_affected_cpus
(
cpu
);
}
void
cpufreq_put_affected_cpus
(
struct
cpufreq_affected_cpus
*
any
)
{
void
cpufreq_put_affected_cpus
(
struct
cpufreq_affected_cpus
*
any
)
{
struct
cpufreq_affected_cpus
*
tmp
,
*
next
;
if
(
!
any
)
...
...
@@ -124,16 +136,19 @@ void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *any) {
}
struct
cpufreq_affected_cpus
*
cpufreq_get_related_cpus
(
unsigned
int
cpu
)
{
struct
cpufreq_affected_cpus
*
cpufreq_get_related_cpus
(
unsigned
int
cpu
)
{
return
sysfs_get_freq_related_cpus
(
cpu
);
}
void
cpufreq_put_related_cpus
(
struct
cpufreq_affected_cpus
*
any
)
{
void
cpufreq_put_related_cpus
(
struct
cpufreq_affected_cpus
*
any
)
{
cpufreq_put_affected_cpus
(
any
);
}
int
cpufreq_set_policy
(
unsigned
int
cpu
,
struct
cpufreq_policy
*
policy
)
{
int
cpufreq_set_policy
(
unsigned
int
cpu
,
struct
cpufreq_policy
*
policy
)
{
if
(
!
policy
||
!
(
policy
->
governor
))
return
-
EINVAL
;
...
...
@@ -141,35 +156,39 @@ int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy) {
}
int
cpufreq_modify_policy_min
(
unsigned
int
cpu
,
unsigned
long
min_freq
)
{
int
cpufreq_modify_policy_min
(
unsigned
int
cpu
,
unsigned
long
min_freq
)
{
return
sysfs_modify_freq_policy_min
(
cpu
,
min_freq
);
}
int
cpufreq_modify_policy_max
(
unsigned
int
cpu
,
unsigned
long
max_freq
)
{
int
cpufreq_modify_policy_max
(
unsigned
int
cpu
,
unsigned
long
max_freq
)
{
return
sysfs_modify_freq_policy_max
(
cpu
,
max_freq
);
}
int
cpufreq_modify_policy_governor
(
unsigned
int
cpu
,
char
*
governor
)
{
int
cpufreq_modify_policy_governor
(
unsigned
int
cpu
,
char
*
governor
)
{
if
((
!
governor
)
||
(
strlen
(
governor
)
>
19
))
return
-
EINVAL
;
return
sysfs_modify_freq_policy_governor
(
cpu
,
governor
);
}
int
cpufreq_set_frequency
(
unsigned
int
cpu
,
unsigned
long
target_frequency
)
{
int
cpufreq_set_frequency
(
unsigned
int
cpu
,
unsigned
long
target_frequency
)
{
return
sysfs_set_frequency
(
cpu
,
target_frequency
);
}
struct
cpufreq_stats
*
cpufreq_get_stats
(
unsigned
int
cpu
,
unsigned
long
long
*
total_time
)
{
struct
cpufreq_stats
*
ret
;
ret
=
sysfs_get_freq_stats
(
cpu
,
total_time
);
return
(
ret
);
struct
cpufreq_stats
*
cpufreq_get_stats
(
unsigned
int
cpu
,
unsigned
long
long
*
total_time
)
{
return
sysfs_get_freq_stats
(
cpu
,
total_time
);
}
void
cpufreq_put_stats
(
struct
cpufreq_stats
*
any
)
{
void
cpufreq_put_stats
(
struct
cpufreq_stats
*
any
)
{
struct
cpufreq_stats
*
tmp
,
*
next
;
if
(
!
any
)
...
...
@@ -183,8 +202,7 @@ void cpufreq_put_stats(struct cpufreq_stats *any) {
}
}
unsigned
long
cpufreq_get_transitions
(
unsigned
int
cpu
)
{
unsigned
long
ret
=
sysfs_get_freq_transitions
(
cpu
);
return
(
ret
);
unsigned
long
cpufreq_get_transitions
(
unsigned
int
cpu
)
{
return
sysfs_get_freq_transitions
(
cpu
);
}
tools/power/cpupower/lib/cpufreq.h
View file @
6c2b8185
...
...
@@ -93,9 +93,9 @@ extern unsigned long cpufreq_get_transition_latency(unsigned int cpu);
* considerations by cpufreq policy notifiers in the kernel.
*/
extern
int
cpufreq_get_hardware_limits
(
unsigned
int
cpu
,
unsigned
long
*
min
,
unsigned
long
*
max
);
extern
int
cpufreq_get_hardware_limits
(
unsigned
int
cpu
,
unsigned
long
*
min
,
unsigned
long
*
max
);
/* determine CPUfreq driver used
...
...
@@ -104,9 +104,9 @@ extern int cpufreq_get_hardware_limits(unsigned int cpu,
* to avoid memory leakage, please.
*/
extern
char
*
cpufreq_get_driver
(
unsigned
int
cpu
);
extern
char
*
cpufreq_get_driver
(
unsigned
int
cpu
);
extern
void
cpufreq_put_driver
(
char
*
ptr
);
extern
void
cpufreq_put_driver
(
char
*
ptr
);
/* determine CPUfreq policy currently used
...
...
@@ -116,7 +116,7 @@ extern void cpufreq_put_driver(char * ptr);
*/
extern
struct
cpufreq_policy
*
cpufreq_get_policy
(
unsigned
int
cpu
);
extern
struct
cpufreq_policy
*
cpufreq_get_policy
(
unsigned
int
cpu
);
extern
void
cpufreq_put_policy
(
struct
cpufreq_policy
*
policy
);
...
...
@@ -129,41 +129,47 @@ extern void cpufreq_put_policy(struct cpufreq_policy *policy);
*/
extern
struct
cpufreq_available_governors
*
cpufreq_get_available_governors
(
unsigned
int
cpu
);
extern
struct
cpufreq_available_governors
*
cpufreq_get_available_governors
(
unsigned
int
cpu
);
extern
void
cpufreq_put_available_governors
(
struct
cpufreq_available_governors
*
first
);
extern
void
cpufreq_put_available_governors
(
struct
cpufreq_available_governors
*
first
);
/* determine CPU frequency states available
*
*
o
nly present on _some_ ->target() cpufreq drivers. For information purposes
* only. Please free allocated memory by calling
cpufreq_put_available_frequencies
* after use.
*
O
nly present on _some_ ->target() cpufreq drivers. For information purposes
* only. Please free allocated memory by calling
*
cpufreq_put_available_frequencies
after use.
*/
extern
struct
cpufreq_available_frequencies
*
cpufreq_get_available_frequencies
(
unsigned
int
cpu
);
extern
struct
cpufreq_available_frequencies
*
cpufreq_get_available_frequencies
(
unsigned
int
cpu
);
extern
void
cpufreq_put_available_frequencies
(
struct
cpufreq_available_frequencies
*
first
);
extern
void
cpufreq_put_available_frequencies
(
struct
cpufreq_available_frequencies
*
first
);
/* determine affected CPUs
/* determine affected CPUs
*
* Remember to call cpufreq_put_affected_cpus when no longer needed
* to avoid memory leakage, please.
*/
extern
struct
cpufreq_affected_cpus
*
cpufreq_get_affected_cpus
(
unsigned
int
cpu
);
extern
struct
cpufreq_affected_cpus
*
cpufreq_get_affected_cpus
(
unsigned
int
cpu
);
extern
void
cpufreq_put_affected_cpus
(
struct
cpufreq_affected_cpus
*
first
);
/* determine related CPUs
/* determine related CPUs
*
* Remember to call cpufreq_put_related_cpus when no longer needed
* to avoid memory leakage, please.
*/
extern
struct
cpufreq_affected_cpus
*
cpufreq_get_related_cpus
(
unsigned
int
cpu
);
extern
struct
cpufreq_affected_cpus
*
cpufreq_get_related_cpus
(
unsigned
int
cpu
);
extern
void
cpufreq_put_related_cpus
(
struct
cpufreq_affected_cpus
*
first
);
...
...
@@ -173,15 +179,16 @@ extern void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first);
* This is not available in all kernel versions or configurations.
*/
extern
struct
cpufreq_stats
*
cpufreq_get_stats
(
unsigned
int
cpu
,
unsigned
long
long
*
total_time
);
extern
struct
cpufreq_stats
*
cpufreq_get_stats
(
unsigned
int
cpu
,
unsigned
long
long
*
total_time
);
extern
void
cpufreq_put_stats
(
struct
cpufreq_stats
*
stats
);
extern
unsigned
long
cpufreq_get_transitions
(
unsigned
int
cpu
);
/* set new cpufreq policy
*
/* set new cpufreq policy
*
* Tries to set the passed policy as new policy as close as possible,
* but results may differ depending e.g. on governors being available.
*/
...
...
@@ -189,7 +196,7 @@ extern unsigned long cpufreq_get_transitions(unsigned int cpu);
extern
int
cpufreq_set_policy
(
unsigned
int
cpu
,
struct
cpufreq_policy
*
policy
);
/* modify a policy by only changing min/max freq or governor
/* modify a policy by only changing min/max freq or governor
*
* Does not check whether result is what was intended.
*/
...
...
@@ -202,11 +209,12 @@ extern int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
/* set a specific frequency
*
* Does only work if userspace governor can be used and no external
* interference (other calls to this function or to set/modify_policy)
* interference (other calls to this function or to set/modify_policy)
* occurs. Also does not work on ->range() cpufreq drivers.
*/
extern
int
cpufreq_set_frequency
(
unsigned
int
cpu
,
unsigned
long
target_frequency
);
extern
int
cpufreq_set_frequency
(
unsigned
int
cpu
,
unsigned
long
target_frequency
);
#ifdef __cplusplus
}
...
...
tools/power/cpupower/lib/sysfs.c
View file @
6c2b8185
...
...
@@ -24,14 +24,14 @@
static
unsigned
int
sysfs_read_file
(
const
char
*
path
,
char
*
buf
,
size_t
buflen
)
{
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
;
numread
=
read
(
fd
,
buf
,
buflen
-
1
);
if
(
numread
<
1
)
{
if
(
numread
<
1
)
{
close
(
fd
);
return
0
;
}
...
...
@@ -39,7 +39,7 @@ static unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen)
buf
[
numread
]
=
'\0'
;
close
(
fd
);
return
numread
;
return
(
unsigned
int
)
numread
;
}
...
...
@@ -65,24 +65,24 @@ static unsigned int sysfs_cpufreq_write_file(unsigned int cpu,
{
char
path
[
SYSFS_PATH_MAX
];
int
fd
;
size_t
numwrite
;
s
s
ize_t
numwrite
;
snprintf
(
path
,
sizeof
(
path
),
PATH_TO_CPU
"cpu%u/cpufreq/%s"
,
cpu
,
fname
);
if
(
(
fd
=
open
(
path
,
O_WRONLY
)
)
==
-
1
)
fd
=
open
(
path
,
O_WRONLY
);
if
(
fd
==
-
1
)
return
0
;
numwrite
=
write
(
fd
,
value
,
len
);
if
(
numwrite
<
1
)
{
if
(
numwrite
<
1
)
{
close
(
fd
);
return
0
;
}
close
(
fd
);
return
numwrite
;
return
(
unsigned
int
)
numwrite
;
}
/* read access to files which contain one numeric value */
...
...
@@ -114,21 +114,23 @@ static const char *cpufreq_value_files[MAX_CPUFREQ_VALUE_READ_FILES] = {
static
unsigned
long
sysfs_cpufreq_get_one_value
(
unsigned
int
cpu
,
enum
cpufreq_value
which
)
{
unsigned
long
value
;
unsigned
long
value
;
unsigned
int
len
;
char
linebuf
[
MAX_LINE_LEN
];
char
*
endp
;
if
(
which
>=
MAX_CPUFREQ_VALUE_READ_FILES
)
if
(
which
>=
MAX_CPUFREQ_VALUE_READ_FILES
)
return
0
;
if
(
(
len
=
sysfs_cpufreq_read_file
(
cpu
,
cpufreq_value_files
[
which
],
linebuf
,
sizeof
(
linebuf
)))
==
0
)
len
=
sysfs_cpufreq_read_file
(
cpu
,
cpufreq_value_files
[
which
],
linebuf
,
sizeof
(
linebuf
));
if
(
len
==
0
)
return
0
;
value
=
strtoul
(
linebuf
,
&
endp
,
0
);
if
(
endp
==
linebuf
||
errno
==
ERANGE
)
if
(
endp
==
linebuf
||
errno
==
ERANGE
)
return
0
;
return
value
;
...
...
@@ -148,7 +150,7 @@ static const char *cpufreq_string_files[MAX_CPUFREQ_STRING_FILES] = {
};
static
char
*
sysfs_cpufreq_get_one_string
(
unsigned
int
cpu
,
static
char
*
sysfs_cpufreq_get_one_string
(
unsigned
int
cpu
,
enum
cpufreq_string
which
)
{
char
linebuf
[
MAX_LINE_LEN
];
...
...
@@ -158,11 +160,13 @@ static char * sysfs_cpufreq_get_one_string(unsigned int cpu,
if
(
which
>=
MAX_CPUFREQ_STRING_FILES
)
return
NULL
;
if
(
(
len
=
sysfs_cpufreq_read_file
(
cpu
,
cpufreq_string_files
[
which
],
linebuf
,
sizeof
(
linebuf
)))
==
0
)
len
=
sysfs_cpufreq_read_file
(
cpu
,
cpufreq_string_files
[
which
],
linebuf
,
sizeof
(
linebuf
));
if
(
len
==
0
)
return
NULL
;
if
(
(
result
=
strdup
(
linebuf
)
)
==
NULL
)
result
=
strdup
(
linebuf
);
if
(
result
==
NULL
)
return
NULL
;
if
(
result
[
strlen
(
result
)
-
1
]
==
'\n'
)
...
...
@@ -195,8 +199,8 @@ static int sysfs_cpufreq_write_one_value(unsigned int cpu,
if
(
which
>=
MAX_CPUFREQ_WRITE_FILES
)
return
0
;
if
(
sysfs_cpufreq_write_file
(
cpu
,
cpufreq_write_files
[
which
],
new_value
,
len
)
!=
len
)
if
(
sysfs_cpufreq_write_file
(
cpu
,
cpufreq_write_files
[
which
],
new_value
,
len
)
!=
len
)
return
-
ENODEV
;
return
0
;
...
...
@@ -235,11 +239,13 @@ int sysfs_get_freq_hardware_limits(unsigned int cpu,
return
0
;
}
char
*
sysfs_get_freq_driver
(
unsigned
int
cpu
)
{
char
*
sysfs_get_freq_driver
(
unsigned
int
cpu
)
{
return
sysfs_cpufreq_get_one_string
(
cpu
,
SCALING_DRIVER
);
}
struct
cpufreq_policy
*
sysfs_get_freq_policy
(
unsigned
int
cpu
)
{
struct
cpufreq_policy
*
sysfs_get_freq_policy
(
unsigned
int
cpu
)
{
struct
cpufreq_policy
*
policy
;
policy
=
malloc
(
sizeof
(
struct
cpufreq_policy
));
...
...
@@ -270,27 +276,24 @@ sysfs_get_freq_available_governors(unsigned int cpu) {
unsigned
int
pos
,
i
;
unsigned
int
len
;
if
(
(
len
=
sysfs_cpufreq_read_file
(
cpu
,
"scaling_available_governors"
,
linebuf
,
sizeof
(
linebuf
)))
==
0
)
{
len
=
sysfs_cpufreq_read_file
(
cpu
,
"scaling_available_governors"
,
linebuf
,
sizeof
(
linebuf
));
if
(
len
==
0
)
return
NULL
;
}
pos
=
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
linebuf
[
i
]
==
' '
||
linebuf
[
i
]
==
'\n'
)
{
if
(
i
-
pos
<
2
)
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
linebuf
[
i
]
==
' '
||
linebuf
[
i
]
==
'\n'
)
{
if
(
i
-
pos
<
2
)
continue
;
if
(
current
)
{
current
->
next
=
malloc
(
sizeof
*
current
);
if
(
!
current
->
next
)
if
(
current
)
{
current
->
next
=
malloc
(
sizeof
(
*
current
)
);
if
(
!
current
->
next
)
goto
error_out
;
current
=
current
->
next
;
}
else
{
first
=
malloc
(
sizeof
*
first
);
if
(
!
first
)
first
=
malloc
(
sizeof
(
*
first
)
);
if
(
!
first
)
goto
error_out
;
current
=
first
;
}
...
...
@@ -298,10 +301,10 @@ sysfs_get_freq_available_governors(unsigned int cpu) {
current
->
next
=
NULL
;
current
->
governor
=
malloc
(
i
-
pos
+
1
);
if
(
!
current
->
governor
)
if
(
!
current
->
governor
)
goto
error_out
;
memcpy
(
current
->
governor
,
linebuf
+
pos
,
i
-
pos
);
memcpy
(
current
->
governor
,
linebuf
+
pos
,
i
-
pos
);
current
->
governor
[
i
-
pos
]
=
'\0'
;
pos
=
i
+
1
;
}
...
...
@@ -310,11 +313,11 @@ sysfs_get_freq_available_governors(unsigned int cpu) {
return
first
;
error_out:
while
(
first
)
{
while
(
first
)
{
current
=
first
->
next
;
if
(
first
->
governor
)
free
(
first
->
governor
);
free
(
first
);
if
(
first
->
governor
)
free
(
first
->
governor
);
free
(
first
);
first
=
current
;
}
return
NULL
;
...
...
@@ -330,30 +333,26 @@ sysfs_get_available_frequencies(unsigned int cpu) {
unsigned
int
pos
,
i
;
unsigned
int
len
;
if
(
(
len
=
sysfs_cpufreq_read_file
(
cpu
,
"scaling_available_frequencies"
,
linebuf
,
sizeof
(
linebuf
)))
==
0
)
{
len
=
sysfs_cpufreq_read_file
(
cpu
,
"scaling_available_frequencies"
,
linebuf
,
sizeof
(
linebuf
));
if
(
len
==
0
)
return
NULL
;
}
pos
=
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
linebuf
[
i
]
==
' '
||
linebuf
[
i
]
==
'\n'
)
{
if
(
i
-
pos
<
2
)
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
linebuf
[
i
]
==
' '
||
linebuf
[
i
]
==
'\n'
)
{
if
(
i
-
pos
<
2
)
continue
;
if
(
i
-
pos
>=
SYSFS_PATH_MAX
)
if
(
i
-
pos
>=
SYSFS_PATH_MAX
)
goto
error_out
;
if
(
current
)
{
current
->
next
=
malloc
(
sizeof
*
current
);
if
(
!
current
->
next
)
if
(
current
)
{
current
->
next
=
malloc
(
sizeof
(
*
current
)
);
if
(
!
current
->
next
)
goto
error_out
;
current
=
current
->
next
;
}
else
{
first
=
malloc
(
sizeof
*
first
);
if
(
!
first
)
first
=
malloc
(
sizeof
(
*
first
)
);
if
(
!
first
)
goto
error_out
;
current
=
first
;
}
...
...
@@ -362,7 +361,7 @@ sysfs_get_available_frequencies(unsigned int cpu) {
memcpy
(
one_value
,
linebuf
+
pos
,
i
-
pos
);
one_value
[
i
-
pos
]
=
'\0'
;
if
(
sscanf
(
one_value
,
"%lu"
,
&
current
->
frequency
)
!=
1
)
if
(
sscanf
(
one_value
,
"%lu"
,
&
current
->
frequency
)
!=
1
)
goto
error_out
;
pos
=
i
+
1
;
...
...
@@ -372,7 +371,7 @@ sysfs_get_available_frequencies(unsigned int cpu) {
return
first
;
error_out:
while
(
first
)
{
while
(
first
)
{
current
=
first
->
next
;
free
(
first
);
first
=
current
;
...
...
@@ -380,8 +379,9 @@ sysfs_get_available_frequencies(unsigned int cpu) {
return
NULL
;
}
static
struct
cpufreq_affected_cpus
*
sysfs_get_cpu_list
(
unsigned
int
cpu
,
const
char
*
file
)
{
static
struct
cpufreq_affected_cpus
*
sysfs_get_cpu_list
(
unsigned
int
cpu
,
const
char
*
file
)
{
struct
cpufreq_affected_cpus
*
first
=
NULL
;
struct
cpufreq_affected_cpus
*
current
=
NULL
;
char
one_value
[
SYSFS_PATH_MAX
];
...
...
@@ -389,29 +389,25 @@ static struct cpufreq_affected_cpus * sysfs_get_cpu_list(unsigned int cpu,
unsigned
int
pos
,
i
;
unsigned
int
len
;
if
(
(
len
=
sysfs_cpufreq_read_file
(
cpu
,
file
,
linebuf
,
sizeof
(
linebuf
)))
==
0
)
{
len
=
sysfs_cpufreq_read_file
(
cpu
,
file
,
linebuf
,
sizeof
(
linebuf
));
if
(
len
==
0
)
return
NULL
;
}
pos
=
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
i
==
len
||
linebuf
[
i
]
==
' '
||
linebuf
[
i
]
==
'\n'
)
{
if
(
i
-
pos
<
1
)
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
i
==
len
||
linebuf
[
i
]
==
' '
||
linebuf
[
i
]
==
'\n'
)
{
if
(
i
-
pos
<
1
)
continue
;
if
(
i
-
pos
>=
SYSFS_PATH_MAX
)
if
(
i
-
pos
>=
SYSFS_PATH_MAX
)
goto
error_out
;
if
(
current
)
{
current
->
next
=
malloc
(
sizeof
*
current
);
if
(
!
current
->
next
)
if
(
current
)
{
current
->
next
=
malloc
(
sizeof
(
*
current
)
);
if
(
!
current
->
next
)
goto
error_out
;
current
=
current
->
next
;
}
else
{
first
=
malloc
(
sizeof
*
first
);
if
(
!
first
)
first
=
malloc
(
sizeof
(
*
first
)
);
if
(
!
first
)
goto
error_out
;
current
=
first
;
}
...
...
@@ -421,7 +417,7 @@ static struct cpufreq_affected_cpus * sysfs_get_cpu_list(unsigned int cpu,
memcpy
(
one_value
,
linebuf
+
pos
,
i
-
pos
);
one_value
[
i
-
pos
]
=
'\0'
;
if
(
sscanf
(
one_value
,
"%u"
,
&
current
->
cpu
)
!=
1
)
if
(
sscanf
(
one_value
,
"%u"
,
&
current
->
cpu
)
!=
1
)
goto
error_out
;
pos
=
i
+
1
;
...
...
@@ -439,15 +435,18 @@ static struct cpufreq_affected_cpus * sysfs_get_cpu_list(unsigned int cpu,
return
NULL
;
}
struct
cpufreq_affected_cpus
*
sysfs_get_freq_affected_cpus
(
unsigned
int
cpu
)
{
struct
cpufreq_affected_cpus
*
sysfs_get_freq_affected_cpus
(
unsigned
int
cpu
)
{
return
sysfs_get_cpu_list
(
cpu
,
"affected_cpus"
);
}
struct
cpufreq_affected_cpus
*
sysfs_get_freq_related_cpus
(
unsigned
int
cpu
)
{
struct
cpufreq_affected_cpus
*
sysfs_get_freq_related_cpus
(
unsigned
int
cpu
)
{
return
sysfs_get_cpu_list
(
cpu
,
"related_cpus"
);
}
struct
cpufreq_stats
*
sysfs_get_freq_stats
(
unsigned
int
cpu
,
unsigned
long
long
*
total_time
)
{
struct
cpufreq_stats
*
sysfs_get_freq_stats
(
unsigned
int
cpu
,
unsigned
long
long
*
total_time
)
{
struct
cpufreq_stats
*
first
=
NULL
;
struct
cpufreq_stats
*
current
=
NULL
;
char
one_value
[
SYSFS_PATH_MAX
];
...
...
@@ -455,28 +454,27 @@ struct cpufreq_stats * sysfs_get_freq_stats(unsigned int cpu, unsigned long long
unsigned
int
pos
,
i
;
unsigned
int
len
;
if
(
(
len
=
sysfs_cpufreq_read_file
(
cpu
,
"stats/time_in_state"
,
linebuf
,
sizeof
(
linebuf
)))
==
0
)
len
=
sysfs_cpufreq_read_file
(
cpu
,
"stats/time_in_state"
,
linebuf
,
sizeof
(
linebuf
));
if
(
len
==
0
)
return
NULL
;
*
total_time
=
0
;
pos
=
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
i
==
strlen
(
linebuf
)
||
linebuf
[
i
]
==
'\n'
)
{
if
(
i
-
pos
<
2
)
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
i
==
strlen
(
linebuf
)
||
linebuf
[
i
]
==
'\n'
)
{
if
(
i
-
pos
<
2
)
continue
;
if
(
(
i
-
pos
)
>=
SYSFS_PATH_MAX
)
if
(
(
i
-
pos
)
>=
SYSFS_PATH_MAX
)
goto
error_out
;
if
(
current
)
{
current
->
next
=
malloc
(
sizeof
*
current
);
if
(
!
current
->
next
)
if
(
current
)
{
current
->
next
=
malloc
(
sizeof
(
*
current
)
);
if
(
!
current
->
next
)
goto
error_out
;
current
=
current
->
next
;
}
else
{
first
=
malloc
(
sizeof
*
first
);
if
(
!
first
)
first
=
malloc
(
sizeof
(
*
first
)
);
if
(
!
first
)
goto
error_out
;
current
=
first
;
}
...
...
@@ -485,7 +483,9 @@ struct cpufreq_stats * sysfs_get_freq_stats(unsigned int cpu, unsigned long long
memcpy
(
one_value
,
linebuf
+
pos
,
i
-
pos
);
one_value
[
i
-
pos
]
=
'\0'
;
if
(
sscanf
(
one_value
,
"%lu %llu"
,
&
current
->
frequency
,
&
current
->
time_in_state
)
!=
2
)
if
(
sscanf
(
one_value
,
"%lu %llu"
,
&
current
->
frequency
,
&
current
->
time_in_state
)
!=
2
)
goto
error_out
;
*
total_time
=
*
total_time
+
current
->
time_in_state
;
...
...
@@ -496,7 +496,7 @@ struct cpufreq_stats * sysfs_get_freq_stats(unsigned int cpu, unsigned long long
return
first
;
error_out:
while
(
first
)
{
while
(
first
)
{
current
=
first
->
next
;
free
(
first
);
first
=
current
;
...
...
@@ -511,29 +511,29 @@ unsigned long sysfs_get_freq_transitions(unsigned int cpu)
static
int
verify_gov
(
char
*
new_gov
,
char
*
passed_gov
)
{
unsigned
int
i
,
j
=
0
;
unsigned
int
i
,
j
=
0
;
if
(
!
passed_gov
||
(
strlen
(
passed_gov
)
>
19
))
return
-
EINVAL
;
strncpy
(
new_gov
,
passed_gov
,
20
);
for
(
i
=
0
;
i
<
20
;
i
++
)
{
for
(
i
=
0
;
i
<
20
;
i
++
)
{
if
(
j
)
{
new_gov
[
i
]
=
'\0'
;
continue
;
}
if
((
new_gov
[
i
]
>=
'a'
)
&&
(
new_gov
[
i
]
<=
'z'
))
{
if
((
new_gov
[
i
]
>=
'a'
)
&&
(
new_gov
[
i
]
<=
'z'
))
continue
;
}
if
((
new_gov
[
i
]
>=
'A'
)
&&
(
new_gov
[
i
]
<=
'Z'
))
{
if
((
new_gov
[
i
]
>=
'A'
)
&&
(
new_gov
[
i
]
<=
'Z'
))
continue
;
}
if
(
new_gov
[
i
]
==
'-'
)
{
if
(
new_gov
[
i
]
==
'-'
)
continue
;
}
if
(
new_gov
[
i
]
==
'_'
)
{
if
(
new_gov
[
i
]
==
'_'
)
continue
;
}
if
(
new_gov
[
i
]
==
'\0'
)
{
j
=
1
;
continue
;
...
...
@@ -627,7 +627,8 @@ int sysfs_set_freq_policy(unsigned int cpu, struct cpufreq_policy *policy)
gov
,
strlen
(
gov
));
}
int
sysfs_set_frequency
(
unsigned
int
cpu
,
unsigned
long
target_frequency
)
{
int
sysfs_set_frequency
(
unsigned
int
cpu
,
unsigned
long
target_frequency
)
{
struct
cpufreq_policy
*
pol
=
sysfs_get_freq_policy
(
cpu
);
char
userspace_gov
[]
=
"userspace"
;
char
freq
[
SYSFS_PATH_MAX
];
...
...
@@ -640,7 +641,7 @@ int sysfs_set_frequency(unsigned int cpu, unsigned long target_frequency) {
ret
=
sysfs_modify_freq_policy_governor
(
cpu
,
userspace_gov
);
if
(
ret
)
{
cpufreq_put_policy
(
pol
);
return
(
ret
)
;
return
ret
;
}
}
...
...
@@ -662,7 +663,7 @@ int sysfs_cpu_exists(unsigned int cpu)
snprintf
(
file
,
SYSFS_PATH_MAX
,
PATH_TO_CPU
"cpu%u/"
,
cpu
);
if
(
stat
(
file
,
&
statbuf
)
!=
0
)
if
(
stat
(
file
,
&
statbuf
)
!=
0
)
return
-
ENOSYS
;
return
S_ISDIR
(
statbuf
.
st_mode
)
?
0
:
-
ENOSYS
;
...
...
tools/power/cpupower/lib/sysfs.h
View file @
6c2b8185
...
...
@@ -5,17 +5,27 @@ extern unsigned int sysfs_cpu_exists(unsigned int cpu);
extern
unsigned
long
sysfs_get_freq_kernel
(
unsigned
int
cpu
);
extern
unsigned
long
sysfs_get_freq_hardware
(
unsigned
int
cpu
);
extern
unsigned
long
sysfs_get_freq_transition_latency
(
unsigned
int
cpu
);
extern
int
sysfs_get_freq_hardware_limits
(
unsigned
int
cpu
,
unsigned
long
*
min
,
unsigned
long
*
max
);
extern
char
*
sysfs_get_freq_driver
(
unsigned
int
cpu
);
extern
struct
cpufreq_policy
*
sysfs_get_freq_policy
(
unsigned
int
cpu
);
extern
struct
cpufreq_available_governors
*
sysfs_get_freq_available_governors
(
unsigned
int
cpu
);
extern
struct
cpufreq_available_frequencies
*
sysfs_get_available_frequencies
(
unsigned
int
cpu
);
extern
struct
cpufreq_affected_cpus
*
sysfs_get_freq_affected_cpus
(
unsigned
int
cpu
);
extern
struct
cpufreq_affected_cpus
*
sysfs_get_freq_related_cpus
(
unsigned
int
cpu
);
extern
struct
cpufreq_stats
*
sysfs_get_freq_stats
(
unsigned
int
cpu
,
unsigned
long
long
*
total_time
);
extern
int
sysfs_get_freq_hardware_limits
(
unsigned
int
cpu
,
unsigned
long
*
min
,
unsigned
long
*
max
);
extern
char
*
sysfs_get_freq_driver
(
unsigned
int
cpu
);
extern
struct
cpufreq_policy
*
sysfs_get_freq_policy
(
unsigned
int
cpu
);
extern
struct
cpufreq_available_governors
*
sysfs_get_freq_available_governors
(
unsigned
int
cpu
);
extern
struct
cpufreq_available_frequencies
*
sysfs_get_available_frequencies
(
unsigned
int
cpu
);
extern
struct
cpufreq_affected_cpus
*
sysfs_get_freq_affected_cpus
(
unsigned
int
cpu
);
extern
struct
cpufreq_affected_cpus
*
sysfs_get_freq_related_cpus
(
unsigned
int
cpu
);
extern
struct
cpufreq_stats
*
sysfs_get_freq_stats
(
unsigned
int
cpu
,
unsigned
long
long
*
total_time
);
extern
unsigned
long
sysfs_get_freq_transitions
(
unsigned
int
cpu
);
extern
int
sysfs_set_freq_policy
(
unsigned
int
cpu
,
struct
cpufreq_policy
*
policy
);
extern
int
sysfs_modify_freq_policy_min
(
unsigned
int
cpu
,
unsigned
long
min_freq
);
extern
int
sysfs_modify_freq_policy_max
(
unsigned
int
cpu
,
unsigned
long
max_freq
);
extern
int
sysfs_set_freq_policy
(
unsigned
int
cpu
,
struct
cpufreq_policy
*
policy
);
extern
int
sysfs_modify_freq_policy_min
(
unsigned
int
cpu
,
unsigned
long
min_freq
);
extern
int
sysfs_modify_freq_policy_max
(
unsigned
int
cpu
,
unsigned
long
max_freq
);
extern
int
sysfs_modify_freq_policy_governor
(
unsigned
int
cpu
,
char
*
governor
);
extern
int
sysfs_set_frequency
(
unsigned
int
cpu
,
unsigned
long
target_frequency
);
extern
int
sysfs_set_frequency
(
unsigned
int
cpu
,
unsigned
long
target_frequency
);
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