Programming Assignment 1: Managing User-Level Threads in Nios Environment
Due date: November 14th, 2007
Your task is to manage eight user threads in a system that only supports single-threaded model. You will carry out your work in the Altera DE-2 with Nios II processor and no operating system. The software development environment, Nios IDE supports programming in C and C++. For more information about installing Nios II on your PC can be found HERE.
Problem statement:
You will manage eight user level threads within a single process (four producer threads and four consumer threads). Each producer thread inserts ‘X’ into a finite buffer of size 3,000,000 bytes. Each consumer thread removes the last inserted character from the same buffer. For this assignment, your goal is to create user level thread management mechanism. You need not worry about mutual exclusion and barrier. You can pick the quantum time yourself. Typically, a common quantum length is 100 or 200 milliseconds. To accomplish this task, you need to create the following functions:
- producer: this function inserts ‘X’ into the shared buffer at the first available slot.
- consumer: this function removes the last inserted character from the shared buffer.
- main: this function creates the shared buffer, create threads, and then start executing threads.
- myThreadCreate: this function acquires necessary resources to support threading. The resources should at least include, but not limited to a space to store the thread context and a space used for execution stack. It then maps previously acquired resources to an execution function, forming an execution thread. Note that this mapping is similar to your lab assignment in which you create a stack space using malloc and a storage space for context using sigjmp_buf.
- myThreadJoin: this function makes a thread runnable. In effect, it inserts a thread into a run queue. At this point, you now have one more threads. For example, if you invoke myThreadJoin one time in the main function, you should now have two threads: the thread you have just started and the main thread. The run queue is managed by function, myScheduler. Since you are likely to store the pointer to the resource space (stack space and context storage space) for each thread in an array, this array can also serve as the run queue.
- myScheduler: this function is invoked when pulse_generator (an software programmable interval timer) sends a timeout signal. When the signal is received, the processor begins executing this code. Thus, its duty should at least include storing the context of the current execution thread, picking the successive thread and restoring its content, and resetting and restarting the timer. The scheduling order is FIFO, meaning that threads are scheduled based on the invocation order of myThreadJoin.
Summary:
The major components should at least include:
- a circular buffer of size 3,000,000 bytes
- all the necessary functions to create threads and start executing them
- eight user-level threads (4 producer and 4 consumer threads)
- a scheduler that works with the pulse_generator timer
- necessary data structures to support threading (e.g. a run queue, thread structure, etc).
Submission procedure:
- Prepare a project report that includes
- Your name
- A read-me section on how to compile and run the program
- The difficulties faced in the project
- Your approach to the problem (design document)
- The number of hours spend on the assignment
- All source code with meaningful comments
- Create a tar-ball that contains all the source files and the project report.
- Submit your tar-ball using hand-in.
Grading Criteria:
Correctness: 70%
Readable and insightful comments: 20%
(hint: at the beginning, provide detailed information of the function. Information can be “what it does and how you build it?”)
Completeness of report: 10%