Skip to content

ZhengShenghan/xv6-riscv

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extended xv6 Operating System
This project extends the xv6 operating system with additional system calls and scheduling functionalities. The focus is on providing more insights into system and process information, as well as implementing different scheduling algorithms.

New System Calls
1. sysinfo(int param)
Provides information about the system based on the input parameter:

param == 0: Returns the total number of active processes in the system.
param == 1: Returns the total number of system calls made since system boot-up.
param == 2: Returns the number of free memory pages in the system.
Otherwise: Returns an error (-1).
2. procinfo(struct pinfo *in)
Provides information specific to the current process:

'''
struct pinfo {
  int ppid;           // PID of the parent process
  int syscall_count;  // Total number of system calls made by the current process
  int page_usage;     // Current process's memory size in pages
};
Returns 0 on success and -1 otherwise.
'''

3. sched_statistics(void)
Prints statistics for each process, including PID, name, ticket value, and the number of times it has been scheduled to run.

4. sched_tickets(int)
Sets the caller process's ticket value to the given parameter. The maximum number of tickets for each process cannot exceed 10000.

5. clone(void *stack)
Creates a kernel-level thread using the parent's address space. The stack argument specifies the starting address of the user-level stack to be used by the child thread.

Scheduling Algorithms
Lottery Scheduler: Implements a basic lottery scheduling algorithm without ticket transfers or compensation tickets.
Stride Scheduler: Implements a basic stride scheduling algorithm using a large constant K (10000) to compute the stride value.
Testing


We have provided the user programs to test all the functionalities we implemented in our xv6. They are user/test1.c, user/test2.c, and user/test3.c.To test the new system calls and scheduling functionalities, you can use the following steps:

under xv6-riscv


(1)test1

make qemu

test1 <#bytes of memeroy per process> <#child process> 

sample output

'''
$ test1 65536 2
[sysinfo] active proc: 3, syscalls: 47, free pages: 32563
[procinfo 4] ppid: 3, syscalls: 10, page usage: 21
[procinfo 5] ppid: 3, syscalls: 10, page usage: 21
[sysinfo] active proc: 5, syscalls: 239, free pages: 32509
'''
(2)test2

make LAB2=LOTTERY(or make LAB2=STRIDE)

test2 <test time in ticks> <#process(k)> <#tick for process 1> <> .. <#tick for process k>

sample output

'''
$ test2 100 3 30 20 10
1(init): tickets: 100, ticks: 24
2(sh): tickets: 100, ticks: 13
3(test2): tickets: 100, ticks: 107
4(test2): tickets: 30, ticks: 101
5(test2): tickets: 20, ticks: 100
6(test2): tickets: 10, ticks: 101
'''
(3)test3

make qemu

test3 <#round> <#thread>

sample output

'''
$ test3 6 4
Round 1: thread 0 is passing the token to thread 1
Round 2: thread 1 is passing the token to thread 2
Round 3: thread 2 is passing the token to thread 3
Round 4: thread 3 is passing the token to thread 0
Round 5: thread 0 is passing the token to thread 1
Round 6: thread 1 is passing the token to thread 2
Frisbee simulation has finished, 6 rounds played in total
'''


Note: TO exit qemu, use ctrl a + c and type quit

About

Xv6 for RISC-V

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 94.8%
  • Assembly 3.1%
  • Makefile 1.8%
  • Other 0.3%