Time Quantum and Context Switch Time - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Time Quantum and Context Switch Time

Description:

CPU scheduling more complex when multiple CPUs are available ... thread runs on the CPU until it (1) blocks, (2) ... perform CPU-intensive task. Thread.yield ... – PowerPoint PPT presentation

Number of Views:279
Avg rating:3.0/5.0
Slides: 22
Provided by: marily227
Category:

less

Transcript and Presenter's Notes

Title: Time Quantum and Context Switch Time


1
Time Quantum and Context Switch Time
2
Turnaround Time Varies With The Time Quantum
3
Turnaroun time when q5
5 8 9
14 15 17
Avg turnaround time (all jobs arrived at t0)
(158917)/4 (3217)/4 49/4 12.25 Time
quantum context switch time ? practical figures
are given in text (P185 3rd paragraph)
4
Multilevel Queue
  • Ready queue is partitioned into separate
    queuesforeground (interactive)background
    (batch)
  • Each queue has its own scheduling algorithm
  • foreground RR
  • background FCFS
  • Scheduling must be done between the queues
  • Fixed priority scheduling (i.e., serve all from
    foreground then from background). Possibility of
    starvation.
  • Time slice each queue gets a certain amount of
    CPU time which it can schedule amongst its
    processes i.e., 80 to foreground in RR
  • 20 to background in FCFS

5
Multilevel Queue Scheduling
6
Multilevel Feedback Queue
  • A process can move between the various queues
    aging can be implemented this way
  • Multilevel-feedback-queue scheduler defined by
    the following parameters
  • number of queues
  • scheduling algorithms for each queue
  • method used to determine when to upgrade a
    process
  • method used to determine when to demote a process
  • method used to determine which queue a process
    will enter when that process needs service

7
Example of Multilevel Feedback Queue
  • Three queues
  • Q0 time quantum 8 milliseconds
  • Q1 time quantum 16 milliseconds
  • Q2 FCFS
  • Scheduling
  • A new job enters queue Q0 which is served FCFS.
    When it gains CPU, job receives 8 milliseconds.
    If it does not finish in 8 milliseconds, job is
    moved to queue Q1.
  • At Q1 job is again served FCFS and receives 16
    additional milliseconds. If it still does not
    complete, it is preempted and moved to queue Q2.

8
Multilevel Feedback Queues
9
Multiple-Processor Scheduling
  • CPU scheduling more complex when multiple CPUs
    are available
  • Homogeneous processors within a multiprocessor
    system. (Symmetric multiprocessing SMP)
  • Load sharing
  • Asymmetric multiprocessing only one processor
    (master processor) accesses the system data
    structures, alleviating the need for data sharing
  • ? master processor do I/O, assign job to each sub
    processor
  • I/O is important enough for the master processor
  • (for example, human eye, ear, mouth ?? brain
    )

10
Real-Time Scheduling
  • Hard real-time systems required to complete a
    critical task within a guaranteed amount of time
  • ? such a guarantee made under resource
    reservation.
  • ? No secondary storage virtual memory
    (explained later)
  • ? general OS cant be used.
  • ? embedded controller OS are generally
    used.
  • Soft real-time computing requires that critical
    processes receive priority over less fortunate
    ones

11
Solaris 2 Scheduling
12
Solaris(SUN) CPU scheduling
  • Priority the higher number, the higher
    priority (0-59)- time quantum Time quantum for
    the associated priority. Lower has larger
  • Time quantum expired priority get lower.
  • Return from sleep priority get higher.
  • (look Fig. 6.11)

- The selected thread runs on the CPU until it
(1) blocks, (2) use its time slice, (3) is
preempted by a higher-priority thread. - If there
are multiple threads with the same priority, the
scheduler uses a round-robin queue.
13
Windows XP Priorities
  • priority based, preemptive scheduling.
  • XP scheduler ensures that the highest priority
    thread will always run.
  • 32 level priority scheme.
  • variable class thread (?? ??? 1-15), real-time
    class(16-32)

14
Window XP
  • each priority class has its base priority.
  • for example,
  • REALTIME_PRIORITY_CLASS 24 refer text
  • NORMAL_PRIORITY_CLASS 8
  • IDLE_PRIORITY_CLASS 4
  • when a threads time quantum runs out, the
    thread is interrupted. If the thread is in
    variable class, its priority is lowered. The
    priority is never lowered below the base
    priority.
  • When a variable-priority thread is released from
    a wait operation, the dispatcher boosts the
    priority. ? a thread waiting for keyboard I/O (or
    mouse I/O) would get a higher priority ? enhance
    its response time.
  • Distinguish between the foreground
    process(currently selected on the screen)
    background processes ? by priority 3.

15
Linux Scheduling (X)
  • Two algorithms time-sharing and real-time
  • Time-sharing
  • Prioritized credit-based process with most
    credits is scheduled next
  • Credit subtracted when timer interrupt occurs
  • When credit 0, another process chosen
  • When all processes have credit 0, recrediting
    occurs
  • Based on factors including priority and history
  • Real-time
  • Soft real-time
  • Posix.1b compliant two classes
  • FCFS and RR
  • Highest priority process always runs first

16
Java Thread Scheduling
  • JVM Uses a Preemptive, Priority-Based Scheduling
    Algorithm
  • FIFO Queue is Used if There Are Multiple Threads
    With the Same Priority

17
Java Thread Scheduling (cont)
  • JVM Schedules a Thread to Run When
  • The Currently Running Thread Exits the Runnable
    State
  • A Higher Priority Thread Enters the Runnable
    State
  • Note the JVM Does Not Specify Whether Threads
    are Time-Sliced or Not

18
Time-Slicing
  • Since the JVM Doesnt Ensure Time-Slicing, the
    yield() Method
  • May Be Used
  • while (true)
  • // perform CPU-intensive task
  • . . .
  • Thread.yield()
  • This Yields Control to Another Thread of Equal
    Priority

19
Thread Priorities
  • Priority Comment
  • Thread.MIN_PRIORITY Minimum Thread Priority
  • Thread.MAX_PRIORITY Maximum Thread Priority
  • Thread.NORM_PRIORITY Default Thread Priority
  • Priorities May Be Set Using setPriority() method
  • setPriority(Thread.NORM_PRIORITY 2)

20
Algorithm Evaluation
  • Deterministic modeling takes a particular
    predetermined workload and defines the
    performance of each algorithm for that workload.
    (Use gantt chart)
  • Queueing models
  • Simulation
  • Implementation the most difficult one

21
Evaluation of CPU Schedulers by Simulation
Write a Comment
User Comments (0)
About PowerShow.com