Exercise #4
Read lesson 5 then 6 on creating a system call.
-
Create two counters inside of the Xv6 kernel to count the number of bytes read and written via the
read()
/write()
system calls. Then create a system call to get the values of those two counters. You may decide for yourselves the names of the counters and system call and its API.Consider placing the system call in the
sysproc.c
file. -
Make a user-space program (
iostat.c
) that uses the system call. With no parameters it should just read and print the current values. With an integer value (N) it should loop and print the values while sleeping every N seconds. Thesleep()
system call sleeps about 100 ticks / second (so multiply N by 100 to get the number of ticks to givesleep()
.) -
The files you will likely need to modify will probably include at a minimum:
Makefile syscall.h syscall.c sysfile.c usys.S user.h iostat.c
Note that the xv6-public
found in the "Class Code" section for this course has
all the solutions to all the exercises (and all the other things done during the
course) already found within it.