コード例 #1
0
ファイル: test_faq7.c プロジェクト: acads/csc501-xinu-mmu
void
procA(void)
{
    int rc = EMPTY;
    int vpage = 6000;
    int npages = 100;
    int bs_id = 5;
    char *x; 
    char temp;

    rc = get_bs(bs_id, npages);
    kprintf("get_bs in %s.. %d\n", __func__, rc);

    rc = xmmap(vpage, bs_id, npages);
    kprintf("xmmap in %s.. %d\n", rc);

    x = (char *) (vpage * NBPG);
    kprintf("%s trying to access vaddr 0x%08x\n", __func__, x); 
    *x = 'Y';
    temp = *x; 
    kprintf("value of temp in %s.. %c\n", __func__, temp);
    sleep(10);

    rc = xmunmap(vpage);
    kprintf("xmunmap in %s.. %d\n", __func__, rc);

    rc = release_bs(bs_id);
    kprintf("release_bs in %s.. %d\n", __func__, rc);
        
    return;
}
コード例 #2
0
ファイル: test_xm.c プロジェクト: acads/csc501-xinu-mmu
void
test_getbs_A(void)
{
    int bs_id = 5;
    int npages = 120;
    int rc = -1; 

    rc = get_bs(bs_id, npages);
    kprintf("%d %s> asked %d, got %d\n", currpid, __func__, npages, rc);
#ifdef DBG_ON
    print_bs_details(bs_id, TRUE);
#endif
    sleep(2);

    rc = release_bs(bs_id);
    kprintf("%d %s: release_bs() returned %d\n", currpid, __func__, rc);
    sleep(2);

    npages = 50; 
    rc = get_bs(bs_id, npages);
    kprintf("%d %s> asked %d, got %d\n", currpid, __func__, npages, rc);
#ifdef DBG_ON
    print_bs_details(bs_id, TRUE);
#endif
    rc = xmmap(4095, 5, 50);
    kprintf("%d %s> xmmap asked %d, got %d\n", currpid, __func__, npages, rc);
    sleep(2);

    return;
}
コード例 #3
0
ファイル: main.c プロジェクト: pvthakka/XINU
void test_default()
{
	char *addr = (char*) 0x40000000; //1G
	bsd_t bs = get_free_bs();

	int i = ((unsigned long) addr) >> 12;	// the ith page

	kprintf("\n\nHello World, Xinu lives %d\n\n", i);

	get_bs(bs, 200);

	if (xmmap(i, bs, 200) == SYSERR) {
		kprintf("xmmap call failed\n");
		return 0;
	}
	else {
			
	}
	for (i = 0; i < 16; i++) {
		*addr = 'A' + i;
		addr += NBPG;	//increment by one page each time
	}

	addr = (char*) 0x40000000; //1G
	for (i = 0; i < 16; i++) {
		kprintf("0x%08x: %c\n", addr, *addr);
		addr += 4096;       //increment by one page each time
	}

	xmunmap(0x40003000 >> 12);
	release_bs(bs);
	//resume(create(main,INITSTK,INITPRIO,INITNAME,INITARGS));
}
コード例 #4
0
ファイル: test_main.c プロジェクト: dichen001/CSC501
void test1()
{
  kprintf("\nTest 1: Testing xmmap.\n");
  char *addr1 = (char*)0x40000000; 
  int i = ((unsigned long)addr1) >> 12; 
  
  get_bs(MYBS1, 100);
  if (xmmap(i, MYBS1, 100) == SYSERR) {
    kprintf("xmmap call failed\n");
    kprintf("\tFAILED!\n");
    return;
  }

  for (i = 0; i < 26; i++) {
    *addr1 = 'A'+i;   //trigger page fault for every iteration
    addr1 += NBPG;    //increment by one page each time
  }

  addr1 = (char*)0x40000000;
  for (i = 0; i < 26; i++) {
    if (*addr1 != 'A'+i) {
      kprintf("\tFAILED!\n");
      return;
    }
    addr1 += NBPG;    //increment by one page each time
  }

  xmunmap(0x40000000>>12);
  release_bs(MYBS1);
  kprintf("\tPASSED!\n");
  return;
}
コード例 #5
0
ファイル: test_main.c プロジェクト: dichen001/CSC501
void proc1_test4(int* ret) {
  char *addr;
  int i;

  get_bs(MYBS1, 100);

  if (xmmap(MYVPNO1, MYBS1, 100) == SYSERR) {
    kprintf("xmmap call failed\n");
    *ret = TFAILED;
    sleep(3);
    return;
  }

  addr = (char*) MYVADDR1;
  for (i = 0; i < 26; i++) {
    *(addr + i * NBPG) = 'A' + i;
  }
  sleep(6);

  /*Shoud see what proc 2 updated*/
  for (i = 0; i < 26; i++) {
    /*expected output is abcde.....*/
    if (*(addr + i * NBPG) != 'a'+i){
      *ret = TFAILED;
      break;    
    }
  }

  xmunmap(MYVPNO1);
  release_bs(MYBS1);
  return;
}
コード例 #6
0
ファイル: main.c プロジェクト: pvthakka/XINU
proc1(char c) {
	
	bsd_t bs = get_free_bs();
	get_bs(bs, 250);

	char *addr = (char*) 0x20000000;

	int i = ((unsigned long) addr) >> 12;
	if (xmmap(i, bs, 250) == SYSERR) {
		kprintf("xmmap call failed\n");
		return 0;
	}
	else {
	
	}
	for (i = 0; i < 250; i++) {
		*addr = 500 + i;
		addr += NBPG;	//increment by one page each time
	}

	sleep(5);
	xmunmap(0x20000000 >> 12);
	release_bs(bs);
	kill(currpid);
}
コード例 #7
0
ファイル: main3.c プロジェクト: LordSanki/XINU_Demand_Paging
void proc1_test1(char *msg ) {
  char *addr;
  int i;

  get_bs(TEST1_BS, 100);

  if (xmmap(PROC1_VPNO, TEST1_BS, 100) == SYSERR) {
    kprintf("xmmap call failed\n");
    sleep(3);
    return;
  }

  addr = (char*) PROC1_VADDR;
  for (i = 0; i < 26; i++) {
	  register char a;
    *(addr + i * NBPG) = a = 'A' + i;
    kprintf("%s Writing 0x%x: %c a=%c\n", msg, (addr + i * NBPG), *(addr + i * NBPG),a);
  }

  sleep(1);

  for (i = 25; i >=0; i--) {
    kprintf("%s 0x%08x: %c\n",msg, addr + i * NBPG, *(addr + i * NBPG));
  }

  xmunmap(PROC1_VPNO);
  sleep(10);
  release_bs(TEST1_BS);
  return;
}
コード例 #8
0
ファイル: test_main.c プロジェクト: dichen001/CSC501
void proc2_test4(int *ret) {
  char *addr;
  int i;

  get_bs(MYBS1, 100);

  if (xmmap(MYVPNO2, MYBS1, 100) == SYSERR) {
    kprintf("xmmap call failed\n");
    *ret = TFAILED;
    sleep(3);
    return;
  }

  addr = (char*) MYVADDR2;

  /*Shoud see what proc 1 updated*/
  for (i = 0; i < 26; i++) {
    /*expected output is ABCDEF.....*/
    if (*(addr + i * NBPG) != 'A'+i){
      *ret = TFAILED;
      break;
    }
  }

  /*Update the content, proc1 should see it*/
  for (i = 0; i < 26; i++) {
    *(addr + i * NBPG) = 'a' + i;
  }

  xmunmap(MYVPNO2);
  release_bs(MYBS1);
  return;
}
コード例 #9
0
ファイル: dustytests.c プロジェクト: michalt25/CSC501_PA3
void kill_task2(int sem) {
    int i,j;
    int rc;
    char * x;
    char *addr = (char*) 0x50000000;
    bsd_t bsid = 5;
    int npages = 5;

    kprintf("kill_task2... start consuming.\n");

    get_bs(bsid, npages);

    rc = xmmap(VA2VPNO(addr), bsid, npages);
    if (rc == SYSERR) {
    	kprintf("xmmap call failed\n");
    	return 0;
    }

    kprintf("kill_task2.. sleeping 5\n");
    sleep(5);

    // Read back all of the values from memory and print them out
    x = addr;
    kprintf("kill_task2 end: ");
    for (i = 0; i < npages; i++) {
        for (j = 0; j < 5; j++) {
            kprintf("%c", *(x + j));
        }
        kprintf(" ");
        x += NBPG;	//go to the next page
    }
    kprintf("\n");

    kprintf("kill_task2.. sleeping 5\n");
    sleep(5);

    // NOTE: This is after other task has been killed

    // Read back all of the values from memory and print them out
    x = addr;
    kprintf("kill_task2 end: ");
    for (i = 0; i < npages; i++) {
        for (j = 0; j < 5; j++) {
            kprintf("%c", *(x + j));
        }
        kprintf(" ");
        x += NBPG;	//go to the next page
    }
    kprintf("\n");

    sleep(1);

    xmunmap(VA2VPNO(addr));

    release_bs(bsid);
}
コード例 #10
0
ファイル: dustytests.c プロジェクト: michalt25/CSC501_PA3
//////////////////////////////////////////////////////////////////////////
//  random_access (tests replacement policies)
//////////////////////////////////////////////////////////////////////////
void random_access_test() {
    int i, x, rc;
    char *addr = (char*) 0x50000000;
    char *w;
    bsd_t bsid = 7;
    int npages = 40;
    pt_t * pt;
    virt_addr_t * vaddr;

    kprintf("\nRandom access test\n");
    srand(25); // some random seed


    rc = get_bs(bsid, npages);
    if (rc == SYSERR) {
    	kprintf("get_bs call failed\n");
    	return 0;
    }

    rc = xmmap(VA2VPNO(addr), bsid, npages);
    if (rc == SYSERR) {
    	kprintf("xmmap call failed\n");
    	return 0;
    }


    for (i=0; i<50; i++) {

        // Get a number between 0 and npages
        // This number will be the page offset from the 
        // beginning of the backing store that we will access
        x = ((int) rand()) % npages; 

        // Get the virtual address
        w = addr + x*NBPG;


        *w = 'F';

        vaddr = &w;
        pt = VPNO2VA(proctab[currpid].pd[vaddr->pd_offset].pt_base);
        kprintf("Just accessed vaddr:0x%08x frame:%d bspage:%d\n",
              w,
              PA2FID(VPNO2VA(pt[vaddr->pt_offset].p_base)),
              x);  
    }

    xmunmap(VA2VPNO(addr));

    release_bs(bsid);
}
コード例 #11
0
ファイル: test_main.c プロジェクト: dichen001/CSC501
/*-------------------------------------------------------------------------------------*/
void proc1_test3(int i,int* ret) {
  char *addr;
  int bsize;
  int r;

  get_bs(i, 100);
  
  if (xmmap(MYVPNO1, i, 100) == SYSERR) {
    *ret = TFAILED;
    return 0;
  }
  sleep(4);
  xmunmap(MYVPNO1);
  release_bs(i);
  return;
}
コード例 #12
0
ファイル: main.c プロジェクト: mclarenrulz/csc501
/*------------------------------------------------------------------------
 *  main  --  user main program
 *------------------------------------------------------------------------
 */
