Homework 4: Multiprocessing on the STM

In this homework, you will convert the STM operating system to support multiple processing with a round-robin scheduler. Call your modified stm program "stm-xxx.c" (replace "xxx" by your own last name).

This involves the following changes and extensions:

Command line

The command line has the following form:
stm-xxx [-q QUANTUM] [-d DEBUGGING-LEVEL] [-m MAX] prog1.stm prog2.stm ...
where Note that the optional argument "-b BASE" from the original SML program is not needed.

Loading

At the beginning of execution, each SML file in the command line gives rise to a process. Each process is given a partition in memory of the size specified at the beginning of the SML file. Partitions are assigned in the order of the command line, starting at physical address 0. The SML code and data from the file is read into the bottom of the corresponding partition.

Process Table

The process table should hold the following information for each process: You may assume that there are no more than 20 processes and that the name of the process is no more than 32 characters.

Process Queue

You should maintain a FIFO queue of processes. When the running process is preempted, it is placed at the back of the queue. When the running process terminates or aborts, it is removed from the queue. When the queue is empty, the STM simulator halts.

Preemption and context switches

A context switch takes control away from the current process under any one of four circumstances: Note that when a process is resumed, it is given exactly the standard time quantum, no more and less. It does not get extra or less time if it failed to use up its previous quantum.

Context switching involves the following:

Coding

The three functions "phys_address", "get_inst", and "exec_inst" correspond to the supposed hardware of the simulated machine. THESE MAY NOT BE CHANGED. You may change any of the other functions.

HINTS

  1. In order to distinguish Input/Output of different processes, we should print a helpful message identifying the process name, and the action being performed (either input or output).
  2. You will need to maintain several lists, including a list of all the current processes. This is a process table. To do this, it would be helpful to know something about the "struct" data type. If you are not familiar with this concept, please check my webpage on the C language for a brief introduction.
  3. This is not required, but can earn you extra credit points. Modify your solution so that the process table is actually loaded in memory. This is, of course, more realistic. In particular, it would be useful to write write/read functions to store/load string data to/from memory.
  4. This is not required, but a suggestion. To make the OS more realistic, we can have the OS execute an infinite while-loop, waiting to interact with the users. A sequence of jobs can be submitted using the same format as the command line argument that we use above:

    E.g.,

    % jobs [-q QUANTUM] [-d DEBUGGING-LEVEL] [-m MAX] prog1.stm prog2.stm ...
    where "%" is the OS prompt, and "jobs" is a key word. You would need to do some simple synchronization since the screen is also used for I/O from your programs.

    You should be able to see the current jobs running by typing

    % status

    Finally, to exit the OS, you type another key word,

    % exit