I. OBJECTIVES
The purpose of this request is to build a package of timing routines for the SAPC and use it to time code on the SAPC to determine memory access time on the SAPC with and without caching. This code does not run on UNIX. Read the Intel 8254 Programmable Interval Timer (PIT) Data Sheet. Look at $pcex/timer.c for an example of C code for accessing the timer. Copy all the files needed for this project.
II. The timing package
A package is a set of utilities that can be called by a program that wants to use them. When designing a package we carefully consider the things in it that must be visible to the caller, specify those, and require that everything else be internal and invisible. The visible parts of the timing package you will build are in “timepack.h”. A customer for the package’s services includes that header file (using #include) in the program for compilation and links his or her object code with “timepack_sapc.opc” to build the executable. You are asked to modify “timepack_sapc.c” to provide a high resolution timer service for programs running on the SAPC.
Existing Code
Every package should have a test program showing that it works by calling it in all important ways. This test program is called a “driver” because it sits on top of the package and drives it like we test-drive a car – start up, do this, do that, stop, shut down. It is also called a “unit test” program because it tests just this one package separate from any other package in a bigger program. If you suspect something is wrong in a certain package, you’ll try to make its unit test fail, and then you debug the problem in the relatively simple environment of the unit test, rather than in the bigger program. The test program for timepack is testpack.c. You can build testpack and testpack.lnx right away and run them. Note what is printed out by testpack.lnx. Capture this in a typescript1 file. It shows that the timing package (as provided) can time things on the SAPC to 55-ms accuracy, but not to the microsecond accuracy we want. The next step is to get your timepack_sapc.c fixed up for the higher resolution and the unit test executable testpack.lnx will show it.
Modifed Code
You’re working directly with the hardware device, the Programmable Interval Timer (PIT) with its interrupt handler. This code has been provided to you in a). The timepack_sapc.c as provided can measure time in timer “ticks” at an 18.2-Hz (55 ms/tick) standard PC tick rate.To use the PIT to measure higher precision, you make use of “downcounts” within the timer chip. What you need to do is determine how many counts have downcounted in the timer since the last tick and compute a higher accuracy time. By doing this at both the start and the end of the time interval being measured, you can compute the elapsed time accurate to a few microseconds, a very respectable timer service. You’ll need to modify the timepack_sapc.c to achieve this.
Since timer downcounts count down from 64K at the tick, you need to subtract the register value from 65536 to get the number of downcounts since last tick:1
number of downcounts since tick = 65536 - observed_count (in register)
Thus the accurate time between A and B is1
2= 202 clock ticks + (65536 – 43000) downcounts - (200 clock ticks + (65536 – 35000) downcounts)
= 2 clock ticks – 8000 downcounts
III. Timing i486 instructions and a C loop
In this part of the request you will use the timing package to time x86 instructions. Instruction execution time is measured in system clock cycles, here 2.5 nsecs for our 400Mhz Pentium systems. The PC timer 0 is accurate only in the usec (microsecond) range so you will need to loop many times and divide by the loop count to get the accuracy needed.
The actual instructions to be timed appear in loops in “itests.s”, which is an x86 assembler source. These are called from itimes.c.
Finish “itests.s”, so that the third instruction to be timed (immediate move of IDATA to register) is properly implemented. Add a fourth instruction of your choice “itests.s” and “itimes.c”
You can use the provided makefile to build an optimized version of the SAPC executable file. The provided makefile has the following definitions:1
2
3
4
5
6
7
8# development build: -g provides debugging support, slows down execution
# Use -O2 optimization, no -g on final timing runs!
PC_CFLAGS_DEV = -g -Wall -Wno-implicit -Wshadow -I$(PC_INC) -I$(TIMING)
PC_CFLAGS_OPT = -O2 -Wall -Wno-implicit -Wshadow -I$(PC_INC) -I$(TIMING)
# make default PC_CFLAGS be PC_CFLAGS_DEV
O = DEV
# allow user to override DEV via O=OPT on the command line
PC_CFLAGS = $(PC_CFLAGS_$(O))
FINAL NOTE
In the event that you are unable to correctly complete this request by the due date, do not remove the work you were able to accomplish – partial credit is always better than none.