Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP604 – Operating Systems

Lab 6 Assignment

Instructions:

This assignment requires you to write a system call for xv6 that checks which page in a process’s virtual address space has been accessed. Detailed descriptions are provided below. Note that a good understanding of Task 6.2 will be helpful. The kernel function ptableprint() could also be useful for debugging the code for this assignment. Therefore you may want to use the same copy of xv6 that you have used for Task 62 for this lab assignment.

Submission:

You are to submit an archive of the whole content of xv6-riscv. To make it easier for you to prepare the file for submission, do the following:

1.    Edit  the   Makefile  to   provide  the   lab  assignment   number   (LABNUM)  and  your  group   number (GROUPNUM) at the top of the file.

2.    In the xv6-riscv directory (i.e. where the Makefile is located), run make submit. A file with extension .tgz will  be  created  in  the  parent  directory  (i.e.  the  directory  above)  the  current  directory,  named Lab<LABNUM>-<GROUPNUM>.tgz. Note that  and  are what you have specified in Step 1. For example, the Lab 6 file of Group 20 will be named Lab6-20.tgz

3.    Submit this file to Canvas.

The text file with the timing results

This lab will contribute 5% towards your overall course marks.

It is sometimes useful to know which pages in a user program’s virtual address space have been accessed (read or write or both). To facilitate this, you will write a system call named pageAccess(), that reports this. The function prototype of this system call for user programs will be:

int pageAccess(char* buf, unsigned int npages, unsigned int* bitmap);

buf points to the start address of the virtual address space that needs to be checked for access.

npages gives the number ofpages that should be examined. It should be not larger than 64.

bitmap is the pointer to an unsigned integer that acts as a bitmap indicating ifa page has been accessed. Each bit of the unsigned integer corresponds to a page. Since an unsigned integer is 64 bits in size, npages is limited to

64.

It should return a negative value if unsuccessful (for any reason). Any other returned value indicates success.

If pages 1, 2, and 30 have been accessed, the lower 32 bits of this integer should have 1’s only for bits 1, 2 and 30 (the rest are 0’s), giving a decimal value of 230+22+21 = 1073741830 (hexadecimal $40000006) as shown below.

31                                        24                                                  16                                                  8                                                   0

1

1

1

An example test program for your system call has been provided in file pgaccess_test.c. This program should be compiled as a user program in xv6. It also serves as an example of how the system call is to be used. The bitmap should be set to the above value for this example test program. But you should check that your system call returns the values correspondingly if other pages have been accessed.

In the implementation of your system call function, you will need to access the arguments using argaddr and argint. This part of sys_pageAcess() is provided for you in pageAccess.c. You should put this function in sysproc.c. With the bitmap, it is easier to store it in a variable in this function and then copy it to the user space before returning using copyout(). The code to do this has also been provided. The remaining code to implement this kernel function will need to be supplied by you.

Also note that:

1.    The kernel function walk() in vm.c is useful for finding the right page table entries (PTEs).

2.   You will want to define PTE_A in riscv.h to indicate the access bit in the PTE similar to PTE_V, PTE_R, PTE_W, etc. that can be found in that file. Consult the lecture slides on xv6 Pagetable or the xv6 Book for the position of these flags.

3.   You need to clear PTE_A after checking if it is set. Otherwise, this bit will be set for all the pages you have examined.

4.   In C, “<<” is a bitwise shift left operator. For example, v << 3 means shift the value of v left 3 bits. Hence, in the test program, when you see 1 << 3, it means shift the value of 1 left by 3 bits. Since 1 is represented in binary as 0…0001, shifting left 3 bits means the value becomes 0…1000, i.e. 8 in decimal.

5.   In C, “|” is a bitwise OR operator. So a | b means performing OR between the corresponding bits of a and b. Hence, bitwise OR of two numbers (in binary) 0…110 and 0…011 results in 0…010.