func OSSimulation() { for { FiveSecTimer := time.NewTimer(time.Second * 5) select { case <-FiveSecTimer.C: access.Running = Processes.Get() case <-access.Skip: } fmt.Println("OS kicked off") } }
func MemoryMgmtHardwareSimulation(fr frame.FreeFrame) { frames = fr /* Use the pid to get the []access.Access element of that particular pid , this array denotes all the remaining requests pertaining to that process */ requestPtr := make(map[uint64][]access.Access) filled := make(map[uint64]int) // The value tells us the index in the []acess.Access that has been processed pTablePtr = make(map[uint64]pageTable.PageTable) // Pagetable per Process f, err := os.Open("C:/Users/Varun/Desktop/mygo/bin/input.txt") if err != nil { fmt.Println(err) os.Exit(1) } //Read All accesses from file var e error s := make([]string, 3) temp := make([]string, 2) n := 0 for e != io.EOF { n, e = fmt.Fscanf(f, "%s%s%s", &s[0], &s[1], &s[2]) if n == 3 { temp = strings.Split(s[0], ",") // Remove commas processid, err := strconv.ParseUint(temp[0], 10, 64) // The first field is assumed to be pid if err != nil { fmt.Println(err) os.Exit(7) } Processes.Add(processid) _, ok := requestPtr[processid] //Denotes the 1st request of that particular process if ok == false { requestPtr[processid] = make([]access.Access, 100) //Fix this filled[processid] = 0 } // Get the [] Accesses for a particular pid, and get the latest elem //for that particular array element,add the REQUEST READ // Len function cannot be used because, it will always return 100 // We, here, want to get the number of entries in the Array of Accesses // and hence, we do not use the len function, and so, we use the // filled map ((requestPtr[processid])[filled[processid]]).AddEntry(strings.Join(s, "")) filled[processid]++ } } access.Running = Processes.Get() for { fmt.Println("---------------------------------------------------------------------") page, pid, access, virtualAddress := access.GetNextMemAccess(Processes, requestPtr, filled) realAddress, ok := VirtAddr2RealAddr(pid, virtualAddress, page) if ok == false { // Page is NOT in Memory // Call the below method to get a new page into memory go OSMemoryMgmtSignalHandler() doTranslation <- SendData{pid, page} <-translationDone // The whole method waits until a page has been got into memory } realAddress, ok = VirtAddr2RealAddr(pid, virtualAddress, page) if ok == true { fmt.Println("\n", realAddress, " issued on adress Lines") _, present := pTablePtr[pid] if !present { pTablePtr[pid] = pageTable.PageTable{make([]int64, 1<<6)} } pTablePtr[pid] = pTablePtr[pid].UseEntry(pid, page, access) // Sets M bit to 1 if Write fmt.Printf("Program %v accessing %v in mode %v\n", pid, virtualAddress, access) } } }