System Software
The Bootstrap Program
• A computer system needs a program that begins to run when the
system is first switched on. At this stage, the operating system
programs are stored on disk so there is no operating system.
However, the computer has stored in ROM a basic input output
system (BIOS) which starts a bootstrap program. It is this bootstrap
program that loads the operating system into memory and sets it
running.
Multi-programming
• An operating system can provide facilities to have more than one
program stored in memory.
• Only one program can access the CPU at any given time but others
are ready when the opportunity arises. This is described as multi-
programming. This will happen for one single user.
• Some systems are designed to have many users simultaneously
logged in . This is a time-sharing system.
The purpose of an OS
• The purposes of an operating system can usefully be
considered from two viewpoints:
• an internal viewpoint and an external viewpoint:
• The internal viewpoint concerns how
the activities of the operating system are organized to
best use the resources available.
• The external viewpoint concerns the facilities made
available to the user.
An OS is a “Resource Manager”!
The three fundamental resources in a computer system are:
• the CPU • the memory • the I/0 (input/output) system.
• Resource management relating to the CPU concerns scheduling to
ensure efficient usage.
• Resource management relating to the memory concerns optimum
usage of main memory.
• The slow speed of I/0 compared to a typical CPU clock cycle shows
that management of CPU usage is vital to ensure that the CPU does
not remain idle while I/0 is taking place.
A 1 GHz CPU is FAST!
Facilities to the user (Key Terms)
• GUI vs. CLI
• Device Driver
• File System, Directory/Folder structure
• Programming environment for programmer (hiding hardware details)
• System Calls (if a program specifies that it needs to read data from a file, the request for the file
is converted into a system call that causes the operating system to take charge, find the file and
make it available to the program.)
• API: An extension of this concept is when an operating system provides
an application programming interface (API)
The Structure of an OS
A modern “Modular Approach”
Program vs. PROCESS
• A PROGRAM in EXECUTION is called a “Process”
• Resources Assigned to the program required for
execution!
Process Scheduling
The RAM & the CPU
• A Program needs space in the RAM in order to get executed by the
CPU.
• RAM is a scarce resource!
• More programs compete for RAM so it is always lesser however
bigger it gets!
• The CPU is the only place where a program gets executed so it has to
be assigned to one program at a time and SWITCHED between various
programs at all times!
Types of SCHEDULERS
• A long-term or high-level scheduler program controls the selection of
a program stored on disk to be moved into main memory.
• Occasionally a program has to be taken back to disk due to the
memory getting overcrowded. This is controlled by a medium-term
scheduler.
• When the program is placed in memory, a short-term or low-level
scheduler controls when it has access to the CPU.
The STATES of a Process
The transitions shown in the previous figure can be described as follows:
• A new process arrives in memory and a PCB is created; it changes to the ready state.
• A process in the ready state is given access to the CPU by the dispatcher; it changes to
the running state.
• A process in the running state is halted by an interrupt; it returns to the ready state.
• A process in the running state cannot progress until some event has occurred ( I/0
perhaps) so it changes to the waiting state (sometimes called the 'suspended' or
'blocked' state)
A process in the waiting state is notified that an event is completed; it returns to the ready
state.
• A process in the running state completes execution; it changes to the terminated state.
How do The INTERRUPTS work?
• An INTERRUPT is a signal from an I/O device or software that primarily is a demand to get the CPU for the
execution of a program (a device driver – the ISR or an OS service)
• Once the ISR is executed the CPU is switched back to the program which was under execution when the interrupt
was encountered!
• When an interrupt comes along, all the register values are copied to a special data structure or memory area called
the 'stack' which is in primary memory. And they stay in the stack whilst the CPU starts executing the interrupt
service routine (ISR). Once the routine is over, the registers are loaded back with their original values from the
stack and can continue with what they were doing before the interrupt came along.
• This jumping of instructions from current CPU operations to the ISR and then back again is called 'context
switching'
Short-term scheduling algorithms
• Pre-emptive vs. Non Pre-emptive:
• A scheduling discipline is preemptive if, once a process has been given the CPU can also
be taken back and allocated to another process.
• A non-preemptive system depends on all tasks being “good citizen” by voluntarily giving
up the processor to be sure all tasks get a chance.
• The simplest possible algorithm is first come first served (FCFS). This is a non-
preemptive algorithm and can be implemented by placing the processes in a
first-in first-out (FIFO) queue. It will be very inefficient if it is the only
algorithm employed but it can be used as part of a more complex algorithm.
• A round-robin algorithm allocates a time slice to each process and is
therefore preemptive, because a process will be halted when its time
slice has run out. It can be implemented as a FIFO queue.
• A priority-based scheduling algorithm is more complicated. One
reason for this is that every ti me a new process enters the ready
queue or when a running process is halted, the priorities for the
processes may have to be re-evaluated .
Memory Management
• One memory management technique is to partition memory with the aim of loading
the whole of a process into one partition.
• Dynamic partitioning allows the partition size to match the process size. An
extension of this idea is to divide larger processes into segments, with each segment
loaded into a dynamic partition.
• Alternatively, a paging method can be used.
The process is divided into equal-sized pages and memory is divided into frames of
the same size. All of the pages are loaded into memory at the same time.
Virtual Memory
• A virtual memory based memory management scheme is based on
paging but with no requirement for all pages to be in memory at the
same time.
• In a virtual memory system, the address space that the CPU uses is
larger than the physical main memory space.
• The starting situation is that the set of pages comprising the process are stored on disk.
• One or more of these pages is loaded into memory when the process is changing to the
ready state.
• When the process is dispatched to the running state, the process starts executing. At some
stage, it will need access to pages still stored on disk which means that a page needs to be
taken out of memory first. This is when a page replacement algorithm is needed .
• A simple algorithm would use a first-in first-out method. A more sensible method would be
the least recently-used page but this requires statistics of page use to be recorded .
VM advantages
• One of the advantages of the virtual memory approach is that a very
large program can be run when an equally large amount of memory
is unavailable.
• Another advantage is that only part of a program needs to be in
memory at any one time. For example, the index tables for a
database could be permanently in memory but the full tables could
be brought in only when required.
VM problems - THRASHING
• The system overhead in running virtual memory can be a
disadvantage.
• The worst problem is 'disk thrashing', when part of a process on one
page requires another page which is on disk. When that page is
loaded it almost immediately requires the original page again . This
can lead to almost perpetual loading and unloading of pages.
• Algorithms have been developed to guard against this but the
problem can still occur, fortunately only rarely.
Virtual Machine
• The principle of a virtual machine is that a process interacts
directly with a software interface provided by the operating
system.
• The kernel of the operating system handles all of the
interactions with the actual hardware of the host system.
• The software interface provided for the virtual machine
provides an exact copy of the hardware.
• The advantage of the virtual machine approach is that more than one
different operating systems can be made available on one computer system.
• This is particularly valuable if an organization has legacy systems and wishes to
continue to use the software but does not wish to keep the aged hardware.
• Alternatively, the same operating system can be made available many times.
This is done by companies with large mainframe computers that offer server
consolidation facilities. Different companies can be offered their own virtual
machine running as a server.
REAL TIME OS (RTOS) in EMBEDDED SYSTEMS
A Real Time Operating System, commonly known as an RTOS, is a
software component that rapidly switches between tasks, giving the
impression that multiple programs are being executed at the same time
on a single processing core.
In actual fact the processing core can only execute one program at any
one time, and what the RTOS is actually doing is rapidly switching
between individual programming threads (or Tasks) to give the
impression that multiple programs are executing simultaneously.
Meeting
Deadlines
Among the many factors that allow an RTOS to fulfill these time
constraints, task scheduling and interrupts deserve special
mention.
With a GPOS, scheduling is handled in a manner that generally
achieves high throughput (i.e., the total number of processes
whose execution completes per unit time). However, this can mean
that the execution of a high-priority process will be delayed in order
to complete multiple low-priority tasks. On the other hand, the
value of an RTOS is gauged on how quickly or predictably it can
respond rather than the amount of work it can perform in a given
period of time.
In an RTOS, scheduling is usually priority based. Most RTOS’s use a pre-emptive task
scheduling method based on priority levels. Here, a high-priority process will be executed
over the low priority processes. With a GPOS, latencies can accumulate as more threads
need to be scheduled. An RTOS has no such issues because the latencies of all the
processes and threads are time bound. The RTOS also provides a way for you to ensure
that the shared system resources are protected from concurrent access.
The kernel of an RTOS is preemptible whereas a GPOS kernel is not preemptible, which is
important when serving high-priority processes and threads first. Without a preemptible
kernel, a request from within the kernel, such as that from a driver or a system service,
would override all other process and threads. With an RTOS, only very important service
requests are kept within the kernel call and all other service requests are treated as
external processes and threads. The kernel-based service requests are associated with
the bounded latency of the RTOS to maintain fast and predictable responses.