int main() {

    int proc_A, proc_B, process_VA;
    int result;
	kprintf("\n\nHello World, Xinu lives\n\n");
	//srpolicy(FIFO);

	char *addr = (char*) 0x40000000; //1G
	bsd_t bs = 1;

	int i = ((unsigned long) addr) >> 12;	// the ith page

	result = get_bs(bs, 200);
	if(result == SYSERR){
		kprintf("get_bs call failed\n");
		return 0;
	}
	else
		kprintf("main get_bs call result %d\n", result);

	if (xmmap(i, bs, 150) == SYSERR) {
		kprintf("xmmap call failed\n");
		return 0;
	}

	for (i = 0; i < 10; i++) {
		*addr = 'A' + i;
		addr += NBPG;	//increment by one page each time
	}

	addr = (char*) 0x40000000; //1G
	for (i = 0; i < 10; i++) {
		kprintf("0x%08x: %c\n", addr, *addr);
		addr += 4096;       //increment by one page each time
	}

	proc_B = create(procB,INITSTK,INITPRIO,"procB",INITARGS);
	resume(proc_B);
	process_VA = vcreate(processVA,INITSTK,100,INITPRIO,"processVA",INITARGS);
	resume(process_VA);
	sleep(2);
	xmunmap(0x40000000 >> 12);
	release_bs(bs);
	kprintf("All izz well\n");
	return 0;
}
コード例 #13
0
ファイル: test_testmain.c プロジェクト: acads/csc501-xinu-mmu
int 
main()
{
    int vpage = 5000;
    int npages = 100;
    bsd_t bs = 1;
    char *addr;
    int i = 0;
    int pA = 0;


    kprintf("\n\nHello World, Xinu lives\n\n");

    pA = create(procA, 1024, 20, "procA", 0, 0);

    addr = (char *) (vpage * NBPG);
    get_bs(bs, npages);

    if (xmmap(vpage, bs, npages) == SYSERR) {
        kprintf("xmmap call failed\n");
        return 0;
    }

    for (i = 0; i < 26; ++i){
        *addr = 'A' + i;
        addr += NBPG;
    }

    kprintf("data in %s..\n", __func__);
    addr = (char *) (vpage * NBPG);
    for (i = 0; i < 26; ++i) {
        kprintf("0x%08x: %c\n", addr, *addr);
        addr += NBPG;
    }

    xmunmap(vpage);
    release_bs(bs);

    resume(pA);
    sleep(10);

    return 0;
}
コード例 #14
0
ファイル: test_main.c プロジェクト: dichen001/CSC501
/*----------------------------------------------------------------*/
void proc_test2(int i,int j,int* ret,int s) {
  char *addr;
  int bsize;
  int r;
  bsize = get_bs(i, j);
  if (bsize != 50)
    *ret = TFAILED;
  r = xmmap(MYVPNO1, i, j);
  if (j<=50 && r == SYSERR){
    *ret = TFAILED;
  }
  if (j> 50 && r != SYSERR){
    *ret = TFAILED;
  }
  sleep(s);
  if (r != SYSERR)
    xmunmap(MYVPNO1);
  release_bs(i);
  return;
}
コード例 #15
0
ファイル: main3.c プロジェクト: LordSanki/XINU_Demand_Paging
void peakLoadTestLaunch(){
	int i, pid[15];

	get_bs(15,128);
	xmmap(0xFFF80,15,128);
//	*(char *)( 0xFFF80*NBPG) = 'P';
	*(char *)( (0xFFF80+127)*NBPG + NBPG -1) = 'L';
	for(i=0;i<15;i++) {
		pid[i] = vcreate(peakLoadTest, 2000, 128, 10, "peakLoadTest", 1,i);
		if(pid[i] == SYSERR) {
			kprintf("Unable to launch virtual mem process. Test FAIL\n");
		}
		resume(pid[i]);
    //sleep(1);
	}
	xmunmap(0xFFF80);
	sleep(100);
  kprintf("Wake Launch\n");
	release_bs(15);
  kprintf("Exit Launch\n");
}
コード例 #16
0
ファイル: test_faq7.c プロジェクト: acads/csc501-xinu-mmu
void
procB(void)
{
    int rc = EMPTY;
    int vpage = 8000;
    int npages = 100;
    int bs_id = 5;
    char *x;
    char temp;

    rc = get_bs(bs_id, npages);
    kprintf("get_bs in %s.. %d\n", __func__, rc);

    rc = xmmap(vpage, bs_id, npages);
    kprintf("xmmap in %s.. %d\n", rc);

    x = (char *) (vpage * NBPG);
    kprintf("%s trying to access vaddr 0x%08x\n", __func__, x);
    temp = *x;
    kprintf("value of temp in %s.. %c\n", __func__, temp);

    sleep(1);

    enable_paging();
    *x =  's';
    temp = *x;
    kprintf("value of temp in %s.. %c\n", __func__, temp);

    rc = xmunmap(vpage);
    kprintf("xmunmap in %s.. %d\n", __func__, rc);

    /* Try to access VM after unmapping it. The process should be killed. */
    kprintf("value of temp in %s.. %c\n", __func__, *x);
    kprintf("This line should never be printed!\n");

    rc = release_bs(bs_id);
    kprintf("release_bs in %s.. %d\n", __func__, rc);
    
    return;
}
コード例 #17
0
ファイル: test_main.c プロジェクト: dichen001/CSC501
/*-------------------------------------------------------------------------------------*/
void proc1_test6(int *ret) {

  char *vaddr, *addr0, *addr_lastframe, *addr_last;
  int i, j;
  int tempaddr;
  int addrs[1200];

  int maxpage = (NFRAMES - (5 + 1 + 1 + 1));
  
  int vaddr_beg = 0x40000000;
  int vpno;
  
  for(i = 0; i < MAX_BSTORE; i++){
    tempaddr = vaddr_beg + 100 * NBPG * i; 
    vaddr = (char *) tempaddr;
    vpno = tempaddr >> 12;
    get_bs(i, 100);
    if (xmmap(vpno, i, 100) == SYSERR) {
      *ret = TFAILED;
      kprintf("xmmap call failed\n");
      sleep(3);
      return;
    }

    for (j = 0; j < 100; j++) {
      *(vaddr + j * NBPG) = 'A' + i;
    }
    
    for (j = 0; j < 100; j++) {
      if (*(vaddr + j * NBPG) != 'A'+i){
        *ret = TFAILED;
        break;
      }
    }    
    xmunmap(vpno);
    release_bs(i);    
  }

  return;
}
コード例 #18
0
ファイル: main3.c プロジェクト: LordSanki/XINU_Demand_Paging
void proc2_test1(char *msg, int a, int b, char *string) {
  char *addr;
  int i;

  get_bs(TEST1_BS, 100);

  if (xmmap(PROC2_VPNO, TEST1_BS, 100) == SYSERR) {
    kprintf("xmmap call failed\n");
    sleep(3);
    return;
  }

  addr = (char*) PROC2_VADDR;
  for (i = 0; i < 26; i++) {
    kprintf("%s 0x%08x: %c\n",msg, addr + i * NBPG, *(addr + i * NBPG));
  }

  xmunmap(PROC2_VPNO);
  release_bs(TEST1_BS);
  kprintf("Multi arg check: %d %d %s \n",a,b,string);
  return;
}
コード例 #19
0
ファイル: main3.c プロジェクト: LordSanki/XINU_Demand_Paging
void pageLoader(char *msg, u_long vpage){
	int i,sum,j,inc;
	int *x;
	get_bs(TEST1_BS, 100);
	if (xmmap(vpage, TEST1_BS, 100) == SYSERR) {
		kprintf("xmmap call failed\n");
		sleep(3);
		return;
	}
	for(i=0,sum=1,j=0,inc=-1;i<100;i++) {
		if(i%4==0) inc = -inc;
		j+=inc;
		x = (int *) ((vpage<<12) + (4+j)*NBPG);
		*x=i;
		sum += *x;
		kprintf("%s: Writing to @[0x%08x] (j=%d) (inc=%d) = %d\n",msg,x,j,inc,*x);
		sleep(1);
	}
	kprintf("%s: Final sum = %d\n",msg,sum);
	xmunmap(vpage);
	release_bs(TEST1_BS);
}
コード例 #20
0
ファイル: test_main.c プロジェクト: dichen001/CSC501
void test2() {
  int pids[16];
  int mypid;
  int i,j;

  int ret = TPASSED;
  kprintf("\nTest 2: Testing backing store operations\n");

  int bsize = get_bs(1, 100);
  if (bsize != 100)
    ret = TFAILED;
  release_bs(1);
  bsize = get_bs(1, 130);
  if (bsize != SYSERR)
    ret = TFAILED;
  bsize = get_bs(1, 0);
  if (bsize != SYSERR)
    ret = TFAILED;

  mypid = create(proc_test2, 2000, 20, "proc_test2", 4, 1,
                 50, &ret, 4);
  resume(mypid);
  sleep(2);
  for(i=1;i<=5;i++){
    pids[i] = create(proc_test2, 2000, 20, "proc_test2", 4, 1,
                     i*20, &ret, 0);
    resume(pids[i]);
  }
  sleep(3);
  kill(mypid);
  for(i=1;i<=5;i++){
    kill(pids[i]);
  }
  if (ret != TPASSED)
    kprintf("\tFAILED!\n");
  else
    kprintf("\tPASSED!\n");
}
コード例 #21
0
ファイル: main3.c プロジェクト: LordSanki/XINU_Demand_Paging
void fifo_test()
{
  // 7 frames allocated before this
  int i,j,k;
  int vpno = 8192;
  int frames = 7;
  frames++;
  for(i=0; i<8; i++){
    char *c = (char *)((vpno+(i*128))*NBPG);
    get_bs(i,128);
    xmmap(VAD2VPN(c), i, 128);
    // 1 frame for PT every 8 cycles
    for(j=0; j<128; j++){
      frames++;
      // 128 frames for data
      c[j*NBPG] = 'A'+i;
    }

    if(i == 7){
      for(j=8; j<16; j++){
        char * b = (char*)((1024 +j)*NBPG);
        if(b[0] != 'H'){
          kprintf("Test Failed expected H got %c at frame %d\n", b[0], j);
          break;
        }
      }
      if(j == 16)
        kprintf("Test Passed \n");
    }
  }
  sleep(2);
  for(i=0; i<8; i++){
    xmunmap( vpno+ (i*128) );
    release_bs(i);
  }
}
コード例 #22
0
/*------------------------------------------------------------------------
 * kill  --  kill a process and remove it from the system
 *------------------------------------------------------------------------
 */
