From 808ff90c55db21813967af8a814b61f520fdaff7 Mon Sep 17 00:00:00 2001 From: Mac Mollison Date: Sat, 3 Apr 2010 23:05:23 -0400 Subject: Rename 'eligible' to 'off_cpu' This much more accurately captures what is going on and should greatly reduce confusion --- unit_trace/gedf_test.py | 53 ++++++++++++++++++++++---------------------- unit_trace/stdout_printer.py | 8 +++---- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/unit_trace/gedf_test.py b/unit_trace/gedf_test.py index d4586ce..478a852 100644 --- a/unit_trace/gedf_test.py +++ b/unit_trace/gedf_test.py @@ -19,8 +19,8 @@ import sys def gedf_test(stream): # System model - eligible = [] # Tasks eligible - on_cpu = [] # Tasks running + on_cpu = [] # Tasks on a CPU + off_cpu = [] # Tasks not on a CPU m = None # CPUs # Time of the last record we saw. Only run the G-EDF test when the time @@ -45,26 +45,27 @@ def gedf_test(stream): # so we only check when the time has moved forward) # Also, need to update the first_event_this_timestamp variable if last_time is not None and last_time != record.when: - errors = _gedf_check(eligible,on_cpu,last_time,m, + errors = _gedf_check(off_cpu,on_cpu,last_time,m, first_event_this_timestamp) first_event_this_timestamp = record.id for error in errors: yield error - # Add a newly-released Job to the eligible queue + # Add a newly-released Job to the off_cpu queue if record.type_name == 'release': - eligible.append(Job(record)) + off_cpu.append(Job(record)) - # Move a Job from the eligible queue to on_cpu + # Move a Job from the off_cpu queue to on_cpu elif record.type_name == 'switch_to': - pos = _find_job(record,eligible) + pos = _find_job(record,off_cpu) if pos is None: - msg = "Event %d tried to switch to a job that was not eligible\n" + msg = "Event %d tried to switch to a job that was not on the" + msg += " off_cpu queue\n" msg = msg % (record.id) sys.stderr.write(msg) exit() - job = eligible[pos] - del eligible[pos] + job = off_cpu[pos] + del off_cpu[pos] on_cpu.append(job) # Mark a Job as completed. @@ -75,8 +76,8 @@ def gedf_test(stream): if pos is not None: on_cpu[pos].is_complete = True else: - pos = _find_job(record,eligible) - del eligible[pos] + pos = _find_job(record,off_cpu) + del off_cpu[pos] # A job is switched away from a CPU. If it has # been marked as complete, remove it from the model. @@ -91,7 +92,7 @@ def gedf_test(stream): job = on_cpu[pos] del on_cpu[pos] if job.is_complete == False: - eligible.append(job) + off_cpu.append(job) # A job has been blocked. elif record.type_name == 'block': @@ -99,16 +100,16 @@ def gedf_test(stream): # What if the job is blocked AFTER being switched away? # This is a bug in some versions of LITMUS. if pos is None: - pos = _find_job(record,eligible) - job = eligible[pos] + pos = _find_job(record,off_cpu) + job = off_cpu[pos] else: job = on_cpu[pos] job.is_blocked = True # A job is resumed elif record.type_name == 'resume': - pos = _find_job(record,eligible) - job = eligible[pos] + pos = _find_job(record,off_cpu) + job = off_cpu[pos] job.is_blocked = False last_time = record.when @@ -136,11 +137,11 @@ class Job(object): # G-EDF errors: the start or end of an inversion class Error(object): id = 0 - def __init__(self, job, eligible, on_cpu,first_event_this_timestamp): + def __init__(self, job, off_cpu, on_cpu,first_event_this_timestamp): Error.id += 1 self.id = Error.id self.job = copy.copy(job) - self.eligible = copy.copy(eligible) + self.off_cpu = copy.copy(off_cpu) self.on_cpu = copy.copy(on_cpu) self.record_type = 'error' self.triggering_event_id = first_event_this_timestamp @@ -161,7 +162,7 @@ def _find_job(record,list): return None # Return records for any inversion_starts and inversion_ends -def _gedf_check(eligible,on_cpu,when,m,first_event_this_timestamp): +def _gedf_check(off_cpu,on_cpu,when,m,first_event_this_timestamp): # List of error records to be returned errors = [] @@ -172,7 +173,7 @@ def _gedf_check(eligible,on_cpu,when,m,first_event_this_timestamp): for x in on_cpu: if x.is_complete is not True and x.is_blocked is not True: all.append(x) - for x in eligible: + for x in off_cpu: if x.is_blocked is not True: all.append(x) @@ -190,14 +191,14 @@ def _gedf_check(eligible,on_cpu,when,m,first_event_this_timestamp): # It's not running and an inversion_start has not been recorded if job not in on_cpu and job.inversion_start is None: job.inversion_start = when - errors.append(Error(job, eligible, on_cpu, + errors.append(Error(job, off_cpu, on_cpu, first_event_this_timestamp)) # It is running and an inversion_start exists (i.e. it it still # marked as being inverted) elif job in on_cpu and job.inversion_start is not None: job.inversion_end = when - errors.append(Error(job, eligible, on_cpu, + errors.append(Error(job, off_cpu, on_cpu, first_event_this_timestamp)) job.inversion_start = None job.inversion_end = None @@ -208,17 +209,17 @@ def _gedf_check(eligible,on_cpu,when,m,first_event_this_timestamp): job = all[x] if job not in on_cpu and job.inversion_start is not None: job.inversion_end = when - errors.append(Error(job, eligible, on_cpu, + errors.append(Error(job, off_cpu, on_cpu, first_event_this_timestamp)) job.inversion_start = None job.inversion_end = None # Look for priority inversions among blocked tasks and end them all = filter(lambda x:x.is_blocked and x.inversion_start is not None, - on_cpu + eligible) + on_cpu + off_cpu) for job in all: job.inversion_end = when - errors.append(Error(job, eligible, on_cpu, + errors.append(Error(job, off_cpu, on_cpu, first_event_this_timestamp)) job.inversion_start = None job.inversion_end = None diff --git a/unit_trace/stdout_printer.py b/unit_trace/stdout_printer.py index b8da9bf..f182b82 100644 --- a/unit_trace/stdout_printer.py +++ b/unit_trace/stdout_printer.py @@ -39,8 +39,8 @@ def _print_inversion_start(record): print "Time: %d" % (record.job.inversion_start) print "Job: %d.%d" % (record.job.pid,record.job.job) print "Deadline: %d" % (record.job.deadline) - print "Eligible: ", - for job in record.eligible: + print "Off CPU: ", + for job in record.off_cpu: print str(job) + " ", print print "On CPU: ", @@ -60,8 +60,8 @@ def _print_inversion_end(record): record.job.inversion_end - record.job.inversion_start) print "Job: %d.%d" % (record.job.pid,record.job.job) print "Deadline: %d" % (record.job.deadline) - print "Eligible: ", - for job in record.eligible: + print "Off CPU: ", + for job in record.off_cpu: print str(job) + " ", print print "On CPU: ", -- cgit v1.2.2