Assignment 6: Design and Implement a CPU Profiler (Part 1)

Introduction

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).

Recommended Background Reading

Part 1: Counting per task scheduling

[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.

Part 1.1. Setup procfs

[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:

Deliverables:

Part 1.2. Setup Kprobes

[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:

Deliverables:

Part 1.3. Count the number of times a PID is scheduled in

[15 points] Next, we will count the times a PID has been scheduled. This will now track all PIDs on your Linux system.

Tasks:

Deliverables: