mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
Merge pull request #15 from derkling/add_shutils_support
Add shutils support
This commit is contained in:
commit
3f1577dd02
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
*.orig
|
||||
.ropeproject
|
||||
*.egg-info
|
||||
devlib/bin/scripts/shutils
|
||||
|
71
devlib/bin/scripts/shutils.in
Executable file
71
devlib/bin/scripts/shutils.in
Executable file
@ -0,0 +1,71 @@
|
||||
#!__DEVLIB_SHELL__
|
||||
|
||||
CMD=$1
|
||||
shift
|
||||
|
||||
BUSYBOX=${BUSYBOX:-__DEVLIB_BUSYBOX__}
|
||||
GREP=${GREP:-$BUSYBOX grep}
|
||||
SED=${SED:-$BUSYBOX sed}
|
||||
|
||||
################################################################################
|
||||
# CPUFrequency Utility Functions
|
||||
################################################################################
|
||||
|
||||
cpufreq_set_all_frequencies() {
|
||||
FREQ=$1
|
||||
for CPU in /sys/devices/system/cpu/cpu[0-9]*; do
|
||||
echo $FREQ > $CPU/cpufreq/scaling_cur_freq
|
||||
done
|
||||
}
|
||||
|
||||
cpufreq_get_all_frequencies() {
|
||||
$GREP '' /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq | \
|
||||
$SED -e 's|/sys/devices/system/cpu/cpu||' -e 's|/cpufreq/scaling_cur_freq:| |'
|
||||
}
|
||||
|
||||
cpufreq_set_all_governors() {
|
||||
GOV=$1
|
||||
for CPU in /sys/devices/system/cpu/cpu[0-9]*; do
|
||||
echo $GOV > $CPU/cpufreq/scaling_governor
|
||||
done
|
||||
}
|
||||
|
||||
cpufreq_get_all_governors() {
|
||||
$GREP '' /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor | \
|
||||
$SED -e 's|/sys/devices/system/cpu/cpu||' -e 's|/cpufreq/scaling_governor:| |'
|
||||
}
|
||||
|
||||
cpufreq_trace_all_frequencies() {
|
||||
FREQS=$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq)
|
||||
CPU=0; for F in $FREQS; do
|
||||
echo "cpu_frequency: state=$F cpu_id=$CPU" > /sys/kernel/debug/tracing/trace_marker
|
||||
CPU=$((CPU + 1))
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Main Function Dispatcher
|
||||
################################################################################
|
||||
|
||||
case $CMD in
|
||||
cpufreq_set_all_frequencies)
|
||||
cpufreq_set_all_frequencies $*
|
||||
;;
|
||||
cpufreq_get_all_frequencies)
|
||||
cpufreq_get_all_frequencies
|
||||
;;
|
||||
cpufreq_set_all_governors)
|
||||
cpufreq_set_all_governors $*
|
||||
;;
|
||||
cpufreq_get_all_governors)
|
||||
cpufreq_get_all_governors
|
||||
;;
|
||||
cpufreq_trace_all_frequencies)
|
||||
cpufreq_trace_all_frequencies $*
|
||||
;;
|
||||
*)
|
||||
echo "Command [$CMD] not supported"
|
||||
exit -1
|
||||
esac
|
||||
|
||||
# vim: tabstop=4 shiftwidth=4
|
@ -349,30 +349,53 @@ class CpufreqModule(Module):
|
||||
for cpu in online_cpus:
|
||||
self.set_frequency(cpu, freq, exact)
|
||||
|
||||
def set_all_frequencies(self, freq, exact=False):
|
||||
self.target.execute(
|
||||
"for CPU in /sys/devices/system/cpu/cpu[0-9]*; do "\
|
||||
"echo {} > $CPU/cpufreq/scaling_cur_freq; "\
|
||||
"done"\
|
||||
.format(freq), as_root=True)
|
||||
def set_all_frequencies(self, freq):
|
||||
"""
|
||||
Set the specified (minimum) frequency for all the (online) CPUs
|
||||
"""
|
||||
return self.target._execute_util(
|
||||
'cpufreq_set_all_frequencies {}'.format(freq),
|
||||
as_root=True)
|
||||
|
||||
def get_all_frequencies(self):
|
||||
"""
|
||||
Get the current frequency for all the (online) CPUs
|
||||
"""
|
||||
output = self.target._execute_util(
|
||||
'cpufreq_get_all_frequencies', as_root=True)
|
||||
frequencies = {}
|
||||
for x in output.splitlines():
|
||||
kv = x.split(' ')
|
||||
if kv[0] == '':
|
||||
break
|
||||
frequencies[kv[0]] = kv[1]
|
||||
return frequencies
|
||||
|
||||
def set_all_governors(self, governor):
|
||||
self.target.execute(
|
||||
"for CPU in /sys/devices/system/cpu/cpu[0-9]*; do "\
|
||||
"echo {} > $CPU/cpufreq/scaling_governor; "\
|
||||
"done"\
|
||||
.format(governor), as_root=True)
|
||||
"""
|
||||
Set the specified governor for all the (online) CPUs
|
||||
"""
|
||||
return self.target._execute_util(
|
||||
'cpufreq_set_all_governors {}'.format(governor),
|
||||
as_root=True)
|
||||
|
||||
def get_all_governors(self):
|
||||
"""
|
||||
Get the current governor for all the (online) CPUs
|
||||
"""
|
||||
output = self.target._execute_util(
|
||||
'cpufreq_get_all_governors', as_root=True)
|
||||
governors = {}
|
||||
for x in output.splitlines():
|
||||
kv = x.split(' ')
|
||||
if kv[0] == '':
|
||||
break
|
||||
governors[kv[0]] = kv[1]
|
||||
return governors
|
||||
|
||||
def trace_frequencies(self):
|
||||
"""
|
||||
Report current frequencies on trace file
|
||||
"""
|
||||
self.target.execute(
|
||||
'FREQS=$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); '
|
||||
'CPU=0; for F in $FREQS; do '
|
||||
' echo "cpu_frequency: state=$F cpu_id=$CPU" > /sys/kernel/debug/tracing/trace_marker; '
|
||||
' let CPU++; '
|
||||
'done',
|
||||
as_root=True
|
||||
)
|
||||
return self.target._execute_util('cpufreq_trace_all_frequencies', as_root=True)
|
||||
|
||||
|
@ -197,6 +197,22 @@ class Target(object):
|
||||
self.execute('mkdir -p {}'.format(self.working_directory))
|
||||
self.execute('mkdir -p {}'.format(self.executables_directory))
|
||||
self.busybox = self.install(os.path.join(PACKAGE_BIN_DIRECTORY, self.abi, 'busybox'))
|
||||
|
||||
# Setup shutils script for the target
|
||||
shutils_ifile = os.path.join(PACKAGE_BIN_DIRECTORY, 'scripts', 'shutils.in')
|
||||
shutils_ofile = os.path.join(PACKAGE_BIN_DIRECTORY, 'scripts', 'shutils')
|
||||
shell_path = '/bin/sh'
|
||||
if self.os == 'android':
|
||||
shell_path = '/system/bin/sh'
|
||||
with open(shutils_ifile) as fh:
|
||||
lines = fh.readlines()
|
||||
with open(shutils_ofile, 'w') as ofile:
|
||||
for line in lines:
|
||||
line = line.replace("__DEVLIB_SHELL__", shell_path)
|
||||
line = line.replace("__DEVLIB_BUSYBOX__", self.busybox)
|
||||
ofile.write(line)
|
||||
self.shutils = self.install(os.path.join(PACKAGE_BIN_DIRECTORY, 'scripts', 'shutils'))
|
||||
|
||||
for host_exe in (executables or []): # pylint: disable=superfluous-parens
|
||||
self.install(host_exe)
|
||||
|
||||
@ -227,6 +243,10 @@ class Target(object):
|
||||
|
||||
# execution
|
||||
|
||||
def _execute_util(self, command, timeout=None, check_exit_code=True, as_root=False):
|
||||
command = '{} {}'.format(self.shutils, command)
|
||||
return self.conn.execute(command, timeout, check_exit_code, as_root)
|
||||
|
||||
def execute(self, command, timeout=None, check_exit_code=True, as_root=False):
|
||||
return self.conn.execute(command, timeout, check_exit_code, as_root)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user