TWiki> CS385fall14 Web>Homework6 (revision 5)EditAttach

adding threading support to xv6

In this homework, we make some major changes to xv6 to add support for kernel threads to the OS. A single process may execute multiple kernel threads, which may operate concurrently on a multi-core machine.

The hw6 template already includes some significant refactoring. The main changes are the replacement of the "proc" global with a "current" global, which holds the current thread. Also, the ptable is an array of struct thread instead of struct proc, where each struct thread has a pointer to a potentially shared struct proc.

However, in the template there is a one-to-one mapping between threads and processes. Your job is to make that a many-to-one mapping by adding thread management facilities and enforcing correct thread semantics on existing system calls.

Basic Thread creation

With fork(), a process is copied wholesale. A skeleton exists for the system call sys_clone(). Complete the implementation, to make each of the thread test cases (programs thread1..threadN) work correctly.

As is usually the case, it'll be easier if you do things a step at a time. For thread creation, I would suggest:

  1. make thread1 print hello world, by a little bit of code in clone that sacrifices the original thread
  2. make thread1 print both hello world and hello from main, by forking off a new thread
  3. make thread2 print a bunch of numbers by setting up shared memory

thread_exit()

You'll find that the third test case, thread3 crashes at the end of its run. When the created thread has finished running f() it tries to return to the calling function, but it doesn't exist.

  • make thread3 not crash by adding a system call thread_exit (to test, temporarily add a call to thread_exit at end of f)
  • update thread_create in ulib.c to have created threads automatically call thread_exit when their initial function returns

Process exit() semantics

When any thread calls exit(), the process should die, which means all threads should stop executing. Update the implementation of the exit() system call to reflect this behavior.

Without this fix, thread4 will output "Done looping" after it has finished executing the function f(). With the fix, the program should quit long before, as the main thread finishes immediately.

thread_join(): waiting for threads to finish

After implementing correct exit() semantics, thread4 will quit immediately. However, the thread4 code actually includes a call to thread_join(). Here, the main thread should wait for the other thread to finish before continuing.

Provide a real implementation of thread_join(), including a new system call sys_join() to support this behavior.

exec() semantics

Edit | Attach | Print version | History: r8 < r7 < r6 < r5 < r4 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r5 - 2014-10-10 - 15:48:10 - Main.jakob
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF