COMP604 – Operating Systems
Lab 6 Assignment
Introduction
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. Note that a good understanding of Task 6.2 will be needed. 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 completed for Task 6.2 in this assignment.
Detailed Description
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 of pages 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 if a 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.
Note: In the code provided for pageAccess, you will note that the function sys_pageAccess does not have any arguments. This is because the call to pageAccess is made in the user program (in user mode). Therefore, they cannot be passed directly to a kernel function (in kernel mode). Instead, the values of the arguments are obtained using argaddr, and argint as appropriate.
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
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.
1 |
1 |
1 |
School of Engineering, Computer and Mathematical sciences, AUT 1
COMP604 – Operating Systems
Also note that:
-
The kernel function walk() in vm.c is useful for finding the right page table entries (PTEs).
A pagetable entry is the content of one element of the pagetable array. This function requires 3 arguments. The first argument is a pointer to the pagetable of the process. This should be obtained from the Process Control Block of the current process. The second argument is the virtual address whose pagetable entry we are looking for (This is what is returned by the function). The third argument should be 0 in our case. Read the comments for this function in vm.c
-
You will want to define PTE_A in riscv.h to indicate the access bit in the PTE. As examples of how this could be done, see PTE_V, PTE_R, PTE_W, etc. (they define different bits) that can be found in that file. Consult the lecture slides on xv6 Pagetable or the xv6 Book for the position of these flags.
-
You must clear PTE_A after checking if it is set. Otherwise, this bit will be set for all the pages you have examined.
-
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.
-
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.
Submission
You are to submit an archive of the whole content of xv6-riscv. To avoid the archive being too big for submission,
you must do the following:
1. Execute the command make clean in the xv6-riscv directory.
2. cd to the parent directory (i.e. the directory above) of the xv6-riscv directory, run
tar cvf Lab6-<GROUPNUM>.tar xv6-riscv
where <GROUPNUM> is your lab assignment group number. For example, Group 20 should use
3. Use the command tar tf Lab6-<GROUPNUM>.tar to check that all the sub-directories and files have been archived.
4. Submit this file to Canvas.
This lab will contribute 5% towards your overall course marks.
Lab6-20.tgz
School of Engineering, Computer and Mathematical sciences, AUT 2