Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 38

BITS Pilani

Pilani Campus

RKTiwary
RTOS
Lec-3
Digital Control
• Controlling some device (the “plant”) using an actuator,
based on sampled sensor data
– y(t) is the measured state of the plant
– r(t) is the desired state of the plant
– Calculate control output u(t) as a function of y(t), r(t)

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Digital Control

• Pseudo-code for the controller:


set timer to interrupt periodically with period T;
at each timer interrupt, do
do analogue-to-digital conversion of y(t) to get yk;
compute control output uk based on reference rk and yk;
do digital-to-analogue conversion of uk to get u(t);
end do;

• Effective control of the plant depends on:


• The correct control law computation and reference input
• The accuracy of the sensor measurements:
• Resolution of the sampled data (i.e. bits per
sample)
• Timing of the clock interrupts (i.e. samples per
second, 1/T)
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Digital Control

The time T between any two consecutive measurement of


y(t), r(t) is the sampling period
– Small T better approximates the analogue behavior
– Large T means less processor-time demands
– Must achieve a compromise
• If T is too large, oscillation will result as the system tries to
adapt

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Digital Control
• How to choose sampling period?

– Rise time – the amount of time that the plant takes to reach
some small neighbor hood around the final state in response to
a step change in the reference input
– If R is the rise time, and T is the period, a good rule of thumb
is that the ratio 10 ≤ R/T ≤ 20

• Must be chosen correctly, and accurately implemented to


ensure stability

• Multi-rate systems – system is composed of multiple sensors


and actuators, each of which require different sampling periods
– Need to run multiple control loops at once, accurately
– Usually best to have the sampling periods for the
different degrees of freedom related in a harmonic way
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-Time Communications

• All data must be delivered reliably


– Is bad if you turn the steering wheel, and nothing happens
• Commands from control system have highest priority, then
sensors and actuators, then control inputs
– Anti-lock brakes have a faster response time than the driver,
so prioritise to ensure the car doesn’t skid
• Network must schedule and prioritise communications
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-Time Communications

• Not only does a system need to run a control law with time
constraints, it must also schedule communications, sending
and receiving messages according to deadlines

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Types of Real-Time Application

• Can divide real-time applications into four types:


– Purely cyclic
• Every task executes periodically
• Demands in (computing, communication, and storage)
resources do not vary significantly from period to period
• Example: most digital controllers and real-time monitors

– Mostly cyclic
• Most tasks execute periodically
• The system must also respond to some external events (fault
recovery and external commands) asynchronously
• Example: modern avionics and process control systems

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Types of Real-Time Application
• Can divide real-time applications into four types:

– Asynchronous and somewhat predictable


• Most tasks are not periodic
• The time between consecutive executions of a task
may vary considerably, or the variations in resource
utilization in different periods may be large
• These variations have either bounded ranges or known
statistics

– Asynchronous and unpredictable


• Applications that react to asynchronous events and have
tasks with high runtime complexity
• Example: intelligent real-time control systems

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Types of Real-Time Application

• As we will see later, the type of application affects


how we schedule tasks, prove correctness

• It is easier to reason about applications that are


more cyclic, synchronous and predictable
– Many real-time systems designed in this manner
– Safe, conservative, design approach, if it
works for your application

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Implementation Considerations
• Some real-time embedded systems are complex, implemented
on high-performance hardware
– Industrial plant control
– Civilian flight control

• Many must be implemented on hardware chosen to be low


cost, low power, light-weight and robust; with performance a
distant concern
– Military flight control, space craft control
– Consumer goods
• Often-times implemented in C or assembler, fitting within a few
kilobytes of memory
– Correctness a primary concern, efficiency a close second

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Classification of scheduling algorithms

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


• Overview of real-time scheduling algorithms
– Clock-driven
– Weighted round-robin
– Priority-driven
• Dynamic vs. static
• Deadline scheduling: EDF and LST
• Validation
 Outline relative strengths, weaknesses

Material corresponds to chapter 4 of Liu’s book

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Approaches to Real-Time Scheduling

Different classes of scheduling algorithm used in real-time


systems:
• Clock-driven
– Primarily used for hard real-time systems where all properties
of all jobs are known at design time, such that offline scheduling
techniques can be used
• Weighted round-robin
– Primarily used for scheduling real-time traffic in high-speed,
switched networks
• Priority-driven
– Primarily used for more dynamic real-time systems with a mix
of time based and event-based activities, where the system must
adapt to changing conditions and events
Look at the properties of each in turn…

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


What Is Clock-Driven Scheduling?

Three tasks:
 180 per second, total computation time 1 ms
