xv6

@xv6

Public team

Joined on Dec 5, 2022

  • ip of xv6: 10.0.2.15 ip of host: 10.0.2.2 這個 lab 要我們完成 e1000_transmit() 和 e1000_recv() trace code 檔案介紹: kernel/e1000.c: init, transmiting, receving kernel/e1000_dev.h: registers and flag by E1000 manual
     Like  Bookmark
  • Uthread: switching between threads user/uthread.c: 定義 context: struct context { uint64 ra; uint64 sp; // callee-saved uint64 s0;
     Like  Bookmark
  • 題目的意圖 fork() 時會把整個 page table 也複製給 child, 但是大多數時候,child 並不會使用這個 page table 常常都是在 fork() 去執行 exec() 這時 exec() 又會把原本的 page table 蓋掉, 這樣太浪費 physical memory 了, 比較好的作法是:fork() 時先讓 parent 跟 child 都指向同樣的 pa , 直到要寫入時,才真正的把 physical memory 的內容複製一份 大致上的流程: fork() 使用 uvmcopy() 把 page table 複製過去在這個 lab 中,我們希望 fork() 後 child 跟 parent 的 page table 都是 map 到相同的 pa 現在的 uvmcopy() 就是把 old 的東西複製到 new
     Like  Bookmark
  • 在處理 page fault 時,我們需要注意的幾件事情 stval: 造成 page fault 的 virtual memory sepc: 造成 page fault 的 program counter instruction: 當下是正在執行什麼 instruction (?) registers stval: va cause page fault scause: the type of faultRead Write Instruction
     Like  Bookmark
  • lab: Traps 一些跟這個 lab 有關的 register Table 4.2 Table 3.7 Figure 4.12 程式碼解析 yeild() yeild() 讓 myproc() 的 state 變成 RUNNABLE
     Like  Bookmark
  • lab pgtbl 大綱 xv6 的 virtual memory 1.1 terms about virtual memory 1.2 virtual memory in xv6 1.3 xv6 中 關於 virtual memory 的程式碼 lab 2.1 Speed up system calls 2.2 Print a page table
     Like 1 Bookmark
  • 6.1810 的課程網址 本文紀錄課程中的作業 Lab: system calls 的解題過程 關於 xv6 的環境架設,可以參考 [MIT-6.S081-2020] OS課程----Xv6作業系統的環境架設 ,但是在這篇文章裡,將會使用 2022 年的版本 大綱 xv6 有哪些 system call,以及他們的作用為何 ? 以程式碼的觀點來理解 xv6 的 system call 流程 Using gdb
     Like 1 Bookmark
  • kernel/proc.c: yeild() yeild() 讓 myproc() 的 state 變成 RUNNABLE 並且呼叫 sched(),sched() 可以讓其他 function 也有機會可以被執行到 yeild() 想要做的事情是: "我用 CPU 用夠久了,可以換其他人使用了" 所謂的 "換其他人使用" 也就是呼叫 sched(),它會幫我們處理 // Give up the CPU for one scheduling round. void yield(void)
     Like  Bookmark
  • 本文目標:照著以下步驟就可以看到整個 system call 的過程 整個過程大致上都是照著這個影片做的,但其中有幾個步驟稍稍的不同。 1. 架設 xv6 的環境 https://pdos.csail.mit.edu/6.S081/2022/tools.html 2. 用 gdb-multiarch debug xv6 的方式 這裡會需要開啟 2 個終端機, 先在其中一個終端機輸入
     Like 2 Bookmark
  • sys_sbrk() 用來改變一個 proc 的大小 什麼時候會需要改變 proc 的大小? 平常寫程式的時候好像不太會使用這個功能(?) uint64 sys_sbrk(void) { int addr;
     Like  Bookmark
  • 2.6 Code: starting xv6, the first process and system call boot loader boot loader 把 xv6 kernal 搬到 memory 在 machine mode,CPU 開始執行 kernel/entry.S: _entryo直接使用 physical address loader 把 xv6 kernel 放到 0x80000000 kernel 放到 0x80000000 是因為較低的 memory 位置 0x0 ~ 0x80000000 包含了 I/O devices 有點看不懂這裡是在做什麼:
     Like  Bookmark
  • fork() 的流程 把 parent 的 pagetable 複製給 child child 中回傳的是 0 parent 中回傳的是 child pid fork 的特性 這是唯一 new 出 process 的方法 程式碼追蹤 // Create a new process, copying the parent.
     Like  Bookmark
  • xv6 開機的三大步驟 entry.S: set up stack start.c: machine mode main.c: supervisor mode modes of xv6 machine mode: 極少的 kernel 會使用 machine mode supervisor mode: 多數 kernel 都是使用這個 mode user mode: user program 使用的 mode
     Like  Bookmark
  • lock 的兩大動作 aquire/hold release/free 問題一: 有很多的 CPU 會 access 到相同的 memory 解決方法: 使用個 lock 例如說: if (lock == 0) hold();
     Like  Bookmark
  • ram size:128 Mbite page table size: 4096 boot sequence 0x8000_0000
     Like  Bookmark