Scheduler - wtrr59/Xv6-Scheduler GitHub Wiki
STRIDE & MLFQ SCHEDULING
How to Implement
Scheduling Procedure in Xv6
- Pick a runnable state process in ptable.proc
- Context switch and run the process
- Return to the cpu scheduler and repeat above procedure
๋ณธ๋ฌธ์์๋ ์ฒซ๋ฒ์งธ ์ ์ฐจ๋ฅผ ์์ ํ ๊ฒ์ด๋ค.
Main Concept
Scheduling Procedure in STRIDE & MLFQ algorithm
- Check that a runnable process is exist in table.proc
Pick the list or process which has min pass
If the list is selected, pick a process corresponding each rules in the list - Context switch and run the process
- Return to the cpu scheduler, repeat above procedure
Stride Scheduler ๋ถ๋ถ์์๋ ptable.proc ๋ด์ Runnable process๊ฐ ์กด์ฌํ๋์ง ํ์ธํ๊ณ ์์ ๊ฒฝ์ฐ ๋ฐ๋ณต๋ฌธ์ ๊ณ์ ๋๊ธฐ๋ง ํ๋ค.
Stride List ์ MLFQ List ๊ทธ๋ฆฌ๊ณ ๋ชจ๋ Share process๋ ๊ฐ๊ฐ์ Pass๋ฅผ ๊ฐ๊ณ ์๋ค.
๋ฐ๋ผ์ ์ ์ค์ ๊ฐ์ฅ Pass๊ฐ ๋ฎ์ ๊ฒ์ ์ฐพ์ ์ด๋ค ํ๋ก์ธ์ค๋ฅผ ์ ํํ ์ง ๊ฒฐ์ ํ๋ค.
.
Proc Structure
struct proc {
...
union sched_data data;
enum schedstate sched_state; // Scheduling state
};
union sched_data{
struct share_data share;
struct mlfq_data mlfq;
struct stride_data stride;
};
struct stride_data {
int swtch; // Default process์ ์คํ ์ฌ๋ถ
};
struct share_data {
double pass;
double strd;
int share; // cpu_share๋ฅผ ํตํด ํ ๋นํ ์ ์ ์จ
};
struct mlfq_data {
int level; // MLFQ ๋ด์ level
int exec_count; // Process ์คํ ํ์
};
Proc ๊ตฌ์กฐ์ฒด์๋ Stride ์ค์ผ์ค๋ง์ ์ํ union๊ณผ ํด๋น Process๊ฐ ์ด๋ค Scheduling์ ์ ์ฉํด์ผํ๋์ง ๊ตฌ๋ถํ๋ enum์ด ์ถ๊ฐ๋์๋ค.
๊ณต์ฉ์ฒด๋ฅผ ์ฌ์ฉํจ์ผ๋ก์จ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ์ต์ ํ ํ์๋ค.
.
Linked List Data Structure
//proc.c
struct proc_list proc_l[NPROC];
...
//proc.h
struct proc_list{
struct proc *p;
struct proc_list *next;
int use;
};
struct proc_header{
int proc_num;
struct proc_list *start;
struct proc_list *end;
};
.
Stride List ์ MLFQ List ๋ชจ๋ Slab ์ ํ์ฉํ Linked List ๋ก ๊ตฌ์ฑ๋์๋ค.
Xv6๊ฐ ์์ฑํ ์ ์๋ ์ต๋ ํ๋ก์ธ์ค์ ๊ฐ์ ๋งํผ ํ ๋นํ๋ฉฐ proc_list์ use ๋ณ์๋ฅผ ํตํด ์ฌ์ฉ ์ค์ธ์ง ์๋์ง ํ๋จํ๋ค.
๋ํ ์์ ํค๋์ proc_num์ ํตํด List ๋ค์ ๋ช ๊ฐ์ node๊ฐ ์๋์ง ๋จผ์ ํ๋จํ ์ ์๋ค.
.
Stride structure
Stride ์๊ณ ๋ฆฌ์ฆ์ ๊ธฐ๋ณธ์ ์ธ ์๋ ๋ฐฉ์์ ์ง๋ถ์จ(ticket)์ ๋ฐ๋ฅธ Stride๋ฅผ ๊ฐ์ ๊ฐ๊ณ ์ง๋์จ Pass๋ฅผ ํ์ธ ํจ์ผ๋ก์จ ์ฐ์ ์์๋ฅผ ๊ฐ๋ฅด๊ฒ ๋์ด์๋ค.
๊ทธ๋ฌ๋ ๋ณธ๋ฌธ์์๋ ์ฝ๊ฐ์ ๋ณํ์ ์ค ๊ฒ์ด๋ค.
Default Case
cpu_share ๋๋ run_MLFQ๋ฅผ ์คํํ์ง ์์๋ค๋ฉด Default stride๋ฅผ ๊ฐ๊ฒ๋๋ค.
Default case์ ๊ฐ์ ๊ฒฝ์ฐ๋ Stride๊ฐ ์ง๋ถ์จ / Default Stride์ ๊ฐ์์ด๋ค.
๊ทธ๋ฌ๋ฏ๋ก Default process ๋ผ๋ฆฌ๋ RR๋ฐฉ์์ผ๋ก ๋์๊ฐ๊ฒ๋๋ค.
๊ตณ์ด RR ๋ฐฉ์์ ์ฑํํ๊ฒ๋ ์ด์ ๋ ๋ง์ฝ default stride๊ฐ ๋ชจ๋๊ฐ ํ ๋ฒ์ฉ ๋์ง์์์ ๋ (์๋ก์ Stride์ ์ฐจ์ด๊ฐ ๋ฐ์ํ์ ๋)
์๋ก์ด Default Stride๊ฐ ๋ค์ด์ค๊ฒ ๋๋ฉด ์๋ก์ด Stride๋ก Pass๋ฅผ ์
๋ฐ์ดํธํ๊ฒ๋๋ค.
๊ฒฐ๊ตญ์ pass์ ์ฐจ์ด๊ฐ ๋ฐ์ํ๊ณ ์ด๊ฒ์ด ์ปค์ง๊ฒ ๋๋ฉด ์คํ ํ์์ ์ฐจ์ด๊ฐ ๋ฐ์ํ ์ ์๊ธฐ ๋๋ฌธ์ ๊ฐ ํ๋ก์ธ์ค๋ ์์ ๋ง์ swtich๋ฅผ ๊ฐ๊ฒ๋๊ณ
STRIDE_struct์ ๊ตฌ์กฐ์ฒด์ ์๋ switch num๊ณผ ๋น๊ต๋ฅผ ํตํด ์คํ๋ process์ธ์ง ํ์ธํ๋ค.
๊ทธ๋ฌ๋ฏ๋ก Default Stride๋ ๊ณต์ Pass๋ฅผ ๊ฐ์ง๋ฏ๋ก ๋์ค์ ์๋ก์ด Process๊ฐ ๋ค์ด์๋ Pass๊ฐ ํ์ด์ง๋ ์ผ์ด ์์ผ๋ฉฐ
์
๋ฐ์ดํธ ๋ํ ์๋ก์ด ํ๋ก์ธ์ค๋ฅผ ํฌํจํ Stride๋ก ์
๋ฐ์ดํธ๋๋ค.
struct STRIDE_struct {
struct proc_header list;
double pass;
double stride;
int switch_num;
};
SHARE case
cpu_share๋ฅผ ์์ฒญํ๊ฒ๋ ๊ฒฝ์ฐ Stride List์์ ๋ฒ์ด๋ ์๊ธฐ๋ง์ Stride, Pass, Share(์ง๋ถ์จ)์ ๊ฐ๊ฒ๋๋ฉฐ
Stride ์๊ณ ๋ฆฌ์ฆ์ ๋ฐ๋ผ ์ ํ๋๋ค.
.
MLFQ structure
struct MLFQ_struct {
struct proc_header first;
struct proc_header second;
struct proc_header third;
int boosting_period;
double pass;
};
MLFQ๋ 3๊ฐ์ ๋ฆฌ์คํธ๋ฅผ ๊ฐ๊ณ ์์ผ๋ฉฐ ๊ฐ๊ฐ์ ํค๋์ ์๋ proc_num์ ํตํด ์คํํ ํ๋ก์ธ์ค๊ฐ ์๋์ง ํ์ธํ ์ ์๋ค.
์๋ก ์์ฑ๋ผ์ ๋ค์ด์จ ํ๋ก์ธ์ค๋ Highest ๋ฆฌ์คํธ์ ์ ์ผ ๋ค์ ์ถ๊ฐ๋๋ฉฐ ์คํ์ ๊ฐ์ฅ ์์์๋ Process๊ฐ ์คํ๋๋ค.
time quantum ์ ๋ค ์คํํ์ ๊ฒฝ์ฐ List์ ๊ฐ์ฅ ๋ค๋ก ๊ฐ๊ฒ๋๋ค.
time allotment์ ๋๋ฌํ์ ๊ฒฝ์ฐ ๋ค์ ํ์ ์ ์ผ ๋ค๋ก ๊ฐ๊ฒ๋๋ค.
๋ํ ์ง๋ถ์จ์ 20%๋ก ๊ณ ์ ํด์ค์ผ๋ก์จ Stride์ ๋ฐ๋ฅธ ์ ํ์ ๋ฐ๊ฒ๋๋ค.
Result
CNT
TICK
Xv6์ 1tick ๋น ์๊ฐ๊ณผ Test program์ 1cnt ๋น ์๊ฐ์ด ์ผ์นํ์ง ์๊ธฐ ๋๋ฌธ์ ์์๊ฐ์ ์ฐจ์ด๊ฐ ๋ฐ์ํ๊ฒ๋๋ค.