ECEn 425

Lab #5: Semaphores and Statistics


Overview

As the next step in the creation of the YAK kernel, you are to add functions to your existing code so that you can correctly execute the application program lab5app.c. You are free to make changes in the kernel code you wrote for the last lab, but you should not need to change the application program provided. You are expected to complete this lab with a partner.

The added functionality comes in two forms: (1) routines to create, pend on, and post to semaphores; and (2) a support mechanism to track the number of context switches and the CPU utilization.

Functionality

You must add these kernel functions to your kernel. You should implement each function exactly according to the prototype detailed on the YAK Kernel webpage. Refer to that web page for additional details about these functions.

In addition to these functions, your ISRs and interrupt handlers should function as in the last lab, with one exception: You should modify your keypress interrupt handler so that it calls YKSemPost(NSemPtr) if the 'p' key is pressed. Other keypresses should behave as before.

You also need to make sure that your kernel code defines and maintains the global variables YKCtxSwCount and YKIdleCount, both unsigned integers that track information about the current workload that the user might be interested in (see the YAK web page). YKCtxSwCount should simply be incremented each time a context switch occurs, and the idle task should repeatedly increment YKIdleCount in its while(1) loop. These variables are used to output simple statistics in the application code provided with this lab.

When the application is run correctly, it should output the text "Hey, it works!" every 6 ticks. When the 'p' key is pressed, it should output a long series of prime numbers. The CPU usage should be fairly low (less than 10%) at a tick rate of 10,000 ticks. Output from a working version of the lab is shown below.

TICK 1
Welcome to the YAK kernel
Determining CPU capacity

TICK 2

TICK 3

TICK 4

TICK 5

TICK 6

TICK 7
"Hey, it works!"

TICK 8

TICK 9

TICK 10

TICK 11

TICK 12

TICK 13
"Hey, it works!"

TICK 14
 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061         <- User pressed 'p' key
 1063 1069 1087
TICK 15
 1091 1093 1097 1103 1109 1117 1123
 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213
 1217 1223
TICK 16
1229 1231 1237 1249 1259 1277 1279 1283
 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361
 1367
TICK 17
 1369 1373 1381 1399 1409 1423 1427 1429 1433
 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489

TICK 18
1493 1499

TICK 19
"Hey, it works!"

TICK 20

TICK 21

TICK 22

Requirements

Implement the required functions and make sure that the application program runs correctly. The system should run correctly when key presses occur in rapid succession and when the timer tick frequency is increased to every 750 instructions.

Pass-off

When the kernel runs the application code correctly, show and demonstrate your code to a TA. Since you must demonstrate working code to a TA on or before the due date, please consider their lab schedule well in advance.

In addition to the demonstration, you must a written summary of problems you encountered, if any, in completing this lab. You should also include a report of the number of hours you spent on the lab, including coding and debugging. A realistic estimate is sufficient. Send a submission even if you didn't encounter any noteworthy bugs along the way. You will not receive full credit for the lab unless you send a report.

New for Fall 2019: we want both your report and your source code for the lab. The easiest way to do this is to create a report file (for consistency call it report.txt or report.pdf), to add it to the working directory for the lab, to create a compressed tar file (with all the files in your directory), and then to upload that file to Learning Suite.

To review, if 425/labx is your working directory for this lab, type the following in the 425 directory:

 tar -cvzf submission.tar.gz labx
and then upload the resulting compressed tar file (submission.tar.gz) to Learning Suite.

Important Notes

Debugging help

Here are comments from student reports (edited only for length) describing their problems and how they tracked them down. As always, take them with a grain of salt.



Last updated 26 August 2019