COP4600 Project 2 Minix Scheduler 2 - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

COP4600 Project 2 Minix Scheduler 2

Description:

Process Aging with Exponentially Weighted Average ... Checkup. Which files to be included and modified? What should be done in clock.c? ... – PowerPoint PPT presentation

Number of Views:178
Avg rating:3.0/5.0
Slides: 26
Provided by: YIK
Category:

less

Transcript and Presenter's Notes

Title: COP4600 Project 2 Minix Scheduler 2


1
COP4600 Project 2Minix Scheduler 2
  • Changwoo Yoon
  • cwyoon_at_cise.ufl.edu

2
Todays Discussion Topic
  • Last Discussion Section Review
  • Design of Aging Scheduler
  • Project 2 Output Format
  • QA

3
Source 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

4
Process 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

5
P(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
6
How sched() is called
sched()
Clock interrupt handler
clock_handler()
do_clocktick()
Interrupt
Hardware
clock_task()
Event Message
CLOCK TASK
7
realtime 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

8
U(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
9
Enumerating 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
10
So
  • 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) ?

11
What 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

12
Sched()
  • 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()

13
What do we need to add in process table?
  • Priority
  • Sub priority
  • CPU(I)
  • U(I)
  • P(I)

14
Continued
  • Add appropriate variables into proc.h
  • Initialization the variables at do_fork() in
    system.c

15
What 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

16
Checkup
  • 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()?

17
Three 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.

18
Sample Output
  • Output from sched()

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.)
19
Sample 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

20
Sample 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

21
Sample 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

22
Sample Output
  • Output from ready()

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
23
Output 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

24
Project 2 Q A
  • Any questions?

25
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com