unit-3 PROCESSES AND OPERATING SYSTEMS
unit-3 PROCESSES AND OPERATING SYSTEMS
• In this case, the initiation interval is equal to one fourth of the period.
• It is possible for a process to have an initiation rate less than the period even in
single-CPU systems.
• If the process execution time is less than the period, it may be possible to initiate
multiple copies of a program at slightly offset times.
Data dependencies among processes
• The system decoder process demultiplexes the audio and video data and
distributes it to the appropriate processes.
• Missing Deadline
• Missing deadline in a multimedia system may cause an audio or video glitch.
• The system can be designed to take a variety of actions when a deadline is
missed.
CPU Metrics
⚫ CPU metrics are described by initiation time and completion time.
⚫ Initiation timeIt is the time at which a process actually starts executing on
the CPU.
⚫ Completion timeIt is the time at which the process finishes its work.
⚫ The CPU time of process i is called Ci .
⚫ The CPU time is not equal to the completion time minus initiation time.
⚫ The total CPU time consumed by a set of processes is
⚫ A process goes into the waiting state when it needs data that it has finished all its work for
the current period.
⚫ A process goes into the ready state when it receives its required data, when it enters
a new period.
⚫ Finally a process can go into the executing state only when it has all its data, is ready to
run, and the scheduler selects the process as the next process to run.
Scheduling Policies
⚫ A scheduling policy defines how processes are selected for promotion from the
ready state to the running state.
⚫ SchedulingAllocate time for execution of the processes in a system .
⚫ For periodic processes, the length of time that must be considered is the hyper period,
which is the least-common multiple of the periods of all the processes.
⚫ Unrolled schedule The complete schedule for the least-common multiple of the
periods.
Types of scheduling
1. Cyclostatic scheduling or Time Division Multiple Access scheduling
⚫ Schedule is divided into equal-sized time slots over an interval equal to the length of the
hyperperiod H. (run in the same time slot)
• When the system begins execution,P2 is the only ready process, so it is selected for execution.
• At T=15, P1 becomes ready; it preempts P2 because p1 has a higher priority, so it execute
immediately
• P3’s data arrive at time 18, it has lowest priority.
• P2 is still ready and has higher priority than P3.
• Only after both P1 and P2 finish can P3 execute
⚫ 5.4.4) Context Switching
⚫ To understand the basics of a context switch, let’s assume that the set of tasks is
in steady state.
⚫ Everything has been initialized, the OS is running, and we are ready for a timer
interrupt.
⚫ This diagram shows the application tasks, the hardware timer, and all the
functions in the kernel that are involved in the context switch.
⚫ vPreemptiveTick() it is called when the timer ticks.
⚫ portSAVE_CONTEXT() swaps out the current task context.
⚫ vTaskSwitchContext ( ) chooses a new task.
⚫ portRESTORE_CONTEXT() swaps in the new context
PRIORITY-BASED SCHEDULING
⚫ Operating system is to allocate resources in the computing system based on
the priority.
⚫ After assigning priorities, the OS takes care of the rest by choosing the highest-
priority ready process.
⚫ There are two major ways to assign priorities.
⚫ Static priorities that do not change during execution
⚫ Dynamic priorities that do change during execution
⚫ Types of scheduling process
1. Rate-Monotonic Scheduling
2. Earliest-Deadline-First Scheduling
Rate-Monotonic Scheduling(RMS)
⚫ Rate-monotonic scheduling (RMS) is one of the first scheduling policies
developed for real-time systems.
⚫ RMS is a static scheduling policy.
⚫ It assigns fixed priorities are sufficient to efficiently schedule the processes in
many situations.
RMS is known as rate-monotonic analysis (RMA), as summarized below.
⚫ All processes run periodically on a single CPU.
⚫ Context switching time is ignored.
⚫ There are no data dependencies between processes.
⚫ The execution time for a process is constant.
⚫ All deadlines are at the ends of their periods.
⚫ The highest-priority ready process is always selected for execution.
⚫ Priorities are assigned by rank order of period, with the process with the
shortest period being assigned the highest priority.
Example-Rate-monotonic scheduling
⚫ set of processes and their characteristics
⚫ In this case, Even though each process alone has an execution time significantly less than
its period, combinations of processes can require more than 100% of the available CPU
cycles.
⚫ During one 12 time-unit interval, we must execute P1 -3 times, requiring 6 units of CPU
time; P2 twice, costing 6 units and P3 one time, costing 3 units.
⚫ The total of 6 + 6 + 3 = 15 units of CPU time is more than the 12 time units available,
clearly exceeding the available CPU capacity(12units).
RMA priority assignment analysis
⚫ Response time The time at which the process finishes.
⚫ Critical instantThe instant during execution at which the task has the largest response
time.
⚫ Let the periods and computation times of two processes P1 and P2 be τ1, τ2 and T1, T2,
with τ 1 < τ 2.
⚫ let P1 have the higher priority. In the worst case we then execute P2 once during its period
and as many iterations of P1 as fit in the same interval.
⚫ Since there are τ2/ τ1 iterations of P1 during a single period of P2.
⚫ The required constraint on CPU time, ignoring context switching overhead, is
⚫ we give higher priority to P2, then execute all of P2 and all of P1 in one of P1’s periods in
the worst case.
⚫ Hyper-period is 60
Dead line Table
⚫ There is one time slot left at t= 30, giving a CPU utilization of 59/60.
⚫ EDF can achieve 100% utilization
⚫ RMS vs. EDF
Ex:Priority inversion
⚫ Low-priority process blocks execution of a higher priority process by keeping hold
of its resource.
Consider a system with two processes
⚫ Higher-priority P1 and the lower-priority P2.
⚫ Each uses the microprocessor bus to communicate to peripherals.
⚫ When P2 executes, it requests the bus from the operating system and receives it.
⚫ If P1 becomes ready while P2 is using the bus, the OS will preempt P2 for P1,
leaving P2 with control of the bus.
⚫ When P1 requests the bus, it will be denied the bus, since P2 already owns it.
⚫ Unless P1 has a way to take the bus from P2, the two processes may deadlock.
Eg:Data dependencies and scheduling
⚫ Data dependencies imply that certain combinations of processes can never occur. Consider the
simple example.
⚫ We know that P1 and P2 cannot execute at the same time, since P1 must finish before P2 can
begin.
⚫ P3 has a higher priority, it will not preempt both P1 and P2 in a single iteration.
⚫ If P3 preempts P1, then P3 will complete before P2 begins.
⚫ if P3 preempts P2, then it will not interfere with P1 in that iteration.
⚫ Because we know that some combinations of processes cannot be ready at the same time,
worst-case CPU requirements are less than would be required if all processes could be ready
simultaneously.
Inter-process communication mechanisms
⚫ It is provided by the operating system as part of the process abstraction.
⚫ Blocking Communication The process goes into the waiting state until it receives a
response
⚫ Non-blocking CommunicationIt allows a process to continue execution after
sending the communication.
Types of inter-process communication
1. Shared Memory Communication
2. Message Passing
3. Signals
Shared Memory Communication
⚫ The communication between inter-process is used by bus-based system.
⚫ CPU and an I/O device, communicate through a shared memory location.
⚫ The software on the CPU has been designed to know the address of the shared location.
⚫ The shared location has also been loaded into the proper register of the I/O device.
⚫ If CPU wants to send data to the device, it writes to the shared location.
⚫ The I/O device then reads the data from that location.
⚫ The read and write operations are standard and can be encapsulated in a procedural
interface.
⚫ CPU and the I/O device want to communicate through a shared memory block.
⚫ There must be a flag that tells the CPU when the data from the I/O device is ready.
⚫ The flag value of 0 when the data are not ready and 1 when the data are ready.
⚫ If the flag is used only by the CPU, then the flag can be implemented using a standard
memory write operation.
⚫ If the same flag is used for bidirectional signaling between the CPU and the I/O device,
care must be taken.
Consider the following scenario to call flag
1. CPU reads the flag location and sees that it is 0.
2. I/O device reads the flag location and sees that it is 0.
3. CPU sets the flag location to 1 and writes data to the shared location.
4. I/O device erroneously sets the flag to 1 and overwrites the data left by the CPU.
Ex: Elastic buffers as shared memory
⚫ The text compressor is a good example of a shared memory.
⚫ The text compressor uses the CPU to compress incoming text, which is then sent on a
serial line by a UART.
⚫ The input data arrive at a constant rate and are easy to manage.
⚫ But the output data are consumed at a variable rate, these data require an elastic buffer.
⚫ The CPU and output UART share a memory area—the CPU writes compressed characters
into the buffer and the UART removes them as necessary to fill the serial line.
⚫ Because the number of bits in the buffer changes constantly, the compression and
transmission processes need additional size information.
⚫ CPU writes at one end of the buffer and the UART reads at the other end.
⚫ The only challenge is to make sure that the UART does not overrun the buffer.
Message Passing
⚫ Here each communicating entity has its own message send/receive unit.
⚫ The message is not stored on the communications link, but rather at the senders/ receivers
at the end points.
⚫ Ex:Home control system
⚫ It has one microcontroller per household device—lamp, thermostat, faucet, appliance.
⚫ The devices must communicate relatively infrequently.
⚫ Their physical separation is large enough that we would not naturally think of them as
sharing a central pool of memory.
⚫ Passing communication packets among the devices is a natural way to describe
coordination between these devices.
Signals
⚫ Generally signal communication used in Unix .
⚫ A signal is analogous to an interrupt, but it is entirely a software creation.
⚫ A signal is generated by a process and transmitted to another process by the OS.
⚫ A UML signal is actually a generalization of the Unix signal.
⚫ Unix signal carries no parameters other than a condition code.
⚫ UML signal is an object, carry parameters as object attributes.
⚫ The sigbehavior( ) behavior of the class is responsible for throwing the signal,
as indicated by<<send>>.
⚫ The signal object is indicated by the <<signal>>
Evaluating operating system performance
⚫ Analysis of scheduling policies is made by the following 4 assumptions
⚫ Assumed that context switches require zero time. Although it is often
reasonable to neglect context switch time when it is much smaller than the
process execution time, context switching can add significant delay in some
cases.
⚫ We have largely ignored interrupts. The latency from when an interrupt is
requested to when the device’s service is complete is a critical parameter of real
time performance.
⚫ We have assumed that we know the execution time of the processes.
⚫ We probably determined worst-case or best-case times for the processes in
isolation.
Context switching time
It depends on following factors
⚫ The amount of CPU context that must be saved.
⚫ Scheduler execution time.
Interrupt latency
⚫ Interrupt latency It is the duration of time from the assertion of a device interrupt to
the completion of the device’s requested operation.
⚫ Interrupt latency is critical because data may be lost when an interrupt is not serviced in
a timely fashion.
childid = fork();
if (childid == 0) { /* must be the child */
execv(“mychild”,childargs);
perror(“execl”);
exit(1);
}
else { /* is the parent */
parent_stuff(); /* execute parent functionality */
wait(&cstatus);
exit(0);
}
The POSIX process model
⚫ Each POSIX process runs in its own address space and cannot directly access the
data or code.
Real-time scheduling in POSIX
⚫ POSIX supports real-time scheduling in the POSIX_PRIORITY_SCHEDULING
resource.
⚫ POSIX supports Rate-monotonic scheduling in the SCHED_FIFO scheduling
policy.
⚫ It is a strict priority-based scheduling scheme in which a process runs until it is
preempted or terminates.
⚫ The term FIFO simply refers processes run in first-come first-served order.
POSIX semaphores
⚫ POSIX supports semaphores and also supports a direct shared memory mechanism.
⚫ POSIX supports counting semaphores in the _POSIX_SEMAPHORES option.
⚫ A counting semaphore allows more than one process access to a resource at a time.
⚫ If the semaphore allows up to N resources, then it will not block until N processes have
⚫ simultaneously passed the semaphore;
⚫ The blocked process can resume only after one of the processes has given up its
semaphore.
⚫ When the semaphore value is 0, the process must wait until another process gives up the
semaphore and increments the count.
POSIX pipes
⚫ Parent process uses the pipe() function to create a pipe to talk to a child.
⚫ Each end of a pipe appears to the programs as a file.
⚫ The pipe() function returns an array of file descriptors, the first for the write end and the
second for the read end.
⚫ POSIX also supports message queues under the _POSIX_MESSAGE_PASSING facility..
Windows CE
⚫ Windows CE is designed to run on multiple hardware platforms and
instruction set architectures.
⚫ It supports devices such as smart phones, electronic instruments etc..,
⚫ Applications run under the shell and its user interface.
⚫ The Win32 APIs manage access to the operating system.
⚫ OEM Adaption Layer (OAL) provides an interface to the hardware and software
architecture.
⚫ OAL provides services such as a real-time clock, power management, interrupts, and a
debugging interface.
⚫ A Board Support Package (BSP) for a particular hardware platform includes the OAL and
drivers.
Memory Space
⚫ It support for virtual memory with a flat 32-bit virtual address space.
⚫ A virtual address can be statically mapped into main memory for key kernel-mode code.
⚫ An address can also be dynamically mapped, which is used for all user-mode and some
kernel-mode code.
⚫ Flash as well as magnetic disk can be used as a backing store
⚫ The top 1 GB is reserved for system elements such as DLLs, memory mapped files, and
shared system heap.
⚫ The bottom 1 GB holds user elements such as code, data, stack, and heap.
User address space in windows CE
⚫ Threads are defined by executable files while drivers are defined by
dynamically-linked libraries (DLLs).
⚫ A process can run multiple threads.
⚫ Threads in different processes run in different execution
environments.
⚫ Threads are scheduled directly by the operating system.
⚫ Threads may be launched by a process or a device driver.
⚫ A driver may be loaded into the operating system or a process.
⚫ Drivers can create threads to handle interrupts
⚫ Each thread is assigned an integer priority.
⚫ 0 is the highest priority and 255 is the lowest priority.
⚫ Priorities 248 through 255 are used for non-real-time threads .
⚫ The operating system maintains a queue of ready processes at each
priority level.
⚫ Execution of a thread can also be blocked by a higher-priority thread.
⚫ Tasks may be scheduled using either of two policies: a thread runs until the end
of its quantum; or a thread runs until a higher-priority thread is ready to run.
⚫ Within each priority level, round-robin scheduling is used.
⚫ WinCE supports priority inheritance.
⚫ When priorities become inverted, the kernel temporarily boosts the priority of
the lower-priority thread to ensure that it can complete and release its
resources.
⚫ Kernel will apply priority inheritance to only one level.
⚫ If a thread that suffers from priority inversion in turn causes priority inversion
for another thread, the kernel will not apply priority inheritance to solve the
nested priority inversion.
Sequence diagram for an interrupt
⚫ Interrupt handling is divided among three entities
⚫ The interrupt service handler (ISH) is a kernel service that provides the first
response to the interrupt.
⚫ The ISH selects an interrupt service routine (ISR) to handle the interrupt.
⚫ The ISR in turn calls an interrupt service thread (IST) which performs most of
the work required to handle the interrupt.
⚫ The IST runs in the OAL and so can be interrupted by a higher-priority
interrupt.
⚫ ISRdetermines which IST to use to handle the interrupt and requests the
kernel to schedule that thread.
⚫ The ISH then performs its work and signals the application about the updated
device status as appropriate.
⚫ kernel-mode and user-mode drivers use the same API.
Distributed Embedded Systems (DES)
⚫ It is a collection of hardware and software and its communication.
⚫ It also has many control system performance.
⚫ Processing Element (PE)is a basic unit of DES.
⚫ It allows the network to communicate.
⚫ PE is an instruction set processor such as DSP,CPU and Microcontroller.
Network abstractions
⚫ Networks are complex systems.
⚫ It provide high-level services such as data transmission from the other
components in the system.
⚫ ISO has developed a seven-layer model for networks known as Open Systems
Interconnection (OSI) models.
OSI model layers
⚫ Physical layer defines the basic properties of the
interface between systems, including the physical
connections, electrical properties & basic procedures
for exchanging bits.
⚫ Data link layer used for error detection and control
across a single link.
⚫ Network layer defines the basic end-to-end data
transmission service.
⚫ Transport layer defines connection-oriented
services that ensure that data are delivered in the
proper order .
⚫ Session layer provides mechanisms for controlling
the interaction of end-user services across a network,
such as data grouping and checkpointing.
⚫ Presentation layer layer defines data exchange
formats
⚫ Application layer provides the application interface
between the network and end-user programs.
Controller Area Network(CAN)Bus
⚫ It was designed for automotive electronics
and was first used in production cars in 1991.
⚫ It uses bit-serial transmission.
⚫ CAN can run at rates of 1 Mbps over a twisted
pair connection of 40 meters.
⚫ An optical link can also be used.
4.7.2.1)Physical-electrical organization of a CAN
bus
⚫ Each node in the CAN bus has its own
electrical drivers and receivers that connect
the node to the bus in wired-AND fashion.
⚫ When all nodes are transmitting 1s, the bus is
said to be in the recessive state.
⚫ when a node transmits a 0s, the bus is in the
dominant state.
Data Frame
⚫ Arbitration field The first field in the packet contains the packet’s destination address 11 bits
⚫ Remote Transmission Request (RTR) bit is set to 0 if the data frame is used to request data
from the destination identifier.
⚫ When RTR = 1, the packet is used to write data to the destination identifier.
⚫ Control field 4-bit length for the data field with a 1 in between.
⚫ Data field0 to 64 bytes, depending on the value given in the control field.
⚫ CRC It is sent after the data field for error detection.
⚫ Acknowledge field identifier signal whether the frame was correctly received.( sender puts a
bit (1) in the ACK slot , if the receiver detected an error, it put (0) value)
Arbitration
⚫ It uses a technique known as Carrier Sense Multiple Access with Arbitration on Message
Priority (CSMA/AMP).
⚫ When a node hears a dominant bit in the identifier when it tries to send a recessive bit, it
stops transmitting.
⚫ By the end of the arbitration field, only one transmitter will be left.
⚫ The identifier field acts as a priority identifier, with the all-0 having the highest priority
Error handling
⚫ An error frame can be generated by any node that detects an error on the bus.
⚫ Upon detecting an error, a node interrupts the current transmission.
⚫ Error flag field followed by an error delimiter field of 8 recessive bits.
⚫ Error delimiter field allows the bus to return to the quiescent state so that data frame
transmission can resume.
⚫ Overload frame signals that a node is overloaded and will not be able to handle the next
message. Hence the node can delay the transmission of the next frame .
Architecture of a CAN controller
⚫ When a master wants to write a slave, it transmits the slave’s address followed by the data.
⚫ When a master send a read request with the slave’s address and the slave transmit the data.
⚫ Transmission address has 7-bit and 1 bit for data direction.( 0 for writing from the master to
the slave and 1 for reading from the slave to the master)
⚫ A bus transaction is initiated by a start signal and completed with an end signal.
⚫ A start is signaled by leaving the SCL high and sending a 1 to 0 transition on SDL.
⚫ A stop is signaled by setting the SCL high and sending a 0 to 1 transition on SDL.
State transition graph for an I2C bus master
⚫ Starts and stops must be paired.
⚫ A master can write and then read by sending a start after the data transmission, followed
by another address transmission and then more data.
Transmitting a byte on the I2C bus
⚫ The transmission starts when SDL is pulled low while SCL remains high.
⚫ The clock is pulled low to initiate the data transfer.
⚫ At each bit, the clock goes high while the data line assumes its proper value of 0 or 1.
⚫ An acknowledgment is sent at the end of every 8-bit transmission, whether it is an
address or data.
⚫ After acknowledgment, the SDL goes from low to high while the SCL is high, signaling
the stop condition.
I2C interface in a microcontroller
⚫ System has a 1-bit hardware interface with routines for byte-level functions.
⚫ I2C device used to generates the clock and data.
⚫ Application code calls routines to send an address, data byte, and also generates the SCL
,SDL and acknowledges.
⚫ Timers is used to control the length of bits on the bus.
⚫ When Interrupts used in master mode, polled I/O may be acceptable.
⚫ If no other pending tasks can be performed, because masters initiate their own transfers.
ETHERNET
⚫ It is widely used as a local area network for general-purpose computing.
⚫ It is also used as a network for embedded computing.
⚫ It is particularly useful when PCs are used as platforms, making it possible to use
standard components, and when the network does not have to meet real-time
requirements.
⚫ It is a bus with a single signal path.
⚫ It supports both twisted pair and coaxial cable.
⚫ Ethernet nodes are not synchronized, if two nodes decide to transmit at the same
time,the message will be ruined.
Ethernet CSMA/CD algorithm
⚫ A node that has a message waits for the
bus to become silent and then starts
transmitting.
⚫ It simultaneously listens, and if it hears
another transmission that interferes with
its transmission, it stops transmitting and
waits to retransmit.
⚫ The waiting time is random, but weighted
by an exponential function of the number
of times the message has been aborted
Ethernet-Packet format
⚫ We have labeled the data transmissions on each arc ,We want to execute the task on the
platform below.
⚫ The platform has two processing elements and a single bus connecting both PEs. Here
are the process speeds:
⚫ As an initial design, let us allocate P1 and P2 to M1 and P3 to M2This schedule shows
what happens on all the processing elements and the network.
⚫ The schedule has length 19. The d1 message is sent between the processes internal to
⚫ P1 and does not appear on the bus.
⚫ Let’s try a different allocation. P1 on M1 and P2 and P3 on M2. This makes P2 run more
slowly. Here is the new schedule:.
⚫ The length of this schedule is 18, or one time unit less than the other schedule. The
⚫ increased computation time of P2 is more than made up for by being able to transmit a
⚫ shorter message on the bus. If we had not taken communication into account when
analyzing total execution time, we could have made the wrong choice of which processes
to put on the same processing element.
Audio player/MP3 Player
Operation and requirements
⚫ MP3 players use either flash memory or disk drives to store music.
⚫ It performs the following functions such as audio storage, audio decompression, and
user interface.
⚫ Audio compression It is a lossy process. The coder eliminates certain features of the audio
stream so that the result can be encoded in fewer bits.
⚫ Audio decompression The incoming bit stream has been encoded using a Huffman style
code, which must be decoded.
⚫ Masking One tone can be masked by another if the tones are sufficiently close in frequency.
Audio compression standards
⚫ Layer 1 (MP1) uses a lossless compression of sub bands and simple masking model.
⚫ Layer 2 (MP2) uses a more advanced masking model.
⚫ Layer 3 (MP3) performs additional processing to provide lower bit rates.
MPEG Layer 1 encoder
⚫ Filter bank splits the signal into a set of 32 sub-
bands that are equally spaced in the frequency
domain and together cover the entire frequency
range of the audio.
⚫ EncoderIt reduce the bit rate for the audio
signals.
⚫ Quantizer scales each sub-band( fits within 6
bits ), then quantizes based upon the current scale
factor for that sub-band.
⚫ Masking model It is driven by a separate Fast
Fourier transform (FFT), the filter bank could be
used for masking, a separate FFT provides better
results.
⚫ The masking model chooses the scale factors for
the sub-bands, which can change along with the
audio stream.
⚫ Multiplexer output of the encoder passes along
all the required data.
MPEG Layer 1 data frame format
⚫ A frame carries the basic MPEG data, error correction codes, and additional information.
⚫ After disassembling the data frame, the data are un-scaled and inverse quantized to
produce sample streams for the sub-band.
Video compression
• MPEG-2 forms the basis for U.S. HDTV
broadcasting.
• This compression uses several
component algorithms together in a
feedback loop.
• Discrete cosine transform (DCT) used in
JPEG and MPEG-2.
• DCT used a block of pixels which is
quantized for lossy compression.
• Variable-length coderassign number of
bits required to represent the block.
Block motion Estimation
⚫ MPEG uses motion to encode one frame in
terms of another.
⚫ Block motion estimationsome frames are
sent as modified forms of other frames
⚫ During encoding, the frame is divided into
macro blocks.
⚫ Encoder uses the encoding information to
recreate the lossily-encoded picture, compares
it to the original frame, and generates an error
signal.
⚫ Decoder keep recently decoded frames in
memory so that it can retrieve the pixel values
of macro-blocks.
5.13.2).Concept of Block motion estimation
⚫ To find the best match between regions in the two frames.
⚫ Divide the current frame into 16 x 16 macro blocks.
⚫ For every macro block in the frame, to find the region in the previous frame that most
closely matches the macro block.
⚫ Measure similarity using the following sum-of-differences measure