Commit ab0cc5e1 by Michael Schmid

seems to work with a few bugs

parent 930ac7c0
...@@ -6,7 +6,7 @@ from simso.core.JobEvent import JobEvent ...@@ -6,7 +6,7 @@ from simso.core.JobEvent import JobEvent
from math import ceil from math import ceil
class Job(Process): class Job:
"""The Job class simulate the behavior of a real Job. This *should* only be """The Job class simulate the behavior of a real Job. This *should* only be
instantiated by a Task.""" instantiated by a Task."""
...@@ -28,7 +28,6 @@ class Job(Process): ...@@ -28,7 +28,6 @@ class Job(Process):
:type etm: AbstractExecutionTimeModel :type etm: AbstractExecutionTimeModel
:type sim: Model :type sim: Model
""" """
Process.__init__(self, env=sim,generator=self.activate_job())
self._task = task self._task = task
self._pred = pred self._pred = pred
self.instr_count = 0 # Updated by the cache model. self.instr_count = 0 # Updated by the cache model.
...@@ -53,7 +52,9 @@ class Job(Process): ...@@ -53,7 +52,9 @@ class Job(Process):
self.processor_ok = self._sim.event() self.processor_ok = self._sim.event()
self.context_ok = self._sim.event() self.context_ok = self._sim.event()
self.context_ok.succeed() self.context_ok.succeed()
self.context_ready=True self.context_ready = True
self.process = self._sim.process(self.activate_job())
def is_active(self): def is_active(self):
""" """
...@@ -92,7 +93,7 @@ class Job(Process): ...@@ -92,7 +93,7 @@ class Job(Process):
self._monitor.observe(JobEvent(self, JobEvent.PREEMPTED)) self._monitor.observe(JobEvent(self, JobEvent.PREEMPTED))
self._sim.logger.log(self.name + " Preempted! ret: " + self._sim.logger.log(self.name + " Preempted! ret: " +
str("Don't know what to pass else?"), kernel=True) # TODO: what to pass as interrupted? str("Don't know what to pass else?"), kernel=True) # TODO: what to pass as interrupted?
def _on_terminated(self): def _on_terminated(self):
self._on_stop_exec() self._on_stop_exec()
...@@ -302,7 +303,7 @@ class Job(Process): ...@@ -302,7 +303,7 @@ class Job(Process):
# Wait an execute order. # Wait an execute order.
try: try:
yield self.processor_ok yield self.processor_ok
self.processor_ok = self._sim.event() self.processor_ok = self._sim.event()
except Interrupt: except Interrupt:
pass pass
else: else:
......
...@@ -48,7 +48,7 @@ class Model(Environment): ...@@ -48,7 +48,7 @@ class Model(Environment):
# Init the processor class. This will in particular reinit the # Init the processor class. This will in particular reinit the
# identifiers to 0. # identifiers to 0.
Processor.init() Processor.init()
# Initialization of the caches # Initialization of the caches
for cache in configuration.caches_list: for cache in configuration.caches_list:
cache.init() cache.init()
...@@ -134,11 +134,11 @@ class Model(Environment): ...@@ -134,11 +134,11 @@ class Model(Environment):
self.scheduler.init() self.scheduler.init()
self.progress.start() self.progress.start()
for cpu in self._processors: # for cpu in self._processors:
self.process(cpu.run()) # self.process(cpu.run())
for task in self._task_list: # for task in self._task_list:
self.process(task.execute()) # self.process(task.execute())
try: try:
self.run(until=self._duration) self.run(until=self._duration)
......
...@@ -34,7 +34,7 @@ class ProcInfo(object): ...@@ -34,7 +34,7 @@ class ProcInfo(object):
self.caches.append(cache) self.caches.append(cache)
class Processor(Process): class Processor:
""" """
A processor is responsible of deciding whether the simulated processor A processor is responsible of deciding whether the simulated processor
should execute a job or execute the scheduler. There is one instance of should execute a job or execute the scheduler. There is one instance of
...@@ -54,7 +54,6 @@ class Processor(Process): ...@@ -54,7 +54,6 @@ class Processor(Process):
cls._identifier = 0 cls._identifier = 0
def __init__(self, model, proc_info): def __init__(self, model, proc_info):
Process.__init__(self, model, self.run())
self._model = model self._model = model
self._internal_id = Processor._identifier self._internal_id = Processor._identifier
Processor._identifier += 1 Processor._identifier += 1
...@@ -74,6 +73,7 @@ class Processor(Process): ...@@ -74,6 +73,7 @@ class Processor(Process):
self.timer_monitor = Monitor( self.timer_monitor = Monitor(
env=model, name="Monitor Timer" + proc_info.name) env=model, name="Monitor Timer" + proc_info.name)
self._speed = proc_info.speed self._speed = proc_info.speed
self.process = self._model.process(self.run())
def resched(self): def resched(self):
""" """
...@@ -169,7 +169,8 @@ class Processor(Process): ...@@ -169,7 +169,8 @@ class Processor(Process):
while not self._evts: while not self._evts:
yield self._model.timeout(1) yield self._model.timeout(1)
if job: if job:
self._model.interrupt(job) # self._model.interrupt(job)
# job.process.interrupt()
self.monitor.observe(ProcCxtSaveEvent()) self.monitor.observe(ProcCxtSaveEvent())
# overhead save context # overhead save context
yield self._model.timeout(self.cs_overhead) yield self._model.timeout(self.cs_overhead)
......
...@@ -107,7 +107,7 @@ class TaskInfo(object): ...@@ -107,7 +107,7 @@ class TaskInfo(object):
return stack return stack
class GenericTask(Process): class GenericTask:
""" """
Abstract class for Tasks. :class:`ATask` and :class:`PTask` inherits from Abstract class for Tasks. :class:`ATask` and :class:`PTask` inherits from
this class. this class.
...@@ -132,7 +132,6 @@ class GenericTask(Process): ...@@ -132,7 +132,6 @@ class GenericTask(Process):
:type sim: Model :type sim: Model
:type task_info: TaskInfo :type task_info: TaskInfo
""" """
Process.__init__(self, env=sim, generator=self.execute())
self.name = task_info.name self.name = task_info.name
self._task_info = task_info self._task_info = task_info
self._monitor = Monitor(name="Monitor" + self.name + "_states", self._monitor = Monitor(name="Monitor" + self.name + "_states",
...@@ -146,6 +145,7 @@ class GenericTask(Process): ...@@ -146,6 +145,7 @@ class GenericTask(Process):
self._cpi_alone = {} self._cpi_alone = {}
self._jobs = [] self._jobs = []
self.job = None self.job = None
self.process = self._sim.process(self.execute())
def execute(self): def execute(self):
pass pass
...@@ -321,7 +321,7 @@ class PTask(GenericTask): ...@@ -321,7 +321,7 @@ class PTask(GenericTask):
self._init() self._init()
# wait the activation date. # wait the activation date.
yield self._sim.timeout(int(self._task_info.activation_date * yield self._sim.timeout(int(self._task_info.activation_date *
self._sim.cycles_per_ms)) self._sim.cycles_per_ms))
while True: while True:
# print self.sim.now, "activate", self.name # print self.sim.now, "activate", self.name
...@@ -340,8 +340,8 @@ class SporadicTask(GenericTask): ...@@ -340,8 +340,8 @@ class SporadicTask(GenericTask):
self._init() self._init()
for ndate in self.list_activation_dates: for ndate in self.list_activation_dates:
yield self._sim.timeout(int(ndate * self._sim.cycles_per_ms) \ yield self._sim.timeout(int(ndate * self._sim.cycles_per_ms)
- self._sim.now) - self._sim.now)
self.create_job() self.create_job()
@property @property
...@@ -360,8 +360,8 @@ class ProbabilisticTask(GenericTask): ...@@ -360,8 +360,8 @@ class ProbabilisticTask(GenericTask):
self._init() self._init()
for ndate in self.list_activation_dates: for ndate in self.list_activation_dates:
yield self._sim.timeout(int(ndate * self._sim.cycles_per_ms) \ yield self._sim.timeout(int(ndate * self._sim.cycles_per_ms)
- self._sim.now) - self._sim.now)
self.create_job() self.create_job()
@property @property
......
...@@ -6,9 +6,8 @@ from simpy import Environment, Process, Interrupt ...@@ -6,9 +6,8 @@ from simpy import Environment, Process, Interrupt
# TODO: allow the user to specify an overhead. # TODO: allow the user to specify an overhead.
class InstanceTimer(Process): class InstanceTimer:
def __init__(self, timer): def __init__(self, timer):
Process.__init__(self, env=timer._sim, generator=self.run())
self._sim = timer._sim self._sim = timer._sim
self.function = timer.function self.function = timer.function
self.args = timer.args self.args = timer.args
...@@ -17,6 +16,7 @@ class InstanceTimer(Process): ...@@ -17,6 +16,7 @@ class InstanceTimer(Process):
self.cpu = timer.cpu self.cpu = timer.cpu
self.running = False self.running = False
self.overhead = timer.overhead self.overhead = timer.overhead
self.process = self._sim.process(self.run())
def call_handler(self): def call_handler(self):
if self.running: if self.running:
...@@ -54,6 +54,7 @@ class Timer(object): ...@@ -54,6 +54,7 @@ class Timer(object):
The delay is expressed in milliseconds by default but it can also be given The delay is expressed in milliseconds by default but it can also be given
in cycles. in cycles.
""" """
def __init__(self, sim, function, args, delay, one_shot=True, prior=False, def __init__(self, sim, function, args, delay, one_shot=True, prior=False,
cpu=None, in_ms=True, overhead=0): cpu=None, in_ms=True, overhead=0):
""" """
...@@ -95,7 +96,8 @@ class Timer(object): ...@@ -95,7 +96,8 @@ class Timer(object):
Start the timer. Start the timer.
""" """
self.instance = InstanceTimer(self) self.instance = InstanceTimer(self)
self._sim.process(self.instance.run()) # TODO: , self.prior what's with this? # TODO: , self.prior what's with this?
self._sim.process(self.instance.run())
def stop(self): def stop(self):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment