What is required • Simulating operating system’s virtual memory management and concurrency control • Processes must be simulated as threads • The simulated system has two CPUs (or CPU cores) ➔ 2...

Java programming assignment


What is required • Simulating operating system’s virtual memory management and concurrency control • Processes must be simulated as threads • The simulated system has two CPUs (or CPU cores) ➔ 2 processes must be selected instead of 1 • Main memory should be simulated as an array (size = number of pages) in your program ! • Disk pages should be simulated in an external file • Virtual memory manager should be simulated as a separate thread as well • For the scheduler you can use the one implemented in the last assignment (In case you have not finished assignment #2 you can work with a FIFO scheduler) Simulating the Processes • For each process you create a thread corresponding to it --> Do not create multiple threads for each process ! • Each thread (simulated process) should call the exposed VMM API services (Store, Release and Lookup) accordingly • Each process should continually call a command from the list of commands (commands.txt). • You can simulate the process to wait for a random time (from 1 to 1000 milliseconds for example) between each API call Simulating the VMM • Should be simulated as a thread as well • Implements the basic services : – Store a variable – Release a variable – Lookup a variable • Variables can be either in – The main memory – The disk • Lookup might involve swapping the variable first before returning it • The VMM is running on its own thread (same as the scheduler in previous assignment) Simulating the VMM • The VMM class: Class VMM { VMM (size); Store (string variableId, unsigned int value); Release (string variableId) ; Lookup (string variableId) ; } Simulating the VMM- VMM Constructor • VMM (size): • Initializes a VMM with the given size for the main memory. • size = the size specified in the memconfig.txt file Simulating the VMM – Store, Release, Lookup • Store (string variableId, unsigned int value): – Stores the given variable id and its value into the main memory array, if there is a free space. Otherwise, it stores them into the vm.txt file • Release (string variableId): • Removes the variable id and its value from the memory so the page which was holding this variable becomes available for further storage • First check if the variable exists in main memory then delete it. Otherwise check if it exists in the vm.txt file then delete it. • Lookup (string variableId): • If (variableId exists in main memory){ then return value; } else if (variableId exists in Disk) { if(spot is available in main memory){ then move variable into main memory and release assigned page in virtual memory } else{ Check for the variable with the smallest Last time access in main memory Swap with this variable } } else{ return -1 (variable doesn’t exist) } Hints for Implementation in Java • Same way as in the previous assignment – You can use suspend() and resume() methods to start and stop your threads – Or use Synchronisation mechanisms in Java: – Mutex reentrant lock – Monitor lock accessed using synchronized – Binary semaphores… – Wait() and notify() methods programming-assignment3-copy-2-0uvbzhtm.pages COEN 346 Programming Assignment #3 The main objective of this assignment is to simulate operating system’s virtual memory management, process scheduling and concurrency/synchronization control as discussed during the Lab sessions. The following features should be considered for this simulation: 1- Processes should be simulated by threads in the application. Each process has a starting time and duration (burst time). “processes.txt” is the input file which contains the number of processes N followed by N lines. Each line contains the process start time and duration. 2- Process Scheduler: A process scheduling thread should be implemented based on the “Round Robin” policy that schedules the processes as discussed during the lab sessions. In this assignment (#3) we assume that the simulated system has two CPUs (or CPU cores). Therefore, two processes can be executed at the same time, i.e. the scheduler must select two processes (from the head of the waiting queue) for execution during each cycle. Additionally, the time slice must be set to 3000 ms.(Alternatively we can use FIFO as specified in the tutorial!) 3- Virtual Memory Management: Virtual memory consists of a fixed size main memory and unlimited disk space. The main memory is divided into frames while the virtual memory is divided into pages. A page has the same size as a frame. The size of the main memory will be given as an input in a file called “memconfig.txt”. This file contains a number indicating number of frames in main memory. The disk space is assumed to be unlimited. Notice that frames in the main memory should be simulated by an array (or vector) in the actual computer physical memory, while virtual memory pages are simulated by an array stored in a text file such as “vm.txt”, which must be accessed every time we need to access the disk space. 4- Processes try to store, release and retrieve “variables” to/from the memory. Each page contains only one variableId and its value. Of course, working with memory can only happen when the process is running. Each variable in the memory has a Last Access property which is a time stamp indicating the last time this variable was accessed. 5- Virtual memory manager should be implemented with a set of APIs (functions) as follows: a. memStore (string variableId, unsigned int value): This instruction stores the given variableId and its value in the first unassigned spot in the memory. b. memFree (string variableId): This instruction removes the variableId and its value from the memory, so the page which was holding this variable becomes available for storage. c. memLookup (string variableId): If the variableId exists in the main memory it returns its value. If the variableId is not in the main memory but exists in disk space (i.e. page fault occurs), then it should move this variable into the memory. Notice that if no spot is available in the memory, program needs to swap this variable with the least recently accessed variable, i.e. the variable with smallest Last Access time, in the main memory. Finally, if the variableId does not exist in the main memory and disk space, the API should return -1. 6- The processes should continuously pick one command from a given list of commands located in the input file called “commands.txt”. The processes should then call the suitable API of virtual memory manager based on the picked command. a. memStore [variableId] [value]: e.g. “memStore 10 5” b. memFree [variableId]: e.g. “memFree 10” c. memLookup [variableId]: e.g. “memLookup 10” 7- Output of the program should be a text file “output.txt” which includes the following events: a. Threads start, resume, pause and finish. b. Each instruction executed by each thread c. Page swapping between the main memory and the disk space Programming Tips: - In order to protect critical sections and ensure mutual exclusion use appropriate tools, semaphores for instance, within the body of each function. - The program must work with arbitrary number of threads and arbitrary memory size. The following can be the list of sample input / output files. Input Files: - processes.txt 3 2 1 1. 2 2. 2 - memconfig.txt 2. - “commands.txt” Store 1 5 Store 2 3 Store 3 7 Lookup 3 Lookup 2 Release 1 Store 1 8 Lookup 1 Lookup 2 Output File: Clock: 1000, Process 2: Started. Clock: 1000, Process 2, Resumed Clock: 1310, Process 2, Store: Variable 1, Value: 5 Clock: 1730, Process 2, Store: Variable 2, Value: 3 Clock: 2000, Process 2, Paused Clock: 2000, Process 1, Started. Clock: 2000, Process 1, Resumed Clock: 2000, Process 2, Resumed Clock: 2350, Process 1, Store: Variable 3, Value: 7 Clock: 2570, Memory Manager, SWAP: Variable 3 with Variable 1 Clock: 2580, Process 2, Lookup: Variable 3, Value: 7 Clock: 3000, Process 2, Paused Clock: 3000, Process 2, Finished Clock: 3000, Process 1, Paused Clock: 3000, Process 1, Finished Clock: 3000, Process 3: Started. Clock: 2000, Process 3, Resumed Clock: 3400, Process 3, Lookup: Variable 2, Value: 3 Clock: 3830, Process 3, Release: Variable 1 Clock: 4000, Process 3, Paused Clock: 4400, Process 3, Store: Variable 1, Value 8 Clock: 4900, Memory Manager, SWAP: Variable 1 with Variable 3 Clock: 4910, Process 3, Lookup: Variable 1, Value 8 Clock: 5000, Process 3: Paused. Clock: 5000, Process 3: Finished.
Mar 17, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here