SYSCALL kill(int pid)
{
	STATWORD ps;    
	struct	pentry	*pptr;		/* points to proc. table for pid*/
	int	dev;

	disable(ps);
	if (isbadpid(pid) || (pptr= &proctab[pid])->pstate==PRFREE) {
		restore(ps);
		return(SYSERR);
	}
	if (--numproc == 0)
		xdone();

	dev = pptr->pdevs[0];
	if (! isbaddev(dev) )
		close(dev);
	dev = pptr->pdevs[1];
	if (! isbaddev(dev) )
		close(dev);
	dev = pptr->ppagedev;
	if (! isbaddev(dev) )
		close(dev);
	
	send(pptr->pnxtkin, pid);

	freestk(pptr->pbase, pptr->pstklen);
	switch (pptr->pstate) {

	case PRCURR:	pptr->pstate = PRFREE;	/* suicide */
			resched();

	case PRWAIT:	semaph[pptr->psem].semcnt++;

	case PRREADY:	dequeue(pid);
			pptr->pstate = PRFREE;
			break;

	case PRSLEEP:
	case PRTRECV:	unsleep(pid);
						/* fall through	*/
	default:	pptr->pstate = PRFREE;
	}

	release_bs(proctab[pid].store);
	
	int i = 0;
	for(i = 0; i < NFRAMES; i++)
		{
		if(frm_tab[i].fr_pid == pid)
			{
			  if(frm_tab[i].fr_type == FR_PAGE)
			  	update_frm_fifo(i);
			  frm_tab[i].cookie = 0;
  			  frm_tab[i].fr_dirty = 0;
  			  frm_tab[i].fr_loadtime = 0;
  			  frm_tab[i].fr_pid = -1;
 			  frm_tab[i].fr_refcnt = 0;
 			  frm_tab[i].fr_status = FRM_UNMAPPED;
 			  frm_tab[i].fr_type = FR_PAGE;
 			  frm_tab[i].fr_vpno = BASE_VIRTUAL_PAGE;
 			  frm_tab[i].next_frame = -1;
			}
		}
	restore(ps);
	return(OK);
}
コード例 #23
0
ファイル: main3.c プロジェクト: LordSanki/XINU_Demand_Paging
void peakLoadTest(int pIdx){
	char *x,*y;
	int i,mypno,m;
	get_bs(15,128);
	mypno = PEAK_VPNO - pIdx;
	//kprintf("get_bs DOne pIdx=%d currpid=%d\n",pIdx,currpid);
	x = vgetmem(128*NBPG);
	//kprintf("vgetmem DOne pIdx=%d currpid=%d x=%x-%x\n",pIdx,currpid, x, x+128*NBPG);
	xmmap(mypno,15,128);
	//kprintf("xmmap DOne pIdx=%d currpid=%d\n",pIdx,currpid);
#if 1
	for(i=0; i<128; i++) {
		x[i] = (char) (pIdx + i);
    //print_PA(x);
		x[i+NBPG-1] = (char) (pIdx*2 +i);
#if 0
    i++;
    x[i] = (char) (pIdx + i);
		x[i+NBPG-1] = (char) (pIdx*2 +i);
    i++;
    x[i] = (char) (pIdx + i);
		x[i+NBPG-1] = (char) (pIdx*2 +i);
    i++;
    x[i] = (char) (pIdx + i);
		x[i+NBPG-1] = (char) (pIdx*2 +i);

    i++;
    x[i] = (char) (pIdx + i);
		x[i+NBPG-1] = (char) (pIdx*2 +i);
    //print_PA(x+i);
#endif

    //sleep(20);
    //kprintf(" writing to %x %x\n", (unsigned int)&x[i], (unsigned int)&x[i+NBPG-1]);
		if(i%15 == pIdx && i!=127) {
			*(char *)( (mypno + i)*NBPG ) = (char) (pIdx+3);
			*(char *)( (mypno + i)*NBPG + NBPG -1) = (char) (pIdx+4);
		}
	}
#endif
	kprintf("Writing DOne pIdx=%d currpid=%d\n",pIdx,currpid);
	xmunmap(mypno);
	//kprintf("Unmap DOne pIdx=%d currpid=%d\n",pIdx,currpid);
	sleep(20);
	//kprintf("Wake DOne pIdx=%d currpid=%d\n",pIdx,currpid);
	mypno--;
	xmmap(mypno,15,128);
#if 1

	xmunmap(mypno);
	sleep(20);
	mypno--;
	xmmap(mypno,15,128);
	y= (char *)((mypno)*NBPG );
	for(i=0; i<128; i++){
		if(x[i] != (char) (pIdx + i) ) kprintf("pIdx=%d Test Fail. x[%d] did not match\n",pIdx, i);
		if(x[i+NBPG-1] != (char) (pIdx*2 + i) ) kprintf("pIdx=%d Test Fail. x[%d] did not match\n",pIdx, i+NBPG-1);
		if(i!=127) {
			m=i%15;
			if( y[i*NBPG] != (char) (m+3) ) kprintf("pIdx=%d Test Fail. y[%d] at i=%d did not match.\n", pIdx, i*NBPG, i);
			if( y[i*NBPG + NBPG -1 ] != (char) (m+4) ) kprintf("pIdx=%d Test Fail. y[%d] at i=%d did not match\n", pIdx, i*NBPG + NBPG -1, i);
		}
	}
	i = NBPG*128 -1;
	if( y[i] != 'L' ) kprintf("pIdx=%d mypno=%x Test Fail. y[0x%08x]=%d (@ 0x%08x )is not L (%d) \n", pIdx,mypno,i,y[i],&y[i],'L');
	kprintf("peakLoadTest pIdx=%d finished. If no errors have been printed yet, it is a pass.\n",pIdx);
#endif
	xmunmap(mypno);
	vfreemem(x,128*NBPG);
	sleep(10);
	release_bs(15);
}
コード例 #24
0
ファイル: test_main.c プロジェクト: dichen001/CSC501
void test_func8_2()
{
  int PAGE0 = 0x40000;
  int i,j,temp;
  int addrs[1200];
  int cnt = 0; 
  //can go up to  (NFRAMES - 5 frames for null prc - 1pd for main - 1pd + 1pt frames for this proc)
  //frame for pages will be from 1032-2047
  int maxpage = (NFRAMES - (5 + 1 + 1 + 1));
  for (i=0;i<=maxpage/100;i++){
    if(get_bs(i,100) == SYSERR)
    {
      kprintf("get_bs call failed \n");
      return;
    }
    if (xmmap(PAGE0+i*100, i, 100) == SYSERR) {
      kprintf("xmmap call failed\n");
      return;
    }
    for(j=0;j < 100;j++)
    {  
      //store the virtual addresses
      addrs[cnt++] = (PAGE0+(i*100) + j) << 12;
    }     
  }
  /* all of these should generate page fault, no page replacement yet
     acquire all free frames, starting from 1032 to 2047, lower frames are acquired first
     */
  char *zero_addr = (char*) 0x0;
  for(i=0; i < maxpage-1; i++)
  {  
    *((int *)addrs[i]) = i + 1;
    if (i + 1 != *((int *)(zero_addr + (i + 1032) * NBPG))) {
      kprintf("\tFAILED!\n");
      kprintf("AA 0x%08x: %d\n", (int *)addrs[i], *((int *)addrs[i]));
      kprintf("BB 0x%08x: %d\n", zero_addr + (i + 1032) * NBPG, *((int *)(zero_addr + (i + 1032) * NBPG)));
    }
  }
  
  for(i=0; i < maxpage/3; i++)
  {  
    *((int *)addrs[i]) = i * 4 + 1;
  }
  i = maxpage-1;
  *((int *)addrs[i]) = i + 1;
  
  //trigger page replacement, this should clear all access bits of all pages
  kprintf("\t8.2 Expected replaced frame: %d\n\t",1032+maxpage/3);

  *((int *)addrs[maxpage]) = maxpage * 5 + 1; 
  temp = *((int *)addrs[maxpage]);
  if (temp != *((int *)((1032+maxpage/3) * NBPG))) {
    kprintf("\tFAILED!\n");
    kprintf("AA 0x%08x: %d\n", (int *)addrs[maxpage], *((int *)addrs[maxpage]));
    kprintf("BB 0x%08x: %d\n", (1032+maxpage/3) * NBPG, *((int *)((1032+maxpage/3) * NBPG)));
  }
    
  for (i=0;i<=maxpage/100;i++){
      xmunmap(PAGE0+(i*100));
      release_bs(i);    
  }
}
コード例 #25
0
ファイル: main3.c プロジェクト: LordSanki/XINU_Demand_Paging
void lru_test()
{
  // 7 frames allocated before this
  int i,j,k;
  int vpno = 8192;
  int frames = 7;
  frames++;
  for(i=0; i<8; i++){
    char *c = (char *)((vpno+(i*128))*NBPG);
    get_bs(i,128);
    xmmap(VAD2VPN(c), i, 128);
    // 1 frame for PT every 8 cycles
    for(j=0; j<128; j++){
      frames++;
      // 128 frames for data
      if(frames == 1000)
      {
        *((char*)(vpno*NBPG)) = 'R';
      }
      if(frames >1024)
      {
        c[j*NBPG] = 'B';
      }
      else{
        c[j*NBPG] = 'A';
      }
    }

    if(i == 7){
      int res = 1;
      for(j=9; j<17; j++){
        char * b = (char*)((1024 +j)*NBPG);
        if(b[0] != 'B'){
          kprintf("Test Failed expected B got %c at frame %d\n", b[0], j);
          res = 0;
          break;
        }
      }
      {
        char * b = (char*)((1024 +8)*NBPG);
        if(b[0] != 'R'){
          kprintf("Test Failed expected R got %c at frame %d\n", b[0], 8);
          res = 0;
        }
      }
      {
        char * b = (char*)((1024 +17)*NBPG);
        if(b[0] != 'A'){
          kprintf("Test Failed expected A got %c at frame %d\n", b[0], 17);
          res = 0;
        }
      }

      if(res == 1)
        kprintf("Test Passed \n");
    }
  }
  sleep(10);
  for(i=0; i<8; i++){
    xmunmap( vpno+ (i*128) );
    release_bs(i);
  }
}
コード例 #26
0
ファイル: main.c プロジェクト: pvthakka/XINU
void test_fifo()
{
	char *addr = (char*) 0x40000000; //1G
	bsd_t bs = get_free_bs();

	int i = ((unsigned long) addr) >> 12;	// the ith page

	kprintf("\n\nTesting FIFO %d\n\n", i);
	
	get_bs(bs, 250);

	if (xmmap(i, bs, 250) == SYSERR) {
		kprintf("xmmap call failed\n");
		return 0;
	}
	else {
	
	}
	for (i = 0; i < 250; i++) {
		*addr = i+0;
		addr += NBPG;	//increment by one page each time
	}

	int prA = vcreate(proc1, 100, 250, 25, "proc A", 'd');

	resume(prA);

	int prB = vcreate(proc2, 100, 250, 25, "proc B", 'd');

	resume(prB);

	char *addr2 = (char*) 0x50000000;
	bsd_t bs2 = get_free_bs();
	int j = ((unsigned long) addr2) >> 12;
	if (xmmap(j, bs2, 250) == SYSERR) {
		kprintf("xmmap call failed\n");
		return 0;
	}
	for (i = 0; i < 250; i++) {
		*addr2 = i+1500;
		addr2 += NBPG;	//increment by one page each time
	}
	
	char *addr3 = (char*) 0x60000000;
	bsd_t bs3 = get_free_bs();
	int k = ((unsigned long) addr3) >> 12;
	if (xmmap(k, bs3, 100) == SYSERR) {
		kprintf("xmmap call failed\n");
		return 0;
	}
	
	char *access = (char *) 0x40000000;
	*access = 'P';
	kprintf("\nAccessing the first memory location to avoid page replacement in aging %c %lu\n",*access, (unsigned long)access);

	for (i = 0; i < 100; i++) {
		*addr3 = i+2000;
		addr3 += NBPG;	//increment by one page each time
	}

	addr = (char*) 0x40000000;
	kprintf("\nAccessing first ever page here %d\n", *addr);

	xmunmap(0x40000000 >> 12);
	xmunmap(0x50000000 >> 12);
	xmunmap(0x60000000 >> 12);
	release_bs(bs);
	release_bs(bs2);
	release_bs(bs3);
	sleep(10);
}
コード例 #27
0
ファイル: kill.c プロジェクト: michalt25/Courses
/*------------------------------------------------------------------------
 * kill  --  kill a process and remove it from the system
 *------------------------------------------------------------------------
 */
