diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-02-21 18:32:24 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-02-21 18:32:24 -0500 |
| commit | 6e2b99a0870e467e35c8b4b95aeb1e665dded413 (patch) | |
| tree | 1e4b4d000c6b53b93a35b5446dc774d4799c987c /run | |
| parent | 9bcbb4048cd82ea11ed469731eae95d808b99449 (diff) | |
Many bugfixes motivated by some end-to-end testing.
Diffstat (limited to 'run')
| -rw-r--r-- | run/executable/executable.py | 9 | ||||
| -rw-r--r-- | run/executable/ftcat.py | 21 | ||||
| -rw-r--r-- | run/experiment.py | 9 | ||||
| -rw-r--r-- | run/litmus_util.py | 10 | ||||
| -rw-r--r-- | run/tracer.py | 19 |
5 files changed, 36 insertions, 32 deletions
diff --git a/run/executable/executable.py b/run/executable/executable.py index bc8edd7..0a408b7 100644 --- a/run/executable/executable.py +++ b/run/executable/executable.py | |||
| @@ -44,7 +44,6 @@ class Executable(object): | |||
| 44 | return full_command | 44 | return full_command |
| 45 | 45 | ||
| 46 | def __str__(self): | 46 | def __str__(self): |
| 47 | print("Full command: %s" % self.__get_full_command()) | ||
| 48 | return " ".join(self.__get_full_command()) | 47 | return " ".join(self.__get_full_command()) |
| 49 | 48 | ||
| 50 | def execute(self): | 49 | def execute(self): |
| @@ -63,7 +62,7 @@ class Executable(object): | |||
| 63 | '''Send the terminate signal to the binary.''' | 62 | '''Send the terminate signal to the binary.''' |
| 64 | self.sp.terminate() | 63 | self.sp.terminate() |
| 65 | 64 | ||
| 66 | def wait(self): | 65 | def wait(self, error=True): |
| 67 | '''Wait until the executable is finished, checking return code. | 66 | '''Wait until the executable is finished, checking return code. |
| 68 | 67 | ||
| 69 | If the exit status is non-zero, raise an exception. | 68 | If the exit status is non-zero, raise an exception. |
| @@ -71,8 +70,10 @@ class Executable(object): | |||
| 71 | ''' | 70 | ''' |
| 72 | 71 | ||
| 73 | self.sp.wait() | 72 | self.sp.wait() |
| 74 | if self.sp.returncode != 0: | 73 | if self.sp.returncode != 0 and error: |
| 75 | print >>sys.stderr, "Non-zero return: %s %s" % (self.exec_file, " ".join(self.extra_args)) | 74 | print >>sys.stderr, "Non-zero return %d: %s %s" % (self.sp.returncode, |
| 75 | self.exec_file, | ||
| 76 | " ".join(self.extra_args)) | ||
| 76 | return 0 | 77 | return 0 |
| 77 | else: | 78 | else: |
| 78 | return 1 | 79 | return 1 |
diff --git a/run/executable/ftcat.py b/run/executable/ftcat.py index 5da8fa7..1f0420b 100644 --- a/run/executable/ftcat.py +++ b/run/executable/ftcat.py | |||
| @@ -1,18 +1,15 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import stat | 2 | import stat |
| 3 | 3 | ||
| 4 | from executable import Executable | 4 | from .executable import Executable |
| 5 | 5 | ||
| 6 | class FTcat(Executable): | 6 | class FTcat(Executable): |
| 7 | '''Used to wrap the ftcat binary in the Experiment object.''' | 7 | '''Used to wrap the ftcat binary in the Experiment object.''' |
| 8 | 8 | ||
| 9 | def __init__(self, ft_cat_bin, stdout_file, stderr_file, dev, events, cpu=None): | 9 | def __init__(self, ft_cat_bin, stdout_file, stderr_file, dev, events, cpu=None): |
| 10 | '''Extends the Executable initializer method with ftcat attributes.''' | 10 | '''Extends the Executable initializer method with ftcat attributes.''' |
| 11 | super(FTcat, self).__init__('/usr/bin/taskset') | ||
| 11 | 12 | ||
| 12 | # hack to run FTCat at higher priority | ||
| 13 | chrt_bin = '/usr/bin/chrt' | ||
| 14 | |||
| 15 | super(FTcat, self).__init__(chrt_bin) | ||
| 16 | self.stdout_file = stdout_file | 13 | self.stdout_file = stdout_file |
| 17 | self.stderr_file = stderr_file | 14 | self.stderr_file = stderr_file |
| 18 | 15 | ||
| @@ -23,11 +20,15 @@ class FTcat(Executable): | |||
| 23 | if events is None: | 20 | if events is None: |
| 24 | raise Exception('No events!') | 21 | raise Exception('No events!') |
| 25 | 22 | ||
| 26 | # hack to run FTCat at higher priority | ||
| 27 | self.extra_args = ['-f', '40'] | ||
| 28 | if cpu is not None: | 23 | if cpu is not None: |
| 29 | # and bind it to a CPU | 24 | # Execute only on the given CPU |
| 30 | self.extra_args.extend(['/usr/bin/taskset', '-c', str(cpu)]) | 25 | self.extra_args = ['-c', str(cpu)] |
| 26 | else: | ||
| 27 | # Execute on any cpu | ||
| 28 | self.extra_args = ['0xFFFFFFFF'] | ||
| 29 | |||
| 31 | events_str_arr = map(str, events) | 30 | events_str_arr = map(str, events) |
| 32 | self.extra_args.extend([ft_cat_bin, dev] + events_str_arr) | 31 | ft_cat_cmd = [ft_cat_bin, dev] + list(events_str_arr) |
| 32 | |||
| 33 | self.extra_args.extend(ft_cat_cmd) | ||
| 33 | 34 | ||
diff --git a/run/experiment.py b/run/experiment.py index c8fc228..ecb0241 100644 --- a/run/experiment.py +++ b/run/experiment.py | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import time | 2 | import time |
| 3 | import litmus_util as lu | 3 | import run.litmus_util as lu |
| 4 | import shutil as sh | ||
| 4 | from operator import methodcaller | 5 | from operator import methodcaller |
| 5 | from tracer import SchedTracer, LogTracer, PerfTracer, LinuxTracer, OverheadTracer | 6 | from run.tracer import SchedTracer, LogTracer, PerfTracer, LinuxTracer, OverheadTracer |
| 6 | 7 | ||
| 7 | class ExperimentException(Exception): | 8 | class ExperimentException(Exception): |
| 8 | '''Used to indicate when there are problems with an experiment.''' | 9 | '''Used to indicate when there are problems with an experiment.''' |
| @@ -78,6 +79,8 @@ class Experiment(object): | |||
| 78 | Experiment.INTERRUPTED_DIR) | 79 | Experiment.INTERRUPTED_DIR) |
| 79 | interrupted = "%s/%s" % (os.path.split(self.working_dir)[0], | 80 | interrupted = "%s/%s" % (os.path.split(self.working_dir)[0], |
| 80 | Experiment.INTERRUPTED_DIR) | 81 | Experiment.INTERRUPTED_DIR) |
| 82 | if os.path.exists(interrupted): | ||
| 83 | sh.rmtree(interrupted) | ||
| 81 | os.rename(self.working_dir, interrupted) | 84 | os.rename(self.working_dir, interrupted) |
| 82 | 85 | ||
| 83 | os.mkdir(self.working_dir) | 86 | os.mkdir(self.working_dir) |
| @@ -154,7 +157,7 @@ class Experiment(object): | |||
| 154 | os.rename(self.working_dir, self.finished_dir) | 157 | os.rename(self.working_dir, self.finished_dir) |
| 155 | 158 | ||
| 156 | def log(self, msg): | 159 | def log(self, msg): |
| 157 | print "[Exp %s]: %s" % (self.name, msg) | 160 | print("[Exp %s]: %s" % (self.name, msg)) |
| 158 | 161 | ||
| 159 | def run_exp(self): | 162 | def run_exp(self): |
| 160 | succ = False | 163 | succ = False |
diff --git a/run/litmus_util.py b/run/litmus_util.py index ec1700e..8a7f87d 100644 --- a/run/litmus_util.py +++ b/run/litmus_util.py | |||
| @@ -4,7 +4,6 @@ import subprocess | |||
| 4 | import os | 4 | import os |
| 5 | import stat | 5 | import stat |
| 6 | import config.config as conf | 6 | import config.config as conf |
| 7 | from common import get_config_option | ||
| 8 | 7 | ||
| 9 | def num_cpus(): | 8 | def num_cpus(): |
| 10 | '''Return the number of CPUs in the system.''' | 9 | '''Return the number of CPUs in the system.''' |
| @@ -19,11 +18,12 @@ def num_cpus(): | |||
| 19 | return cpus | 18 | return cpus |
| 20 | 19 | ||
| 21 | def ft_freq(): | 20 | def ft_freq(): |
| 22 | '''The frequency (in MHz) of the clock used by feather trace.''' | 21 | umachine = subprocess.check_output(["uname", "-m"]) |
| 23 | if get_config_option('CPU_V7') == 'y': | 22 | |
| 23 | if re.match("armv7", umachine): | ||
| 24 | # Arm V7s use a millisecond timer | 24 | # Arm V7s use a millisecond timer |
| 25 | freq = 1000.0 | 25 | freq = 1000.0 |
| 26 | elif get_config_option('X86') == 'y': | 26 | elif re.match("x86", umachine): |
| 27 | # X86 timer is equal to processor clock | 27 | # X86 timer is equal to processor clock |
| 28 | reg = re.compile(r'^cpu MHz\s*:\s*(?P<FREQ>\d+)', re.M) | 28 | reg = re.compile(r'^cpu MHz\s*:\s*(?P<FREQ>\d+)', re.M) |
| 29 | with open('/proc/cpuinfo', 'r') as f: | 29 | with open('/proc/cpuinfo', 'r') as f: |
| @@ -76,7 +76,7 @@ def is_device(dev): | |||
| 76 | return not (not mode & stat.S_IFCHR) | 76 | return not (not mode & stat.S_IFCHR) |
| 77 | 77 | ||
| 78 | def waiting_tasks(): | 78 | def waiting_tasks(): |
| 79 | reg = re.compile(r'^ready.*(?P<READY>\d+)$', re.M) | 79 | reg = re.compile(r'^ready.*?(?P<READY>\d+)$', re.M) |
| 80 | with open('/proc/litmus/stats', 'r') as f: | 80 | with open('/proc/litmus/stats', 'r') as f: |
| 81 | data = f.read() | 81 | data = f.read() |
| 82 | 82 | ||
diff --git a/run/tracer.py b/run/tracer.py index 5d00e86..723bcad 100644 --- a/run/tracer.py +++ b/run/tracer.py | |||
| @@ -1,10 +1,9 @@ | |||
| 1 | import litmus_util | 1 | from . import litmus_util |
| 2 | import os | 2 | import os |
| 3 | import config.config as conf | 3 | import config.config as conf |
| 4 | 4 | ||
| 5 | from operator import methodcaller | 5 | from operator import methodcaller |
| 6 | from executable.ftcat import FTcat,Executable | 6 | from run.executable.ftcat import FTcat,Executable |
| 7 | |||
| 8 | 7 | ||
| 9 | class Tracer(object): | 8 | class Tracer(object): |
| 10 | def __init__(self, name, output_dir): | 9 | def __init__(self, name, output_dir): |
| @@ -19,7 +18,6 @@ class Tracer(object): | |||
| 19 | map(methodcaller('terminate'), self.bins) | 18 | map(methodcaller('terminate'), self.bins) |
| 20 | map(methodcaller('wait'), self.bins) | 19 | map(methodcaller('wait'), self.bins) |
| 21 | 20 | ||
| 22 | |||
| 23 | class LinuxTracer(Tracer): | 21 | class LinuxTracer(Tracer): |
| 24 | EVENT_ROOT = "/sys/kernel/debug/tracing" | 22 | EVENT_ROOT = "/sys/kernel/debug/tracing" |
| 25 | LITMUS_EVENTS = "%s/events/litmus" % EVENT_ROOT | 23 | LITMUS_EVENTS = "%s/events/litmus" % EVENT_ROOT |
| @@ -45,7 +43,6 @@ class LinuxTracer(Tracer): | |||
| 45 | map(methodcaller('interrupt'), self.bins) | 43 | map(methodcaller('interrupt'), self.bins) |
| 46 | map(methodcaller('wait'), self.bins) | 44 | map(methodcaller('wait'), self.bins) |
| 47 | 45 | ||
| 48 | |||
| 49 | class LogTracer(Tracer): | 46 | class LogTracer(Tracer): |
| 50 | DEVICE_STR = '/dev/litmus/log' | 47 | DEVICE_STR = '/dev/litmus/log' |
| 51 | 48 | ||
| @@ -63,6 +60,9 @@ class LogTracer(Tracer): | |||
| 63 | def enabled(): | 60 | def enabled(): |
| 64 | return litmus_util.is_device(LogTracer.DEVICE_STR) | 61 | return litmus_util.is_device(LogTracer.DEVICE_STR) |
| 65 | 62 | ||
| 63 | def stop_tracing(self): | ||
| 64 | map(methodcaller('interrupt'), self.bins) | ||
| 65 | map(methodcaller('wait', False), self.bins) | ||
| 66 | 66 | ||
| 67 | class SchedTracer(Tracer): | 67 | class SchedTracer(Tracer): |
| 68 | DEVICE_STR = '/dev/litmus/sched_trace' | 68 | DEVICE_STR = '/dev/litmus/sched_trace' |
| @@ -76,14 +76,14 @@ class SchedTracer(Tracer): | |||
| 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') |
| 78 | dev = '{0}{1}'.format(SchedTracer.DEVICE_STR, cpu) | 78 | dev = '{0}{1}'.format(SchedTracer.DEVICE_STR, cpu) |
| 79 | ftc = FTcat(conf.BINS['ftcat'], stdout_f, stderr_f, dev, conf.SCHED_EVENTS, cpu=cpu) | 79 | ftc = FTcat(conf.BINS['ftcat'], stdout_f, stderr_f, dev, |
| 80 | conf.SCHED_EVENTS, cpu=cpu) | ||
| 80 | 81 | ||
| 81 | self.bins.append(ftc) | 82 | self.bins.append(ftc) |
| 82 | 83 | ||
| 83 | @staticmethod | 84 | @staticmethod |
| 84 | def enabled(): | 85 | def enabled(): |
| 85 | return litmus_util.is_device("%s%d" % (SchedTracer.DEVICE_STR, 0)) | 86 | return litmus_util.is_device("%s%d" % (SchedTracer.DEVICE_STR, 0)) |
| 86 | |||
| 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,8 +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 litmus_util.is_device(OverheadTracer.DEVICE_STR) |
| 104 | |||
| 105 | 104 | ||
| 106 | class PerfTracer(Tracer): | 105 | class PerfTracer(Tracer): |
| 107 | def __init__(self, output_dir): | 106 | def __init__(self, output_dir): |
