Skip to content

Commit

Permalink
fix allocator bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Jia-Sian committed May 31, 2021
1 parent bb2961b commit 79247a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lab8/inc/allocator.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "allocator.h"
#include "mmio.h"
#include "error.h"
#define debug 0
#if debug
#include "uart.h"
Expand All @@ -25,6 +26,8 @@ int listInsert(List* l,int v){
}

int listGet(List* l,int i){
if((l->beg<=l->end&&(i<l->beg||i>=l->end))||
(l->beg>l->end&&(i>=l->end||i<l->beg)))ERROR("index out of bound!");
int ret=l->data[i];
l->data[i]=l->data[l->beg];
l->beg=(l->beg+1)%(F_NUM+1);
Expand Down Expand Up @@ -92,6 +95,11 @@ void reclaimFrame(int i){
int p=i;
int level=__lg(p);
while(frame_table[p^1]>=0){
//beg will be moved in listGet(),
//so it need to update its bucket position
int beg_id=lists[level].data[lists[level].beg];
frame_table[beg_id]=frame_table[p^1];

listGet(&lists[level],frame_table[p^1]);
frame_table[p^1]=-1;

Expand Down Expand Up @@ -129,6 +137,7 @@ int findFrame(int tar_size){
int end=lists[i].end;
if(cur_size>=F_SIZE&&cur_size>=tar_size&&beg!=end){
int ret=listGet(&lists[i],beg);
if(frame_table[ret]==-1)ERROR("the frame is being used!");
frame_table[ret]=-1;

ret=getFrame(ret,tar_size,cur_size);
Expand Down
6 changes: 5 additions & 1 deletion lab8/inc/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void exit(){
sys_close(i);
}
}
if(cur->page_table)removePT(cur->page_table,0);
if(cur->page_table!=0)removePT(cur->page_table,0);
cur->status|=TASKEXIT;
threadSchedule();

Expand Down Expand Up @@ -379,7 +379,11 @@ void threadTest(){
threadCreate(foo);

idle();

//no task anymore
ffree((unsigned long)cur);
rq.beg=rq.end=0;
task_cnter=0;
}

void foo1(){
Expand Down
2 changes: 1 addition & 1 deletion lab8/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ start.o:start.S

run:
make all
qemu-system-aarch64 -M raspi3 -kernel $(APP).img -display none -serial null -serial stdio -drive if=sd,file=./archive/sdcard/sfn_nctuos.img,format=raw #-d int
qemu-system-aarch64 -M raspi3 -kernel $(APP).img -display none -serial null -serial stdio -drive if=sd,file=./archive/sdcard/sfn_nctuos.img,format=raw #-d in_asm
#qemu-system-aarch64 -M raspi3 -kernel $(APP).img -display none -serial null -serial pty -initrd ./archive/initramfs.cpio
#qemu-system-aarch64 -M raspi3 -kernel $(APP).img -display none -serial null -serial pty -initrd ./archive/initramfs.cpio -d int

Expand Down

0 comments on commit 79247a5

Please sign in to comment.