예제 #1
0
 def testGetPCB(self):
     queue = ReadyPriority.ReadyPriority("cpu")
     p1 = PCBPriority.PCBPriority(PCB.PCB(0), 2)
     p2 = PCBPriority.PCBPriority(PCB.PCB(1), 5)
     p3 = PCBPriority.PCBPriority(PCB.PCB(2), 1)
     queue.put(p1)
     queue.put(p2)
     queue.put(p3)
     self.assertEqual(2, queue.get().getPID())
     self.assertEqual(0, queue.get().getPID())
     self.assertEqual(1, queue.get().getPID())
예제 #2
0
 def testGetPCB(self):
     p1 = PCB.PCB(0, 3)
     p2 = PCB.PCB(1, 3)
     p3 = PCB.PCB(2, 3)
     queue = ReadyFIFO.ReadyFIFO(None, None)
     queue.put(p1)
     queue.put(p2)
     queue.put(p3)
     self.assertEqual(0, queue.get().getPID())
     self.assertEqual(1, queue.get().getPID())
     self.assertEqual(2, queue.get().getPID())
 def start_program( self, program, run=True):
     '''loads program into new process, adds it to runnable list'''
     loaded= self.os.loader.load( program )
     pid= self._generate_pid()
     sched_info= self.os.scheduler.new_sched_info()
     address= loaded.get_ram_address()
     pcb= PCB(pid, address, len(loaded), address+loaded.start_offset, sched_info, self._changestate_callback)
     self.pcbs[pid]= pcb
     pcb.not_started=True
     if run:
         self.run_started_program(pcb)
     else:
         #program will be started later
         pass
     log.debug("created process: "+str(pcb))
     return pcb
예제 #4
0
    def do_a(self, args):
        """
		User input: A
		Get and validate process size. If process is larger than total memory or max process size, 
		reject process. Else, create a new process. If enough memory, add to ready queue, else 
		go to job pool. 
		"""

        procsize = io.get_valid_int("Process size")
        if procsize > self.total_mem_size:
            print io.err("Proccess cannot be larger than total memory")
        elif procsize > self.max_proc_size:
            print io.err(
                "Proccess cannot be larger than maximum process size of " +
                str(self.max_proc_size))
        else:
            # Create new process
            self.pid_count += 1
            pages = int(ceil(procsize / self.page_size))
            new_proc = PCB(self.pid_count, procsize, pages, self.page_size,
                           self.alpha, self.tau)

            # If enough memory, new process can run, else goes to job pool
            if self.lts.schedule(new_proc):
                self.cpu.enqueue(new_proc)
예제 #5
0
파일: automaker.py 프로젝트: hornc/QEDA
 def __init__(self):
     self.pcb = PCB()
     x = Module.from_library('Resistors_SMD', 'R_0805')
     x.set_reference('x')
     y = Module.from_library('Resistors_SMD', 'R_0805')
     y.set_reference('y')
     z = Module.from_library('Resistors_SMD', 'R_0805')
     z.set_reference('z')
     a = Module.from_library('Resistors_SMD', 'R_0805')
     a.set_reference('a')
     b = Module.from_library('Resistors_SMD', 'R_0805')
     b.set_reference('b')
     c = Module.from_library('Resistors_SMD', 'R_0805')
     c.set_reference('c')
     qcode = [[a, b, c], [x, y], [z]]
     self.automake(qcode)
     pass
예제 #6
0
def quick_load():
    # quick load processes.txt under the same folder
    with open('processes.txt') as f:
        reader = csv.reader(f)
        next(reader, None) # skip the header row
        queue = ready_queue
        for row in reader:
            pid, arrival_time, burst_time, priority = row
            pcb = PCB(pid, arrival_time, burst_time, priority)
            queue.add(pcb, None)
예제 #7
0
def pcb_main():
    while True:
        op = pcb_main_menu()
        if op == '1':
            queue = ready_queue if pcb_queue_menu() == '1' else waiting_queue
            add_mode = pcb_add_menu()
            if add_mode == '2':
                insert_to_pid = pcb_sub_menu(1)
            else:
                insert_to_pid = None
            file_path = pcb_sub_menu(0)
            try:
                with open(file_path) as f:
                    reader = csv.reader(f)
                    next(reader, None) # skip the header row
                    for row in reader:
                        pid, arrival_time, burst_time, priority = row
                        pcb = PCB(pid, arrival_time, burst_time, priority)
                        queue.add(pcb, insert_to_pid)
            except Exception as e:
                warn(f'\n{e}\n')
                nav('Press any key to continue...')
        elif op == '2':
            queue = ready_queue if pcb_queue_menu() == '1' else waiting_queue
            add_mode = pcb_add_menu()
            if add_mode == '2':
                insert_to_pid = pcb_sub_menu(1)
            else:
                insert_to_pid = None
            pid = pcb_sub_menu(2)
            arrival_time = pcb_sub_menu(3)
            burst_time = pcb_sub_menu(4)
            priority = pcb_sub_menu(5)
            pcb = PCB(pid, arrival_time, burst_time, priority)
            try:
                queue.add(pcb, insert_to_pid)
            except Exception as e:
                warn(f'\n{e}\n')
                nav('Press any key to continue...')
        elif op == '3':
            queue = ready_queue if pcb_queue_menu() == '1' else waiting_queue
            pid = pcb_sub_menu(6)
            try:
                queue.delete(pid)
            except Exception as e:
                warn(f'\n{e}\n')
                nav('Press any key to continue...')
        elif op == '4':
            queue = ready_queue if pcb_queue_menu() == '1' else waiting_queue
            pid = pcb_sub_menu(6)
            try:
                pcb_info = queue.inspect(pid)
                pcb_print([pcb_info])
            except Exception as e:
                warn(f'\n{e}\n')
            nav('Press any key to continue...')
        elif op == '5':
            queue = ready_queue if pcb_queue_menu() == '1' else waiting_queue
            queue_info = queue.info()
            if queue_info == None:
                warn('\nEmpty Queue!\n')
            else:
                pcb_print(queue_info)
            nav('Press any key to continue...')
        elif op == '6':
            break
