05 Concur Rre Ncy
05 Concur Rre Ncy
05 Concur Rre Ncy
Fall 2024
1
CONCURRENCY
Overview
n Concurrency
n How do we make things happen at the right
times?
MCU Hardware & Software for Concurrency
n CPU executes instructions
from one or more threads
of execution
n Specialized hardware
peripherals add dedicated
concurrent processing
n DMA - transferring data
between memory and
peripherals
n Watchdog timer
n Analog interfacing
n Timers
n Communications with
other devices
n Detecting external signal
events
n Peripherals use interrupts
to notify CPU of events
Concurrent Hardware & Software Operation
Software Hardware Software Hardware Software
Time
Dec
Check
Rec
Sw
LCD
Time
How do we schedule these tasks?
n Task scheduling: Deciding which
Dec task should be run now
Check n Two fundamental questions
n Do we run tasks in the same
Rec
order every time?
Sw n Yes: Static schedule (cyclic
executive, round-robin)
LCD n No: Dynamic, prioritized schedule
n Can one task preempt another,
or must it wait for completion?
n Yes: Preemptive
n No: Non-preemptive (cooperative,
run-to-completion)
Static Schedule (Cyclic Executive)
Dec Check Rec S LCD Dec
w
n Pros
n Very simple
n Cons while (1){
n Always run the same schedule, Dec();
regardless of changing conditions and Check();
relative importance of tasks. Rec();
n All tasks run at same rate. Changing Sw();
rates requires adding extra calls to the
function.
LCD();
n Maximum delay is sum of all task run
}
times. Polling/execution rate is 1/
maximum delay.
Static Schedule Example
GPS Data Checking
Arrives complete
Response Time
Response Time
n Pros
n Preemption offers best response time
n Can do more processing (support more potholes, or higher
vehicle speed)
n Or can lower processor speed, saving money, power
n Cons
n Requires more complicated programming, more memory
n Introduces vulnerability to data race conditions
Common Schedulers
n Cyclic executive - non-preemptive and static
24
Task State and Scheduling Rules
n Scheduler chooses
among Ready tasks for
execution based on
priority What the Ready
task needs
happens
n Scheduling Rules This is This isn’t
n A task’s activities may highest highest
lead it to waiting Waiting priority priority
(blocked) ready task ready task
n A waiting task never
gets the CPU. It must
be signaled by an ISR Task needs
or another task. something Running
n Only the scheduler to happen
moves tasks between
ready and running 25
What’s an RTOS?
n What does Real-Time mean?
n Can calculate and guarantee the maximum response time for
each task and interrupt service routine
n This “bounding” of response times allows use in hard-real-time
systems (which have deadlines which must be met)
n What’s in the RTOS
n Task Scheduler
n Preemptive, prioritized to minimize response times
n Interrupt support
n Core Integrated RTOS services
n Inter-process communication and synchronization (safe data sharing)
n Time management
n Optional Integrated RTOS services
n I/O abstractions?
n memory management?
n file system?
n networking support?
n GUI??
Comparison of Timing Dependence
Non-preemptive Non-preemptive Preemptive
Static Dynamic Dynamic
Device A ISR
Device A ISR Device A ISR
Device B ISR
Device B ISR Device B ISR
Device ... ISR
Device ... ISR
Device ... ISR
Device Z ISR Device Z ISR
Device Z ISR
Slowest Task
Task 1 Code
Task 5 Code Task 1 Code
Task 1 Code Task 4 Code
Task 2 Code Task 6 Code
Task 3 Code Task 2 Code
Task 2 Code
29