Title: COP4600 Project 2 Minix Scheduler 2
1COP4600 Project 2Minix Scheduler 2
- Changwoo Yoon
- cwyoon_at_cise.ufl.edu
2Todays Discussion Topic
- Last Discussion Section Review
- Design of Aging Scheduler
- Project 2 Output Format
- QA
3Source Files
- cop4600.h
- Basic defines and declaration
- clock.c
- realtime should be global
- proc.h
- Add fields (priority, sub priority, utilization
time, etc) - proc.c
- sched(), ready(), and three functions
- system.c
- do_fork() should be modified to initialization of
fields in struct proc
4Process Aging Algorithm
- Process Aging with Exponentially Weighted Average
- Recent past is more weighted than the distant
past. - IO bound v.s CPU bound processes
- P(I) CPU(I-1)/2 U(I)/2
- P(I) process priority
- CPU(I-1) exponentially weighted process util.
Average - U(I) process utilization
5P(I)CPU(I) CPU(I-1)/2 U(I)/2
lt- Calculated using realtime
Ticks0
40
80
80
4
30
24
I0
I1
I2
I3
CPU(0)0 U(0)0
CPU(1)U(1)/2CPU(0)/22 U(1)4 P(1)CPU(0)0
CPU(2)U(2)/2CPU(1)/216 U(2)30 P(2)CPU(1)2
CPU(3)U(3)/2CPU(2)/218 U(3)24 P(3)CPU(2)16
6How sched() is called
sched()
Clock interrupt handler
clock_handler()
do_clocktick()
Interrupt
Hardware
clock_task()
Event Message
CLOCK TASK
7realtime variable
- Use realtime variable defined in clock.c
- It keeps the system ticks
- Make it a global variable
- Use it in sched() to count the ticks between
priority calculations - In sched() at proc.c
- Check realtime
- Compare it with previous time
- Save current realtime as previous time
- If the difference is grater than PERIOD(40)
- Calculate priority
8U(I) - processor utilization time
- User_time Sys_time of process
Blocked or Sleep Context switch may occur
sys_time
Kernel Mode
sys_time
interrupt
restore
user_time
User Mode
user_time
9Enumerating for loop
- struct proc pr_ptr NULL
- for (pr_ptr BEG_USER_ADDR pr_ptr lt
END_PROC_ADDR pr_ptr) - if (!(pr_ptr-gtp_flags P_SLOT_FREE)) //
if struc proc in use -
-
END_PROC_ADDR
bclocked
unused
User proc
ready
unused
BEG_USER_ADDR
System/Task proc
Start of struct proc array
10So
- Use
- pr_ptr-gtuser_time
- pr_ptr-gtsys_time
- Caution this is accumulated time from the start
of process running - So U(I) ?
- And CPU(I) ?
11What to do in sched()?
- Priority Calculation
- At Every 2 Seconds whenever sched() is called.
How do we count 2 seconds? - Priority calculations for all the user processes
(ready or blocked). How do you enumerate all
processes? What are other type of processes? - Scheduling
- Every 2 ticks when sched() is called
- Highest priority process first (considering both
priority and sub priority). - Increase sub priority by 1
12Sched()
- Check realtime
- 40 ticks past? Then calculate priority of all
current processes - Pick the process having lowest priority
- If the priority is same? Then compare sub
priority - Place THAT(picked one) at the head of rdy list.
- Increase sub priority
- Write output
- Call pick_proc() already written in sched()
13What do we need to add in process table?
- Priority
- Sub priority
- CPU(I)
- U(I)
- P(I)
14Continued
- Add appropriate variables into proc.h
- Initialization the variables at do_fork() in
system.c
15What to do in ready()?
- Scheduling
- Ready() is called whenever a process is unblocked
from the blocked state. Would the blocked process
also age? - Highest priority process first (considering both
priority and sub priority). - Increase sub priority by 1
16Checkup
- Which files to be included and modified?
- What should be done in clock.c?
- What should be done in system.c?
- What should be done in do_fork()?
- What should be done in proc.c?
- What should be done in sched()?
- What should be done in ready()?
17Three Output Functions
- write_string()
- writes a string passed in the argument buf to
logfile. - write_ready_queue()
- writes the user process ready queue to logfile
using write_string() . - print_ready_queue()
- prints the user process ready queue on the
screen.
18Sample Output
Highest priority process is at the head of proc
ready list
New priority calculation starts here User proc
ready queue at 0 th sched() call within an
interval pid 40, name loop, P(i) 1, CPU(i)
0, subP(i) 1, U(i) 0, T_time 431 pid 39,
name loop, P(i) 19, CPU(i) 29, subP(i) 0,
U(i) 40, T_time 858 pid 42, name loop, P(i)
7, CPU(i) 3, subP(i) 0, U(i) 0, T_time
437 pid 43, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 433 pid 41,
name loop, P(i) 1, CPU(i) 0, subP(i) 0,
U(i) 0, T_time 430
U(I) CPU(I-1), CPU(I) U(I)/2 P(I)/2
Sum is about 40 ticks (2 sec.)
19Sample Output
As pid 40s subpid increased by 1, pid 41 is now
at the head of the ready queue
- New priority calculation starts here
- User proc ready queue at 0 th sched() call within
an interval - pid 40, name loop, P(i) 1, CPU(i) 0,
subP(i) 1, U(i) 0, T_time 431 - pid 39, name loop, P(i) 19, CPU(i) 29,
subP(i) 0, U(i) 40, T_time 858 - pid 42, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 437 - pid 43, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 433 - pid 41, name loop, P(i) 1, CPU(i) 0,
subP(i) 0, U(i) 0, T_time 430 - User proc ready queue at 1 th sched() call within
an interval - pid 41, name loop, P(i) 1, CPU(i) 0,
subP(i) 1, U(i) 0, T_time 430 - pid 40, name loop, P(i) 1, CPU(i) 0,
subP(i) 1, U(i) 0, T_time 431 - pid 39, name loop, P(i) 19, CPU(i) 29,
subP(i) 0, U(i) 40, T_time 858 - pid 42, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 437 - pid 43, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 433
20Sample Output
- User proc ready queue at 2 th sched() call within
an interval - pid 41, name loop, P(i) 1, CPU(i) 0,
subP(i) 2, U(i) 0, T_time 430 - pid 40, name loop, P(i) 1, CPU(i) 0,
subP(i) 1, U(i) 0, T_time 431 - pid 39, name loop, P(i) 19, CPU(i) 29,
subP(i) 0, U(i) 40, T_time 858 - pid 42, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 437 - pid 43, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 433 - User proc ready queue at 3 th sched() call within
an interval - pid 40, name loop, P(i) 1, CPU(i) 0,
subP(i) 2, U(i) 0, T_time 431 - pid 41, name loop, P(i) 1, CPU(i) 0,
subP(i) 2, U(i) 0, T_time 430 - pid 39, name loop, P(i) 19, CPU(i) 29,
subP(i) 0, U(i) 40, T_time 858 - pid 42, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 437 - pid 43, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 433
21Sample Output
- User proc ready queue at 12 th sched() call
within an interval - pid 40, name loop, P(i) 1, CPU(i) 0,
subP(i) 7, U(i) 0, T_time 431 - pid 41, name loop, P(i) 1, CPU(i) 0,
subP(i) 6, U(i) 0, T_time 430 - pid 39, name loop, P(i) 19, CPU(i) 29,
subP(i) 0, U(i) 40, T_time 858 - pid 42, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 437 - pid 43, name loop, P(i) 7, CPU(i) 3,
subP(i) 0, U(i) 0, T_time 433 - New priority calculation starts here
- User proc ready queue at 0 th sched() call within
an interval - pid 40, name loop, P(i) 0, CPU(i) 11,
subP(i) 1, U(i) 22, T_time 453 - pid 41, name loop, P(i) 0, CPU(i) 9,
subP(i) 0, U(i) 18, T_time 448 - pid 39, name loop, P(i) 29, CPU(i) 14,
subP(i) 0, U(i) 0, T_time 858 - pid 42, name loop, P(i) 3, CPU(i) 1,
subP(i) 0, U(i) 0, T_time 437 - pid 43, name loop, P(i) 3, CPU(i) 1,
subP(i) 0, U(i) 0, T_time 433
22Sample Output
User proc ready queue at -1 th sched() call
within an interval pid 44, name doze, P(i)
0, CPU(i) 0, subP(i) 0, U(i) 0, T_time
0 pid 42, name loop, P(i) 0, CPU(i) 6,
subP(i) 1, U(i) 12, T_time 28 pid 39, name
loop, P(i) 20, CPU(i) 15, subP(i) 0, U(i)
10, T_time 60 pid 41, name loop, P(i) 0,
CPU(i) 5, subP(i) 0, U(i) 10, T_time
26 pid 43, name loop, P(i) 0, CPU(i) 5,
subP(i) 0, U(i) 10, T_time 28 pid 40, name
loop, P(i) 15, CPU(i) 7, subP(i) 0, U(i)
0, T_time 86
23Output printing
- Maintain tick_counter in sched()
- Call write_ready_queue(tick_counter) before
pick_proc() - In ready()
- Call write_ready_queue(-1) before end of
function
24Project 2 Q A
25(No Transcript)