Submit: Turn in your
entire xinu-hw9
directory source files
using the turnin command
on morbius.mscsnet.mu.edu or one of the other
Systems Lab machines. Please run "make clean" in
the
compile/ subdirectory just before submission to reduce
unnecessary space consumption.
Work should be completed in pairs. Be certain to include both names in the comment block at the top of all source code files, with a TA-BOT:MAILTO comment line including any addresses that should automatically receive results. It would be courteous to confirm with your partner when submitting the assignment.
Make a fresh copy of your work thus far.
cp -R xinu-hw8 xinu-hw9
Then, untar the new project files on top of it:
tar xvzf ~brylow/os/Projects/xinu-hw9.tgz
Be certain to make clean before compiling for the first time.
The distinction between the concepts of "threads" and "processes" can be an important one. Our textbook provides the definition that processes execute in their own memory space, whereas threads share the same memory space within a process. But beyond that, most of the aspects of processes we have already studied seem to repeat for threads -- you need a thread control block, each thread gets its own stack of activation records, we need to worry about a scheduling policy for deciding which thread we will context switch to next, etc.
In truth, in the context of a simplified, embedded, educational operating system like ours, the distinction between processes and threads is not very relevant. We could label it either way, and build out the system in more concrete ways to reinforce that interpretation. In this assignment, we muddy the waters slightly further by implementing a crucial subset of the standard PThreads API using what the lightweight processes we've been working with all along.
In addition to the code changes below, there are a few minor changes needed to get this assignment running. The first change is a minor fix. The second and third changes
are related to sharing a page table between child and parent processes. Since children and parent processes share a page table, they can't all have the same virtual address
for their process stack and swaparea. Otherwise, they'd all overwrite each other! Thus, we must give threads a unique virtual addresses for a virtual stack and swap area.
To do this, we take into account the PID (unique to each process and thread) when creating the virtual addresses for the thread stack and swap area.
To quickly access the PID in interrupt.S, we store the PID in the tp register. We use the equation [PROCSTACKADDR OR SWAPAREAADDR] - ((pid+1) * PAGE_SIZE)
to
calculate the virtual address for the thread stack and swap area.
The new tarball provides an include/pthread.h header that defines the crucial #defines and function prototypes to mimic the standard POSIX PThreads interface. Chapter 27 in our textbook explains how this API works, and gives excellent examples.
The mapping of these PThread functions to existing Embedded Xinu functions is the primary content of this assignment.
Each of the four PThread API functions above should be implemented as system calls by extending the trap handlers we built in Project 5: Trap Handlers.
Add new entries to the global syscall_table in syscall_dispatch.c. Note that the row in the table must correspond to the correct syscall numbers defined above. The first column in the table is the number of arguments the syscall expects.
Repeat this process for our new PThreads interface:
#define SYSCALL_PTCREATE 13 /**< PThread create */
#define SYSCALL_PTLOCK 15 /**< PThread mutex lock */
#define SYSCALL_PTUNLOCK 16 /**< PThread mutex unlock */
When all is said and done, you should be able to compile and execute our lab demo PThread code correctly on your Embedded Xinu kernel.
[Revised 2023 Apr 19 23:31 DWB]