3 Revize

Autor SHA1 Zpráva Datum
  423A35C7 7a698a8313 README添加实验三 před 7 měsíci
  423A35C7 e312fbdbd6 完成实验3 před 7 měsíci
  423A35C7 4c81247971 实验3环境初始化 před 7 měsíci
8 změnil soubory, kde provedl 61 přidání a 14 odebrání
Rozdělené zobrazení
  1. +1
    -1
      .vscode/c_cpp_properties.json
  2. +1
    -1
      .vscode/launch.json
  3. +1
    -1
      .vscode/tasks.json
  4. +9
    -1
      README.md
  5. binární
      assets/实验三演示.gif
  6. +4
    -2
      labcodes_answer/lab3_result/Makefile
  7. +25
    -7
      labcodes_answer/lab3_result/kern/mm/swap_fifo.c
  8. +20
    -1
      labcodes_answer/lab3_result/kern/mm/vmm.c

+ 1
- 1
.vscode/c_cpp_properties.json Zobrazit soubor

@ -6,7 +6,7 @@
"${workspaceFolder}/**",
// "${workspaceFolder}/labcodes_answer/**/",
// lab1_resultlab2_result
"${workspaceFolder}/labcodes_answer/lab2_result/kern/mm/"
"${workspaceFolder}/labcodes_answer/lab3_result/**/"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",

+ 1
- 1
.vscode/launch.json Zobrazit soubor

@ -11,7 +11,7 @@
"program": "bin/kernel",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/labcodes_answer/lab2_result",
"cwd": "${workspaceFolder}/labcodes_answer/lab3_result",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",

+ 1
- 1
.vscode/tasks.json Zobrazit soubor

