contributed by < Julian-Chu >
linux2021
LKM: Linux Loadable Kernel Module
dev_read
test_xoro.cc
重點: uint64_t 與 char * 的互換, bit operation, little endian
q1: Test reading different numbers of bytes 設計的使用場景?
你可嘗試用
uintptr_t
(C99 規範)
jservImage Not Showing Possible ReasonsLearn More →
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
make check
: run check and plot
main.c
next()回傳 uint64, 使用 cmpint 比較 uint64 會導致排序錯誤, 新增 cmpuint64
在 dev_read 內部利用 next() 產生待排序資料, 利用 cmpuint64 跟 sort_impl 進行排序, 量測排序時間並檢驗排序結果
對 LKM 新增 write 方法回傳量測時間
test_xoro.c
更動 test_xoro.c
, 由於用到 write, 需要設定 fd 可寫入, 將原本的 O_RDONLY
改為 O_RDWR
, 使用 write 回傳資料
記得 read/write 回傳都要 error check, 善用 errno
提高 debug 效率
跑 10 次的結果
修改 sort.h 使之可以被使用在 Linux 核心,移除 C 標準函式庫和執行環境的依賴,改用 Linux 核心內建的 API。
整合後發現排序錯誤, 原因是使用 demo 裡面的定義給 int 的 SORT_CMP 會導致 uint 的情況錯誤, (x-y) 不會小於零, 使用預設 SORT_CMP 即可修正
改寫 dev_read
讓回傳時間可以透過 copy_to_user
回傳
todo: 利用 preprocessor 與 goto 簡化程式碼
排序 100 筆資料
排序 1000 筆資料
排序 1500 筆資料
嘗試排序 2000 筆資料以上會發生 page fault 錯誤, 找問題中
q: 除了 dmesg, 在 kernel debug 的技巧?
透過 UML 搭配 GDB 來除錯!
jservImage Not Showing Possible ReasonsLearn More →
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
sort.h 遇到的 static analysis issue, 新增下列的 cppcheck arguments 暫時忽略。