COS 318 - Project 4

Project 4: Inter-Process Communication and Process Management


Overview

This project is made up of basically two parts; inter-process communication (IPC) and process management. These two parts are separable, they can be worked on separately. We provide some hints on scheduling and testing in a later section. The IPC part aims at making the processes communicate each other with a mechanism which is very similar to the Linux's pipe mechanism where the processes send data to each other through a FIFO structure in memory. In order to develop this mechanism, you will develop two pieces of sub-mechanisms:
(1) Enhancing the the previous project's synchronization and mutual exclusion primitives (Section 1),
(2) Implementing the bounded buffer problem by making use of (1). After completing the implementation of IPC, you will also be asked to handle keyboard input from the user while which you will make use the IPC mechanism. Process management part involves dynamically loading processes into the system, rather than placing them on the disk at system start. You will implement the handlers of the two system calls: 1) Reading file directory from the USB flash disk, 2) Creating a new process from the program disk data. Note: Actually many portions of the code for implementing the keyboard interrupt and the process management part are provided to you. You will find many differences between the code that we provide to you in this project and the code in previous projects (ex: pcb, entry.s,..). Nevertheless, this will not affect the part you will implement. Minor differences are talked about in the description.

Yun Zhang will be the TA in charge of this project.

Important Dates

Precept 1: Nov 12, Wed, 20:30-21:30, COS 105.
Slides
Design Review 1: Nov 17, Mon, 19:00-21:00, FC 010, sign up here
Precept 2: Nov 19, Wed, 20:30-21:30, COS 105, Slides
Project Due: Nov 24, Mon, 23:59

Design Review

Design Review is graded as follows:
Locking mechanism
1 point. Describe lock implementation with spinlock in pseudo code format
Data structure
1 point. Explain briefly which fields in the mbox_t structure correspond to which fields in textbook's example readers-writers implementation in Figure 2-27 at page 117. What differences do you see between that example and the one you are going to build.
Interrrupt
1 point. What does keyboard_init do? Explain the possible problems that can occur in keyboard getchar and putchar because of interrupts IRQ0 and IRQ1. What is a solution?
Process Management
1 point. Give the formula of the sector number in the image to read the program directory from, in readdir. Then give the formula of start and end locations of the process (inside memory) to be loaded by loadproc.
Communication
1 point. As we mentioned before, since messages are variable sized, a single mbox_recv call can allow several mbox_send operations to execute rather than one. Argue on how to achieve that.

Glossary

IPC
MOS 2.3.
Pipe
check reference here
bounded buffer problem
Also known as producer-consumer problem, check MOS monitor implementation of the bounded buffer problem.

Extra Credit

For 1 point extra credit:
Kill
Implement a UNIX-like kill command, so that the user can type "kill" in the shell and kill a process specified by its pid. Note: It's okay to not be able to kill a thread, because our threads are linked statically with the kernel. You should take care of locks and condition variables that a process being killed owns. If a process is killed while executing a system call, killing the process has to be delayed until the system call ends; this ensures no locks are held by that process.

For 1 point extra credit:
Memory Relcaimation
After process exits or gets killed (if you implement kill), you should free all the memory the process uses, and the PCB entry as well, so that the next newly started process can reuse this memory. You can use any cheap management algorithm, such as First Fit (Section 4.2.2 in textbook). Also, you can have fixed-size PCB table in your kernel, so that the user can create no more than this number of processes. Note: You must implement your own memory manager and a malloc-like function. You can't use the standard malloc() function in C library, because we are not linking against any standard libraries.

Hints

(borrowed from previous years. Hints will be updated as questions come out from office hours / design reviews)

Normally, the implementation of mbox.c depends on thread.c primitives and the implementation of keyboard.c depends on mbox.c. To make your life a little bit easier, we will give you the solution object files of those four source files that you will be modifying, namely, given/mbox.o, given/keyboard.o, given/thread.o, and given/kernel.o. You can use these given object files to test your program incrementally in any order you like.

One possible scheduling can be first complete mbox.c, then keyboard.c, thread.c and finally kernel.c.

Submission

Submit to blackboard as you do in the previous projects.

Grading Criteria