예제 #8
0
파일: automaker.py 프로젝트: hornc/QEDA
class Automaker():
    def __init__(self):
        self.pcb = PCB()
        x = Module.from_library('Resistors_SMD', 'R_0805')
        x.set_reference('x')
        y = Module.from_library('Resistors_SMD', 'R_0805')
        y.set_reference('y')
        z = Module.from_library('Resistors_SMD', 'R_0805')
        z.set_reference('z')
        a = Module.from_library('Resistors_SMD', 'R_0805')
        a.set_reference('a')
        b = Module.from_library('Resistors_SMD', 'R_0805')
        b.set_reference('b')
        c = Module.from_library('Resistors_SMD', 'R_0805')
        c.set_reference('c')
        qcode = [[a, b, c], [x, y], [z]]
        self.automake(qcode)
        pass

    def _find_max_x(self, comp):
        """Returns the maximal X size as an integer"""
        max_x = 0
        geo = comp.geometry()
        x = [each for each in geo]
        for each in x:
            if each.start == None and each.end != None:
                y = abs(0 - each.end[0])
            elif each.end == None and each.start != None:
                y = abs(each.start)
            elif each.start == each.end == None:
                pass
            else:
                y = abs(each.start[0] - each.end[0])
                if y > max_x:
                    max_x = y
        return ceil(max_x)

    def _find_max_y(self, comp):
        """Return maximal Y size as an integer"""
        max_y = 0
        geo = comp.geometry()
        x = [each for each in geo]
        for each in x:
            if each.start == None and each.end != None:
                y = abs(0 - each.end)
            if each.end == None and each.start != None:
                y = abs(each.start)
            elif each.start == each.end == None:
                pass
            else:
                y = abs(each.start[1] - each.end[1])
                if y > max_y:
                    max_y = y
        return ceil(max_y)

    def _find_maxes(self, comp):
        """Returns the maximal x and y value of a component (starting at 0,0)"""
        x = self._find_max_x(comp)
        y = self._find_max_y(comp)
        return int(x), int(y)

    def _find_x(self, pos, maxx):
        """Returns the x coordinates"""
        return pos[0] + maxx

    def _find_y(sef, pos, maxy):
        return pos[1] + maxy

    def _autoplace_unitary_gates(self, qcode):
        pos = {'X': 0, 'Y': 0}
        max_y = 0
        for qubit in qcode:
            for i in range(len(qubit)):
                # Place component (horizontal line)
                self.pcb._place_component(qubit[i], pos['X'], pos['Y'])
                print('Component is at ', qubit[i].at)
                x, y = self._find_maxes(qubit[i])
                # update x, y values
                pos['X'] = pos['X'] + x
                if y > max_y:
                    max_y += y
                # loop
            # Step down y by max_x
            pos['X'] = 0
            pos['Y'] = pos['Y'] + max_y


