Hobbits give presents to other people on their own birthdays. Not very expensive ones, as a rule, but it was not a bad system. Actually in Hobbiton and Bywater every day in the year it was somebody's birthday, so that every hobbit in those parts had a fair chance of at least one present at least once a week.
—The Fellowship of the Ring, Book 1, Chapter 1
Linux's CFS strives to be completely fair, meaning that all processes should recieve an appropriately weighted proportion of the processor time. In particular, if there are a total of N processes in the system, then (if they have the same nice values) all processes will ideally recieve exactly 1/Nth of the processor time. In this studio we will explore the CFS from user space.
In this studio, you will:
Please complete the required exercises below, as well as any optional enrichment exercises that you wish to complete.
As you work through these exercises, please record your answers, and when finished email your results to email@example.com with the phrase CFS Studio in the subject line.
Make sure that the name of each person who worked on these exercises is listed in the first answer, and make sure you number each of your responses so it is easy to match your responses with each exercise.
/proc/sys/kernel/sched_autogroup_enabledfrom 1 to 0 on your Raspberry Pi. To do that, first log into your Raspberry Pi and obtain a root terminal (
sudo bash) in order to have permission to modify the value.
Show the current value of that file using the
then modify the file's value
echo 0 > /proc/sys/kernel/sched_autogroup_enabled
and then show the file's new value
and then exit the root terminal. As the answer to this exercise please show the terminal output with the previous and new values of that file.
while(1)loop, but we want a little control over where this task executes. To do this, we will use Linux's processor affinities.
For this exercise, write a infinite-loop program that takes a single integer argument
from the command line, which gives the processor that the program should execute upon.
In order to control where your process is allowed to run, use the function
sched_setaffinity(). You will need to specify
the set of allowable CPUs with a variable of type
order to manipulate this data type you should use the functions documented in
man CPU_SET. This is a nonstandard extension, so your program will
#define _GNU_SOURCE before
Hint: make sure to use
cpu_set_t variable, before setting the
processor on which you wish it to run.
trace-cmd commands to
verify that your program runs continuously on a processor of your
choosing, and as the answer to this exercise please show the output
that confirms this is working correctly.
While those are running, run a few tasks of your own choosing (text editing, internet
browsing, etc.), and notice how well the system responds. Then use
in each of the background workload windows to stop the task in each one, and see how
well the system runs without the background workload running.
As the answer to this question, describe briefly how well the system responded when the background tasks were running, versus when they were not.
dense_mmprogram from previous studios to examine the behavior of CPU-bound tasks on a heavily loaded system. First, use the command
time ./dense_mm 300to get a rough measure of program execution time on a quiet system. Now, restart the background tasks and run the same command again.
As the answer to this exercise, copy and paste the output from each run of
time ./dense_mm 300.
usertimings. As the answer to this exercise, answer the following questions: what does the previous exercise tell you about the way that two CPU-bound tasks share a processors under the default Linux scheduler (CFS)? What do you predict will happen to the
dense_mm 300if you were to increase the number of background tasks?
The following tips may be helpful, so you don't have to deal with myriad terminal windows. You can detach a command from the terminal by executing it
with an ampersand (&) at the end. Also, you can kill all tasks matching a
a certain string with the
pkill command. For example, if I named
my infinite loop task
while, then I could create multiple tasks
on processor zero with the command
./while 0 &. When I was
done, I could kill all outstanding tasks with the command
Then, execute the command
time ./dense_mm 300 and as the answer to
this exercise show the results and explain briefly whether or not they support your
prediction, and why they do or do not.
nicepriorities can influence the proportion of time a task recieves. Run the command
time sudo nice -n -20 ./dense_mm 300. As the answer to this exercise, say what proportion of time (
real) the task recieved.
CTRL-C. Compute their runtime proportions, and list those as the answer to this exercise.