CS 354: Fall 2018

Lab 1: Creating and Synchronizing Processes in XINU

Due: Sunday, September 16th, 2018, before 11:59 PM

1. Objectives


2. Setup

We will use a different tar.gz file for this lab that includes two extra files and a different main.c. Create a directory for lab1, change to that directory, and then untar and unzip the tar.gz file in that directory using the following command:

tar zxvf /u/u3/cs354/Fall2018/lab1/xinu-x86.tar.gz


3. Readings

Read Chapters 1-2 of the textbook, and study the prototypes of the functions: create, resume, kill, semcreate, semdelete, wait, signal, sleep, sleepms, kprintf.

4. What to do?

Background

In Lab 0, we experimented with creating multiple concurrent processes. In this lab, we will use process synchronization primitives (semaphores).

Along with the main code for XINU, this tarball contains the following files:

Task 1:

In the file "system/prod_cons.c", there are function declarations for void insert_buffer(...) and uint8 remove_buffer().

Remember that we need mutual exclusion here!

Task 2:

In the file "system/prod_cons.c", there are function declarations for void producer(...) and void consumer(...). These functions are the producer process and the consumer process, respectively.

Task 3:

In the file "system/prod_cons.c", implement the function void start_prod_con(void) . This is an initialization function that creates all necessary processes and starts the producer/consumer simulation running. For now, set the process priority for all producers and consumers to the same value, 20.

Task 4:

In the file "system/prod_cons.c", complete the function void stop_prod_con(void). This is the function that stops the currently executing producer/consumer simulation.

For tasks 3 and 4, you will want to use the system calls create(), resume() and kill(), all defined in the systems/ folder.

Task 5:

In the file "system/prod_cons.c", complete the function void print_report(void). This function, at the end of the simulation, outputs a report of the counts along with the contents of the shared buffer. The output should look like this:

      Producer A: created xxx items
      Producer B: created xxx items
      Producer C: created xxx items

      Consumer a: deleted XXX items from producer A, XXX items from producer B, and XXX items from producer C
      Consumer b: deleted XXX items from producer A, XXX items from producer B, and XXX items from producer C
      Consumer c: deleted XXX items from producer A, XXX items from producer B, and XXX items from producer C
        
      The shared buffer contains: xxx items from producer A, xxx items from producer B, and xxx items from producer C
    
At the end of the simulation, the number of items created and deleted should add up accordingly to ensure that extra items were not produced nor were extra items consumed. For example, the number of he items created by producer A minus the number of items left in the shared buffer from producer A should equal the sum of all items deleted by consumers from producer A.

Make sure not to put any dependent code in main.c or any variable declarations specific to your implementation in prod_cons.h. Put all dependent code only in prod_cons.c.

Task 6 (10 pts Extra Credit):

In your initial implementation, all processes are created with a priority of 20. Experiment with changing the process priorities:

Compare the results by looking at the statistics from print_report. Does changing the process priorities of producers and consumers affect "fair" access to the shared buffer? If so, how? Be sure to give a description using experimental results and make sure you explain your definition of "fair".

Turn-in Instructions and Written Report

Submit using the turnin command (see below) your complete source code (all of XINU) including the any files you added to complete the lab. In the system/ directory include a PDF file called lab1_analysis.pdf with a report (15 pts) discussing:

  1. (5 pts) How does your solution guarantee that only one process will attempt to delete an item at a given time?
  2. (5 pts) In your solution, when a producer needs to insert an item in the shared buffer, are consumers also excluded, or can consumers continue concurrently? Explain.
  3. (5 pts) When a consumer starts to extract items, does your system guarantee that the consumer will receive contiguous locations in the shared buffer, or do consumers contend for items? Explain.
  4. Your results from the extra credit experiment if you completed it.

Please be concise! Make sure you put your name on your report, that the file is named exactly as specified (lab1_analysis.pdf), and the file located in the directory specified (system/).

Before submitting any lab assignment throughout the semester, make sure to double-check Piazza to ensure that all requirements and instructions have been followed.

To submit:

        i) Go to the xinu-x86/compile directory and run "make clean".

        ii) Go to the directory of which your xinu-x86 directory is a subdirectory. (Note: please do not rename xinu-x86 or any of its subdirectories.)

                e.g., if /homes/bob/lab1/xinu-x86 is your directory structure, go to /homes/bob/lab1

        iii) Type the following command

                turnin -c cs354 -p lab1 xinu-x86

Remember that re-submitting erases your old submission and its timestamp. If you submit even one second late, it is deducted from your four flexible (late) days. No assignments will be accepted beyond the remaining late days you have. Please make sure to disable all debugging output before submitting your code for any assignment, and make sure your code is well-commented.