Exemple #1
0
        public static void run()
        {
            RAM.init();
            Disk.init();
            PCBManager.init();
            osStartTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();

            Loader loader = new Loader("C:/Users/HOME/Documents/Visual Studio 2017/Projects/OSSImulator/OS-Simulator/OSSImulator/OSSImulator/Program-File.txt");

            loader.Start();

            jobMetricses = new JobMetrics[PCBManager.getJobListSize()];
            for (int i = 0; i < jobMetricses.Length; i++)
            {
                jobMetricses[i] = new JobMetrics();
            }


            string s = Disk.readDisk(2);

            Console.WriteLine("DISK TEST: " + s);

            while (custardStands())
            {
                ready();
                aim((schedulingType != null) ? schedulingType : Schedulingtype.FIFO);
                fire();
            }
        }
Exemple #2
0
 public static void terminateJobs()
 {
     for (int i = 0; i < Driver.CPUs.Length; i++)
     {
         int currentJobNumber = Driver.CPUs[i].currentJobNumber();
         try
         {
             if (Driver.CPUs[i].isIdle() && Driver.CPUs[i].shouldTerminate())
             {
                 Console.WriteLine(String.Format("TERMINATING" + currentJobNumber + ":is idle:{0} shouldTerminate:{1} cpu loaded:{2} shouldUnload:{3}", Driver.CPUs[i].isIdle(), Driver.CPUs[i].shouldTerminate(), Driver.CPUs[i].isJobLoaded(), Driver.CPUs[i].shouldUnload()));
                 Console.WriteLine("Terminating Job" + currentJobNumber + "ON CPU:" + i);
                 Driver.commands[currentJobNumber] += "TERMINATING JOB" + currentJobNumber + "ON CPU: " + i;
                 Driver.CPUs[i].unload(PCBManager.getPCB(currentJobNumber));
                 MMU.synchronizeCache(PCBManager.getPCB(currentJobNumber));
                 RAM.deallocatePcb(PCBManager.getPCB(currentJobNumber));
                 Console.WriteLine(string.Format("TERMINATED" + currentJobNumber + ":is idle:%s shouldTerminate:%s cpu loaded:%s shouldUnload:%s", Driver.CPUs[i].isIdle(), Driver.CPUs[i].shouldTerminate(), Driver.CPUs[i].isJobLoaded(), Driver.CPUs[i].shouldUnload()));
                 if (PCBManager.getPCB(currentJobNumber).getProcessStatus() == PCB.PROCESS_STATUS.TERMINATE)
                 {
                     Driver.completedJobs++;
                 }
                 Driver.updateOsMetric();
             }
         }
         catch (IndexOutOfRangeException ex)
         {
             throw new IndexOutOfRangeException("Exception Terminating Job" + currentJobNumber + "On CPU:" + i + " " + ex.ToString());
         }
     }
 }
Exemple #3
0
        public void PrioSchedule()
        {
            int totalJobs = 0;

            if (PCBManager.getCurrentPcbSortType() != PCBManager.PCB_SORT_TYPE.JOB_PRIORITY)
            {
                PCBManager.sortPcbList(PCBManager.PCB_SORT_TYPE.JOB_PRIORITY);
            }
            for (int i = 1; i < totalJobs + 1; i++)
            {
                readyQueue.Add(PCBManager.getPCB(i));
            }
            sortType = PCBManager.PCB_SORT_TYPE.JOB_PRIORITY;
        }
 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));
             }
         }
     }
 }
        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));
            }
        }
Exemple #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;
                }
            }
        }
Exemple #7
0
        public void Schedule(Schedulingtype type)
        {
            PCBManager.PCB_SORT_TYPE sort_type = PCBManager.PCB_SORT_TYPE.JOB_NUMBER;
            switch (type)
            {
            case Schedulingtype.PRIORITY:
                sort_type = PCBManager.PCB_SORT_TYPE.JOB_PRIORITY;
                break;

            case Schedulingtype.FIFO:
                sort_type = PCBManager.PCB_SORT_TYPE.JOB_NUMBER;
                break;

            case Schedulingtype.SJF:
                sort_type = PCBManager.PCB_SORT_TYPE.SHORTEST_JOB;
                break;
            }
            PCBManager.sortPcbList(sort_type, readyQueue);
        }
Exemple #8
0
        public void FIFOSChedule()
        {
            int totalJobs = PCBManager.getJobListSize();

            if (PCBManager.getCurrentPcbSortType() != PCBManager.PCB_SORT_TYPE.JOB_NUMBER)
            {
                ;
            }
            {
                PCBManager.sortPcbList(PCBManager.PCB_SORT_TYPE.JOB_NUMBER);
            }
            if (readyQueue.Count() == 0)
            {
                readyQueue.Clear();
            }
            for (int i = 1; i < totalJobs + 1; i++)
            {
                readyQueue.Add(PCBManager.getPCB(i));
            }
            sortType = PCBManager.PCB_SORT_TYPE.JOB_NUMBER;
        }
Exemple #9
0
 public static void updateOsMetric()
 {
     int       jobsInProgress = numberOfBusyCpus();
     OSMetrics osMetrics      = new OSMetrics(PCBManager.getJobListSize(), numberOfBusyCpus(), completedJobs, getAverageWaitTime(), getAverageRunTime());
     //update OsMetrics
 }
Exemple #10
0
 public static bool custardStands()
 {
     return(!PCBManager.allJobsDone() && !isOSComplete);
 }