# [2021 年暑期 Linux 核心](https://hackmd.io/@sysprog/linux2021-summer/) 第 3 週測驗題 ###### tags: `linux2021` :::info 目的: 檢驗學員對 Linux 核心 API、中斷處理和並行程式設計的認知 ::: ### 測驗 `1` 給定一個名為 `simrupt` (由 simulate 和 interrupt 二個單字組合) 的 character 裝置驅動程式,其作用是模擬 [IRQ 事件](https://www.kernel.org/doc/html/latest/core-api/genericirq.html),並展示以下 Linux 核心機制的運用: - irq - softirq - tasklet - workqueue - kernel thread - [kfifo](https://www.kernel.org/doc/htmldocs/kernel-api/kfifo.html) - [memory barrier](https://www.kernel.org/doc/Documentation/memory-barriers.txt) 測試: ```shell $ sudo insmod simrupt.ko $ sudo cat /dev/simrupt ``` 在終端機內容可見每隔 0.1 秒會出現一個字元,可按下 Ctrl-C 組合鍵離開,參考的 `dmesg` 輸出: ``` [91654.675582] simrupt: [CPU#0] produce data [91654.675616] simrupt: [CPU#0] scheduling tasklet [91654.675629] simrupt: [CPU#0] timer_handler in_irq: 48 usec [91654.675863] simrupt: [CPU#0] simrupt_tasklet_func in_softirq: 33 usec [91654.675888] simrupt: [CPU#1] simrupt_work_func [91654.826743] simrupt: [CPU#0] enter timer_handler ``` 程式碼列表可見: [simrupt.c](https://gist.github.com/jserv/08f8cfb651231043f18ce5d7a4e66477) [已遮蔽部分程式碼] 對應的 `Makefile`: ``` NAME = simrupt obj-m := $(NAME).o KDIR ?= /lib/modules/`uname -r`/build PWD := $(shell pwd) all: $(MAKE) -C $(KDIR) M=$(PWD) modules clean: $(MAKE) -C $(KDIR) M=$(PWD) clean ``` ==作答區== RRR = ? TTT = ? MMBB = ? :::success 延伸問題: 1. 解釋本核心模組運作原理,應探討對應核心子系統的行為,指出實作缺失並修正 2. 修改裝置驅動程式,提供 [poll](https://man7.org/linux/man-pages/man2/poll.2.html) 系統呼叫的支援,並探討其使用方式 3. 討論 [kfifo](https://www.kernel.org/doc/htmldocs/kernel-api/kfifo.html) 和 circular buffer 的使用是否會遭遇到並行的問題? 4. 改寫原有 `producer_lock` 和 `consumer_lock` 的使用,引入 lock-free 實作 ::: --- ### 測驗 `2`  > 取自 [WiLink8 Linux Wi-Fi Driver Release R8.8 Build User's Guide](https://www.ti.com/lit/ug/swru561a/swru561a.pdf) [vwifi.c](https://gist.github.com/jserv/44f1c9572e053f91382b868f30158056)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up