# Mini Project 2 Answers
# xv6
## Installation
PopOS users, please try the following:
```shell
sudo apt upgrade
sudo apt-get update && sudo apt-get install git nasm build-essential qemu gdb
```
If the version of xv6 provided in GitHub Classroom does not work for you, you can try using the latest version of xv6-riscv from [this github repo](https://github.com/mit-pdos/xv6-riscv/). Make sure you place it in the corresponding folder and the `make` commands still work after this replacement if you are doing this.
As a last resort, you can use a docker container, according to the instructions mentioned [here](https://hub.docker.com/r/wtakuo/xv6-env) or [here](https://github.com/SaiVK/xv6-riscv-docker) or [here](https://courses.cs.duke.edu/fall23/compsci310/tools.html). You will need to install [Docker](https://www.docker.com/get-started/) first. Note that this will require a lot of RAM and is not guaranteed to work. This method is NOT recommended.
## System calls
### 1. Gotta count 'em all
Q1) Can we use exec to run the command[args] ?
[SA] yes
Q2) Can the parent call the getsyscount system call and print the returned value in parent,or does the getsystem call should print and return the count value?
[SA] your choice
Q3) Do we need to count the no.of time a syscall is called for that particular command or all the commands till now ?
[SA] Only for the command that is run in "syscount <mask> command [args]"
Q4) If the parent and child both calls the system call do we consider only child's count or do we have to add it to the parent's count as well?
[SA] add the childs count to the parent. This is mentioned in the doc: "The number of times the corresponding system call is called by the children of the process called with syscount should also be added to the same total."
Q5) The command result would be printed right? I have not changed their codes like for eg grep will print its result?
[SA] yes
Q6) Do we need to count the number of times the systemcall is made by background processes also ?
[SA] dont exactly get your question, but just count the number of times the parent (which is the command you gave after syscount) and its children called the system call (while the children are not orphaned).
Q7) Should the syscall also count no. of calls made by processes that are children/grandchildren after they have been orphaned?
[SA] no need, maintain this count as long as the parent is alive.
Q8) what is the output of the command : syscount 65536 echo hello ? pls clarify
[SA] I ran it and got 2. Once to write the 5 characters in hello and once to put the newline
Q9) Can we store how many time it is called in the proc struct?
[SA] yes
Q10) Do we need to add all the extra syscalls we are making like sysreturn etc?
[IG] No need.
Q11) Is it okay if some usertests are failing after modifications?
[IG] No.
### 2. Wake me up when my timer ends
Q1) Do we test our code with alarmtest.c that is already present in the user folder?
[SA] yes
Q4) alarmtest.c tests the syscall functionality by calling sigalarm(interval, handler) but the Specification tells that an application will call alarm(interval, handler)
You should add a new sigalarm(interval, handler) system call.
If an application calls alarm(n, fn) , then after every n ”ticks” of CPU time
that the program consumes, the kernel will cause application function fn to be called.
When fn returns, the application will resume where it left off.
Which one should we implement ?
[SA] sorry for the confusion, you can add sigalarm(interval, handler) as the system call. updated on the website
## Scheduling
Q1) Will scheduling be tested on multiple CPUs? Or is implementing it for a single CPU enough?
[SA] MLFQ will be tested on a single CPU. Lottery scheduling may be tested on multiple CPUs.
Q2) Are there sample test case files for all the scheduling schemes?
[SA] No. Lottery is random, and you will be able to infer the correctness of your MLFQ implementation when you plot the analysis graph for the report.
### 1. The process powerball
Q1) If a process won the lottery and started running does it have to run till it exits or should the timer interrupt stop it at some point and make the lottery ticket again to run another process?
[SA] It is preemptive, so timer interrupts will hand control back to the OS, which will conduct the lottery again.
Q2) at one place it is mentioned that the default ticket=1 and in the note it is written that You’ll need to assign tickets to a process when it is created.so which one to follow?
[SA] When a process is created, it gets 1 ticket by default. This is inherited from its parent, so if the parent process has more than 1 ticket, the child also inherits the same number of tickets. If a process is created and its parent has/had 1 ticket at the time of creating the process, it also gets 1 ticket (the default) when it is created. If its parent has/had 3 tickets at the time of creating the new process, it also gets 3 tickets when it is created.
### 2. MLF who? MLFQ!
Q1) Do we need to implement queues in MLFQ using linkedlists or arrays are enough? Will we get any extra points if we implement it efficiently (if arrays are enough)?
[SA] anything is fine. You will get bragging rights if you implement it efficiently (on your github/resume possibly)
# Networking
## 1. XOXO
Q1) Are we allowed to use threads? In the sense of the inbuilt functions for thread in the library <pthread.h>?
[AA] Yes but not compulsory.
Q2) Can we have both clients playing the game in one terminal or is it compulsory to have a terminal for each player?? So implementation is like server operates through one terminal and both players through another terminal.
[AA] Different terminals.
Q3) Should the game be accessible by users with different ip? that is server on one system and players on different systems?
[AA] Different IPs on the same network? Yes.
Q4) Is it okay if the updated board with the move of player1 is only sent to the player2 or is it compulsory that both players should recieve the updated board ?
[AA] Player 1 should also be shown the state of the board after his move is made. Now whether you show him his move locally as soon as he makes it or if the server sends him the updated board is up to you.
Q6) When the server closes connection for both players, will it continue to wait for other players to connect or will it stop running ?
[AA] This is just a simulation, so it's fine if the server also stops *in the end*.
Q7) Instead of (coloumn, row), if we take input as numbers starting from 1 from top-left to 9 till bottom-right is it alright?
[AA] Clearly mention in the README.
Q8) Can we use select()?
[AA] You can if you want.
Q9) What is expected when:
The player who doesnot have a turn makes a move. As per the specification, we should ordinarily impose that the moves are made in correct order. So, should we keep the turn made in the buffer or should we print error messages.
[AA] You ~~should~~ print an error message telling the user to wait for their turn.
**[Update] You're free to deal with it however you like.**
Q10) Do we need server to handle multiple pair of clients that does we need to have multiple matches?
[AA] Not necessary.
Q11) Do we need create different c files for TCP and UDP ? or do we need to do it in the same c file?
[AA] Keep them in different files (and folders, ideally).
Q12) Is it okay if we hardcode the server's IP address (so the client knows the server's IP)?
[AA] Yes, but make sure that it doesn't only work on your local machine.
Q14) Can we assume that once we have connected the client we will not send stop signal (ctrl Z) to server or other client?
[AA] Yes.
Q15) The option to replay the game should be given to both clients together or we can ask one of the client first , and based on their response ask the second client?
[AA] You can do either way. Specify in your README.
Q16) If after games ends, and only one of the client refuses to replay, still the process for both clients as well as server should be stopped right ?
[AA] Yes, with the appropriate messages.
Q17) For implementing UDP can we use flags like MSG_CONFIRM, MSG_WAITALL ?
[AA] You can.
Q18) What is the expected behavior of clients when the server is terminated manually? Should both clients be terminated? Should only a message be sent to the clients saying "Server Disconnected". Similarly, what is the expected behavior of server when both or one of the clients is terminated manually? Currently I am terminating the clients in case server is terminated manually (using CTRL + C).
[AA] We won't penalize for any way of handling this, but ideally yes, terminate after printing a message.
Q19) Should we print the board at server terminal as well?
[AA] Would be good to have, but not necessary.
Q20) Regarding q9 is it fine if we dont do anything and just clear the buffer if the player makes a move?
[AA] Yes.
Q21) Regarding Q3, how exactly can we test if it works across different IP's on the same network? All the testing I've done is on the same machine, just different terminals. Is cross-machine compatibility required?
[AA] Yes. It should work for any IP on the same network. Assume the client knows the exact address and port.
Q22) Can the server ip address be put as an argument while running the client? Eg ./client 192.168.1.1
[AA] Yes.
Q23) Can we assume that both the server/client terminal wont stop the game abruptly(ctrl-C or ctrl-Z)?
[IG] You can assume that clients may crash but server cannot. Handle accordingly.
Q24) For every response received from client I have to enter a newline to continue normal execution, is it fine if I specify this in README??
[AA] What do you mean by enter a newline?
## 2. Fake it till you make it
Q1) Pls explain what is use of non blocking sockets here
[DP] As stated in the doc `the sender shouldn’t wait for receiving acknowledgement for a previously sent chunk before transmitting the next chunk` which opens up the scope of using non blocking sockets.
Q2) can we assume the max size of the message we are sending and receiving ( size=number_of_chunks* chunk_size) ?
[MS] yes
Q3) Just like tic-tac-toe, can we assume that the client and server will take turns to send messages and not just server/client sending the messages? I mean, are we expected to implement the following case
`server sending "hi client" to the client`
`server sending "how are you doing?" to the client`
`client sending "hello server, I'm doing great" to the server`
or implementing the below case would suffice where server and client can only send messages alternatively
`server sending "hi client" to the client`
`client sending "hi server" to the server`
`server sending "how are you doing?" to the client`
`client sending "I'm doing great" to the server`
[MS] second one is enough
Q4) If the server skips sending ack packet then should the client retransmit till the server sends ack for the chunk?
[MS] yes
Q5) Can we send the syn and ack packets separately? Or do we have to bundle both together?
[MS] implement as you like
Q6) Can we use two sockets?
[MS] no , but you can transmit sequentialy
Q7) a.Do we have to implement alternate control between the server and client? Like first the server sends message to client then client becomes server and message is sent? Or do we keep asking the client each time ' Do you want to receive or send data' ?
b. We are expected to implement bidirectional communication but in a sequential manner or in a simultaneous manner where both nodes in the network send each other data as they receive each other's data?
c. Do we have to provide input from the terminal for both nodes in the network? Or can we work with a few selected phrases?
[MS] a) no client cannot become server
instead you can assume that client starts interaction , and then server and client take alternate turns to send request like 3rd question 2nd case
b)bidirectional communication but in a sequential manner
c) provide input from the terminal for both nodes in the network
Q10) can we put a limit for retransmissions ? MAX_RETRANSMISSIONS?
[IG] Yes.
# General
Q1) we are allowed to change any file and any syscall already present in XV6 right?
[DP] There isn't any restriction but as a word of caution, whenever you modify something in XV6 to implement a functionality, ensure performance integrity of the XV6 OS using `usertests`.
Q2) Will there be moss for this mp?
[DP] *Irrelevant*.
Q3) The latest version of XV6 does not have the schedulertest command required for the report. What should we do in this case?
[SA] Schedulertest seems to be a user program. Can you try taking it from the inital-xv6 repo and seeing if it works (remember to modify the Makefile)
Q4) How do you debug xv6?
[SA] https://www.cse.iitd.ernet.in/~sbansal/os/previous_years/2014/lec/l3-hw1.html
See the section on "Remote Debugging xv6 under QEMU". For macOS users, after running `make qemu-gdb`, run `lldb` in a separate terminal, then run `target create kernel/kernel` and `gdb-remote localhost:25501` inside `lldb`.