diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2016-04-26 13:18:13 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-07-01 16:22:46 +0100 |
commit | cee685ca0d29b022e0665fccf58de006e7ffaef1 (patch) | |
tree | 614e98c3f53374424aac37f798ecbbe24f288715 | |
parent | 7d42ceae3a42f7a6580436b113c47aad37717293 (diff) | |
download | poky-cee685ca0d29b022e0665fccf58de006e7ffaef1.tar.gz |
oeqa.buildperf: functionality to drop kernel caches
Add a new utility class for dropping Linux kernel caches. It uses sudo
and tee to write to the drop_caches file. Checking if the user has the
permissions to drop caches (without a password) is done by trying to
writing an invalid value to the drop_caches file. This way, we will find
if writing (with tee) is possible but not really dropping caches, yet.
User can avoid giving the password by adding something like:
<user> ALL = NOPASSWD: /usr/bin/tee /proc/sys/vm/drop_caches
to the system sudoers file.
(From OE-Core rev: c9cb248429ced50c96d11ba5361c272d4c9b9323)
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/buildperf/__init__.py | 1 | ||||
-rw-r--r-- | meta/lib/oeqa/buildperf/base.py | 46 | ||||
-rwxr-xr-x | scripts/oe-build-perf-test | 4 |
3 files changed, 51 insertions, 0 deletions
diff --git a/meta/lib/oeqa/buildperf/__init__.py b/meta/lib/oeqa/buildperf/__init__.py index c9535591e2..bab122e4ec 100644 --- a/meta/lib/oeqa/buildperf/__init__.py +++ b/meta/lib/oeqa/buildperf/__init__.py | |||
@@ -10,3 +10,4 @@ | |||
10 | # more details. | 10 | # more details. |
11 | # | 11 | # |
12 | """Build performance tests""" | 12 | """Build performance tests""" |
13 | from .base import KernelDropCaches | ||
diff --git a/meta/lib/oeqa/buildperf/base.py b/meta/lib/oeqa/buildperf/base.py new file mode 100644 index 0000000000..3cbdfa7818 --- /dev/null +++ b/meta/lib/oeqa/buildperf/base.py | |||
@@ -0,0 +1,46 @@ | |||
1 | # Copyright (c) 2016, Intel Corporation. | ||
2 | # | ||
3 | # This program is free software; you can redistribute it and/or modify it | ||
4 | # under the terms and conditions of the GNU General Public License, | ||
5 | # version 2, as published by the Free Software Foundation. | ||
6 | # | ||
7 | # This program is distributed in the hope it will be useful, but WITHOUT | ||
8 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
9 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
10 | # more details. | ||
11 | # | ||
12 | """Build performance test base classes and functionality""" | ||
13 | from oeqa.utils.commands import runCmd | ||
14 | |||
15 | |||
16 | class KernelDropCaches(object): | ||
17 | """Container of the functions for dropping kernel caches""" | ||
18 | sudo_passwd = None | ||
19 | |||
20 | @classmethod | ||
21 | def check(cls): | ||
22 | """Check permssions for dropping kernel caches""" | ||
23 | from getpass import getpass | ||
24 | from locale import getdefaultlocale | ||
25 | cmd = ['sudo', '-k', '-n', 'tee', '/proc/sys/vm/drop_caches'] | ||
26 | ret = runCmd(cmd, ignore_status=True, data=b'0') | ||
27 | if ret.output.startswith('sudo:'): | ||
28 | pass_str = getpass( | ||
29 | "\nThe script requires sudo access to drop caches between " | ||
30 | "builds (echo 3 > /proc/sys/vm/drop_caches).\n" | ||
31 | "Please enter your sudo password: ") | ||
32 | cls.sudo_passwd = bytes(pass_str, getdefaultlocale()[1]) | ||
33 | |||
34 | @classmethod | ||
35 | def drop(cls): | ||
36 | """Drop kernel caches""" | ||
37 | cmd = ['sudo', '-k'] | ||
38 | if cls.sudo_passwd: | ||
39 | cmd.append('-S') | ||
40 | input_data = cls.sudo_passwd + b'\n' | ||
41 | else: | ||
42 | cmd.append('-n') | ||
43 | input_data = b'' | ||
44 | cmd += ['tee', '/proc/sys/vm/drop_caches'] | ||
45 | input_data += b'3' | ||
46 | runCmd(cmd, data=input_data) | ||
diff --git a/scripts/oe-build-perf-test b/scripts/oe-build-perf-test index 9fb431045b..9589dee3ac 100755 --- a/scripts/oe-build-perf-test +++ b/scripts/oe-build-perf-test | |||
@@ -22,6 +22,7 @@ import sys | |||
22 | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/lib') | 22 | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/lib') |
23 | import scriptpath | 23 | import scriptpath |
24 | scriptpath.add_oe_lib_path() | 24 | scriptpath.add_oe_lib_path() |
25 | from oeqa.buildperf import KernelDropCaches | ||
25 | from oeqa.utils.commands import runCmd | 26 | from oeqa.utils.commands import runCmd |
26 | 27 | ||
27 | 28 | ||
@@ -71,6 +72,9 @@ def main(argv=None): | |||
71 | if not pre_run_sanity_check(): | 72 | if not pre_run_sanity_check(): |
72 | return 1 | 73 | return 1 |
73 | 74 | ||
75 | # Check our capability to drop caches and ask pass if needed | ||
76 | KernelDropCaches.check() | ||
77 | |||
74 | return 0 | 78 | return 0 |
75 | 79 | ||
76 | 80 | ||