Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help to write the int getcount function to compute the result tested by the test program getcount.c. My idea so far is to
I need help to write the int getcount function to compute the result tested by the test program getcount.c.
My idea so far is to proc.h structure to add a count array to the proc struct. every time there is a system call occur, it will increment the designed element of the array. Every syscall get its own num.
The first system call you'll add is one we'll name getcount, which, when passed a valid system call number (listed in the file "syscall.h") as an argument, will return the number of times the referenced system call was invoked by the calling process E.g., the following test program #include #include #include "types.h" "user"h" "syscall,h" int main (int argc, char *argv]) printf(1, "initial if (fork()0) printf(1, printf(1, fork count %d ", getcount (SYS-fork)); "child "child fork count %d ", getcount (SYS-fork)); write count %d ", getcount(SYS-write)); else t wait); printf(1, printf(1, "parent "parent fork count %d ", getcount(SYS-fork)); write count %d ", getcount (SYS-write)); printf(1, exit); "wait count %d ", getcount (SYS-wait)); should produce the following output (note that each character is output with a separate call to write in xv6): initial fork count child fork count 0 child write count 19 wait count parent fork count 1 parent write count 41 wait count l Hints You will need to modify a number of different files for this exercise, though the total number of lines of code you'll be adding is quite small. At a minimum, you'll need to alter syscall.h, syscall.c, user.h, and usys. S to implement your new system call (try tracing how some other system call is implemented, e.g., uptime, for clues). You will likely also need to update struct proc, located in proc.h, to add a syscall-count tracking data structure for each process. To re-initialize your data structure when a process terminates, you may want to look into the functions found in proc.c Chapter 3 of the xv6 book contains details on traps and system calls (though most of the low level details won't be necessary for you to complete this exercise) The first system call you'll add is one we'll name getcount, which, when passed a valid system call number (listed in the file "syscall.h") as an argument, will return the number of times the referenced system call was invoked by the calling process E.g., the following test program #include #include #include "types.h" "user"h" "syscall,h" int main (int argc, char *argv]) printf(1, "initial if (fork()0) printf(1, printf(1, fork count %d ", getcount (SYS-fork)); "child "child fork count %d ", getcount (SYS-fork)); write count %d ", getcount(SYS-write)); else t wait); printf(1, printf(1, "parent "parent fork count %d ", getcount(SYS-fork)); write count %d ", getcount (SYS-write)); printf(1, exit); "wait count %d ", getcount (SYS-wait)); should produce the following output (note that each character is output with a separate call to write in xv6): initial fork count child fork count 0 child write count 19 wait count parent fork count 1 parent write count 41 wait count l Hints You will need to modify a number of different files for this exercise, though the total number of lines of code you'll be adding is quite small. At a minimum, you'll need to alter syscall.h, syscall.c, user.h, and usys. S to implement your new system call (try tracing how some other system call is implemented, e.g., uptime, for clues). You will likely also need to update struct proc, located in proc.h, to add a syscall-count tracking data structure for each process. To re-initialize your data structure when a process terminates, you may want to look into the functions found in proc.c Chapter 3 of the xv6 book contains details on traps and system calls (though most of the low level details won't be necessary for you to complete this exercise)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started