# Demystifying the Linux CPU Scheduler
## 1. Basic of the Linux Kernel
### 1.1 Operating Systems
Page 2
:::danger
:radioactive_sign: one could start to wonder ~~what is the actual responsibility of operating systems~~.
:+1: one could start to wonder **what the actual responsibility of operating systems is**.
:::
:::warning
:-1: we first load in the OS kernel at boot time and then bring in the application software afterward.
:+1: **We should have the OS kernel loaded into the DRAM at boot time (by boot loader), and make CPU jump to the first instruction of it for execution (arch/arm64/kernel/head.S). Finally, the kernel will bring the application software to the world (EL1 --> EL0).**
:::
:::warning
:-1: In fact, to ensure reliable interactions between hardware ...
:+1: In fact, to ensure **the** reliable interactions between hardware ...
:::
:::warning
:-1: The concept of computation isolation, which serves to prevent ~~undesired~~ interactions while still supporting necessary interactions, has a long-standing heritage.
:+1: **The concept of computation isolation has a long-standing heritage in supporting necessary interactions while preventing *undesirable* ones.**
:::
Page 3
:::warning
:-1: The kernel has to fulfill the requests for resources in an exact order to provide an abstraction for cooperation from multiple upper-layer applications, exploiting the computing resources.
:+1: **The kernel has to fulfill the requests for the resources in an exact order by exploiting the computing resources to provide an abstraction for the cooperation from multiple upper-layer applications.**
:::
<br/>
### 1.2 A general overview
Page 3
:::warning
:-1: it is necessary to grant the kernel the full access privilege to all hardware resources ...
:+1: it is necessary to grant **kernel the privilege of the full access** to all hardware resources ...
:::
:::warning
:-1: the operating system seeks a protection mechanism to fulfill the stability and security needs of the whole system, separating the design into the kernel and user application codes.
:+1: the operating system seeks a protection mechanism **by separating *the codes between kernel design and user application* to fulfill the stability and security needs *for* the whole system**.
:::
:::warning
:-1: While, in practice, ...
:+1: **In practice,** depending on the configuration settings at compile time, ...
:::
:::warning
:-1: Such a memory partitioning mechanism ensures that the kernel data and user data do not interfere with each other.
:+1: Such a memory partitioning mechanism ensures that **the data between kernel space and user space** do not interfere with each other.
:::
Page 4
:::warning
:-1: Also, it is a security measure to protect the entire system from a malfunctioning or malicious user program.
:+1: **Moreover**, it is a security measure ...
:::
#### 1.2.1 System calls
Page 6
:::warning
:-1: The process execution is suspended and the control passes to the kernel (kernel mode), which will look up the entry 128 in the interrupt vector table.
:+1: The process execution is suspended and the control passes to the kernel (kernel mode) **for looking up the entry 128 in the interrupt vector table**.
:::
#### 1.2.2 File systems
Page 7
:::warning
:-1: Nevertheless, a limited number of writable files exist, which permit modifications to the kernel variables.
:+1: **While** a substantial portion of the files within this filesystem exhibit read-only properties, **a limited number of writable files exist for kernel modifications.**
:::
:::warning
:-1: The directory /proc/sys houses several writable files that corresponds to kernel variables, allowing for direct modification by writing to them or through utilization of the sysctl utility.
:+1: The directory /proc/sys houses several writable files **for** kernel variables, **and direct modification is allowed either by writing to them or through the sysctl utility.**
:::
#### 1.2.3 A different kind of software
Page 8
:::warning
:-1: it is shown an example of code where the panic() rotine is called.
:+1: **An exmple of code is shown for how the panic() routine is called.**
:::
:::danger
:radioactive_sign: printk() is also able to reliably handle~~s~~ concurrent writes from different cores,...
:+1: printk() is also able to reliably **handle** concurrent writes from different cores,...
:::
Page 10
:::warning
:-1: the answer is straightforward: first, to use a small amount of kernel memory, and secondly, because of fragmentation.
:+1: the answer is straightforward: **one reason is to use a small amount of kernel memory, and the other is to avoid fragmentation.**
:::
Page 11
:::danger
:radioactive_sign: , and communication between the servers, applications, and the kernel ~~rely~~ on message passing.
:+1: , and **the** communication **among** the servers, applications, and the kernel **relies** on message passing.
:::
## 2. The Linux CPU scheduler
## 3.
## 4.
## 5.
## 6. Tracing with ftrace
Page 176
:::warning
:-1: Also, it is a great educational tool, not just to peek at what happends in the kernel, but also to help approach the source code by observing the function flow.
:+1:
:::
:::warning
:-1: To understand what they do and why they are useful, it is necessary to understand ftrace, which is the tool that uses them.
:+1:
:::
### 6.1 How does it work?
### 6.2 Enable the kernel tracing infrastructure
### 6.3 Interfacing with ftace
page 180
:::danger
:radioactive_sign: Tracing necessitates an extremely lightweight mechanism, as it is ~~common~~ used to monitor events that occur frequently.
:+1: Tracing necessitates an extremely lightweight mechanism, as it is **commonly** used to monitor events that occur frequently.
:::
:::warning
:-1: the ftrace output, which is produced from the kernel, is read from user space.
:+1: **the ftace output produced in the kernel is read from user space**.
:::
:::warning
:-1: tracefs is a specialized filesystem that resides in another filesystem sysfs, which contains files and directories to interact with ftrace.
:+1: tracefs is a specialized filesystem that resides in another filesystem sysfs, **and it contains files and directories to interact with ftrace**.
:::
:::warning
:-1: The purpose of some of these files is not to set options. Rather, it is to list available options.
:+1: **Instead of setting options to those files, some of those files are only to list available options.**
:::
### 6.4 Ftrace usage
#### 6.4.1 Function tracing