contributed by < SmallHanley
>
參照 Linux 核心模組掛載機制,解釋 $ sudo insmod khttpd.ko port=1999
這命令是如何讓 port=1999
傳遞到核心,作為核心模組初始化的參數呢?
過程中也會參照到 你所不知道的 C 語言:連結器和執行檔資訊
參考 lkmpg 4.5 Passing Command Line Arguments to a Module,我們可以從 command line 傳入參數到核心模組。將欲接收傳入值的變數宣告成全域變數,並使用 module_param()
macro (另外還有 module_param_array()
、module_param_string()
)。而 module_param()
macro 是宣告在 include/linux/moduleparam.h:
其中 param_check_##type()
會根據 type
展開成以下獨一無二名字的函式:
而 __always_unused
include 至 include/linux/compiler_attributes.h,展開後是 __attribute__((__unused__))
,參考 Common-Function-Attributes 的 unused
attribute。
This attribute, attached to a function, means that the function is meant to be possibly unused. GCC does not produce a warning for this function.
使得程式可以在編譯時期檢查 type 是否為規範的 type。
接著,以下是 module_param_cb()
的展開:
如果要方便觀察展開內容,可以使用 gcc toolchain 讓 gcc 命令執行到前置處理器結束,尚未進入編譯階段 (使用 -E
flag):
TODO
參考 Linux 核心模組掛載機制,使用 strace
追蹤 insmod
的系統呼叫:
若是傳入多個參數:
參照 CS:APP 第 11 章,給定的 kHTTPd 和書中的 web 伺服器有哪些流程是一致?又有什麼是你認為 kHTTPd 可改進的部分?
htstress.c
用到 epoll 系統呼叫,其作用為何?這樣的 HTTP 效能分析工具原理為何?
給定的 kecho
已使用 CMWQ,請陳述其優勢和用法
核心文件 Concurrency Managed Workqueue (cmwq) 提到 "The original create_*
workqueue() functions are deprecated and scheduled for removal",請參閱 Linux 核心的 git log (不要用 Google 搜尋!),揣摩 Linux 核心開發者的考量
解釋 user-echo-server
運作原理,特別是 epoll 系統呼叫的使用
是否理解 bench
原理,能否比較 kecho
和 user-echo-server
表現?佐以製圖
解釋 drop-tcp-socket
核心模組運作原理。TIME-WAIT
sockets 又是什麼?