[xv6 學習紀錄 07-1] Thread Switching
課程影片連結: 6.S081 Fall 2020 Lecture 11: Thread Switching thread 的目標與手段 我們希望 multi-threading,是因為希望可以有多個 thread 去分享同一個 CPU,在 xv6 中,是以「過了一段時間換人使用」作為 thread switching 的依據。在這個目標之下,我們可以來思考以下幾件事情: 什麼是「(該換人 (thread) 使用 CPU) 的時間到了」 我們需要 save/restore 哪些關於 thread 的資訊 完整的流程該如何實做 1. 什麼是「(該換人 (thread) 使用 CPU) 的時間到了」? kernel/trap.c: usertrap(): void usertrap(void) { // [...] // give up the CPU if this is a timer interrupt. if(which_dev == 2) yield(); usertrapret(); } 在 usertrap() 中,如果是遇到 timer interrupt,則會進入到 yield(),進去之後會進入後續 thread switching 的處理 ...