diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-03-18 13:15:42 -0400 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-03-18 13:15:42 -0400 |
| commit | 16dfc8df20c6befeed423217a2e0f5ae59b5a04d (patch) | |
| tree | 722ff18b111f6ab2fc11fffa46e78889bd2d5708 /run/litmus_util.py | |
| parent | 652a57b5a53e41e585c7e0d10601c807ba08c36f (diff) | |
Use smarter defaults which can handle data from Bjorns scripts.
Diffstat (limited to 'run/litmus_util.py')
| -rw-r--r-- | run/litmus_util.py | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/run/litmus_util.py b/run/litmus_util.py index 8a7f87d..b9080c1 100644 --- a/run/litmus_util.py +++ b/run/litmus_util.py | |||
| @@ -1,43 +1,8 @@ | |||
| 1 | import re | 1 | import re |
| 2 | import time | 2 | import time |
| 3 | import subprocess | 3 | import subprocess |
| 4 | import os | ||
| 5 | import stat | ||
| 6 | import config.config as conf | 4 | import config.config as conf |
| 7 | 5 | ||
| 8 | def num_cpus(): | ||
| 9 | '''Return the number of CPUs in the system.''' | ||
| 10 | |||
| 11 | lnx_re = re.compile(r'^(processor|online)') | ||
| 12 | cpus = 0 | ||
| 13 | |||
| 14 | with open('/proc/cpuinfo', 'r') as f: | ||
| 15 | for line in f: | ||
| 16 | if lnx_re.match(line): | ||
| 17 | cpus += 1 | ||
| 18 | return cpus | ||
| 19 | |||
| 20 | def ft_freq(): | ||
| 21 | umachine = subprocess.check_output(["uname", "-m"]) | ||
| 22 | |||
| 23 | if re.match("armv7", umachine): | ||
| 24 | # Arm V7s use a millisecond timer | ||
| 25 | freq = 1000.0 | ||
| 26 | elif re.match("x86", umachine): | ||
| 27 | # X86 timer is equal to processor clock | ||
| 28 | reg = re.compile(r'^cpu MHz\s*:\s*(?P<FREQ>\d+)', re.M) | ||
| 29 | with open('/proc/cpuinfo', 'r') as f: | ||
| 30 | data = f.read() | ||
| 31 | |||
| 32 | match = re.search(reg, data) | ||
| 33 | if not match: | ||
| 34 | raise Exception("Cannot parse CPU frequency from x86 CPU!") | ||
| 35 | freq = int(match.group('FREQ')) | ||
| 36 | else: | ||
| 37 | # You're on your own | ||
| 38 | freq = 0 | ||
| 39 | return freq | ||
| 40 | |||
| 41 | def switch_scheduler(switch_to_in): | 6 | def switch_scheduler(switch_to_in): |
| 42 | '''Switch the scheduler to whatever is passed in. | 7 | '''Switch the scheduler to whatever is passed in. |
| 43 | 8 | ||
| @@ -60,21 +25,6 @@ def switch_scheduler(switch_to_in): | |||
| 60 | if switch_to != cur_plugin: | 25 | if switch_to != cur_plugin: |
| 61 | raise Exception("Could not switch to plugin: %s" % switch_to) | 26 | raise Exception("Could not switch to plugin: %s" % switch_to) |
| 62 | 27 | ||
| 63 | def uname_matches(reg): | ||
| 64 | data = subprocess.check_output(["uname", "-r"]) | ||
| 65 | return bool( re.match(reg, data) ) | ||
| 66 | |||
| 67 | def is_executable(fname): | ||
| 68 | '''Return whether the file passed in is executable''' | ||
| 69 | mode = os.stat(fname)[stat.ST_MODE] | ||
| 70 | return mode & stat.S_IXUSR and mode & stat.S_IRUSR | ||
| 71 | |||
| 72 | def is_device(dev): | ||
| 73 | if not os.path.exists(dev): | ||
| 74 | return False | ||
| 75 | mode = os.stat(dev)[stat.ST_MODE] | ||
| 76 | return not (not mode & stat.S_IFCHR) | ||
| 77 | |||
| 78 | def waiting_tasks(): | 28 | def waiting_tasks(): |
| 79 | reg = re.compile(r'^ready.*?(?P<READY>\d+)$', re.M) | 29 | reg = re.compile(r'^ready.*?(?P<READY>\d+)$', re.M) |
| 80 | with open('/proc/litmus/stats', 'r') as f: | 30 | with open('/proc/litmus/stats', 'r') as f: |
