def schedule_0(self): """ Schedule this proper sub-system. """ self.to_reschedule = False decision = [] self.virtual = [] active_servers = [s for s in self.root.children if not s.dummyServer and s.budget > 0] if self.is_idle is True and self.keep is False and active_servers: self.sim.logger.log("was idle in t {}".format(self.processors[0].name)) servers = [s for s in self.root.children if not s.dummyServer] # Prolongamento do job dummy liberado em idle_time self.slack = algorithm_1(self, servers, self.sim.now()) # tempo de computação total do job dummy liberado em idle_time delta = self.sim.now() - self.idle_time + self.slack self.sim.logger.log("original slack {} omega {}".format(self.slack, self.sim.now() - self.idle_time)) # período ocioso exato delta self.processors[0].set_idle(delta) # Se houve prolongamento, o nível continua ocioso if self.slack > 0: self.add_timer(self.slack, self.processors[0]) self.keep = True self.is_idle = False self.slack += self.sim.now() # Caso contrário, o nível fica ocupado else: self.is_idle = False self.keep = False elif active_servers and self.sim.now() >= self.slack: self.is_idle = False self.keep = False # Processor level control if not self.busy: self.busy = True self.sim.logger.log("Servidores ativos, BUSY {}, slack {}".format(self.processors[0].name, self.slack)) else: self.sim.logger.log("Sem servidores ativos, IDLE {}, slack {}".format(self.processors[0].name, self.slack)) self.is_idle = True self.idle_time = self.sim.now() # se o tempo acabar antes de aglomerar # Sinaliza início da ociosidade para energy self.processors[0]._power.flag(self.sim.now()) selected = select_jobs(self, self.root, self.virtual) idle = [s for s in selected if s.task.name == 'IdleTask'] jobs = [s.job for s in selected if s.task.name != 'IdleTask' and s.task.name != "wcet"] """if (idle and not self.keep): servers = [s for s in self.root.children if not s.dummyServer] start_slack = min(servers, key=lambda s: s.next_deadline).next_deadline - self.sim.now() if start_slack > 2: self.slack = uni_algorithm_1(self, servers, self.sim.now()+start_slack) self.slack += start_slack #self.sim.logger.log("slack {}, sub {}, start {}".format(self.slack, self.identifier, start_slack)) if int(self.slack) > 0 and self.utilization < 0.985: self.add_timer(self.slack, self.processors[0]) self.keep = True else: self.is_idle = False self.keep = False """ wakeup_delay = min([s.budget for s in self.virtual if s.budget > 0]) """old = self.virtual while wakeup_delay == 0: old.remove(min_s) min_s = min(old, key=lambda s: s.budget) wakeup_delay = min_s.budget""" if wakeup_delay > 0: self.timer = Timer(self.sim, ProperSubsystem.virtual_event, (self, self.processors[0]), wakeup_delay, cpu=self.processors[0], in_ms=False) self.timer.start() cpus = [] #first, leave already executing tasks on their current processors; for cpu in self.processors: if cpu.running in jobs: #cpus.append(cpu) jobs.remove(cpu.running) # remove job and cpu else: cpus.append(cpu) # second, assign previously idle tasks to their last-used processor, when its available aux_jobs = list(jobs) for job in aux_jobs: if job.task.last_cpu in cpus: decision.append((job, job.task.last_cpu)) jobs.remove(job) cpus.remove(job.task.last_cpu) # third, assign remaining tasks to free processors arbitrarily for cpu in cpus: if jobs: decision.append((jobs.pop(), cpu)) else: period = 0 """if self.keep and self.slack > 0: period = self.slack #self.sim.logger.log("slack {}".format(self.slack)) self.slack = 0 cpu.set_idle(period) elif not self.keep and idle: period = next_activation(idle.pop()) - self.sim.now() #self.sim.logger.log("next_activation {}".format(period)) cpu.set_idle(period) """ decision.append((None, cpu)) return decision
def schedule(self): """ Schedule this proper sub-system. """ self.to_reschedule = False self.virtual = [] decision = [] processors = [] processors = self.processors self.CSC(self.sim.now()) t = self.sim.now() if t >= self.idleBegin and t < self.idleEnd: self.is_idle = True # add schedule event - end of idle period self.add_timer(self.idleEnd - t, self.processors[0]) else: self.is_idle = False selected = select_jobs(self, self.root, self.virtual) idle = [s for s in selected if s.task.name == 'IdleTask'] jobs = [ s.job for s in selected if s.task.name != 'IdleTask' and s.task.name != "wcet" ] if idle: # CSC dual level if self.level % 2 == 0: # use busyInterval to save energy self.processors[0].set_dummy(self.busyEnd - t) # CSC primal level else: # use idleInterval to save energy self.processors[0].set_dummy(self.idleEnd - t) processors = self.processors[ 1:] # Refresh available processors list decision.append( (None, self.processors[0])) # Set dummy to first processor else: self.processors[0].stop_dummy() wakeup_delay = min([s.budget for s in self.virtual if s.budget > 0]) if wakeup_delay > 0: self.timer = Timer(self.sim, ProperSubsystem.virtual_event, (self, self.processors[0]), wakeup_delay, cpu=self.processors[0], in_ms=False) self.timer.start() cpus = [] #first, leave already executing tasks on their current processors; for cpu in processors: if cpu.running in jobs: jobs.remove(cpu.running) # remove job and cpu else: cpus.append(cpu) # second, assign previously idle tasks to their last-used processor, when its available aux_jobs = list(jobs) for job in aux_jobs: if job.task.last_cpu in cpus: decision.append((job, job.task.last_cpu)) jobs.remove(job) cpus.remove(job.task.last_cpu) # third, assign remaining tasks to free processors arbitrarily for cpu in cpus: if jobs: decision.append((jobs.pop(), cpu)) else: decision.append((None, cpu)) return decision
def schedule_1(self): """ Schedule this proper sub-system. """ self.to_reschedule = False self.virtual = [] decision = [] processors = [] processors = self.processors active_servers = [s for s in self.root.children if not s.dummyServer and s.budget > 0] if self.is_idle is True and self.keep is False and active_servers: self.sim.logger.log("was idle in t {}".format(self.processors[0].name)) servers = [s for s in self.root.children if not s.dummyServer] self.slack = algorithm_1(self, servers, self.sim.now()) self.sim.logger.log("slack {}, sub {}".format(self.slack, self.identifier)) if self.slack > 0: self.add_timer(self.slack, self.processors[0]) self.keep = True # calcular o mínimo ocioso apartir do slack d = self.sim.now() + (float(self.slack)/(1-self.dummyTask[0].utilization)) self.lower_bound = d - self.slack - self.sim.now() self.sim.logger.log("lower_bound {}, d {}, u={}".format(self.lower_bound/self.sim.cycles_per_ms, d, self.dummyTask[len(self.dummyTask)-1].utilization)) self.slack += self.sim.now() else: self.is_idle = False self.keep = False elif active_servers and self.sim.now() >= self.slack: self.is_idle = False self.keep = False if self.lower_bound <= 0: self.lower_bound = sum(s.budget for s in active_servers) self.processors[0].set_idle_extend(self.lower_bound) # Processor level control if not self.busy: self.busy = True processors = self.processors[1:] # Refresh avaliable processors list decision.append((None, self.processors[0])) # Set dummy to first processor self.sim.logger.log("Servidores ativos, BUSY {}".format(self.processors[0].name)) else: self.sim.logger.log("Sem servidores ativos, IDLE {}".format(self.processors[0].name)) self.is_idle = True # Processor level control if self.busy: self.processors[0].stop_idle_extend() self.busy = False self.lower_bound = 0 selected = select_jobs(self, self.root, self.virtual) idle = [s for s in selected if s.task.name == 'IdleTask'] jobs = [s.job for s in selected if s.task.name != 'IdleTask' and s.task.name != "wcet"] wakeup_delay = min([s.budget for s in self.virtual if s.budget > 0]) """old = self.virtual while wakeup_delay == 0: old.remove(min_s) min_s = min(old, key=lambda s: s.budget) wakeup_delay = min_s.budget""" if wakeup_delay > 0: self.timer = Timer(self.sim, ProperSubsystem.virtual_event, (self, self.processors[0]), wakeup_delay, cpu=self.processors[0], in_ms=False) self.timer.start() cpus = [] #first, leave already executing tasks on their current processors; for cpu in processors: if cpu.running in jobs: #cpus.append(cpu) jobs.remove(cpu.running) # remove job and cpu else: cpus.append(cpu) # second, assign previously idle tasks to their last-used processor, when its available aux_jobs = list(jobs) for job in aux_jobs: if job.task.last_cpu in cpus: #if job.task.last_cpu.is_running(): decision.append((job, job.task.last_cpu)) jobs.remove(job) cpus.remove(job.task.last_cpu) # third, assign remaining tasks to free processors arbitrarily for cpu in cpus: if jobs: decision.append((jobs.pop(), cpu)) else: decision.append((None, cpu)) return decision
def schedule(self): """ Schedule this proper sub-system. """ self.to_reschedule = False decision = [] self.virtual = [] active_servers = [ s for s in self.root.children if s.budget > 0 and not s.dummyServer ] selected = select_jobs(self, self.root, self.virtual) idle = [s for s in selected if s.task.name == 'IdleTask'] jobs = [ s.job for s in selected if s.task.name != 'IdleTask' and s.task.name != "wcet" ] wcet = [s for s in selected if s.task.name == "wcet"] min_s = min(self.virtual, key=lambda s: s.budget) wakeup_delay = min_s.budget old = self.virtual while wakeup_delay == 0: old.remove(min_s) min_s = min(old, key=lambda s: s.budget) wakeup_delay = min_s.budget if wakeup_delay > 0: self.timer = Timer(self.sim, ProperSubsystem.virtual_event, (self, self.processors[0]), wakeup_delay, cpu=self.processors[0], in_ms=False) self.timer.start() processors = [] if idle: processors = self.processors[1:] decision.append((None, self.processors[0])) soma = sum([s.budget for s in active_servers]) self.sim.logger.log("DUMMY TASK Executing on {}".format( self.processors[0].name)) self.processors[0].set_idle_extend(soma) #self.processors[0].set_dummy() else: processors = self.processors #self.sim.logger.log("stop".format()) self.processors[0].stop_idle_extend() #self.processors[0].set_busy() cpus = [] #first, leave already executing tasks on their current processors; for cpu in processors: if cpu.running in jobs: #cpus.append(cpu) jobs.remove(cpu.running) # remove job and cpu else: cpus.append(cpu) # second, assign previously idle tasks to their last-used processor, when its available aux_jobs = list(jobs) for job in aux_jobs: if job.task.last_cpu in cpus: #if job.task.last_cpu.is_running(): decision.append((job, job.task.last_cpu)) jobs.remove(job) cpus.remove(job.task.last_cpu) # third, assign remaining tasks to free processors arbitrarily for cpu in cpus: if jobs: decision.append((jobs.pop(), cpu)) else: decision.append((None, cpu)) return decision
def schedule(self): """ Schedule this proper sub-system. """ self.to_reschedule = False decision = [] self.virtual = [] active_servers = [ s for s in self.root.children if s.budget > 0 and not s.dummyServer ] selected = select_jobs(self, self.root, self.virtual) idle = [s for s in selected if s.task.name == 'IdleTask'] jobs = [ s.job for s in selected if s.task.name != 'IdleTask' and s.task.name != "wcet" ] min_s = min(self.virtual, key=lambda s: s.budget) wakeup_delay = min_s.budget if wakeup_delay > 0: self.timer = Timer(self.sim, ProperSubsystem.virtual_event, (self, self.processors[0]), wakeup_delay, cpu=self.processors[0], in_ms=False) self.timer.start() processors = [] t = self.sim.now() beta = sum([s.budget for s in active_servers]) omega = max(0, self.root.next_deadline - t, beta) if idle: if self.level % 2 == 0: decision.append((None, self.processors[0])) self.processors[0].set_dummy(beta) # primal level else: self.processors[0].set_dummy(omega) processors = self.processors[ 1:] # Refresh available processors list decision.append( (None, self.processors[0])) # Set dummy to first processor else: processors = self.processors self.processors[0].stop_dummy() cpus = [] #first, leave already executing tasks on their current processors; for cpu in processors: if cpu.running in jobs: jobs.remove(cpu.running) # remove job and cpu else: cpus.append(cpu) # second, assign previously idle tasks to their last-used processor, when its available aux_jobs = list(jobs) for job in aux_jobs: if job.task.last_cpu in cpus: decision.append((job, job.task.last_cpu)) jobs.remove(job) cpus.remove(job.task.last_cpu) # third, assign remaining tasks to free processors arbitrarily for cpu in cpus: if jobs: decision.append((jobs.pop(), cpu)) else: period = 0 decision.append((None, cpu)) return decision
def schedule(self): """ Schedule this proper sub-system. """ self.to_reschedule = False self.virtual = [] decision = [] processors = [] processors = self.processors active_servers = [s for s in self.root.children if not s.dummyServer and s.budget > 0] if self.is_idle is True and self.keep is False and active_servers: self.sim.logger.log("was idle in t {}".format(self.processors[0].name)) servers = [s for s in self.root.children if not s.dummyServer] beta = sum(s.budget for s in servers) self.slack = max(0, self.root.next_deadline - self.sim.now() - beta) # tempo de computação total do job dummy liberado em idle_time delta = self.sim.now() - self.idle_time + self.slack self.sim.logger.log("original slack {} omega {}".format(self.slack, self.sim.now() - self.idle_time)) # período ocioso exato delta self.processors[0].set_idle(delta) # Se houve prolongamento, o nível continua ocioso if self.slack > 0: self.add_timer(self.slack, self.processors[0]) self.keep = True self.is_idle = False self.slack += self.sim.now() # Caso contrário, o nível fica ocupado else: self.is_idle = False self.keep = False elif active_servers and self.sim.now() >= self.slack: self.is_idle = False self.keep = False # Processor level control if not self.busy: self.busy = True self.sim.logger.log("Servidores ativos, BUSY {}, slack {}".format(self.processors[0].name, self.slack)) else: self.sim.logger.log("Sem servidores ativos, IDLE {}, slack {}".format(self.processors[0].name, self.slack)) self.is_idle = True self.idle_time = self.sim.now() # se o tempo acabar antes de aglomerar # Sinaliza início da ociosidade para energy self.processors[0]._power.flag(self.sim.now()) selected = select_jobs(self, self.root, self.virtual) #idle = [s for s in selected if s.task.name == 'IdleTask'] jobs = [s.job for s in selected if s.task.name != 'IdleTask' and s.task.name != "wcet"] #wcet = [s for s in selected if s.task.name == "wcet"] wakeup_delay = min([s.budget for s in self.virtual if s.budget > 0]) if wakeup_delay > 0: self.timer = Timer(self.sim, ProperSubsystem.virtual_event, (self, self.processors[0]), wakeup_delay, cpu=self.processors[0], in_ms=False) self.timer.start() cpus = [] #first, leave already executing tasks on their current processors; for cpu in processors: if cpu.running in jobs: #cpus.append(cpu) jobs.remove(cpu.running) # remove job and cpu else: cpus.append(cpu) # second, assign previously idle tasks to their last-used processor, when its available aux_jobs = list(jobs) for job in aux_jobs: if job.task.last_cpu in cpus: #if job.task.last_cpu.is_running(): decision.append((job, job.task.last_cpu)) jobs.remove(job) cpus.remove(job.task.last_cpu) # third, assign remaining tasks to free processors arbitrarily for cpu in cpus: if jobs: decision.append((jobs.pop(), cpu)) else: decision.append((None, cpu)) return decision
def schedule(self): """ Schedule this proper sub-system. """ self.to_reschedule = False self.virtual = [] decision = [] processors = [] processors = self.processors active_servers = [ s for s in self.root.children if not s.dummyServer and s.budget > 0 ] if self.is_idle is True and self.keep is False and active_servers: self.sim.logger.log("was idle in t".format()) servers = [s for s in self.root.children if not s.dummyServer] # Prolongamento do job dummy liberado em idle_time self.slack = algorithm_1(self, servers, self.sim.now()) # tempo de computação total do job dummy liberado em idle_time omega = self.sim.now() - self.idle_time + self.slack self.sim.logger.log("original slack {} omega {}".format( self.slack, self.sim.now() - self.idle_time)) # calculo do deadline do job dummy d = self.sim.now() + (float(omega) / (1 - self.dummyTask[0].utilization)) # estimativa do período ocioso no real self.lower_bound = d - omega - self.sim.now() if self.lower_bound < sum(s.budget for s in servers): self.lower_bound = sum(s.budget for s in servers) self.sim.logger.log("lower_bound {}, d {}, u={}".format( self.lower_bound / self.sim.cycles_per_ms, d, self.dummyTask[len(self.dummyTask) - 1].utilization)) # Se houve prolongamento, o nível continua ocioso if self.slack > 0: self.add_timer(self.slack, self.processors[0]) self.keep = True self.is_idle = False self.slack += self.sim.now() # Caso contrário, o nível fica ocupado e o real ocioso, portanto ativa-se um estado de economia de energia else: self.processors[0].set_idle_extend(self.lower_bound) self.is_idle = False self.keep = False elif active_servers and self.sim.now() >= self.slack: self.is_idle = False self.keep = False if self.lower_bound <= 0: self.lower_bound = sum(s.budget for s in active_servers) self.processors[0].set_idle_extend(self.lower_bound) # Processor level control if not self.busy: self.busy = True processors = self.processors[ 1:] # Refresh avaliable processors list decision.append( (None, self.processors[0])) # Set dummy to first processor self.sim.logger.log("Servidores ativos, BUSY".format()) else: self.sim.logger.log("Sem servidores ativos, IDLE".format()) self.is_idle = True self.idle_time = self.sim.now() # Processor level control if self.busy: self.processors[0].stop_idle_extend() self.busy = False self.lower_bound = 0 selected = select_jobs(self, self.root, self.virtual) #idle = [s for s in selected if s.task.name == 'IdleTask'] jobs = [ s.job for s in selected if s.task.name != 'IdleTask' and s.task.name != "wcet" ] #wcet = [s for s in selected if s.task.name == "wcet"] wakeup_delay = min([s.budget for s in self.virtual if s.budget > 0]) if wakeup_delay > 0: self.timer = Timer(self.sim, ProperSubsystem.virtual_event, (self, self.processors[0]), wakeup_delay, cpu=self.processors[0], in_ms=False) self.timer.start() cpus = [] #first, leave already executing tasks on their current processors; for cpu in processors: if cpu.running in jobs: #cpus.append(cpu) jobs.remove(cpu.running) # remove job and cpu else: cpus.append(cpu) # second, assign previously idle tasks to their last-used processor, when its available aux_jobs = list(jobs) for job in aux_jobs: if job.task.last_cpu in cpus: #if job.task.last_cpu.is_running(): decision.append((job, job.task.last_cpu)) jobs.remove(job) cpus.remove(job.task.last_cpu) # third, assign remaining tasks to free processors arbitrarily for cpu in cpus: if jobs: decision.append((jobs.pop(), cpu)) else: decision.append((None, cpu)) return decision