Try   HackMD

2021 年暑期 Linux 核心 第 3 週測驗題

tags: linux2021

目的: 檢驗學員對 Linux 核心 API、中斷處理和並行程式設計的認知

測驗 1

給定一個名為 simrupt (由 simulate 和 interrupt 二個單字組合) 的 character 裝置驅動程式,其作用是模擬 IRQ 事件,並展示以下 Linux 核心機制的運用:

測試:

$ 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 [已遮蔽部分程式碼]

對應的 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 = ?

延伸問題:

  1. 解釋本核心模組運作原理,應探討對應核心子系統的行為,指出實作缺失並修正
  2. 修改裝置驅動程式,提供 poll 系統呼叫的支援,並探討其使用方式
  3. 討論 kfifo 和 circular buffer 的使用是否會遭遇到並行的問題?
  4. 改寫原有 producer_lockconsumer_lock 的使用,引入 lock-free 實作

測驗 2

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

取自 WiLink8 Linux Wi-Fi Driver Release R8.8 Build
User's Guide

vwifi.c