Example #1
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;
         }
     }
 }
Example #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");
        }
Example #3
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++;
            }
        }