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 | |
parent | 652a57b5a53e41e585c7e0d10601c807ba08c36f (diff) |
Use smarter defaults which can handle data from Bjorns scripts.
Diffstat (limited to 'run')
-rw-r--r-- | run/executable/executable.py | 2 | ||||
-rw-r--r-- | run/litmus_util.py | 50 | ||||
-rw-r--r-- | run/tracer.py | 10 |
3 files changed, 6 insertions, 56 deletions
diff --git a/run/executable/executable.py b/run/executable/executable.py index 0a408b7..02e35ae 100644 --- a/run/executable/executable.py +++ b/run/executable/executable.py | |||
@@ -1,7 +1,7 @@ | |||
1 | import sys | 1 | import sys |
2 | import subprocess | 2 | import subprocess |
3 | import signal | 3 | import signal |
4 | from ..litmus_util import is_executable | 4 | from common import is_executable |
5 | 5 | ||
6 | class Executable(object): | 6 | class Executable(object): |
7 | '''Parent object that represents an executable for use in task-sets.''' | 7 | '''Parent object that represents an executable for use in task-sets.''' |
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: |
diff --git a/run/tracer.py b/run/tracer.py index 303aae0..065797c 100644 --- a/run/tracer.py +++ b/run/tracer.py | |||
@@ -1,7 +1,7 @@ | |||
1 | from . import litmus_util | ||
2 | import os | 1 | import os |
3 | import config.config as conf | 2 | import config.config as conf |
4 | 3 | ||
4 | from common import is_device,num_cpus | ||
5 | from operator import methodcaller | 5 | from operator import methodcaller |
6 | from run.executable.ftcat import FTcat,Executable | 6 | from run.executable.ftcat import FTcat,Executable |
7 | 7 | ||
@@ -58,7 +58,7 @@ class LogTracer(Tracer): | |||
58 | 58 | ||
59 | @staticmethod | 59 | @staticmethod |
60 | def enabled(): | 60 | def enabled(): |
61 | return litmus_util.is_device(LogTracer.DEVICE_STR) | 61 | return is_device(LogTracer.DEVICE_STR) |
62 | 62 | ||
63 | def stop_tracing(self): | 63 | def stop_tracing(self): |
64 | map(methodcaller('interrupt'), self.bins) | 64 | map(methodcaller('interrupt'), self.bins) |
@@ -71,7 +71,7 @@ class SchedTracer(Tracer): | |||
71 | super(SchedTracer, self).__init__("Sched Trace", output_dir) | 71 | super(SchedTracer, self).__init__("Sched Trace", output_dir) |
72 | 72 | ||
73 | if SchedTracer.enabled(): | 73 | if SchedTracer.enabled(): |
74 | for cpu in range(litmus_util.num_cpus()): | 74 | for cpu in range(num_cpus()): |
75 | # Executable will close the stdout/stderr files | 75 | # Executable will close the stdout/stderr files |
76 | stdout_f = open('%s/st-%d.bin' % (self.output_dir, cpu), 'w') | 76 | stdout_f = open('%s/st-%d.bin' % (self.output_dir, cpu), 'w') |
77 | stderr_f = open('%s/st-%d-stderr.txt' % (self.output_dir, cpu), 'w') | 77 | stderr_f = open('%s/st-%d-stderr.txt' % (self.output_dir, cpu), 'w') |
@@ -83,7 +83,7 @@ class SchedTracer(Tracer): | |||
83 | 83 | ||
84 | @staticmethod | 84 | @staticmethod |
85 | def enabled(): | 85 | def enabled(): |
86 | return litmus_util.is_device("%s%d" % (SchedTracer.DEVICE_STR, 0)) | 86 | return is_device("%s%d" % (SchedTracer.DEVICE_STR, 0)) |
87 | 87 | ||
88 | class OverheadTracer(Tracer): | 88 | class OverheadTracer(Tracer): |
89 | DEVICE_STR = '/dev/litmus/ft_trace0' | 89 | DEVICE_STR = '/dev/litmus/ft_trace0' |
@@ -100,7 +100,7 @@ class OverheadTracer(Tracer): | |||
100 | 100 | ||
101 | @staticmethod | 101 | @staticmethod |
102 | def enabled(): | 102 | def enabled(): |
103 | return litmus_util.is_device(OverheadTracer.DEVICE_STR) | 103 | return is_device(OverheadTracer.DEVICE_STR) |
104 | 104 | ||
105 | class PerfTracer(Tracer): | 105 | class PerfTracer(Tracer): |
106 | def __init__(self, output_dir): | 106 | def __init__(self, output_dir): |