27
SCHEDULING SCHEDULING

scheduling ppt

Embed Size (px)

Citation preview

Page 1: scheduling ppt

SCHEDULINGSCHEDULING

Page 2: scheduling ppt

The embedded software consists of number of tasks

These tasks include the os tasks and application specific tasks

Each task has it’s name ,ID, a priority, a stack and task control block which contains all the information related to task

Task schedulingTask scheduling

Page 3: scheduling ppt

Since only one cpu has to handle multiple tasks, Since only one cpu has to handle multiple tasks, the tasks have to share the cpu time in the tasks have to share the cpu time in disciplined mannerdisciplined manner

The mechanism for deciding which task will get The mechanism for deciding which task will get cpu time next is called Task schedulingcpu time next is called Task scheduling

The object that does task scheduling is called as The object that does task scheduling is called as schedularschedular

Page 4: scheduling ppt

Task statesTask states

NewNew

Running Running

WaitingWaiting

Ready-to-runReady-to-run

TerminatedTerminated

Page 5: scheduling ppt

CONTEXT SWITCHCONTEXT SWITCH

Context is nothing but current state of the task presently Context is nothing but current state of the task presently running on the cpurunning on the cpu

Switching the cpu from one task to another task requires Switching the cpu from one task to another task requires state save of presently running task and restore of a state save of presently running task and restore of a different task.This is known as “Context Switching”.different task.This is known as “Context Switching”.

Page 6: scheduling ppt

When scheduling takes place?When scheduling takes place?

CPU scheduling decisions may take place when a task:

1.Switches from running to waiting state

2.Switches from running to ready state

3.Switches from waiting to ready

4.Terminats

• Scheduling under 1 and 4 is non-preemptive

• All other scheduling is preemptive

Page 7: scheduling ppt

Scheduling criteriaScheduling criteria

UTILIZATIONUTILIZATION :The fraction of time a device is in use. :The fraction of time a device is in use.

THROUGHPUTTHROUGHPUT: The number of tasks completions in a : The number of tasks completions in a period of time.period of time.

TURNAROUND TIME: TURNAROUND TIME: The interval from the time of The interval from the time of submission of a task to the time of completion.submission of a task to the time of completion.

WAITING TIME: WAITING TIME: TimeTime spends in waiting in ready queue.spends in waiting in ready queue.

RESPONSE TIME: RESPONSE TIME: Time from submission of request Time from submission of request until first response is produced.until first response is produced.

Page 8: scheduling ppt

SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS

FIRST-COME, FIRST SERVEDFIRST-COME, FIRST SERVED

SHORTEST JOB FIRSTSHORTEST JOB FIRST

ROUND ROBINROUND ROBIN

PREEMPTIVE SCHEDULINGPREEMPTIVE SCHEDULING

NON-PREEMPTIVE SCHEDULINGNON-PREEMPTIVE SCHEDULING

RATE MONOTONIC ANALYSISRATE MONOTONIC ANALYSIS

DEADLINE MONOTONIC ANALYSISDEADLINE MONOTONIC ANALYSIS

EARLIEST DEADLINE FIRSTEARLIEST DEADLINE FIRST

LEAST SLACK TIME FIRSTLEAST SLACK TIME FIRST

SCHEDULING OF PERIODIC AND APERIODIC TASKSSCHEDULING OF PERIODIC AND APERIODIC TASKS

Page 9: scheduling ppt

FIRST-COME, FIRST SERVEDFIRST-COME, FIRST SERVED

It serves on First-com-First served basisIt serves on First-com-First served basis

Simple and fairSimple and fair

Suitable for systems, with few tasks with small execution Suitable for systems, with few tasks with small execution times times

If there are no time-criticality of jobs, it is betterIf there are no time-criticality of jobs, it is better

But poor performance. Average queueing time may be But poor performance. Average queueing time may be long.long.

Throughput is lowThroughput is low

No priorityNo priority

Not used for real time systemsNot used for real time systems

Page 10: scheduling ppt

SHORTEST JOB FIRSTSHORTEST JOB FIRST

Priority is based on execution timePriority is based on execution time

Optimal for minimizing waiting timeOptimal for minimizing waiting time

Throughput will be increasedThroughput will be increased