@ -9,7 +9,7 @@
"env": {
"DISPLAY": ":0",
},
"cwd": "${workspaceFolder}/labcodes_answer/lab2_result"
"cwd": "${workspaceFolder}/labcodes_answer/lab3_result"
},
"problemMatcher": [

+ 9
- 1
README.md Zobrazit soubor

@ -12,4 +12,12 @@
### 效果
![](assets/实验二演示.gif)
### 原理
在default_pmm.c文件中,修改default_alloc_pages(或者新建一个函数),记录下循环首次适应算法的指针,每次从该指针的位置开始继续查找下一个空闲块。(原有的测试函数default_check、basic_check也需要略微更改)
在default_pmm.c文件中,修改default_alloc_pages(或者新建一个函数),记录下循环首次适应算法的指针,每次从该指针的位置开始继续查找下一个空闲块。(原有的测试函数default_check、basic_check也需要略微更改)
## 实验三
### 题目
编程实现第二次机会页面置换算法。
### 效果
![](assets/实验三演示.gif)
### 原理
在swap_fifo.c文件中,修改_fifo_swap_out_victim(或者新建一个函数)。当需要换出页面时,从链表尾部取出一个页面,如果这个页面的访问位是1,那么将其访问位改为0,并放到链表头部。接着再从链表尾部检测下一个页面,直到找到一个访问位为0页面的作为换出的页面。(测试函数_fifo_check_swap也需要略微更改)

binární
assets/实验三演示.gif Zobrazit soubor

Před Za
Šířka: 569  |  Výška: 1161  |  Velikost: 375 KiB

+ 4
- 2
labcodes_answer/lab3_result/Makefile Zobrazit soubor

@ -210,7 +210,8 @@ endif
# files for grade script
TARGETS: $(TARGETS)
targets: $(TARGETS)
all: $(TARGETS)
.DEFAULT_GOAL := TARGETS
QEMUOPTS = -hda $(UCOREIMG) -drive file=$(SWAPIMG),media=disk,cache=writeback
@ -225,7 +226,8 @@ qemu-nox: $(UCOREIMG) $(SWAPIMG)
$(V)$(QEMU) -serial mon:stdio $(QEMUOPTS) -nographic
TERMINAL := gnome-terminal
gdb: $(UCOREIMG) $(SWAPIMG)
$(V)$(QEMU) -S -s -parallel stdio $(QEMUOPTS) -serial null
debug: $(UCOREIMG) $(SWAPIMG)
$(V)$(QEMU) -S -s -parallel stdio $(QEMUOPTS) -serial null &
$(V)sleep 2

+ 25
- 7
labcodes_answer/lab3_result/kern/mm/swap_fifo.c Zobrazit soubor

@ -69,7 +69,25 @@ _fifo_swap_out_victim(struct mm_struct *mm, struct Page ** ptr_page, int in_tick
//(1) unlink the earliest arrival page in front of pra_list_head qeueue
//(2) set the addr of addr of this page to ptr_page
/* Select the tail */
list_entry_t *le = head->prev;
// 访
list_entry_t *current = head->prev;
list_entry_t *le = NULL;
for (; current != head; current = current->prev) {
pte_t *ptep = get_pte(mm->pgdir, le2vma(current, vm_start), 0);
cprintf("@@@ %d %x :a page\n", *ptep & PTE_A, current);
if (*ptep & PTE_A) { // 访1
*ptep &= !PTE_A; // 访
list_del(current); //
list_add(head, current); //
cprintf("### %d %x :clear access\n", *ptep & PTE_A, current);
} else {
le = current;
break;
}
}
if (le == NULL) {
le = head->prev; //
}
assert(head!=le);
struct Page *p = le2page(le, pra_page_link);
list_del(le);
@ -97,26 +115,26 @@ _fifo_check_swap(void) {
assert(pgfault_num==5);
cprintf("write Virt Page b in fifo_check_swap\n");
*(unsigned char *)0x2000 = 0x0b;
assert(pgfault_num==5);
assert(pgfault_num==6); // FIFO不同了
cprintf("write Virt Page a in fifo_check_swap\n");
*(unsigned char *)0x1000 = 0x0a;
assert(pgfault_num==6);
cprintf("write Virt Page b in fifo_check_swap\n");
*(unsigned char *)0x2000 = 0x0b;
assert(pgfault_num==7);
assert(pgfault_num==6);
cprintf("write Virt Page c in fifo_check_swap\n");
*(unsigned char *)0x3000 = 0x0c;
assert(pgfault_num==8);
assert(pgfault_num==7);
cprintf("write Virt Page d in fifo_check_swap\n");
*(unsigned char *)0x4000 = 0x0d;
assert(pgfault_num==9);
assert(pgfault_num==8);
cprintf("write Virt Page e in fifo_check_swap\n");
*(unsigned char *)0x5000 = 0x0e;
assert(pgfault_num==10);
assert(pgfault_num==8);
cprintf("write Virt Page a in fifo_check_swap\n");
assert(*(unsigned char *)0x1000 == 0x0a);
*(unsigned char *)0x1000 = 0x0a;
assert(pgfault_num==11);
assert(pgfault_num==9);
return 0;
}

+ 20
- 1
labcodes_answer/lab3_result/kern/mm/vmm.c Zobrazit soubor

@ -260,13 +260,32 @@ check_pgfault(void) {
*(char *)(addr + i) = i;
sum += i;
}
for (i = 0; i < 100; i ++) {
//
pte_t *pte = get_pte(pgdir, addr + i, 0);
if (pte != NULL && (*pte & PTE_P)) {
// 访
if (*pte & PTE_A) {
// A
cprintf("Access bit is set.\n");
} else {
// A
cprintf("Access bit is not set.\n");
}
} else {
//
cprintf("PTE not present.\n");
}
}
for (i = 0; i < 100; i ++) {
sum -= *(char *)(addr + i);
}
assert(sum == 0);
page_remove(pgdir, ROUNDDOWN(addr, PGSIZE));
free_page(pde2page(pgdir[0]));
free_page(pa2page(pgdir[0]));
pgdir[0] = 0;
mm->pgdir = NULL;

Načítá se…
Zrušit
Uložit