public void load(PCB job) { Console.WriteLine("cpu.loading job: " + job.getJobNumber()); jobNumber = job.getJobNumber(); printFlags("PRE LOADING"); // int instructionCounter = 1; jobMemoryStartAddress = job.getJobMemoryAddress(); start = DateTimeOffset.Now.ToUnixTimeMilliseconds(); j = job; IOCount = 0; tempBuffer = j.getTemporaryBuffer(); inputBuffer = j.getInputBuffer(); outputBuffer = j.getOutputBuffer(); jobCounter = j.getJobInstructionCount(); cacheSize = tempBuffer + inputBuffer + outputBuffer + jobCounter; cache = new String[cacheSize]; instructionCache = new String[jobCounter]; VMA = job.getAllocatedVirtualPages(); for (int i = 0; i < cacheSize; i++) { cache[i] = read(i); } programCounter = j.getProgramCounter(); setIdleFlag(false); setTerminateFlag(false); setJobLoaded(true); Console.WriteLine("cpu.loading jon: " + job.getJobNumber() + " complete"); updateMetrics(CPUMetrics.CPU_STATE.LOADING, "N/A"); sleep(3); updateOsMetrics(); printFlags("POST LOADING"); }
public void loadJobToRAM(PCB block) { int jobNo = block.getJobNumber(); int i = 0; int k; int m = PCBManager.getPCB(jobNo).getJobInstructionCount(); int dataCardSize = block.getInputBuffer() + block.getOutputBuffer() + block.getTemporaryBuffer(); int memory = PCBManager.getPCB(jobNo).getJobInstructionCount() + dataCardSize; int numPages = (int)Math.Ceiling((double)memory / (double)RAM.getPageSize()); int startAddress = block.getJobDiskAddress(); int currentDiskAddress = startAddress; int physPageNo; int virtualPageNo = RAM.getNextAvaliableVirtualPageNumber(); string[] chunk; List <int> virtualAllocatedPages = RAM.Allocate(numPages); if (virtualAllocatedPages.Capacity != 0) { Console.WriteLine(jobNo); PCBManager.getPCB(jobNo).setJobInMemory(true); PCBManager.getPCB(jobNo).setJobMemoryAddress(virtualPageNo * RAM.getPageSize()); PCBManager.getPCB(jobNo).setProcessStatus(PCB.PROCESS_STATUS.READY); PCBManager.getPCB(jobNo).setPagesNeeded(numPages); PCBManager.getPCB(jobNo).setAllocatedVirtualPages(virtualAllocatedPages); int n = RAM.getNextAvaliableVirtualPageNumber(); for (int j = 0; j < virtualAllocatedPages.Capacity; j++) { physPageNo = RAM.getPhysicalPageNumber(virtualAllocatedPages[j]); chunk = Disk.getChunk(currentDiskAddress, calculateChunkSize(block, currentDiskAddress)); try { RAM.fillPage(physPageNo, chunk); } catch (Exception e) { } currentDiskAddress += RAM.getPageSize(); } JobMetrics metrics = new JobMetrics(); metrics.setTimestamp(DateTimeOffset.Now.ToUnixTimeMilliseconds()); metrics.setJobNumber(jobNo); metrics.setStartWaitTime(metrics.getTimestamp()); metrics.setBlocksUsed(memory); Driver.jobMetricses[jobNo - 1].update(metrics); Driver.shortTermScheduler.addToReadyQueue(PCBManager.getPCB(jobNo)); } }
public static void loadJobs() { for (int i = 0; i < Driver.CPUs.Length; i++) { if (Driver.CPUs[i].isIdle() && Driver.shortTermScheduler.readyQueue.Capacity > 0) { PCB pcb = Driver.shortTermScheduler.readyQueue[0]; Driver.shortTermScheduler.readyQueue.RemoveAt(0); if (Driver.CPUs[i].shouldUnload()) { Console.WriteLine(string.Format("Job:%sCPU:%sTrapped!", Driver.CPUs[i].currentJobNumber(), i)); terminateJobs(); } Driver.jobMetricses[pcb.getJobNumber() - 1].setTimestamp(DateTimeOffset.Now.ToUnixTimeMilliseconds()); Driver.jobMetricses[pcb.getJobNumber() - 1].setJobNumber(pcb.getJobNumber()); Driver.jobMetricses[pcb.getJobNumber() - 1].setEndWaitTime(DateTimeOffset.Now.ToUnixTimeMilliseconds()); Driver.jobMetricses[pcb.getJobNumber() - 1].setCpuNo(i + 1); Driver.updateJobMetrics(Driver.jobMetricses[pcb.getJobNumber() - 1]); Driver.commands[pcb.getJobNumber()] += "loading job:" + pcb.getJobNumber() + "cpu:" + i; Driver.CPUs[i].load(pcb); } } }