Average turnaround time will be optimalAverage turnaround time will be optimal

Tasks with highest execution time has to wait for long Tasks with highest execution time has to wait for long timetime

Not suitable for real time systemsNot suitable for real time systems

Page 11: scheduling ppt

ROUND ROBINROUND ROBIN

A certain time slice is allocated for each process, called A certain time slice is allocated for each process, called quantumquantum

Use a timer to cause an interrupt after a predetermined time. Use a timer to cause an interrupt after a predetermined time. Preempts if task exceeds it’s quantum.Preempts if task exceeds it’s quantum.

The control gives to next task ifThe control gives to next task if

1.The current task completed its work with in time 1.The current task completed its work with in time

sliceslice

2. The current task has no work to do2. The current task has no work to do

3. The current task has completed its time slice3. The current task has completed its time slice

It is very simple to implementIt is very simple to implement

Here all tasks are consider of equal importanceHere all tasks are consider of equal importance

If there are no time-criticality of jobs, it is sufficientIf there are no time-criticality of jobs, it is sufficient

Page 12: scheduling ppt

Issues in round robinIssues in round robin

The performance of Round Robin is depends on size of The performance of Round Robin is depends on size of time quantumtime quantum

If time quantum is to small , most of time is wasted in If time quantum is to small , most of time is wasted in context switchescontext switches

If time quantum is to large it becomes FCFS policyIf time quantum is to large it becomes FCFS policy

As a rule of thumb , time quantum should be greater As a rule of thumb , time quantum should be greater than execution times of 80% jobs.than execution times of 80% jobs.

Page 13: scheduling ppt

Round robin with priorityRound robin with priority

The Round Robin algorithm is slightly modified by The Round Robin algorithm is slightly modified by assigning priority levels to some or all tasks.assigning priority levels to some or all tasks.

High priority task can interrupt the cpu sothat it can be High priority task can interrupt the cpu sothat it can be executed.executed.

This scheduling algorithm can meet the desired This scheduling algorithm can meet the desired response for a high priority task .response for a high priority task .

Page 14: scheduling ppt

Weighted Round robinWeighted Round robin

In weighted round robin each job Ji is assigned a weight wi; the job will receive wi consecutive time slices each round, and– Equivalent to regular round robin if all weights equal 1

Simple to implement, since it doesn’t require a sorted priority queue

Only limited use in real-time systems

Page 15: scheduling ppt

MULTI-LEVEL QUEUESMULTI-LEVEL QUEUES

Ready queue is divided into several separate queuesReady queue is divided into several separate queuesEach queue has its scheduling algorithm.Each queue has its scheduling algorithm.Then some other algorithm (perhaps priority based) Then some other algorithm (perhaps priority based) arbitrates between queues.arbitrates between queues.Can use feedback to move between queuesCan use feedback to move between queuesMethod is complex but flexible.Method is complex but flexible.For example, could separate system processes, For example, could separate system processes, interactive and batch processesinteractive and batch processes

Page 16: scheduling ppt

Preemptive priority based schedulingPreemptive priority based scheduling

Each task is assigned a priority based on importance of Each task is assigned a priority based on importance of jobs ,periodicity or deadline of jobsjobs ,periodicity or deadline of jobs

High priority task is always executed by cpu, by High priority task is always executed by cpu, by suspending the low priority tasksuspending the low priority task

The main attraction of this algorithm is that execution The main attraction of this algorithm is that execution time of high priority task can be calculated.time of high priority task can be calculated.

Most of the real time embedded systems use this Most of the real time embedded systems use this algorithm algorithm

Page 17: scheduling ppt

Non-preemptive priority schedulingNon-preemptive priority scheduling

After completion of low priority task only ,high priority After completion of low priority task only ,high priority task will take the cpu .task will take the cpu .

Easy to understand and implement.Easy to understand and implement.

Main disadvantage is high priority task has to wait for a Main disadvantage is high priority task has to wait for a long timelong time

Page 18: scheduling ppt

Rate Monotonic SchedulingRate Monotonic Scheduling

It assumes all tasks are periodic.It assumes all tasks are periodic.

Assign the priority of each task according to its period, Assign the priority of each task according to its period,

