0% found this document useful (0 votes)
16 views40 pages

Unit 2 Part 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views40 pages

Unit 2 Part 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

CS 3691

EMBEDDED SYSTEMS AND IOT


Link

https://referenceglobe.com/CollegeLibrary/library_books/2018
0226061001computers-as-components-principles-of-embedded-com
puting-system-design-2nd-edition-wayne-wolf-elsevier-2008-%5
Bbookspar.com%5D.pdf
1. Tasks and Processes
1. Tasks and Processes
Example of Compressor
Explanation

● The device connects to serial ports on both ends, taking in uncompressed bytes as input.
● It outputs compressed bits based on a predefined compression table.
● It's commonly used to compress data before sending it to a modem.
● Programs may need to handle different rates of receiving and sending data, such as emitting 2 bits for the first byte
and then 7 bits for the second byte.
● This rate difference influences the structure of the code.
● An elegant solution involves creating a queue for output bits, which are sent to the serial port in sets of 8 bits.
● Besides organizing the code's control structure, it's crucial to manage input and output rates properly.
● Spending too much time on output packaging might lead to dropping input characters, presenting a timing challenge
to solve.
Explanation

● The compression box and a control panel on a machine demonstrate rate control problems.
● The compression box's control panel may have a compression mode button to enable or disable compression.
● Pressing the compression mode button can happen asynchronously compared to character arrivals.
● Buttons are pressed much less frequently than characters are received.
● Managing input/output while monitoring the button can lead to complex control code.
● Sampling the button too slowly might miss button depressions, while sampling too frequently can cause incorrect
data compression.
● One solution involves using a counter in the main compression loop to check the button periodically.
● However, this solution fails if either the compression loop or the button-handling routine has variable execution
times, leading to potential data loss.
● Processes allow for separate handling of tasks with different timing requirements, addressing these control
challenges.
● These examples highlight how timing and execution rate requirements can complicate programming, leading to
complex control structures that are challenging to verify for functionality and timing properties.
2. Multi rate systems

● Implementing code that satisfies timing requirements is even more complex


when multiple rates of computation must be handled.

● Multirate embedded computing systems are very common,including automobile


engines, printers, and cell phones. In all these systems,certain
operations must be executed periodically,and each operation is executed at
its own rate.
Example: Two wheeler spark plug
3. Timing Requirements on Processes

● Processes can have several different types of timing requirements imposed on them by the
application.
● The timing requirements on a set of processes strongly influence the type of scheduling
that is appropriate.
● A scheduling policy must define the timing requirements that it uses to determine whether
a schedule is valid
● The release time is the time at which the process becomes
ready to execute; this is not necessarily the time at which it
actually takes control of the CPU and starts to run.
○ An aperiodic process is by definition initiated by an
event, such as external data arriving or data
computed by another process. The release time is
generally measured from that event.
○ For a periodically executed process, there are two
common possibilities. In simpler systems, the
process may become ready at the beginning of the
period.
○ More sophisticated systems, such as those with data
dependencies between processes, may set the release
time at the arrival time of certain data, at a time after
the start of the period.
● A deadline specifies when a computation must be finished.
○ The deadline for an aperiodic process is generally
measured from the release time, since that is the
only reasonable time reference.
○ The deadline for a periodic process may in general
occur at some time other than the end of the period.
● A set of processes with data
dependencies is known as a task
graph.
● consider a component of the task
graph (a set of nodes connected by
data dependencies) as a task and the
complete graph as the task set
● The two tasks ({P1, P2, P3, P4} and
{P5, P6}) have no timing
relationships between them.
● Communication among processes that
run at different rates cannot be
represented by data dependencies
because there is no one-to-one
relationship between data coming out
of the source process and going into
the destination process.
4. CPU Metrics
● The initiation time is the time at which a process
actually starts executing on the CPU. The completion time
is the time at which the process finishes its work.
5. Process State and Scheduling
● Cyclostatic schedule is divided into

6. Some scheduling Policies equal-sized time slots over an interval equal


