---
# System prepended metadata

title: 2025q1 Homework1 (ideas)

---

# 2025q1 Homework1 (ideas)
contributed by < `SimonLiu423` >

## 還政於民的 sched_ext 及機器學習如何幫助 CPU 排程
> [Link](https://hackmd.io/@sysprog/BJdyxvxX0)

### About
#### CPU scheduling
- schedulable unit: task(sched_entity)
- tasks are run by CPU
- scheduler pick tests & most suitable CPU to run

#### CPU Load Balancing
- Distribute tasks evenly over CPUs.
- Make overall processing more efficient
- Optimize response time

#### SCX (scheduler extension and tools)
![image](https://hackmd.io/_uploads/rJFZqQnjye.png)
- eBPF to kernel is like JS to HTML
- SCX exposes interface for users to implement BPF scheduler
- **Speeds up experiments** of scheduling policies
- **Customization**
- **Rapid scheduler deployment**


#### Integrate ML into CPU scheduler
- collect data via **kprobe**
- use ML to determine whether to perform task migration or not (`can_migrate_task()` in Linux Kernel)

##### Experiment for integrating to SCX
- Create load imbalance with mixtures of CPU-bound tasks and I/O-bound tasks
- CPU-bound task: linux kernel compilation
- I/O-bound task: fio disk I/O task


### Questions
- The experiment only shows that using ML for load balancing is effective when there's a highly CPU intensive task and a I/O intensive task. But what about other cases?

---

## 高性能網頁伺服器
### About
kHTTPd uses kernel thread to process connections, a new thread is created for each time a new connection occurs. 
When there's a large amount of connections, it would spend a lot of time creating threads. 

#### CMWQ (Concurrency Managed Workqueue)
- Threads are created beforehand
- Assign tasks to threads directly

#### Content Cache
- Uses RCU
- calculate hash for request url and store in hash table

#### Introduce timer to cleanup timeout connections
- Implemented with priority queue
- Constantly check the queue using another thread and delete timed out connections
- uses spinlock

---

## 打造具備網路連線的精簡虛擬機器
### About
- System VM
    - Need to run OS
    - Need virtualization for hardware
- Process VM
    - Runs program (e.g. Java VM)
- Hypervisor
    - Type-1
        - Can access hardware directly
    - Type-2
        - An application running on OS
        - Less efficient than Type-1
- KVM (Kernel-based Virtual Machine)
    - Make kernel serve as Hypervisor

- KVM-Host
    - based on KVM
    - simple
    - no network connection

- VirtIO
    - virtualization standard
    - PCI device
    - Virtqueue

---

## 開發無線網路裝置驅動程式