SYSCALL kill(int pid)
{
	STATWORD ps;    
	struct	pentry	*pptr;		/* points to proc. table for pid*/
	int	dev;

	disable(ps);
	if (isbadpid(pid) || (pptr= &proctab[pid])->pstate==PRFREE) {
		restore(ps);
		return(SYSERR);
	}
	if (--numproc == 0)
		xdone();

	dev = pptr->pdevs[0];
	if (! isbaddev(dev) )
		close(dev);
	dev = pptr->pdevs[1];
	if (! isbaddev(dev) )
		close(dev);
	dev = pptr->ppagedev;
	if (! isbaddev(dev) )
		close(dev);
	
	send(pptr->pnxtkin, pid);

	freestk(pptr->pbase, pptr->pstklen);
	switch (pptr->pstate) {

	case PRCURR:	pptr->pstate = PRFREE;	/* suicide */
			resched();

	case PRWAIT:	semaph[pptr->psem].semcnt++;

	case PRREADY:	dequeue(pid);
			pptr->pstate = PRFREE;
			break;

	case PRSLEEP:
	case PRTRECV:	unsleep(pid);
						/* fall through	*/
	default:	pptr->pstate = PRFREE;
			bs_map_t *temp;
			int i;
                        for (i=0;i<16;i++)
			{
				temp = &bsm_tab[i];
				 while(temp !=NULL)
			        {
			                if(temp->bs_pid == currpid)
			                {
			                        xmunmap(temp->bs_vpno);
						if(temp->bs_private_heap == 1)
							release_bs(i);
			                        return OK;
				         }
			                temp=temp->next;
				}

	}			}
	restore(ps);
	return(OK);
}
コード例 #28
0
ファイル: main.c プロジェクト: dichen001/CSC501
void proc1_test2() {
	kprintf("\nRuning proc1_test2() \n\n");
	int i,temp;
	i = 0;
	kprintf("&i = %8x, i = %d\n",&i,i);
	
	int *y;
	struct	mblock	*x;
	
	kprintf("************************************\n");
	x = vgetmem(1000);
	//x= (struct	mblock *)x;
	kprintf("x=%8x \t x->mnext=%8x \t x->mlen=%d\n",x,x->mnext,x->mlen);
	y=x;
	kprintf("&y=%x y=%x *y=%d\n",&y,y,*y);
	*y = 100; 
	kprintf("&y=%x y=%x *y=%d\n",&y,y,*y);
    y++; 
    kprintf("&y=%x y=%x *y=%d\n",&y,y,*y);
    *y = 200; 
    kprintf("&y=%x y=%x *y=%d\n",&y,y,*y);
    temp = *y; 
    kprintf("temp=%d\n",temp);
	kprintf("####################################\n");
	vfreemem(--y,1000);
	kprintf("\n vfreemem(x,1000); \n\n");
	
	/*
	kprintf("************************************\n");
	x = vgetmem(1000);
	kprintf("####################################\n");
	vfreemem(x,500);
	kprintf("\n freemem(x,500); \n\n");
	
	kprintf("************************************\n");
	x = vgetmem(1000);
	kprintf("####################################\n");
	vfreemem(x+500,500);
	kprintf("\n freemem(x+500,500); \n\n");
	*/

	kprintf("************************************\n");
	i = get_bs(4, 100); 
	kprintf("i=%d\n",i);
	kprintf("####################################\n");
	
	xmmap(7000,4,100);
	char *addr =7000*4096;
	kprintf("&addr=%x addr=%x *addr=%c\n",&addr,addr,*addr);
	*addr = 'Y';
	kprintf("&addr=%x addr=%x *addr=%c\n",&addr,addr,*addr);
	char tem = *addr;
	kprintf("tem=%c\n",tem);

	xmunmap(7000);
	release_bs(4);
	kprintf("************************************\n");

	/*
	  int *x;

	  kprintf("ready to allocate heap space\n");
	  x = vgetmem(1024);
	  kprintf("heap allocated at %x\n", x);
	  *x = 100;
	  *(x + 1) = 200;

	  kprintf("heap variable: %d %d\n", *x, *(x + 1));
	  vfreemem(x, 1024);
	*/
}
コード例 #29
0
ファイル: dustytests.c プロジェクト: michalt25/CSC501_PA3
void shmemconsumer(int sem) {
    int i,j;
    int rc;
    char * x;
    char *addr = (char*) 0x50000000;
    bsd_t bsid = 5;
    int npages = 5;

    kprintf("shmemconsumer... start consuming.\n");

    get_bs(bsid, npages);

    rc = xmmap(VA2VPNO(addr), bsid, npages);
    if (rc == SYSERR) {
    	kprintf("xmmap call failed\n");
    	return 0;
    }

    // Consume
    x = addr;
    for (i = 0; i < npages; i++) {
        for (j = 0; j < 5; j++) {
            
            // get semaphore
            rc = wait(sem);
            if (rc == SYSERR) {
                kprintf("shmemconsumer: sem returned SYSERR\n");
                return;
            }

            kprintf("read: 0x%08x = %c\n", (x + j), *(x + j));
            signal(sem);
            sleep(1);
        }
        x += NBPG;	//go to the next page
    }


    // Read back all of the values from memory and print them out
    x = addr;
    rc = wait(sem);
    kprintf("shmemconsumer end: ");
    if (rc == SYSERR) {
        kprintf("shmemconsumer: sem returned SYSERR\n");
        return;
    }
    for (i = 0; i < npages; i++) {
        for (j = 0; j < 5; j++) {
            kprintf("%c", *(x + j));
        }
        kprintf(" ");
        x += NBPG;	//go to the next page
    }
    kprintf("\n");
    signal(sem);

    sleep(1);

    xmunmap(VA2VPNO(addr));

    release_bs(bsid);
}