def __init__(self,memory): self.pcbTable = PcbTable() self.memory = memory self.disc = Disc() self.cpu = CPU() self.programLoader = Loader(self.memory,self.disc) self.readyQueue = Queue() self.interruptionManager = InterruptionManager()
def test_terminated(self): #load some program with base dir = 3, has 6 instructions and the pc is in the last instruction of the pcb pcbTerminado = PCB(pid=0,pc=6,basedir=3,numberofinstructions=6) self.cpu = CPU(self.memory, pcbTerminado) self.assertTrue(self.cpu.terminated()) #def test_NOTterminated(self): # self.assertFalse(self.cpu.terminated()) #fetch_instruction #def test_fetchFirstInstruction(self): #instruction = self.cpu.fetch_instruction() #the third instruction of the pcb is instruction3 #self.assertEquals("instruction3",instruction.element) pass
class TestCpu(unittest.TestCase): def setUp(self): self.memory = Memory(begin=0,end=13) #load some program with base dir = 3 and has 6 instructions self.pcb = PCB(pid=0,pc=2,basedir=3,numberofinstructions= 6) self.interruptionManager = InterruptionManager() self.cpu = CPU(self.memory, self.pcb,self.interruptionManager) def test_terminated(self): #load some program with base dir = 3, has 6 instructions and the pc is in the last instruction of the pcb pcbTerminado = PCB(pid=0,pc=6,basedir=3,numberofinstructions=6) self.cpu = CPU(self.memory, pcbTerminado) self.assertTrue(self.cpu.terminated()) #def test_NOTterminated(self): # self.assertFalse(self.cpu.terminated()) #fetch_instruction #def test_fetchFirstInstruction(self): #instruction = self.cpu.fetch_instruction() #the third instruction of the pcb is instruction3 #self.assertEquals("instruction3",instruction.element) pass
class Kernel: def __init__(self,memory): self.pcbTable = PcbTable() self.memory = memory self.disc = Disc() self.cpu = CPU() self.programLoader = Loader(self.memory,self.disc) self.readyQueue = Queue() self.interruptionManager = InterruptionManager() def run(self,cmd,programName): try: #tested program = self.programLoader.getFromDisc(programName) #tested pcb = self.pcbTable.isPcbOf(program) #pass the pcb to set the basedir if(pcb is None): #new NewInterruption instructionNew = Instruction(InstructionType.New) newPcb = self.pcbTable.createPcbFor(self,program) self.interruptionManager.enqueueInterruption(instructionNew,newPcb) else: self.programLoader.loadToMemory(program,pcb) if(self.readyQueue.empty()): self.cpu.setPCB(pcb) else: self.readyQueue.put(pcb) except ProgramNotInDiscException as p: print(p.getMessage()) #-pasar de running a ready -> interrupcion de timeout. Alerta va al kernel #-pasar de running a terminado -> disparo interrupcxion de kill, estoy en la ultima instruccion. #algun componente tuyo te lo expropia, limpia memoria y elimina pcb #y el scheduler le asigna un nuevo pcb al cpu #-interrupcion de termine de hacer IO #si cola de ready esta vacia va a cpu directo #cpu le avisa al kernel que hay interrupcion #reloj envia click y cpu hace fetch de instruccion #falta setear estados a los pcbs #modo usuario - cpu ejecuta instruccion #modo kernel - tareas de SO. el Clock no puede generar clicks #mientras se ejecuta una interrupcion no se pueden hacer clicks y por ende fetchs de instruccion #programar por prioridad con round robin. Cuando creas el kernel configuras con que politica de planificacion queres que trabaje ################# #from threading import Thread #class Impresor(Thread) #def __init__(self,name): # Thread.__init__(self) # self.name = name #def run #sstart() #CPU es un thread, i/o es otro thread #cola I/O es estructura compartida entre dos Threads distintos. El CPU para grabar e I/O para acceder #cola de ready tambien porque es leida por el scheduler y escrita por el kernel. Manejador de interrupciones #Thread CPU #mientras SO este running #hago fetch
def setUp(self): self.memory = Memory(begin=0,end=13) #load some program with base dir = 3 and has 6 instructions self.pcb = PCB(pid=0,pc=2,basedir=3,numberofinstructions= 6) self.interruptionManager = InterruptionManager() self.cpu = CPU(self.memory, self.pcb,self.interruptionManager)