Beomseok Nam (남범석) § 9. Lottery Scheduling: : Proportional Share Scheduling • à Will comeback to Chapter 9 next week § 10. Multi-CPU Scheduling • à Advanced topic

§ The project description will be announced soon. § Stay tuned… § 6th Edition a.k.a. Version 6 Unix § First public release of Unix from § Unix Bible: • Commentary on UNIX 6th Edition by § Reimplementation of V6 in ANSI out of MIT for x86 systems § The entire can be converted to a PDF via make print § Textbook/commentary: : a simple, Unix-like teaching § Online: http://pdos.csail.mit.edu/6.828/2012/xv6/book-rev7.pdf 1. Install qemu (You don’t need this step in swin.skku.edu) 1. cd 2. git clone https://github.com/geofft/qemu.git -b 6.828-1.7.0 3. sudo apt-get install libsdl1.2-dev 4. sudo apt-get install autoconf 5. sudo apt-get install libtool 6. cd qemu 7. git submodule update --init pixman 8. ./configure --disable-kvm --target-list="i386-softmmu x86_64- softmmu" --disable-werror 9. make 10. sudo make install 1. Install xv6 1. cd 2. git clone git://github.com/mit-pdos/xv6-public.git 3. cd xv6-public 4. make

2. Run xv6 1. cd 2. cd xv6-public 3. make qemu-nox § Monolithic kernel which provides services to running programs, called processes § Processes use system calls to access kernel services § A system call is a procedure call in the OS interface § System calls enter kernel space, force the kernel to perform a service, and then return § A process alternates between user and kernel space

§ OS defines a set of system calls • Programming interface to the services provided by OS • OS protects the system by rejecting illegal requests • OS may impose a quota on a certain resource • OS may consider fairness while sharing a resource

§ A system call is a protected procedure call • System call routines are in the OS code • Executed in the kernel mode • On entry, user mode à kernel mode switch • On exit, CPU mode is changed back to the user mode § Interrupts • Generated by hardware devices – Triggered by a signal in INTR or NMI pins (IA-32) • Asynchronous

§ Exceptions • Generated by software executing instructions – Divide-by-zero – INT instruction in IA-32 • Synchronous • Exception handling is same as interrupt handling § Traps • Intentional • System call traps, breakpoint traps, special instructions, … • Return control to “next” instruction § Faults • Unintentional but possibly recoverable • Page faults (recoverable), protection faults (unrecoverable), … • Either re-execute faulting (“current”) instruction or abort § Aborts • Unintentional and unrecoverable • Parity error, machine check, … • Abort the current program § There must be a special “trap” instruction that: • Causes an exception, which invokes a kernel handler • Passes a parameter indicating which system call to invoke • Saves caller’s state (registers, mode bits) • Returns to user mode when done with restoring its state • OS must verify caller’s parameters (e.g. pointers)

Examples: INT instruction (IA-32) SVC instruction (ARM) count = read (fd, buffer, nbytes); User Application

C Library (libc) User space

System Call Interface Kernel space

Kernel

Arch-dependent kernel code

Hardware Platform § Write three system calls – getnice, setnice, ps

§ Name • getnice, setnice – get and set the nice value • ps – print out process(s)’s information

§ Synopsis • int getnice(int pid) • int setnice(int pid, int value) • void ps(int pid); § Description • The getnice function obtains the nice value of a process. • The setnice function sets the nice value of a process. • The default nice value is 20. Lower nice values cause more favorable scheduling. The range of valid nice value is [0, 40]. • The ps function prints out process(s)’s information, which includes pid, nice, status, and name of each process. If the pid is 0, print out all processes’ information. Otherwise, print out corresponding process’s information. If there is no process corresponding to the pid, print out nothing.

§ Return value • getnice: Return the nice value of target process on success. Return -1 if there is no process corresponding to the pid. • setnice: Return 0 on success. Return -1 if there is no process corresponding to the pid or the nice value is invalid. • ps: No return value. § How to start • git clone https://github.com/jinsoox/xv6-skku.git -b pa1

• Modifications – halt system call • Halt xv6 program – make tarball • Compress your source codes into one .tar.gz file for submission • You should enter your ID & project no. on Makefile – CPUS=1 § To add a system call in xv6, you should read and modify the following files • sysproc.c add the implementation of your method here • syscall.h define the position of the system call vector that connect to your implementation • user.h define the function that can be called through the shell • syscall.c external define the function that connect the shell and the kernel, use the position defined in syscall.h to add the function to the system call vector • usys.S use the macro to connect the call of user to the system call function • defs.h add a forward declaration for your new system call • sysfunc.h add the new system call handler into this file too like "int sys_newsystemcall(void)”

§ Reference: http://zoo.cs.yale.edu/classes/cs422/2010/xv6-book/trap.pdf § Due: 9/30 11:59pm § How and where to submit? • yourid@swin:~/$ os_submit project1 xv6-project-1-yourid.tar.gz