Exemplo n.º 1
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());
            }
        }
Exemplo n.º 2
0
 public void Schedule()
 {
     if (!RAM.isRAWFull())
     {
         int totalJobs = PCBManager.getJobListSize();
         for (int i = 1; i <= totalJobs; i++)
         {
             if (!PCBManager.getPCB(i).isJobInMemory() && PCBManager.getPCB(i).getProcessStatus() == PCB.PROCESS_STATUS.NEW && !RAM.isRAWFull())
             {
                 loadJobToRAM(PCBManager.getPCB(i));
             }
         }
     }
 }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
0
        public static void fillPage(int pageNum, string[] data)
        {
            int i = 0;

            _memBlock[pageNum] = new Page(RAM.getPageSize());
            while (!_memBlock[pageNum].isFull() && i < data.Length)
            {
                _memBlock[pageNum].addToPage(data[i]);
                i++;
            }
            if (i < data.Length)
            {
                Console.WriteLine("page size mismatch");
            }
        }
Exemplo n.º 5
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++;
            }
        }
Exemplo n.º 6
0
 public static int getPageNumberFromAddress(int address)
 {
     return(address / RAM.getPageSize());
 }
Exemplo n.º 7
0
 public static int getPhysicalPageNumber(int virtualPageNumber)
 {
     return(RAM.getPhysicalPageNumber(virtualPageNumber));
 }
Exemplo n.º 8
0
 public static int getOffset(int virtualAddress)
 {
     return(virtualAddress % RAM.getPageSize());
 }
Exemplo n.º 9
0
 public static int getVirtualPageNumber(int virtualAddress)
 {
     return(virtualAddress / RAM.getPageSize());
 }
Exemplo n.º 10
0
 public static string readFromPhysical(int physicalPageNumber, int offset)
 {
     return(RAM.readRam(physicalPageNumber, offset));
 }
Exemplo n.º 11
0
 public static void writeToPhysical(int physicalPageNumber, int offset, string value)
 {
     RAM.writeRam(physicalPageNumber, offset, value);
 }
Exemplo n.º 12
0
 private String read(int address)
 {
     return(MMU.read(VMA[address / RAM.getPageSize()] * RAM.getPageSize() + (address % RAM.getPageSize())));
 }