Read sensor data
Compute the control laws of the inner yaw-control loop
Apply the control laws results to the actuators
Perform internal checks
2 90 per second, total computation time 3 ms:
Compute the control laws of the inner pitch-control loop
Compute the control laws of the inner roll- and collective-
control loop
3 30 per second, total computation time 10 ms:
Compute the control lows of the outer loops
How to implement this control system?

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


What Is Clock-Driven Scheduling?

 Decision are only made at a priory chosen time instants


 It is sufficient to have a hardware timer (no need for OS)
 Regularly spaced time instants are popular
 Schedule is computed off-line and stored for use at run-time
 All parameters of hard real-time jobs are fixed and known
 Scheduling overhead during run time is minimal
 Complexity of the scheduling algorithm is not important
 Good (optimal) off-line schedules can be found
 Disadvantage: no flexibility
 Applicable only when we know all about the system in
advance
 Fixed set of tasks, fixed and known task parameters and
resource requirements
 Met by many safety-critical applications
 Easier to certify
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
What Is Clock-Driven Scheduling?

 For this lecture, we will consider the following periodic model:


 n periodic tasks τ1 ; : : : ; τn ; n is constant
 We assume the “rest of world” model.
 τi is specified with tuple (ϕi ; Ti ; Ci ; Di), where
 ϕi is task phase,
 Ti is task period,
 Ci is execution time of i and
 Di is relative deadline.
 We will shorten this as (Ti ; Ci ; Di), if ϕi = 0 and
as (Ti ; Ci) if ϕi = 0 & Ti = Di.
 In addition, we consider aperiodic jobs released in arbitrary
instants.
 Later, we will look at sporadic tasks as well.
 We are interested in scheduling for one processor.
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
What Is Clock-Driven Scheduling?
Schedule table

The scheduler will schedule periodic tasks according to a static


schedule, which is computed offline and stored in a table.
 Every element of the table specifies decision time and
scheduled task.
 If no task is to be scheduled, the special symbol X (idle) is
stored there.
 We will look at a simple algorithm how to construct the
schedule
 Aperiodic jobs can be scheduled at idle intervals

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


What Is Clock-Driven Scheduling?
Example

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Weighted Round-Robin Scheduling

Regular round-robin scheduling is commonly used for


scheduling time-shared applications
– Every job joins a FIFO queue when it is ready for execution
– When the scheduler runs, it schedules the job at the head of
the queue to execute for at most one time slice

• Sometimes called a quantum – typically O(tens of ms)


– If the job has not completed by the end of its quantum, it is
preempted and placed at the end of the queue
– When there are n ready jobs in the queue, each job gets one
slice every n time slices (n time slices is called a round)
– Only limited use in real-time systems

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Weighted Round-Robin Scheduling

• In weighted round robin each job Ji is assigned a weight


wi ; the job will receive wi consecutive time slices each
round, and the duration of a round is

– Equivalent to regular round robin if all weights equal 1


– Simple to implement, since it doesn’t require a sorted
priority queue
• Partitions capacity between jobs according to some
ratio
• Offers throughput guarantees
– Each job makes a certain amount of progress each round

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Weighted Round-Robin Scheduling
Drawback
• By giving each job a fixed fraction of the processor time, a
round-robin scheduler may delay the completion of every
job
– A precedence constrained job may be assigned processor
time, even while it waits for its predecessor to complete; a job
can’t take the time assigned to its successor to finish earlier

– Not an issue for jobs that can incrementally consume output


from their predecessor, since they execute concurrently in a
pipelined fashion

Weighted round-robin is primarily used for real-time


networking

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Priority-Driven Scheduling
 Assign priorities to jobs, based on some algorithm
 Make scheduling decisions based on the priorities, when
events such as releases and job completions occur
 Priority scheduling algorithms are event-driven
 Jobs are placed in one or more queues; at each event, the
ready job with the highest priority is executed
 The assignment of jobs to priority queues, along with rules
such as whether preemption is allowed, completely defines
a priority scheduling algorithm
 Priority-driven algorithms make locally optimal decisions
about which job to run
 Locally optimal scheduling decisions are often not globally
optimal
 Priority-driven algorithms never intentionally leave any
resource idle
 Leaving a resource idle is not locally optimal
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Priority-Driven Scheduling

 Basic rule: Never leave processor idle when there is work to


be done. (such schedulers are also called work conserving)
 Based on list-driven,
 Priority list
 greedy scheduling greedy
 To meet Local optima
 Priority Driven
 Examples: FIFO, LIFO, SETF, LETF, EDF.

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Priority-Driven Scheduling

 Possible implementation of preemptive priority-driven


