diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2012-11-26 17:06:27 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2012-11-26 17:06:27 -0500 |
| commit | b43b83beead92ff7cf28a5fe5a2710537268aae1 (patch) | |
| tree | d9c29b14cd18a9df520f36d7e85eb460c30fa7a9 /experiment/litmus_util.py | |
| parent | cb8db5d30ee769304c2c2b00f2a7d9bcb3c4098f (diff) | |
Read locations of binary files from path instead of config.py.
Diffstat (limited to 'experiment/litmus_util.py')
| -rw-r--r-- | experiment/litmus_util.py | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/experiment/litmus_util.py b/experiment/litmus_util.py deleted file mode 100644 index fb2b341..0000000 --- a/experiment/litmus_util.py +++ /dev/null | |||
| @@ -1,79 +0,0 @@ | |||
| 1 | import re | ||
| 2 | import time | ||
| 3 | import subprocess | ||
| 4 | import os | ||
| 5 | import stat | ||
| 6 | import config.config as conf | ||
| 7 | |||
| 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 cpu_freq(): | ||
| 21 | ''' | ||
| 22 | The frequency (in MHz) of the CPU. | ||
| 23 | ''' | ||
| 24 | reg = re.compile(r'^cpu MHz\s*:\s*(\d+)', re.M) | ||
| 25 | with open('/proc/cpuinfo', 'r') as f: | ||
| 26 | data = f.read() | ||
| 27 | |||
| 28 | match = re.search(reg, data) | ||
| 29 | if not match: | ||
| 30 | raise Exception("Cannot parse CPU frequency!") | ||
| 31 | return int(match.group(1)) | ||
| 32 | |||
| 33 | def switch_scheduler(switch_to_in): | ||
| 34 | '''Switch the scheduler to whatever is passed in. | ||
| 35 | |||
| 36 | This methods sleeps for two seconds to give Linux the chance to execute | ||
| 37 | schedule switching code. Raises an exception if the switch does not work. | ||
| 38 | |||
| 39 | ''' | ||
| 40 | |||
| 41 | switch_to = str(switch_to_in).strip() | ||
| 42 | |||
| 43 | with open('/proc/litmus/active_plugin', 'w') as active_plugin: | ||
| 44 | subprocess.Popen(["echo", switch_to], stdout=active_plugin) | ||
| 45 | |||
| 46 | # it takes a bit to do the switch, sleep an arbitrary amount of time | ||
| 47 | time.sleep(2) | ||
| 48 | |||
| 49 | with open('/proc/litmus/active_plugin', 'r') as active_plugin: | ||
| 50 | cur_plugin = active_plugin.read().strip() | ||
| 51 | |||
| 52 | if switch_to != cur_plugin: | ||
| 53 | raise Exception("Could not switch to plugin: %s" % switch_to) | ||
| 54 | |||
| 55 | def uname_matches(reg): | ||
| 56 | data = subprocess.check_output(["uname", "-r"]) | ||
| 57 | return bool( re.match(reg, data) ) | ||
| 58 | |||
| 59 | def is_executable(fname): | ||
| 60 | '''Return whether the file passed in is executable''' | ||
| 61 | mode = os.stat(fname)[stat.ST_MODE] | ||
| 62 | return mode & stat.S_IXUSR and mode & stat.S_IRUSR | ||
| 63 | |||
| 64 | def is_device(dev): | ||
| 65 | if not os.path.exists(dev): | ||
| 66 | return False | ||
| 67 | mode = os.stat(dev)[stat.ST_MODE] | ||
| 68 | return not (not mode & stat.S_IFCHR) | ||
| 69 | |||
| 70 | def release_tasks(): | ||
| 71 | |||
| 72 | try: | ||
| 73 | data = subprocess.check_output([conf.BINS['release']]) | ||
| 74 | except subprocess.CalledProcessError: | ||
| 75 | raise Exception('Something went wrong in release_ts') | ||
| 76 | |||
| 77 | released = re.findall(r"([0-9]+) real-time", data)[0] | ||
| 78 | |||
| 79 | return int(released) | ||
