Linux Kernel Programming
This is the home page for the "Linux Kernel Programming" course.
Here, you will find (in a badly-organised form) all the
material, slides, and information needed to attend the course
For the previous editions of the "Kernel Programming" course, check the old websites: 2018 and 2019.
Lessons:
This is a tentative schedule for the course:
- First lesson: 2020/10/12, 9:30 -> 12:00
- Introduction to the course: why kernel programming is "special", ...
- Introduction to the Linux kernel.
Bring your laptop with you, we will compile a kernel,
and maybe test a simple "hello world" in kernel land!
- Second lesson: 2020/10/19, 9:30 -> 12:00 (video of the
second part of the lesson, in italian)
- Third lesson: 2020/10/26, 9:30 -> 12:00 (videos of the
first part,
second part and
third part
of the lesson, in italian)
- Fourth lesson: 2020/11/09, 9:30 -> 12:00 (videos of the
first part and
second part
of the lesson, in italian)
- Blocking a task, again
- Competitive synchronization vs cooperative synchronization
- Examples about mutexes and "handmade" cooperative synchronization
- Interruptible sleep and signal handling
- Fifth lesson: 2020/11/16, 9:30 -> 12:00 (videos of the
first part,
second part, and
third part
of the lesson, in italian)
- Sixth lesson: 2020/11/23, 9:30 -> 12:00 (videos of the first part and second part of the lesson, in italian)
- Seventh lesson: 2020/11/30, 9:30 -> 12:00 (videos of the first part and second part of the lesson, in italian)
- Again on kernel threads: example mixing kernel threads and devices
- Mutex debugging with lockdep
- The CPU scheduler
- Eighth lesson: 2020/12/07, 9:30 -> 12:00 (videos of the first part and second part of the lesson, in italian)
Slides:
More Information:
This is some documentation about
the programming interface provided by the Linux kernel.
And here are
few notes about kernel memory allocation flags.
Some more details about the allocator can be found
here
(for the curious).
Experiments:
Project Ideas:
Here are some ideas for possible projects for the exam.
Of course, if you already have some idea for a project, we can discuss about it (these ideas are just suggestions)
Keep in mind that some projects are more complex than others and
remember to contact me before starting to work on a project,
so that I can send you some clarifications and details.
- Write some kind of module implementing kernel-space/user-space
communication through a misc device and synchronizing user-space
processes and threads. For example, you can extend the example
showed during the lessons, to implement synchronous communication
(a "write" operation blocks until the whole data has been received
by a "read" operation).
Or you can implement some mechanism to direct the data to specific
processes, maybe using capabilities (see
https://www.slideshare.net/mdecky/ipc-in-microkernel-systems-capabilities
around slide 10. Or you can implement some kind of security mechanism in the message-passing module
- Implement a module creating a "periodic device": one ore more
processes or thread can open the device, select a period (by
writing to the device or using an ioctl()), and sleep periodically
on the device (for example, by reading data from it: when a read()
is performed on the device, the caller is blocked until the beginning
of the next period --- the period size is set as mentioned above)
- Improvement: when a task sets its period (by writing on the
device, or something else) its priority is automatically set
according to RM
- Implement a "cyclic executive" scheduling module: a static schedule
(specifying when to schedule some tasks, and specifying the task ID
for each task) can be set by writing to a misc device, then when the
schedule is started the module will schedule/deschedule each thread
at the right time
- Run some experiments with the
threaded NAPI patchset
and virtio network devices (measuring the network performance with
and without the patchset). Optionally, try to use the IRQ threads
as NAPI threads when threaded interrupt handlers are used
(see the "threadirqs"
kernel boot parameter)