scheduling:
 Assign priorities to jobs.
 Scheduling decisions are made when
 Job becomes ready
 Processor becomes idle
 Priorities of jobs change( Round robin too)
 At each scheduling decision time, choose ready task with
highest priority.

 In non-preemptive case, scheduling decisions are made only


when processor becomes idle.

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Priority-Driven Scheduling

Other commonly used names for this approach


are
 greedy scheduling,:
A priority-driven algorithm is greedy because it
tries to make locally optimal decisions.
 list scheduling and
any priority-driven algorithm can be implemented
by assigning priorities to jobs
 work-conserving scheduling.

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example: Schedule of jobs on two processors

Consider the following task:


 Jobs J1, J2, …, J8, where Ji had higher priority than Jk if i < k
 J5 is released at time 4

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example: Schedule of jobs on two processors

Consider the following task:


– Jobs J1, J2, …, J8, where Ji had higher priority than Jk if i < k

Jobs are scheduled on two


processors P 1 and P 2
– Jobs communicate via shared
memory, so communication cost is
negligible
– The schedulers keep one common
priority queue of ready jobs

Schedulers
– Preemptable – scheduling decisions are made whenever some job
becomes ready for execution or a job completes
– Non-preemptable – scheduling decision are delayed until a running job
completes.

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example contnd.

Note: The ability to preempt lower priority jobs slowed


down the overall completion of the task
 This is not a general rule, but shows that priority
scheduling results can be non-intuitive
 Different priority scheduling algorithms can have very
different properties

 In a multiprocessor system the minimum makespan of


optimal preemptive algorithm < makespan achievable by an
optimal non-preemptive algorithm

 4/3

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Dynamic vs. Static Systems

 If jobs are scheduled on multiple processors, and a job can be


dispatched from the priority run queue to any of the processors,
the system is dynamic
 A job migrates if it starts execution on one processor and is
resumed on a different processor
 If jobs are partitioned into subsystems, and each subsystem
is bound statically to a processor, we have a static system
 Expect static systems to have inferior performance (in
terms of overall response time of the jobs) relative to
dynamic systems
 But it is possible to validate static systems, whereas this is
not always true for dynamic systems
 For this reason, most hard real time systems are static

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


DYNAMIC VERSUS STATIC SYSTEMS
 above eg is dynamic system, because jobs are dynamically
dispatched to processors.
 preempted job to resume on any processor
 bind jobs to a processor and they r called static
 As an example put J1, J2, J3, and J4 on P1
 and remaining on P2
 The priority list is segmented into two parts:
(J1, J2, J3, J4) and (J5, J6, J7, J8).

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


 jobs in Figure above be partitioned as
 J1, J2, J3, and J4 on P1
 remaining jobs on P2
 priority list is segmented into two parts
 (J1, J2, J3, J4) and (J5, J6, J7, J8)
 Then
J1 J2 J3 J4
3 4 6 8

J7 J5 J6 J8
4 6 10 11
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Effective Release Times and Deadlines

• Timing constraints are often inconsistent with


precedence constraints
Example: d1>d2, but J1J2
• Effective timing constraints on a single processor:
– Effective release time: ri eff : max{ri , {rjeff | J j  J i }}
– Effective deadline: d ieff : min{d i , {d eff
j | J i  J j }}

– The effective release time/deadline of all jobs can be


computed in O(n2) where n is the number of jobs

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Effective Release Times and Deadlines

 Sometimes the release time of a job may be later than that


of its successors, or its deadline may be earlier than that
specified for its predecessors

 This makes no sense: derive an effective release time or


effective deadline consistent with all precedence constraints,
and schedule using that

 Effective release time


 If a job has no predecessors, its effective release time is its
release time
 If it has predecessors, its effective release time is the
maximum of its release time and the effective release times
of its predecessors

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Effective Release Times and Deadlines

Effective deadline
 If a job has no successors, its effective deadline
is its deadline
 It if has successors, its effective deadline is the
minimum of its deadline and the effective
deadline of its successors

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Effective Release Times and Deadlines

• In the above example, the effective release time of J3 is


2, and its effective deadline is 8
• J1 and J2 effective release time 2 & 0 and J3 is 2.
• rest of the jobs are 4, 2, 4, and 6
• J6 and J7 have no successors effective deadlines 20
and 21
• J5 the effective deadline is 8
• J4 the effective deadline is 9
• J3 the effective deadline is 8
• J1 & J2 the effective deadline are 8to be&University
BITS Pilani, Deemed 7 respectively
under Section 3 of UGC Act, 1956
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

You might also like