This project aims to design and implement a CPU profiling tool. The tool will be developed as a single kernel module that, when loaded, tracks statistics for each task on the system, such as total CPU time and the number of times a task is scheduled in and out. The module will display profiling results using the proc
file system. This project is divided into two parts (A6
and A7
) but will use and update the same kernel module code created in Part 1 (A6
).
[40 points] In part 1, you will design a kernel module that counts how many times a task has been scheduled onto the CPU. To achieve this, you will use Kprobes
, a debugging tool in the Linux kernel that allows you to break at any kernel address. Kprobes
can be configured to trigger when a specific function is executed, transferring control to an event handler routine.
[10 points] The results of the profiler tool should be displayed using the /proc file system. The first step is to create a /proc file for the profiler.
Tasks:
perftop
;perftop
should create a /proc file named perftop
;cat /proc/perftop
should display "Hello World".Deliverables:
perftop
kernel module;cat /proc/perftop
;[15 points] Next, we will count the number of times the proc file we created in Part 1.1 (i.e., /proc/perftop
) is opened using Kprobes
.
Tasks:
Kprobes
;Kprobes
should call an event handler every time cat /proc/perftop
is invoked;cat /proc/perftop
.Deliverables:
perftop
kernel module;cat /proc/perftop
3 times;[15 points] Next, we will count the times a PID has been scheduled. This will now track all PIDs on your Linux system.
Tasks:
Kprobes
hook on pick_next_task_fair
function;task_struct
;task_struct
, extract the associated PID of the task;open
function of the proc file to print (with cat /proc/perftop
) the PIDs and their corresponding values (the number of times that PID was scheduled).Deliverables:
perftop
modulecat /proc/perftop