Lab 3 consists of two sections. Both use C/C++ as the programming language. In section 1, you will use the performance analyzing tool perf to measure the cache miss rate of your program. In section 2, you will practice how to directly manipulate GPIO registers from Raspberry Pi OS. Please refer to the lab slides and video for more details.
Section 1 (50%): Monitor Cache Misses of Your Code
Please write C/C++ code to multiple two N by N matrices. Please follow the (element data type, matrix size) specified in the table below to
1. Test your program with randomly generated matrices and analyze the cache misses using perf. Record the runtime (s) and L1 data cache miss rate (%) of your program for each test. Fill the table with your measurements.
2. Is the cache miss rate of your implementation < 0.1%? If not, can you meet this constraint by optimizing your code? (Hint: try swapping the order of your loops)
| Configuration | int, N=256 | int, N=512 | int, N=1024 |
| Runtime (s) | |||
| Cache miss rate (%) |
You can use:
1. malloc() to allocate memory blocks.
2. rand() to generate random numbers and then cast to your desired data type.
3. clock() for runtime measurement. You may need to take average from multiple tries.
Section 2 (50%): Direct GPIO Access on Raspberry Pi OS (50%)
Please write C/C++ code to directly manipulate GPIO registers from Raspberry Pi OS (Raspbian).
For security reasons, the operating system itself does not provide direct access to the physical memory and users are basically doing all their work on the virtual memory. You need to use mmap() and the device file dev/mem to create a mapping from virtual memory (user space) to physical memory (GPIO registers), such that you will be able to manipulate GPIO registers through your program.
To debug and demonstrate your code, you could control the GPIO pins to generate some waveform (e.g. square wave) and use the multimeter or the oscilloscope to verify your configuration. You need to explain your code to the TA.
1. You can find the physical address of GPIO registers and how to control them in this manual.
2. You can quickly check GPIO pinouts in this website.
3. If you don't know where to start, please read and try to understand the code samples here with the above materials.