contributed by < Herakleos >
lsmod
的輸出結果有一欄名為 Used by
,這是 "each module's use count and a list of referring modules",但如何實作出來呢?模組間的相依性和實際使用次數 (reference counting) 在 Linux 核心如何追蹤呢?
搭配閱讀 The Linux driver implementer’s API guide » Driver Basics
fibdrv.c
存在著 DEFINE_MUTEX
, mutex_trylock
, mutex_init
, mutex_unlock
, mutex_destroy
等字樣,什麼場景中會需要呢?撰寫多執行緒的 userspace 程式來測試,觀察 Linux 核心模組若沒用到 mutex,到底會發生什麼問題。嘗試撰寫使用 POSIX Thread 的程式碼來確認。The same as I mentioned in lab0-c.
Install linux-headers
package and make sure the package has been installed correctly.
After I compiled and test (make check
) the original program, instead of showing Passed [-]
, it turns out with several problems.
I am still working on this problem.
As above, something went wrong while installing kernal-modules.
After all these steps, Passed [-]
will be correctly displayed.
GRUB_CMDLINE_LINUX_DEFAULT
in /etc/default/grub
.In order not to do this step repeatly, I put this line in Makefile
.
taskset
Working on…
Replace skipped operation fib_write() to get ktime.
This will cause line diff
return make error, the script/expected.txt
should therefore be refined.
Fix the original fib_sequence(), C99 variable-length array (VLA) is not allowed in Linux kernel.
According to the article, we may calculate fibonacci number by the following formula.
After reading Calculating Fibonacci Numbers by Fast Doubling, I tried to modify fib_sequence()
as following.
By the way, the above article use a for loop to get the MSB.
__builtin_clz
and other bitwise operation to find MSBWorking on…
Use escape
(return of fib_seq_fd_clz
) to avoid the function be removed after optimization.
After add fib_sequence using fast doubling, fib_write should be modified.
To-do: statistics
Reading KYG-yaya573142
linux2022