From 6e2b99a0870e467e35c8b4b95aeb1e665dded413 Mon Sep 17 00:00:00 2001 From: Jonathan Herman Date: Thu, 21 Feb 2013 18:32:24 -0500 Subject: Many bugfixes motivated by some end-to-end testing. --- run/executable/executable.py | 9 +++++---- run/executable/ftcat.py | 21 +++++++++++---------- run/experiment.py | 9 ++++++--- run/litmus_util.py | 10 +++++----- run/tracer.py | 19 +++++++++---------- 5 files changed, 36 insertions(+), 32 deletions(-) (limited to 'run') 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): return full_command def __str__(self): - print("Full command: %s" % self.__get_full_command()) return " ".join(self.__get_full_command()) def execute(self): @@ -63,7 +62,7 @@ class Executable(object): '''Send the terminate signal to the binary.''' self.sp.terminate() - def wait(self): + def wait(self, error=True): '''Wait until the executable is finished, checking return code. If the exit status is non-zero, raise an exception. @@ -71,8 +70,10 @@ class Executable(object): ''' self.sp.wait() - if self.sp.returncode != 0: - print >>sys.stderr, "Non-zero return: %s %s" % (self.exec_file, " ".join(self.extra_args)) + if self.sp.returncode != 0 and error: + print >>sys.stderr, "Non-zero return %d: %s %s" % (self.sp.returncode, + self.exec_file, + " ".join(self.extra_args)) return 0 else: 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 @@ import os import stat -from executable import Executable +from .executable import Executable class FTcat(Executable): '''Used to wrap the ftcat binary in the Experiment object.''' def __init__(self, ft_cat_bin, stdout_file, stderr_file, dev, events, cpu=None): '''Extends the Executable initializer method with ftcat attributes.''' + super(FTcat, self).__init__('/usr/bin/taskset') - # hack to run FTCat at higher priority - chrt_bin = '/usr/bin/chrt' - - super(FTcat, self).__init__(chrt_bin) self.stdout_file = stdout_file self.stderr_file = stderr_file @@ -23,11 +20,15 @@ class FTcat(Executable): if events is None: raise Exception('No events!') - # hack to run FTCat at higher priority - self.extra_args = ['-f', '40'] if cpu is not None: - # and bind it to a CPU - self.extra_args.extend(['/usr/bin/taskset', '-c', str(cpu)]) + # Execute only on the given CPU + self.extra_args = ['-c', str(cpu)] + else: + # Execute on any cpu + self.extra_args = ['0xFFFFFFFF'] + events_str_arr = map(str, events) - self.extra_args.extend([ft_cat_bin, dev] + events_str_arr) + ft_cat_cmd = [ft_cat_bin, dev] + list(events_str_arr) + + self.extra_args.extend(ft_cat_cmd) 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 @@ import os import time -import litmus_util as lu +import run.litmus_util as lu +import shutil as sh from operator import methodcaller -from tracer import SchedTracer, LogTracer, PerfTracer, LinuxTracer, OverheadTracer +from run.tracer import SchedTracer, LogTracer, PerfTracer, LinuxTracer, OverheadTracer class ExperimentException(Exception): '''Used to indicate when there are problems with an experiment.''' @@ -78,6 +79,8 @@ class Experiment(object): Experiment.INTERRUPTED_DIR) interrupted = "%s/%s" % (os.path.split(self.working_dir)[0], Experiment.INTERRUPTED_DIR) + if os.path.exists(interrupted): + sh.rmtree(interrupted) os.rename(self.working_dir, interrupted) os.mkdir(self.working_dir) @@ -154,7 +157,7 @@ class Experiment(object): os.rename(self.working_dir, self.finished_dir) def log(self, msg): - print "[Exp %s]: %s" % (self.name, msg) + print("[Exp %s]: %s" % (self.name, msg)) def run_exp(self): 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 import os import stat import config.config as conf -from common import get_config_option def num_cpus(): '''Return the number of CPUs in the system.''' @@ -19,11 +18,12 @@ def num_cpus(): return cpus def ft_freq(): - '''The frequency (in MHz) of the clock used by feather trace.''' - if get_config_option('CPU_V7') == 'y': + umachine = subprocess.check_output(["uname", "-m"]) + + if re.match("armv7", umachine): # Arm V7s use a millisecond timer freq = 1000.0 - elif get_config_option('X86') == 'y': + elif re.match("x86", umachine): # X86 timer is equal to processor clock reg = re.compile(r'^cpu MHz\s*:\s*(?P\d+)', re.M) with open('/proc/cpuinfo', 'r') as f: @@ -76,7 +76,7 @@ def is_device(dev): return not (not mode & stat.S_IFCHR) def waiting_tasks(): - reg = re.compile(r'^ready.*(?P\d+)$', re.M) + reg = re.compile(r'^ready.*?(?P\d+)$', re.M) with open('/proc/litmus/stats', 'r') as f: data = f.read() 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 @@ -import litmus_util +from . import litmus_util import os import config.config as conf from operator import methodcaller -from executable.ftcat import FTcat,Executable - +from run.executable.ftcat import FTcat,Executable class Tracer(object): def __init__(self, name, output_dir): @@ -19,7 +18,6 @@ class Tracer(object): map(methodcaller('terminate'), self.bins) map(methodcaller('wait'), self.bins) - class LinuxTracer(Tracer): EVENT_ROOT = "/sys/kernel/debug/tracing" LITMUS_EVENTS = "%s/events/litmus" % EVENT_ROOT @@ -45,7 +43,6 @@ class LinuxTracer(Tracer): map(methodcaller('interrupt'), self.bins) map(methodcaller('wait'), self.bins) - class LogTracer(Tracer): DEVICE_STR = '/dev/litmus/log' @@ -63,6 +60,9 @@ class LogTracer(Tracer): def enabled(): return litmus_util.is_device(LogTracer.DEVICE_STR) + def stop_tracing(self): + map(methodcaller('interrupt'), self.bins) + map(methodcaller('wait', False), self.bins) class SchedTracer(Tracer): DEVICE_STR = '/dev/litmus/sched_trace' @@ -76,14 +76,14 @@ class SchedTracer(Tracer): stdout_f = open('%s/st-%d.bin' % (self.output_dir, cpu), 'w') stderr_f = open('%s/st-%d-stderr.txt' % (self.output_dir, cpu), 'w') dev = '{0}{1}'.format(SchedTracer.DEVICE_STR, cpu) - ftc = FTcat(conf.BINS['ftcat'], stdout_f, stderr_f, dev, conf.SCHED_EVENTS, cpu=cpu) + ftc = FTcat(conf.BINS['ftcat'], stdout_f, stderr_f, dev, + conf.SCHED_EVENTS, cpu=cpu) self.bins.append(ftc) @staticmethod def enabled(): - return litmus_util.is_device("%s%d" % (SchedTracer.DEVICE_STR, 0)) - + return litmus_util.is_device("%s%d" % (SchedTracer.DEVICE_STR, 0)) class OverheadTracer(Tracer): DEVICE_STR = '/dev/litmus/ft_trace0' @@ -100,8 +100,7 @@ class OverheadTracer(Tracer): @staticmethod def enabled(): - return litmus_util.is_device(OverheadTracer.DEVICE_STR) - + return litmus_util.is_device(OverheadTracer.DEVICE_STR) class PerfTracer(Tracer): def __init__(self, output_dir): -- cgit v1.2.2