Lab 5: CPU frequency control over Raspberry Pi

- 6% of your final grade.

- Individual lab, not a team lab. Collaboration is not allowed.

- Comply with Academic Integrity of University of Pittsburgh. Similar lab assignments are found, zero for the lab score will be applied to every student involved!

 

Lab 5 consists of 2 sections.

Section 1: Manipulating CPU frequencies on Raspberry Pi (45%)

In this section, you will use the sysfs pseudo-filesystem to interact with the Linux kernel and manipulate Raspberry Pi CPU frequencies on the fly.

 

Hint: For more information about the sysfs pseudo-filesystem, please refer to the manual page: sysfs(5) (http://man7.org/linux/man-pages/man5/sysfs.5.html).

 

1.       Use the information provided by sysfs to find out the available CPU frequencies allowed by the hardware. How many logical cores are there on your Raspberry Pi? What is the maximum CPU frequency supported by your Raspberry Pi? What about the minimum frequency supported?

2.       Use the information provided by sysfs to find out the available CPU frequency governors on your system. What are the meanings of those governors? How will they affect the CPU frequencies? Please try with the following governors: "performance", "powersave" and "ondemand" and demonstrate how they impact the CPU frequency under different workload.

3.       Use the interfaces provided by sysfs to set your Raspberry Pi to be running at certain CPU frequency. Specifically, please demonstrate that you may lock the CPU frequency to either the maximum frequency or the minimum frequency.

4.       Show that the same amount of workload takes different amount of time to finish under different CPU frequencies. An example workload is provided as below.

 

int main() {

int result = 0; const long int repeating_time = 500000000;

for (long int i = 0; i < repeating_time; i++) {

       if (result > 1000) { result -= 1; } else { result += 1; }}

return 0;

}

Section 2: Implementing custom userspace CPU frequency governor (55%)

In this section, you will implement a customized userspace CPU frequency governor.

1.       Please read through the description part of a Linux kernel patch email at https://lkml.org/lkml/2016/3/17/420 carefully and understand how the newly-added "schedutil" frequency scaling governor initially works. We will mimic their way of using CPU utilization information as input for making CPU frequency decisions, except that everything happen in userspace rather than kernel space.

2.       Assume that the CPU utilization information provided by the Raspberry Pi is frequency-invariant. The coefficient we use is the same as described in the lkml email.

3.       Implement a custom userspace CPU frequency governor by specifying the "userspace" mode governor in sysfs and keep your program running in the background. Your userspace governor should periodically read system CPU utilization information and calculate the next_freq value based on that. To set the desired frequency, find out the nearest available CPU frequency as allowed by your Raspberry Pi and use the interfaces provided by sysfs to set the frequency.

4.       Enable your custom CPU frequency governor on Raspberry Pi and test it with different workloads.

 

HINTS:

- You may use the programming language of your choice to implement your userspace CPU frequency governor.

- Your governor program must be run with privilege.

- Due to the limitation of Raspberry Pi, you cannot individually set different CPU frequencies for different cores. Please find out the highest CPU utilization across all cores and use this certain value to calculate the desired CPU frequency.

- You should make the CPU utilization collection interval no longer than 1 second to ensure that the real-time property of the governor holds.

Work submission

Ask the TA to check you off after you finish and submit your code for section 2 to the TA.