#                if i == len(qubit)-1:
#                    start, end, np_pos = self.pcb._final_compute(qubit[i])
#                else:
#                    start, end, np_pos = self.pcb._compute_positions(
#                        qubit[i], qubit[i+1])
#                # Create segments
#                self.pcb._create_segment(start, end, self.pcb.nets[1])

    def _autoplace_controlled_gates(self, qcode):
        pos = {'X': 0, 'Y': 0}
        max_y = 0

    def _autoplace3(self, qcode):
        """Automagically places components where they need to be"""
        pos = {'X': 0, 'Y': 0}
        cur_x = 0
        cur_y = 0
        for qubit in qcode:
            for i in range(len(qubit)):
                # Connect pads
                # self.pcb._connect_pad(qubit[i], 1, 1)
                # Find maxes
                x, y = self._find_maxes(qubit[i])
                print(x)
                # Place component
                cur_x += x
                pos['X'] = cur_x
                cur_y += y
                print("Placing Component: ", qubit[i].name, ' at coordinates',
                      pos)
                self.pcb._place_component(qubit[i], pos['X'], pos['Y'])
                print('Component is at ', qubit[i].at)
                # compute and place vias
                if i == len(qubit) - 1:
                    start, end, pos_np = self.pcb._final_compute(qubit[i])
                else:
                    start, end, pos_np = self.pcb._compute_positions(
                        qubit[i], qubit[i + 1])
                # Create segments
                self.pcb._create_segment(start, end, self.pcb.nets[1])
                print('Rechecking, component is at ', qubit[i].at)
            cur_x = 0
            pos['X'] = cur_x
            pos['Y'] = cur_y

    def automake(self, qcode):
        """Attempts to automagically make a PCB from modules

        To start, we have our qcode which is in list format:
        1,H,CX,...,MEASURE
        2,I,I,..., MEASURE
        3,I,CX,...,MEASURE
        ... etc
        pass

        For quantum gates, we only need to place footprints.

        For electrical/analog gates we will need to computer positions, vias, etc"""
        # Place components
        self._autoplace(qcode)
        # Create PCB Zones
        self.pcb._create_zones()
        # Make the PCB
        self.pcb._create_pcb()
예제 #9
0
from keyboard.layoutengine import KeyboardLayoutEngine


# Convert millimetres to the units used by EDA (decamil? centiinches?)
def mm2eda(mm):
    return mm * 100.0 / 25.4


kle = KeyboardLayoutEngine()
kle.load_layout_from_file('layouts/simple 2x2.json')
(switches, bbox) = kle.layout_switches()

switch = PCBBlock('blocks/cherry mx switch 1U.json')
controller = PCBBlock('blocks/teensy 2.0++.json')

pcb = PCB()
iopads = {}
sw_cnt = 0
for sw in switches:
    x = switch.clone()
    x.translate(mm2eda(sw['x']), mm2eda(sw['y']))
    rowname = 'ROW%d' % (sw['row'] + 1)
    colname = 'COL%d' % (sw['col'] + 1)
    x.update_net('1', rowname)
    x.update_net('2', colname)
    pcb.add_component(x)
    if rowname not in iopads:
        pad = iopads[rowname] = controller.allocate_io(r'IO\.(.*)', rowname)
        print("Allocated pad %s for %s" % (pad, rowname))
    if colname not in iopads:
        pad = iopads[colname] = controller.allocate_io(r'IO\.(.*)', colname)
예제 #10
0
    ins4p1 = Instruction.Instruction(False, "resultado ins4p1", 10)
    instructionsP1 = [ins1p1, ins2p1, ins3p1, ins4p1]
    p1 = Process.Process(1, instructionsP1)

    ins1p2 = Instruction.Instruction(True, "resultado ins1p2")
    ins2p2 = Instruction.Instruction(True, "resultado ins2p2")
    ins3p2 = Instruction.Instruction(True, "resultado ins3p2")
    ins4p2 = Instruction.Instruction(False, "resultado ins4p2", 5)
    instructionsP2 = [ins1p2, ins2p2, ins3p2, ins4p2]
    p2 = Process.Process(2, instructionsP2)

    memory = Memory.Memory()
    memory.putProcess(p1)
    memory.putProcess(p2)

    pcbP1 = PCB.PCB(1, len(p1.getInstructions()))
    pcbP2 = PCB.PCB(2, len(p2.getInstructions()))

    #pcbP1 = PCBPriority.PCBPriority(pcbP1, 10)
    #pcbP2 = PCBPriority.PCBPriority(pcbP2, 3)

    cpu = Cpu.Cpu(memory)
    policy = Simple.Simple()
    #policy = RoundRobin.RoundRobin(1)
    scheduler = ReadyFIFO.ReadyFIFO(cpu, policy)
    #scheduler = ReadyPriority.ReadyPriority(cpu, policy)
    scheduler.put(pcbP1)
    scheduler.put(pcbP2)
    io = IO.IO(memory)
    end = End.End()
예제 #11
0

freeBlock1 = Block(0, 3)
freeBlock2 = Block(6, 7)
freeBlock3 = Block(10, 15)

occupedBlock1 = Block(4, 5)
occupedBlock2 = Block(8, 9)
occupedBlock3 = Block(16, 20)

freeBlocks = FreeBlock()
freeBlocks.put(freeBlock1)
freeBlocks.put(freeBlock2)
freeBlocks.put(freeBlock3)

pcb1 = PCB.PCB(1, 2)
pcb2 = PCB.PCB(2, 2)
pcb3 = PCB.PCB(3, 5)

occupedBlocks = OccupedBlock()
occupedBlocks.put(pcb1, occupedBlock1)
occupedBlocks.put(pcb2, occupedBlock2)
occupedBlocks.put(pcb3, occupedBlock3)

allocationMethod = FirstFit(freeBlocks, occupedBlocks)

allocationMethod.memoryCompact()

print(allocationMethod.getOccupedBlocks()[0][1].getBase())
print(allocationMethod.getOccupedBlocks()[0][1].getLimit())
print(allocationMethod.getOccupedBlocks()[1][1].getBase())