to the length of the hyperperiod H.
● Processes always run in the same time slot.
● Two factors affect utilization: the number of
time slots used and the fraction of each time
slot that is used for useful work. Depending
on the deadlines for some of the
processes,we may need to leave some time
slots empty.
● And since the time slots are of equal
size,some short processes may have time left
over in their time slot
● Round robin uses the same hyperperiod as
does cyclostatic. It also evaluates the
processes in order does not have any useful
work to do, the round-robin scheduler
moves on to the next process in order to fill
the time slot with useful work.
7. Running Periodic Processes

For the moment,let’s think of a process as a subroutine;we


will call them p1( ), p2( ), etc. for simplicity. Our goal
is to run these subroutines at rates determined by the
system designer.

No control over rate of execution


Soln: we could pad the loop with
useless operations (NOPs) to make the
execution time of an iteration equal
to the desired period
PREEMPTIVE REAL-TIME OPERATING SYSTEMS - Preemption

❖ Preemption is an alternative to the C function call as a way to control execution.To be able to take full
advantage of the timer.
❖ The kernel is the part of the OS that determines what process is running. The kernel is activated periodically
by the timer. The length of the timer period is known as the time quantum because it is the smallest
increment in which we can control CPU activity.
❖ The kernel determines what process will run next and causes that process to run. On the next timer interrupt,
the kernel may pick the same process or another process to run.
❖ The set of registers that define a process are known as its context and switching from one process’s register
set to another is known as context switching. The data structure that holds the state of the process is known
as the process control block.
Priorities - to decide which process to pick

● If we assign each task a numerical priority, then the


kernel can simply look at the processes and their
priorities,see which ones actually want to execute (some
may be waiting for data or for some event),and select the
highest priority process that is ready to run.
● This mechanism is both flexible and fast.
● The priority is a non-negative integer value.
Context Switching
Explanation
1. Everything has been initialized, the OS is running, and
we are ready for a timer interrupt.
2. This diagram shows the application tasks, the hardware
timer, and all the functions in the kernel that are
involved in the context switch:
vPreemptiveTick

● has been declared as a naked function; this means that it


does not use the normal procedure entry and exit code
that is generated by the compiler.
● Because the function is naked, the registers for the
process that was interrupted are still available;
vPreemptiveTick() doesn’t have to go to the procedure
call stack to get their values.
● This is particularly handy since the procedure mechanism
would save only part of the process state,making the
state-saving code a little more complex
1. SAVE CONTEXT of the task that was interrupted.
2. It then performs some housekeeping, such as
portSAVE_CONTEXT() incrementing the tick count.
3. The tick count is the internal timer that is
used to determine deadlines.
4. After the tick is incremented, some tasks may
have become ready as they passed their
deadlines.

vTaskSwitchContext() 1. After some more housekeeping, it uses port


RESTORE_CONTEXT() to restore the context of the
task that was selected by vTaskSwitchContext().
2. The action of portRESTORE_CONTEXT() causes
control to transfer to that task without using
the standard C return mechanism. The code for
portSAVE_CONTEXT(), in the file portmacro.h, is
defined as a macro and not as a C function. It
is structured in this way so that it doesn’t
disturb the register values that need to be
saved.
1. Rate Monotonic Scheduling
Earliest-Deadline-First Scheduling
RMS VS EDF
1. EDF can extract higher utilization out of
the CPU, but it may be difficult to
diagnose the possibility of an imminent
overload.
2. Because the scheduler does take some
overhead to make scheduling
decisions,a factor that is ignored in the
schedulability analysis of both EDF and
RMS, running a scheduler at very high
utilizations is somewhat problematic.
3. RMS achieves lower CPU utilization
but is easier to ensure that all deadlines
will be satisfied
Modeling Assumptions

● we have assumed that each process is totally self contained.


○ It’s not possible always because a process may need a system resource,such as an I/O device or the
bus,to complete its work.
○ Scheduling the processes without considering the resources those processes require can cause priority
inversion, in which a low-priority process blocks execution of a higher priority process by keeping hold
of its resource.
● Rate-monotonic scheduling assumes that there are no data dependencies between
processes.

You might also like