Project #4: Cooperating Scheduling

Submit: Turn in your create.c, ctxsw.S, and testcases.c source files using the turnin command on morbius.mscsnet.mu.edu or one of the other Systems Lab machines.

Work should be completed in pairs. Be certain to include both names in the comment block at the top of all source code files. It would be courteous to confirm with your partner when submitting the assignment. You may modify any files in the operating system, but only changes to ctxsw.S, create.c and testcases.c will be graded for this assignment.

Processes

Preparation

First, make a copy of your Project 3 directory:
    cp -R xinu-hw3 xinu-hw4
Then, untar the new project files on top of it:
    tar xvzf ~brylow/os/Projects/xinu-hw4.tgz

New files:

system/initialize.c   Updated initialization for Project 4.
system/main.c   A "main program" for testing scheduling.
system/queue.c   An implementation of the queue data structure.
system/create.c   A partial function for creating a new process.
system/ctxsw.S   An incomplete assembly routine for switching process contexts.
system/ready.c   An complete function for adding a process to a ready queue.
system/kill.c   An complete function for killing processes in any state.
include/proc.h   Process table declarations and constants.
include/queue.h   Process queue entries.
include/kernel.h   Definitions of XINU standard function prototypes such as kprintf().
include/xinu.h   Includes all necessary XINU header files.
include/stddef.h   Various standard XINU type definitions.

The create() and ctxsw() functions are incomplete and must be filled in. The major locations are marked with "// TODO... ." File system/testcases.c contains code to test your create() and ctxsw() with three processes, each of which prints a process ID and then yields. Once your creation and context switch functions are working, you will see these three processes take turns running on a single core.

 

Some Assembly Required

An operating system's context switch function typically must be written in assembly language because the low level manipulations it performs are not modeled well in higher-level languages. If you have not worked in RISC-V assembly language before, there are many helpful resources available online. Despite its low-level nature, a context switch does not require complex instructions. Our context switch can be completed using the load doubleword (ld), store doubleword (sd), move (mv), and jump-and-link-register (jalr) opcodes.

Please refer to RISC-V Reference Card by the University of Cambridge for an explanation of general RISC-V opcodes.

Note: The Sipeed Nezha is equipped with a Allwinner D1 processor, which implements the RISC-V 64-bit instruction set.

 

Testing

The default test cases provided with the tarball are necessary, but not sufficient. Just because it switches between a handful of identical processes does not guarantee correctness. In embedded systems, details matter. (A LOT!) Students in previous terms have found that subtle bugs in this phase of the term project were responsible for nightmares weeks and months down the line. Test your code thoroughly:

You have a working I/O driver, and a kprintf() function for formatted output. Use these to explore every aspect of the operating system structures you are building.


[back]

[Revised 2023 Feb 08 10:09 DWB]