示例#1
0
int MATIntro_test2()
{
  at_set_perm(0, 0);
  if (at_is_norm(0) != 0 || at_is_allocated(0) != 0) {
    at_set_perm(0, 0);
    dprintf("test 2 failed.\n");
    return 1;
  }
  at_set_perm(0, 1);
  if (at_is_norm(0) != 0 || at_is_allocated(0) != 0) {
    at_set_perm(0, 0);
    dprintf("test 2 failed.\n");
    return 1;
  }
  at_set_perm(0, 2);
  if (at_is_norm(0) != 1 || at_is_allocated(0) != 0) {
    at_set_perm(0, 0);
    dprintf("test 2 failed.\n");
    return 1;
  }
  at_set_perm(0, 100);
  if (at_is_norm(0) != 1 || at_is_allocated(0) != 0) {
    at_set_perm(0, 0);
    dprintf("test 2 failed.\n");
    return 1;
  }
  at_set_perm(0, 0);
  dprintf("test 2 passed.\n");
  return 0;
}
示例#2
0
int MATOp_test1()
{
  int page_index = palloc();
  if (page_index < 262144) {
    pfree(page_index);
    dprintf("test 1 failed.\n");
    return 1;
  }
  if (at_is_norm(page_index) != 1) {
    pfree(page_index);
    dprintf("test 1 failed.\n");
    return 1;
  }
  if (at_is_allocated(page_index) != 1) {
    pfree(page_index);
    dprintf("test 1 failed.\n");
    return 1;
  }
  pfree(page_index);
  if (at_is_allocated(page_index) != 0) {
    dprintf("test 1 failed.\n");
    return 1;
  }
  dprintf("test 1 passed.\n");
  return 0;
}
/**
 * Initializes the container data for the root process (the one with index 0).
 * The root process is the one that gets spawned first by the kernel.
 */
void container_init(unsigned int mbi_addr)
{
  unsigned int real_quota;
  // TODO: define your local variables here.
  int max_nps;
  int i;
  pmem_init(mbi_addr);
  real_quota = 0;
  max_nps = get_nps();
  /**
   * TODO: compute the available quota and store it into the variable real_quota.
   * It should be the number of the unallocated pages with the normal permission
   * in the physical memory allocation table.
   */
  for (i = 0; i < max_nps; i++) 
  {
    if (at_is_norm(i) == 1 && at_is_allocated(i) == 0)
    {
      real_quota += 1;
    }
  }
  KERN_DEBUG("\nreal quota: %d\n\n", real_quota);

  CONTAINER[0].quota = real_quota;
  CONTAINER[0].usage = 0;
  CONTAINER[0].parent = 0;
  CONTAINER[0].nchildren = 0;
  CONTAINER[0].used = 1;
}
/**
 * Initializes the container data for the root process (the one with index 0).
 * The root process is the one that gets spawned first by the kernel.
 */
void container_init(unsigned int mbi_addr)
{
  unsigned int real_quota;
  unsigned int nps, i, norm, used;

  pmem_init(mbi_addr);
  real_quota = 0;

  /**
   * compute the available quota and store it into the variable real_quota.
   * It should be the number of the unallocated pages with the normal permission
   * in the physical memory allocation table.
   */
  nps = get_nps();
  i = 1;
  while (i < nps) {
    norm = at_is_norm(i);
    used = at_is_allocated(i);
    if (norm == 1 && used == 0)
      real_quota++;
    i++;
  }
  KERN_DEBUG("\nreal quota: %d\n\n", real_quota);

  CONTAINER[0].quota = real_quota;
  CONTAINER[0].usage = 0;
  CONTAINER[0].parent = 0;
  CONTAINER[0].nchildren = 0;
  CONTAINER[0].used = 1;
}
示例#5
0
文件: MATOp.c 项目: konlzp/mcertikos
/**
 * Allocation of a physical page.
 *
 * 1. First, implement a naive page allocator that scans the allocation table (AT) 
 *    using the functions defined in import.h to find the first unallocated page
 *    with usable permission.
 *    (Q: Do you have to scan allocation table from index 0? Recall how you have
 *    initialized the table in pmem_init.)
 *    Then mark the page as allocated in the allocation table and return the page
 *    index of the page found. In the case when there is no avaiable page found,
 *    return 0.
 * 2. Optimize the code with the memorization techniques so that you do not have to
 *    scan the allocation table from scratch every time.
 */
unsigned int
palloc()
{
    unsigned int tnps;
    unsigned int palloc_index;
    unsigned int palloc_cur_at;
    unsigned int palloc_is_norm;
    unsigned int palloc_free_index;
    tnps = get_nps();
    palloc_index = last_palloc_index + 1;
    palloc_free_index = tnps;
    while( palloc_index < tnps && palloc_free_index == tnps )
    {
        palloc_is_norm = at_is_norm(palloc_index);
        if (palloc_is_norm == 1)
        {
            palloc_cur_at = at_is_allocated(palloc_index);
            if (palloc_cur_at == 0)
                palloc_free_index = palloc_index;
        }
        palloc_index ++;
    }
    if (palloc_free_index == tnps)
      palloc_free_index = 0;
    else
    {
      at_set_allocated(palloc_free_index, 1);
    }
    last_palloc_index = palloc_free_index % tnps;
    return palloc_free_index;
} 
// frees the physical page and reduces the usage by 1.
void container_free(unsigned int id, unsigned int page_index)
{
  if (at_is_allocated(page_index)) {
    pfree(page_index);
    if (CONTAINER[id].usage > 0)
      CONTAINER[id].usage -= 1;
  }
}
示例#7
0
/**
 * Write Your Own Test Script (optional)
 *
 * Come up with your own interesting test cases to challenge your classmates!
 * In addition to the provided simple tests, selected (correct and interesting) test functions
 * will be used in the actual grading of the lab!
 * Your test function itself will not be graded. So don't be afraid of submitting a wrong script.
 *
 * The test function should return 0 for passing the test and a non-zero code for failing the test.
 * Be extra careful to make sure that if you overwrite some of the kernel data, they are set back to
 * the original value. O.w., it may make the future test scripts to fail even if you implement all
 * the functions correctly.
 */
int MATIntro_test_own()
{
  // TODO (optional)
  // dprintf("own test passed.\n");
   
   if (at_is_allocated(1050000) == 0) {
    dprintf("TEST OWN: Page Index Check Failed!\n");
    return 1;
   }
   dprintf("*TEST OWN: Page Index Check Test Passed!\n");
   return 0;
}
示例#8
0
int MATIntro_test3()
{
  at_set_allocated(1, 0);
  if (at_is_allocated(1) != 0) {
    at_set_allocated(1, 0);
    dprintf("test 3 failed.\n");
    return 1;
  }
  at_set_allocated(1, 1);
  if (at_is_allocated(1) != 1) {
    at_set_allocated(1, 0);
    dprintf("test 3 failed.\n");
    return 1;
  }
  at_set_allocated(1, 100);
  if (at_is_allocated(1) != 1) {
    at_set_allocated(1, 0);
    dprintf("test 3 failed.\n");
    return 1;
  }
  at_set_allocated(1, 0);
  dprintf("test 3 passed.\n");
  return 0;
}