Homework 2 - Running and Measuring software on OpenMSP430
- Introduction
- Using the Timer Module
- Question 1 (6 points)
- Question 2 (6 points)
- Question 3 (8 points)
- What to turn in
Introduction
Homework 2 implements the MSP-430 on your DE1-SoC kit, and runs a sample application to evaluate its performance. You have to pick up a DE1-SoC kit before you can start solving the homework.
Also, before you start with this assignment, familiarize yourself with the (example-openmsp430de)[https://github.com/vt-ece4530-f19/example-openmsp430de] application discussed in lecture 4. Make sure that you have complete all the steps described in the lecture, including the following.
- Compiling the msp430de1soc hardware platform
- Compiler the demode1soc software example
- Downloading the hardware bitstream and the software binary to a DE1-SoC board
- Connecting a MobaXterm application while the application is running, and observing a data stream printed on the User UART of the msp430de1soc platform
After you are able to complete these four steps, download the homework assignment.
- Browse to github.com and accept the homework assignment 2 from github classroom.
- Download the homework.
git clone https://github.com/vt-ece4530-f17/hw1-ece4530-f17-user
Using the Timer Module
In this homework, we will use the timer peripheral to measure the execution time of MSP430 software on the DE1SoC board. Precise measurement of performance is crucial to make proper decisions on hardware/software partitioning, design of hardware accelerators, and so forth.
The timer module is compatible with the MSP430 module; the details of the programming model are explained in the MSP430x1x Family Users Guide. Chapter 11 explains the details of the TimerA module used in this design.
After you have configured the MSP430 hardware onto the FPGA board, create a new software application in a directory timerperf
, parallel to demode1soc
. You will need a main C file (given), a linker description file, and a makefile
. You can use the other software applications as an example. A copy of the main.c
you should use is shown below. There’s also a copy of this file located in the top-level directory of your homework 2 repository.
#include "omsp_de1soc.h"
char c16[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void puthex(unsigned k) {
putchar(c16[((k>>12) & 0xF)]);
putchar(c16[((k>>8 ) & 0xF)]);
putchar(c16[((k>>4 ) & 0xF)]);
putchar(c16[((k ) & 0xF)]);
}
unsigned count = 0;
unsigned TimerLap() {
unsigned lap;
TACTL &= ~(MC1 | MC0);
lap = TAR - count;
count = TAR;
TACTL |= MC1;
return lap;
}
unsigned euclid(unsigned a, unsigned b) {
while (a != b) {
if (a > b)
a = a - b;
else
b = b - a;
}
return a;
}
int main(void) {
int i, j, k;
int c = 0;
TACTL |= (TASSEL1 | MC1 | TACLR);
de1soc_init();
while (1) {
for (i=1; i<4096; i++) {
for (j=1; j<=4096; j++) {
TimerLap();
c += euclid(i, j);
k = TimerLap();
de1soc_hexlo(i);
puthex(i);
putchar(' ');
puthex(j);
putchar(' ');
puthex(k);
putchar('\n');
putchar('\r');
long_delay(100);
}
}
}
LPM0;
return 0;
}
Let’s analyze what this program does.
It programs the timer TACTL
to run continuously, clocked from the internal 50MHz clock. The program then computes the function euclid
, which takes two
arguments, for every combination of arguments between 1 and 4096. For each call to euclid
the program measures the cycle count, and it prints out
the cycle count on the console. In addition, it also displays
the outer loop counter i
in the HEX display, so that you get an idea how
far the program is along.
On the console, you will see a long list of numbers appear which
show the arguments i
and j
, and the cycle count to execute {\tt euclid}.
The first few entries of that list are shown below.
0001 000C 0084
0001 000D 008E
0001 000E 0098
0001 000F 00A2
0001 0010 00AC
0001 0011 00B6
0001 0012 00C0
0001 0013 00CA
...
To understand the principle of timing measurement, refer to the class notes of Lecture 5. In a nutshell, to measure the execution time of a piece of code, one would call:
TimerLap();
Run the code that needs to be measured;
Time = TimerLap();
Question 1 (6 points)
You can answer the following question by making changes to the initial program and running experiments. You have to write up your findings in a PDF (homework2-user.pdf where user is replaced by your github username), which you will include in the root of your homework repository.
Question 1 is as follows. Find the combination of arguments that lead to either the
largest execution time of euclid
. That is, find all pairs (i, j)
, for which the
execution time of euclid
is the largest possible execution time for
all combinations of 1 <= i, j < 1024
. Keep in mind that calling TimerLap()
comes with overhead. Your answer needs to eliminate this overhead.
You can write up your answer in a PDF, which will be
part of your application homework2sw
. Your answer to this question
should contain at least all the pairs (i,j)
with maximum execution time,
along with the exact cycle count to execute euclid
for these arguments.
In addition, explain your measurement methodology. You can add example code
inside of the PDF.
Question 2 (6 points)
You can answer the following question by making changes to the initial program and running experiments. You have to write up your findings in a PDF (homework2-user.pdf where user is replaced by your github username), which you will include in the root of your homework repository. You can add your answer to Question 2 under the answer to Question 1.
Question2 is as follows. Assume that argument i
from euclid(i,j)
is hardwired to 1. Find the value of j
that will cause almost timer overflow, ie. that will cause
euclid(1,j+1)
to require more than 65535 cycles. The value of j
must be chosen such that euclid(1,j)
does not cause timer overflow, while euclid(1,j+1)
does cause timer overflow.
Your answer to this question should contain the value of j
. In addition, you should explain your measurement methodology. You can add example code inside of the PDF
Question 3 (8 points)
You can answer the following question by making changes to the initial program and running experiments. You have to write up your findings in a PDF (homework2-user.pdf where user is replaced by your github username), which you will include in the root of your homework repository. You can add your answer to Question 2 under the answer to Question 2.
Find the time for a call to euclid
that makes exactly four iterations.
That is, if we would enumerate the C statements
in euclid
, we would see:
main
function callseuclid
while (a != b)
evaluates true, if-statement executes.while (a != b)
evaluates true, if-statement executes.while (a != b)
evaluates true, if-statement executes.while (a != b)
evaluates false,euclid
terminates.
Your answer to this question
should contain the value of the pair (i,j)
with this desired behavior, along
with the number of clock cycles it takes to execute this combination. In addition, you should explain your measurement methodology. You can add example code inside of the PDF.
What to turn in
-
When you are done, add the
homework2-user.pdf
to your root repository for this homework, commit the changes and push the result back to github -
Also, push back the modified
openmsp430de
repository that you used for your experiments. In case of doubt on your answers inhomework2-user.pdf
, we may still refer to this repository. -
Note that the timestamp of the git push on github counts as your Homework turn-in time.
git commit -m 'Homework 2 result'
git push
Good Luck!