so that the shorter the period the higher the priority.so that the shorter the period the higher the priority. The rate monotonic algorithm (RMA) is a procedure for The rate monotonic algorithm (RMA) is a procedure for assigning fixed priorities to tasks to maximize their assigning fixed priorities to tasks to maximize their "schedulability”."schedulability”.

One major limitation of fixed-priority scheduling is that it One major limitation of fixed-priority scheduling is that it is not always possible to fully utilize the CPU. Even is not always possible to fully utilize the CPU. Even though RMA is the optimal fixed-priority scheme, it has a though RMA is the optimal fixed-priority scheme, it has a

worst-case schedulable bound of:worst-case schedulable bound of: Wn = n * (2 Wn = n * (2 (1/n )-(1/n )- 1) 1)

Page 19: scheduling ppt

Deadline Monotonic Scheduling

The deadline monotonic algorithm assigns task priority according to relative deadlines ,the shorter the relative deadline, the higher the priority

When the relative deadlines are arbitrary: - Deadline monotonic can sometimes produce a

feasible schedule in cases where rate monotonic cannot

– But, rate monotonic always fails when deadline monotonic fails

Page 20: scheduling ppt

Earliest deadline first (EDF)

Assign priority to jobs based on deadline

Earlier the deadline, higher the priority

Simple, just requires knowledge of deadlines

Used in real time scheduling

Page 21: scheduling ppt

Least Slack Time first (LST)

A job Ji has deadline di, execution time ei, and was released at time ri

At time t < di:

• Remaining execution time trem = ei - (t - ri)

• Slack time tslack = di - t - trem

Assign priority to jobs based on slack time, tslack

The smaller the slack time, the higher the priority

More complex, requires knowledge of execution times and deadlines

Page 22: scheduling ppt

Scheduling of periodic and Scheduling of periodic and a-periodic jobsa-periodic jobs

Assume there are both pre-emptable periodic tasks and a-periodic tasks .

Schedule the periodic tasks using any priority based algorithm

Schedule the a-periodic tasks using following two approaches

1. Execute the a-periodic jobs in the background

2. Execute the a-periodic jobs by interrupting

the periodic jobs

Page 23: scheduling ppt

Background Scheduling ofBackground Scheduling ofA-periodic JobsA-periodic Jobs

A-periodic jobs are scheduled and executed only at A-periodic jobs are scheduled and executed only at times when there are no periodic jobs ready for times when there are no periodic jobs ready for executionexecution

AdvantagesAdvantages

Easy to implementEasy to implement

Clearly produces correct schedules Clearly produces correct schedules

DisadvantagesDisadvantages

Execution of a-periodic jobs is delayed and Execution of a-periodic jobs is delayed and response time is also large.response time is also large.

Page 24: scheduling ppt

Interrupt Scheduling of A-periodic Interrupt Scheduling of A-periodic JobsJobs

Whenever an a-periodic job arrives, the execution of periodic tasks is interrupted, and the a-periodic job is executed.

Reduces response times of a-periodic jobs

It will often cause periodic tasks in the system to miss some deadlines

Page 25: scheduling ppt

Slack Stealing for A-periodic JobsSlack Stealing for A-periodic Jobs

Neither background or interrupt driven execution Neither background or interrupt driven execution idealideal

A better alternative is A better alternative is slack stealingslack stealing

Periodic jobs are be scheduled to complete Periodic jobs are be scheduled to complete before their deadline; there may be some before their deadline; there may be some slack slack time between completion of the periodic job and time between completion of the periodic job and its deadlineits deadline

Execute a-periodic jobs in the slack time, ahead Execute a-periodic jobs in the slack time, ahead of periodic jobsof periodic jobs

Reduces response time for a-periodic jobs and Reduces response time for a-periodic jobs and is correct, but more complex and difficult .is correct, but more complex and difficult .

Page 26: scheduling ppt

Periodic servers for A-periodic JobsPeriodic servers for A-periodic Jobs

A task that behaves much like a periodic task,but is created for the purpose of executing a-periodic jobs, is a periodic server

A periodic server, T = (p, e) never executes for more than e units of time in any time interval of length p.

it is idle if the queue is empty

The periodic server is scheduled as any other periodic task based upon the priority scheme used by the scheduling algorithm

Page 27: scheduling ppt

THANK YOUTHANK YOU