1 CS 471 Operating Systems Fall 2020 Programming Assignment 1 (PA1): Due date: Friday, October 23, 11:59 pm Table of contents 1. Introduction 2. Begin your assignment 3. Concurrent Programming with...

it is attached


1 CS 471 Operating Systems Fall 2020 Programming Assignment 1 (PA1): Due date: Friday, October 23, 11:59 pm Table of contents 1. Introduction 2. Begin your assignment 3. Concurrent Programming with OS/161 4. Written Exercises (25 points) 5. Coding Exercises (75 points) 6. Coding style, submission and grading 1. Introduction We finished the discussion of threads and general synchronization in class, and you became familiar with the basic OS/161 environment in the first assignment (PA0). In this assignment you will implement synchronization primitives for OS/161 and learn how to use them to solve a synchronization problem. Once you have completed the written and programming exercises you should have a fairly solid grasp of the pitfalls of concurrent programming and synchronization. To complete this assignment you will need to be familiar with the OS/161 thread code. The thread system provides interrupts, control functions, and semaphores. Note that in addition to developing non-trivial synchronization code in C, you will need to again do some code reading and directory exploring in OS/161. This is normal. Considering that debugging synchronization programs requires also more time, make sure to allocate sufficient time from the beginning – if you start just a few days before the due date, you are likely to experience significant difficulties. Working with partner In this assignment you can - and you are ENCOURAGED to - work with a partner: another CS 471 student from your own section. No team can have more than two members. If you have worked alone in Project 0, you can form a team with another CS 471 student who worked alone in Project 0. You can also continue to work with the same partner you worked with in Project 0 (however, you cannot switch to a new partner). If believe you can finish it without a partner, you are welcome to work alone; but there will not be any bonus points for those working alone, and you should keep in mind that the assignment 2 specification has been developed assuming that two students will actively interact and cooperate in exploring OS/161 and developing a synchronization program. 2. Begin your assignment Download necessary files For this assignment, you need to replace 3 of your existing files as follows: • menu.c in ‘kern/main/’ • test.h in ‘kern/include/’ • stoplight.c in ‘kern/asst1/’ The updated versions of these files can be downloaded from Blackboard. You must replace these three files accurately before you start coding the solution. Tag your Git Repository Before you do any real work on this assignment, tag your Git repository. The purpose of tagging your repository is to make sure that you have something against which to compare your final tree. Make sure that you do not have any outstanding updates in your tree. Use git commit to get your tree committed in the state from which you want to begin this assignment. % git commit -am “End of project-0” % git push Now, tag your repository as shown below. % cd ~/os161/os161-1.11 % git tag asst1-begin NOTE: If you are working with a partner, you may want to set up the GitLab repository so that it may be accessed by both members of your group. In case you have not setup GitLab, the instructions for the initial setup can be found here: https://mason.gmu.edu/~aroy6/gitlab_setup.html Configure OS/161 for ASST1 We have provided you with a framework to run your solutions for ASST1. This framework consists of driver code (found in kern/asst1/stoplight.c) and menu items that can be used to execute the solutions from the OS/161 kernel boot menu. You have to reconfigure your kernel before you can use this framework. The procedure for configuring a kernel is the same as in ASST0, except you will use the ASST1 configuration file: 3 % cd ~/os161/os161-1.11/kern/conf % ./config ASST1 You should now see an ASST1 directory in the compile directory. Building for ASST1 As in PA0, in order to build kernel, you have two options. You can use the php file provided by the TA or use the alternative method. Before starting any of the methods, make sure to issue the module load command % module load sys161/1.14 IMPORTANT: You should remember to issue the module load command above every time you logon to zeus when you intend to work on os161! In the first method, you must enter the following: % wget http://mason.gmu.edu/~aroy6/build-asst1.php % php build-asst1.php Or as the second method, you can run make from compile/ASST1. % cd os161-1.11 % ./configure --ostree=$HOME/os161/root % cd kern/conf % ./config ASST1 % cd ~/os161/os161-1.11/kern/compile/ASST1 % make depend % make % make install Command Line Arguments to OS/161 Your solutions to ASST1 will be tested by running OS/161 with command line arguments that correspond to the menu options in the OS/161 boot menu. IMPORTANT: DO NOT change the menu option strings! "Physical" Memory In order to execute the tests in this assignment, you will need more than the 512 KB of memory configured into System/161 by default. We suggest that you allocate at least 2MB of RAM to System/161. This configuration option is passed to the busctl device with the ramsize parameter in your sys161.conf file. Make sure the busctl device line looks like the following: 31 busctl ramsize=2097152 (Note: 2097152 bytes is 2MB). Helpful hint: The php script will replace this sys161.conf file every time it is executed. Commenting out line 38 in the php script will fix that. 4 3. Concurrent Programming with OS/161 If your code is properly synchronized, the timing of context switches and the order in which threads run should not change the behavior of your solution. Of course, your threads may print messages in different orders, but you (and we!) should be able to easily verify that they follow all of the constraints applied to them and that they do not deadlock. Built--in thread tests When you booted OS/161 in ASST0, you may have seen the options to run the thread tests. The thread test code uses the semaphore synchronization primitive. You should trace the execution of one of these thread tests in GDB to see how the scheduler acts, how threads are created, and what exactly happens in a context switch. You should be able to step through a call to mi_switch() and see exactly where the current thread changes. Thread test 1 ( "tt1" at the prompt or tt1 on the kernel command line) prints the numbers 0 through 7 each time each thread loops. Thread test 2 ("tt2") prints only when each thread starts and exits. The latter is intended to show that the scheduler doesn't cause starvation -- the threads should all start together, spin for a while, and then end together. Debugging concurrent programs thread_yield() is automatically called for you at intervals that vary randomly. While this randomness is fairly close to reality, it complicates the process of debugging your concurrent programs. The random number generator used to vary the time between these thread_yield() calls uses the same seed as the random device in System/161. This means that you can reproduce a specific execution sequence by using a fixed seed for the random number generator. You can pass an explicit seed into random device by editing the "random" line in your sys161.conf file. For example, to set the seed to 1, you would edit the line to look like: 28 random seed=1 We recommend that while you are writing and debugging your solutions you pick a seed and use it consistently. Once you are confident that your threads do what they are supposed to do, set the random device to autoseed. This should allow you to test your solutions under varying conditions and may expose scenarios that you had not anticipated. 5 4. Written Exercises (25 points) Please answer the following questions and submit them with your assignment in code-reading.txt. Code reading To implement synchronization primitives, you will have to understand the operation of the threading system in OS/161. It may also help you to look at the provided implementation of semaphores. When you are writing solution code for the synchronization problems it will help if you also understand exactly what the OS/161 scheduler does when it dispatches among threads. Place the answers to the following questions in code-reading.txt. Thread Questions 1. What happens to a thread when it exits (i.e., calls thread_exit())? What about when it sleeps? 2. What function(s) handle(s) a context switch? 3. What does it mean for a thread to be in each of the possible thread states? 4. What does it mean to turn interrupts off? How is this accomplished? Why is it important to turn off interrupts in the thread subsystem code? 5. What happens when a thread wakes up another thread? How does a sleeping thread get to run again? Scheduler Questions 6. What function is responsible for choosing the next thread to run? 7. How does that function pick the next thread? 8. What role does the hardware timer play in scheduling? What hardware independent function is called on a timer interrupt? Synchronization Questions 9. Describe how thread_sleep() and thread_wakeup() are used to implement semaphores. What is the purpose of the argument passed to thread_sleep()? 10. Why does the lock API in OS/161 provide lock_do_i_hold(), but not lock_get_holder()? 5. Coding Exercises (75
Oct 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here