contributed by < eastWillow
>
$ uname -a
Linux jens 6.8.0-52-generic #53~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jan 15 19:18:46 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 48 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: AuthenticAMD
Model name: AMD Ryzen 7 7800X3D 8-Core Processor
CPU family: 25
Model: 97
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
Stepping: 2
CPU max MHz: 5050.0000
CPU min MHz: 545.0000
BogoMIPS: 8399.99
針對執行順序與檢查的項目來寫作業,要把時間花在刀口上,卡超過2 天就參考同學的寫法
單獨執行檢查分數的指令scripts/driver.py -c
commit 1acccae
參考第一周作業
commit c01a625
發現 string.h 當中原來有 strdup 可以直接使用
練習都使用 $ man strdup
當記憶體無法成功配置的時候會回傳 NULL
根據前面的作業練習,要考慮這些fail 的情境
因為還有發現malloc 失敗的比例是可以設定的,代表這件事情很重要,先放在心上
commit 96d8835
想了一陣子發現一個關鍵第一個節點當作head ,必須是第二個節點以後才能使用list_entry
附上Debug 用的表達式
(element_t*)((char*)head->next - (sizeof(element_t) - sizeof(struct list_head)))
隱藏關卡,這一題沒有寫qtest 會跳錯誤
ERROR: Freed queue, but 1 blocks are still allocated
參考 q_insert_head
參考 q_remove_head, 因為是circular linkage list, 直接使用 head->prev
[n / 2]th node from the start using 0-based indexing
驗算一下公式
$ man strcmp
strcmp, strncmp - compare two strings
int strcmp(const char *s1, const char *s2);
• 0, if the s1 and s2 are equal;
• a negative value if s1 is less than s2;
• a positive value if s1 is greater than s2.
descending order is : 5, 4, 3, 2, 1
排列演算法先直接使用第一周作業
2025 年春季「Linux 核心設計」第 1 週測驗題
附上當時寫隨堂測驗的心得 第一週: 誠實面對自己
這裡傳入的list_head *head
是 &chain.head
,所以看物件的角度要換成chain
(queue_contex_t*)((char*)head->next - (sizeof(queue_contex_t) - sizeof(struct queue_chain_t)))
queue_contex_t *node = list_entry(head->next, queue_contex_t, chain);
拿到第一個queue
list_is_singular(&node->chain) 才是代表第一個queue 的head_list *head
參考 2025 年 Linux 核心設計課程作業 —— lab0 (E)
你所不知道的 C 語言: linked list 和非連續記憶體
參考 Linux 核心原始程式碼的 lib/list_sort.c 當中的Merge
需要注意 sort stability 排序的穩定與不穩定
因為卡住超過三天,研究一下其他同學的寫法
https://hackmd.io/@Charlie1123/linux2025-homework1 merge 的寫法最接近教材
取得第一個 a list
(element_t*)((char*)a->next - (sizeof(element_t) - sizeof(struct list_head)))
取得第二個 b list
(element_t*)((char*)b->next - (sizeof(element_t) - sizeof(struct list_head)))
如果有人想要使用vscode + gdb 可以參考以下這一部的設定,剩下使用vscode 的預設就可以了
"program": "${workspaceFolder}/qtest",
"args": [
"-v",
"3",
"-f",
"traces/trace-03-ops.cmd"
],
"cwd": "${workspaceFolder}",
改用 list_is_singular