Пример #1
0
        public void unload(PCB current)
        {
            updateMetrics(CPUMetrics.CPU_STATE.UNLOADING, "N/A");
            printFlags("PRE UNLOADING");
            Console.WriteLine("UNLOADING JOB " + currentJobNumber() + "PROGRAM COUNTER:" + programCounter + " JOB CNTR:" + jobCounter);

            current.setTemporaryBuffer(tempBuffer);
            current.setInputBuffer(inputBuffer);
            current.setOutputBuffer(outputBuffer);
            current.setJobinstructionCount(jobCounter);
            current.setRegisters(registers);
            current.setProgramCounter(programCounter);
            current.setCache(cache);
            current.setCacheSize(cacheSize);

            if (programCounter < jobCounter)
            {
                // setTerminateFlag(false);
                current.setProcessStatus(PCB.PROCESS_STATUS.WAIT);
            }
            else
            {
                // setTerminateFlag(true);
                current.setProcessStatus(PCB.PROCESS_STATUS.TERMINATE);
            }

            setIdleFlag(true);
            setUnload(false);
            setTerminateFlag(false);
            setJobLoaded(false);
            sleep(2);
            updateOsMetrics();
            updateMetrics(CPUMetrics.CPU_STATE.IDLE, "N/A");
            printFlags("POST UNLOADING");
        }
Пример #2
0
        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");
        }
Пример #3
0
 public static void deallocatePcb(PCB pcb)
 {
     if (pcb.getProcessStatus() == PCB.PROCESS_STATUS.TERMINATE)
     {
         int startingVirtualPageNum = Helpers.getPageNumberFromAddress(pcb.getJobMemoryAddress());
         for (int i = 0; i < pcb.getAllocatedVirtualPages().Capacity; i++)
         {
             int virtualPageNum  = pcb.getAllocatedVirtualPages()[i];
             int physicalPageNum = _pageTable[virtualPageNum];
             _memBlock[physicalPageNum] = null;
             _pageTable[virtualPageNum] = -1;
         }
     }
 }
Пример #4
0
        private int calculateChunkSize(PCB pcb, int currentDiskAddress)
        {
            int dataCardSize = pcb.getInputBuffer() + pcb.getOutputBuffer() + pcb.getTemporaryBuffer();
            int memory       = pcb.getJobInstructionCount() + dataCardSize;

            if (currentDiskAddress + RAM.getPageSize() > pcb.getJobDiskAddress() + memory)
            {
                return((pcb.getJobDiskAddress() + memory) - currentDiskAddress);
            }
            else
            {
                return(RAM.getPageSize());
            }
        }
Пример #5
0
        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));
            }
        }
Пример #6
0
        public void Start()
        {
            string line         = "";
            int    currentIndex = 0;
            int    currentJob   = 0;

            string[] splitLine;
            PCB      pcb;

            while (!loadingComplete)
            {
                line = fileReader.ReadLine();
                if (line != null)
                {
                    if (line.Contains("JOB"))
                    {
                        splitLine  = line.Split("\\s+");
                        currentJob = Convert.ToInt32(splitLine[JOB_NUM_POS], 16);
                        PCBManager.insertPCB(new PCB(currentJob, Convert.ToInt32(splitLine[JOB_PRIORITY_POS], 16), Convert.ToInt32(splitLine[JOB_INSTR_COUNTR_POS], 16), currentIndex));
                    }
                    else if (line.Contains("Data"))
                    {
                        splitLine = line.Split("\\s+");
                        if (PCBManager.getCurrentPcbSortType() != PCBManager.PCB_SORT_TYPE.JOB_NUMBER)
                        {
                            PCBManager.sortPcbList(PCBManager.PCB_SORT_TYPE.JOB_NUMBER);
                        }
                        PCB currentPCB = PCBManager.getPCB(currentJob);
                        currentPCB.setDataDiskAddress(currentIndex);
                        currentPCB.setInputBuffer(Convert.ToInt32(splitLine[DATA_IN_BUFF_POS], 16));
                        currentPCB.setOutputBuffer(Convert.ToInt32(splitLine[DATA_OUT_BUFF_POS], 16));
                        currentPCB.setTemporaryBuffer(Convert.ToInt32(splitLine[DATA_TEMP_BUFF_POS], 16));
                    }
                    else if (line.Contains("END"))
                    {
                    }
                    else
                    {
                        Disk.writeDisk(line, currentIndex);
                        currentIndex++;
                    }
                }
                else
                {
                    loadingComplete = true;
                }
            }
        }
Пример #7
0
        public static void synchronizeCache(PCB job)
        {
            int cacheSize            = job.getCacheSize();
            int startDiskAddress     = job.getJobDiskAddress();
            int currentDiskAddress   = startDiskAddress;
            int currentMemoryAddress = job.getJobMemoryAddress();

            for (int i = 0; currentDiskAddress < startDiskAddress + cacheSize; i++)
            {
                int virtualPage          = job.getAllocatedVirtualPages()[i / RAM.getPageSize()];
                int virtualPageTimesSize = virtualPage * RAM.getPageSize();
                int finalAdd             = virtualPageTimesSize + i % RAM.getPageSize();
                write(job.getAllocatedVirtualPages()[i / RAM.getPageSize()] * RAM.getPageSize() + i % RAM.getPageSize(), job.getCache()[i]);
                Disk.writeDisk(job.getCache()[i], currentDiskAddress);
                currentDiskAddress++;
                currentMemoryAddress++;
            }
        }
Пример #8
0
 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);
         }
     }
 }
Пример #9
0
 public void addToReadyQueue(PCB pcb)
 {
     readyQueue.Add(pcb);
 }
Пример #10
0
 public static void insertPCB(PCB pcb)
 {
     pcbList.Add(pcb);
 }