Operating System projects

wuthreads: Implementing a User-space Threading Library

Fred Kuhns


Project Overview

This project will focus on the design and implementation of the threading model and a light weight, extensible scheduling framework for real-time, event driven applications. You want to design a library which targets networked, multiprocessor systems and real-time applications such as multi-media players, network port processors, embedded web servers, system controllers (automotive engine or avionic) and related transaction-oriented applications. The project may be broken down into serveral phases: the development of a user-space threading library with a hierarchical scheduling framework which supports prioritized thread scheduling and preemption; implementation of a timed wait facility and synchronization primitives; add real-time scheduling classes.

I have a short powerpoint presentation which gives the overall architecture and thread states for my implementation, see wuthreads.ppt.

Finally, I encourage each of you to implement your project iteratively. For example, first make sure you know how to use sigsetjump and siglongjmp. Then try saving several contexts and altering the contents of the sigjump_buf by changing the stack and PC pointers. From there you can try creating threads and adding them to a simple FIFO queue, and so forth. I have created three simple programs to illustrate what I mean, see setjmp1.c, setjmp2.c and setjmp3.c. You can compile these programs using the command

  gcc -o setjmp1 setjmp1.c
  gcc -o setjmp2 setjmp2.c
  gcc -o setjmp3 -I$WUSRC setjmp3.c
  # where $WUSRC references the directory where you have located the wulib
  # sources (needed for the include file wulib/queue.h).

Project Requirements

You must create a user-space threading library that supports priority-driven, preemptive, scheduling policies. Specifically, you must support the following:

Phase 1

Phase 2

In short, you must make the following changes and additions to your user-space threading library implemented in phase 1 of this project:

Phase 3

Add real-time scheduling classes to your design.

Designing and implementing the library is half the story, you must also create a test environment for validating your library. Specifically you must create tests that verify the operation of your synchronization mechanisms (mutex and condition variables), the scheduling framework and new scheduling classes.

Using wulib

You will need the library and header files wulib/*.h and wulib/Linux/libwu.a and the wuthreads specific logging modifications in wuthreads/wlog.c and wuthreads/wlog.h. Or you can build it yourself using the provided source.

There are several utility functions and macros available in the wulib library. You can use the logging facility (log.{h,c}), timer functions (timer.{h,c}) and queue manipulation code (queue.h and pqueue.{h,c}).


Required interface specification

Phase 1

You must implement the following interface, the interface is defined in wth.h which you must use without modification (read the header file for a more detailed description of the API):

Phase 2

You must implement the following interface, the interface is defined in sync.h which you must use with the modification specified above, for a more detailed description of the API see the header file sync.h (mutex and condition variable) or wth.h (timed wait):

Phase 3

No additional extensions to the interface are required.

Platform Requirements

You must use Linux for the project.

Library Verification

While you are responsible for the testing and verification of the overall all project (in particular the real-time classes) I am providing programs to assist with verifying the first two phases.

I have added two test programs called callout.c and testapp.c: testapp.c is to verify the first phase of the project and callout.c is for the second. The following commands can be used to compile your test applications on the CEC Linux hosts, where $WUSRC references the class direcotry with the wulib sources and $WUCSE is your top-level project directory:

      gcc  -DMyOS=Linux -DPTHREADS -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE -Wall -g -DWUDEBUG \
      -I${WUSRC} -I/usr/include -I${WUCSE} -I. -o Linux/callout.o -c callout.c

      gcc  -DMyOS=Linux -DPTHREADS -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE -Wall -g -DWUDEBUG \
      -o Linux/callout Linux/callout.o [Your wuthreads library] -L${WUSRC}/wulib/Linux -lwu -lm

      gcc  -DMyOS=Linux -DPTHREADS -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE -Wall -g -DWUDEBUG  \
      -I${WUSRC} -I/usr/include -I${WUCSE} -I.  -o Linux/testapp.o -c testapp.c

      gcc  -DMyOS=Linux -DPTHREADS -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE -Wall -g -DWUDEBUG \
      -o Linux/testapp Linux/testapp.o [Your wuthreads library] \
      -o Linux/callout Linux/callout.o [Your wuthreads library] -L${WUSRC}/wulib/Linux -lwu -lm

      If you created an archive library of your wuthreads source then you can
      add the following where it says [Your wuthreads library]:

      -L[your path]/Linux -lwth

      Or list all the object files.
    

Turning in your project

Varies by semester, see the current homework URL for details.