ECS150 Course Website

last updated
Programming Assignment #2

Lab 2 Clarifications

The due date for lab 2 has been extended to 10:00am, Monday, March 1st. Interactive grading will be held Monday March 1st, Tuesday March 2nd, Thursday March 4th, and Friday March 5th.

Testing: Note that the lab requires you provide a method for testing the correctness of your solutions. If you do not have any test programs at the time of interactive grading, you will be docked points. You may download the following tester programs:

Part 1 Clarification: Part 1 asks to record the "time of creation" for user processes. You may record this time in seconds since boot, or real time in seconds. (To record time in seconds since boot, you *may* use get_uptime().) Those students that get the real time in seconds (from do_get_time()) will get extra credit.

Part 2 Clarification: Part 2 asks to record the number of "system calls" made by user processes. To be specific, it is asking the number of times sys_call gets called (not the number of times fork or getpid, etc. are called).

Part 3 Clarification: Part 3 asks to toggle between 2 and 3 seconds for the max response time. Instead, please toggle between 0.1 second (100 milliseconds) and 2 seconds (2000 milliseconds). You will not be docked points for toggling between 2 and 3 seconds as originally asked.

Handin Procedure

For interactive grading, you will have to demonstrate your solutions on either the CSIF computers -or- on your own personal laptop. You must have your kernel compiled BEFORE the interactive grading session. If your kernel was compiled AFTER the due date, your lab will be considered late (and hence points will be docked).

You will also have to email your compiled kernel to by 10:00am Monday, March 1st. To do this, follow these instructions:

  1. Make sure you have compiled the version of the kernel you want to submit.
  2. Copy the compiled kernel image to the virtual floppy drive
    • mount /dev/fd1 /fd1
    • cp /minix/2.0.3r* /fd1/lab2
  3. Compress the virtual floppy image using zip
    • zip -v [lastname] floppy.img
  4. Email the compressed zip file to with the subject line "ECS150 Lab 2"

PLEASE follow directions! (or face consequences...)

Lab 2 Hints & Tips

Before starting on this lab at all, I would read the Using Minix section. You'll find several hints and tips as far as compiling the Minix kernel there.

Hot Keys/Function Keys

Before starting on part 1, I would suggest trying to print out "hello world" when a function key (specifically F4) is pressed. To do this, first open file /usr/src/kernel/keyboard.c. On line 370, there is a function called func_key that maps a particular function to a function key. Add a case for F4 that calls my_dmp(). Below is func_key with the case for F4 added:

 *				func_key				     *
PRIVATE int func_key(scode)
int scode;			/* scan code for a function key */
/* This procedure traps function keys for debugging and control purposes. */

  unsigned code;

  if (scode & 0200) return(FALSE);              /* key release */
  code = map_key0(scode);                       /* first ignore modifiers */
  if (code < F1 || code > F12) return(FALSE);   /* not our job */

  switch (map_key(scode)) {         /* include modifiers */

  case F1:  p_dmp(); break;         /* print process table */
  case F2:  map_dmp(); break;       /* print memory map */
  case F3:  toggle_scroll(); break; /* hardware vs. software scrolling */
  case F4:  my_dmp(); break;        /* print custom proc fields */

#if ENABLE_DP8390
  case F5:	dp_dump(); break;       /* network statistics */
  case CF7:	sigchar(&tty_table[CONSOLE], SIGQUIT); break;
  case CF8:	sigchar(&tty_table[CONSOLE], SIGINT); break;
  case CF9:	sigchar(&tty_table[CONSOLE], SIGKILL); break;
  default:	return(FALSE);

Next, you must define function my_dmp(). I would do this in file /usr/src/kernel/dmp.c, since that is where p_dmp() is located (and you'll eventually want to copy some of the code used in p_dmp() to do the assignment). Try defining your function towards the top of the file, and avoid defining my_dmp within any #if statements. Here is some example code:

 *				my_dmp    				     *
PUBLIC void my_dmp()
	printf( "superpotato!\n");

You must also add the prototype for my_dmp() in the file /usr/src/kernel/proto.h. Here is an example snippet of proto.h:

/* dmp.c */
_PROTOTYPE( void map_dmp, (void)					);
_PROTOTYPE( void p_dmp, (void)						);
_PROTOTYPE( void my_dmp, (void)						);
_PROTOTYPE( void reg_dmp, (struct proc *rp)				);

Once you are done with this, try recompiling the kernel, rebooting, and then pressing F4!

Part 1

It always helps to break down problems in to small parts. The fewer changes you make between compiles, the fewer lines of code you have to debug. You can avoid compiling the entire kernel each time you make a change by manually compiling the files you modified and checking for errors and warnings. I suggest breaking part 1 into the following chunks:
  • Add field to process table that records the time of creation of each user process
  • Initialize that field to zero. Then compile and test using F4.
  • Initialize that field to the time of creation. Then compile and test using F4.
The files you may want to edit for this assignment are (list may not be complete):
  • /usr/src/kernel/proc.h (contains process table)
  • /usr/src/kernel/system.c (contains fork code)

Part 2

The files you may want to edit for this assignment are (list may not be complete):
  • /usr/src/kernel/proc.h (contains process table)
  • /usr/src/kernel/proc.c (contains sys_call, mini_send and mini_rec)

Part 3

The files you may want to edit for this assignment are (list may not be complete):
  • /usr/src/kernel/clock.c (contains clock information and functions)
  • /usr/src/kernel/proc.c (contains scheduling code)