Operating Systems Concepts For Soc Design

Download as pdf or txt
Download as pdf or txt
You are on page 1of 63

Operating Systems Concepts

for SoC Design

Chi-Sheng Shih

http://www.csie.ntu.edu.tw/~cshih
Outline
What’s an Operating Systems?
Operating Systems Services
General Operating System Structure
Operating Systems for embedded systems,
real-time systems.

Note: Parts of the materials are supplied courtesy of Prof. Chih-Wen Hsueh. Please
do not distribute the materials without further permission.
What Operating Systems Have You Ever
used?

Courtesy of http://www.wst.nu/statistics/operatingsystems.htm
What is an Operating System?
A program that acts as an intermediary
between a user of a computer and the
computer hardware.
Operating system goals:
Execute user programs and make solving
user problems easier.
Make the computer system convenient to
use.
Use the computer hardware in an
efficient manner.
Computer System Structure
Computer system can be divided into four
components
Hardware – provides basic computing resources
CPU, memory, I/O devices
Operating system
Controls and coordinates use of hardware among various
applications and users
Application programs – define the ways in which the
system resources are used to solve the computing
problems of the users
Word processors, compilers, web browsers, database
systems, video games
Users
People, machines, other computers
Four Components of
a Computer System
Operating System Definition
OS is a resource allocator
Manages all resources
Decides between conflicting requests
for efficient and fair resource use
OS is a control program
Controls execution of programs to
prevent errors and improper use of the
computer
Operating System Definition
(cont.)
No universally accepted definition
“Everything a vendor ships when you
order an operating system” is good
approximation
But varies wildly
“The one program running at all times
on the computer” is the kernel.
Everything else is either a system
program (ships with the operating
system) or an application program
作業系統特徵遷移示意圖
1950 1960 1970 1980 1990 2000
大型電腦 MULTICS
無軟體 編譯器 分時 多使用者 分散式系統
批次 多處理器
常駐監控常式 網路 容錯
UNIX
迷你電腦
無軟體 編譯器
分時 多使用者 多處理器
常駐監控常式 網路 容錯
叢集
UNIX
個人電腦
無軟體 編譯器
交談式 多處理器
多使用者
網路
UNIX
手持式電腦
編譯器 無軟體
交談式
網路
Computer Startup
bootstrap program is loaded at power-up
or reboot
Typically stored in ROM or EPROM, generally
known as firmware
Initializates all aspects of system
Loads operating system kernel and starts
execution
Computer System Organization
Computer-system operation
One or more CPUs, device controllers connect through
common bus providing access to shared memory
Concurrent execution of CPUs and devices competing
for memory cycles
How a Modern Computer
System Works?
instruction
execution

Cache
cycle

Thread of execution data


CPU (*N) movement instructions
and data
I/O request

interrupt
data

DMA memory

device
(*M)
Operating Systems Services
Objectives
To describe the services an operating
system provides to users, processes, and
other systems
To discuss the various ways of structuring
an operating system
To explain how operating systems are
installed and customized and how they
boot
Operating System Services
One set of operating-system services provides
functions that are helpful to the user:
User interface - Almost all operating systems have a user interface (UI)
Varies between Command-Line (CLI), Graphics User Interface (GUI),
Batch
Program execution - The system must be able to load a program into
memory and to run that program, end execution, either normally or
abnormally (indicating error)
I/O operations - A running program may require I/O, which may
involve a file or an I/O device.
File-system manipulation - The file system is of particular interest.
Obviously, programs need to read and write files and directories,
create and delete them, search them, list file Information, permission
management.
Operating System Services (Cont.)
One set of operating-system services provides
functions that are helpful to the user (Cont):
Communications – Processes may exchange information, on
the same computer or between computers over a network
Communications may be via shared memory or through message
passing (packets moved by the OS)
Error detection – OS needs to be constantly aware of possible
errors
May occur in the CPU and memory hardware, in I/O devices, in
user program
For each type of error, OS should take the appropriate action to
ensure correct and consistent computing
Debugging facilities can greatly enhance the user’s and
programmer’s abilities to efficiently use the system
Operating System Services (Cont.)
Another set of OS functions exists for ensuring the efficient
operation of the system itself via resource sharing
Resource allocation - When multiple users or multiple jobs
running concurrently, resources must be allocated to each of
them
Many types of resources - Some (such as CPU cycles,mainmemory,
and file storage) may have special allocation code, others (such as
I/O devices) may have general request and release code.
Accounting - To keep track of which users use how much and
what kinds of computer resources
Protection and security - The owners of information stored in a
multiuser or networked computer system may want to control use
of that information, concurrent processes should not interfere with
each other
Protection involves ensuring that all access to system resources is
controlled
Security of the system from outsiders requires user authentication,
extends to defending external I/O devices from invalid access
attempts
If a system is to be protected and secure, precautions must be
instituted throughout it. A chain is only as strong as its weakest link.
User Operating System Interface - GUI

User-friendly desktop metaphor interface


Usually mouse, keyboard, and monitor
Icons represent files, programs, actions, etc
Various mouse buttons over objects in the interface cause
various actions (provide information, options, execute function,
open directory (known as a folder)
Invented at Xerox PARC
Many systems now include both CLI and GUI
interfaces
Microsoft Windows is GUI with CLI “command” shell
Apple Mac OS X as “Aqua” GUI interface with UNIX kernel
underneath and shells available
Solaris is CLI with optional GUI interfaces (Java Desktop, KDE)
Simple Structure
MS-DOS – written to provide the most
functionality in the least space
Not divided into modules
Although MS-DOS has some structure, its
interfaces and levels of functionality are not
well separated
MS-DOS Layer Structure
Layered Approach
The operating system is divided into a
number of layers (levels), each built on top
of lower layers. The bottom layer (layer 0),
is the hardware; the highest (layer N) is the
user interface.
With modularity, layers are selected such
that each uses functions (operations) and
services of only lower-level layers
Layered Operating System
UNIX
UNIX – limited by hardware functionality,
the original UNIX operating system had
limited structuring. The UNIX OS consists
of two separable parts
Systems programs
The kernel
Consists of everything below the system-call
interface and above the physical hardware
Provides the file system, CPU scheduling, memory
management, and other operating-system functions;
a large number of functions for one level
UNIX System Structure
Microkernel System Structure
Moves as much from the kernel into “user” space
Communication takes place between user
modules using message passing
Benefits:
Easier to extend a microkernel
Easier to port the operating system to new
architectures
More reliable (less code is running in kernel mode)
More secure
Detriments:
Performance overhead of user space to kernel space
communication
Mac OS X Structure
Modules
Most modern operating systems
implement kernel modules
Uses object-oriented approach
Each core component is separate
Each talks to the others over known
interfaces
Each is loadable as needed within the kernel
Overall, similar to layers but with more
flexible
Solaris Modular Approach
Operating Systems for Embedded and
Real-Time Systems
What is an Embedded System?
Typical textbook definition:
“A computer that is a component in a larger
system, and is not visible as a computer to
a user of that system.”
But - An embedded system may:
Look and function like a traditional computer,
Have a typical computer User Interface, or
Not contain a traditional CPU at all!
“Embedded System” Defined
Our definition:
“A programmable component or subsystem providing some
intelligence functions to the system of which it is a part.”
This can include:
Any device, or collection of devices, that contain one or more dedicated
computers, microprocessors, or microcontrollers.
Microprocessor chips
Programmable logic elements (FPGA, ASIC etc.)
Device(s) may be local - Printer, automobile, etc.
Devices may be distributed - Aircraft, ship, internet appliance.
A PC or workstation may be an embedded system.
Key point:
Embedded computing devices have rigidly defined operational bounds.
Not general purpose computers (PC, Unix workstation).
Characteristics of Embedded
Systems
z In general, there is no architectural link to standard platforms
z PC ( Win9X, NT, XP, Linux), MAC, HP, Sun are considered the standard platforms.
z Almost every embedded design ( hardware and software ) is unique
z The hardware and software are highly integrated and interdependent, such as ASICs,
microcontrollers
z Typically, embedded systems have moderate to severe real-time constraints
z Real-time means system must be able to respond to the outside world.
z Embedded systems may or may not have Operating System (OS) services
available
z No printf() for debugging when there is no terminal!
z Tolerance for bugs is 1000X ( or more ) lower in embedded systems then in
desktop computers.
z May be life-threatening consequences if system fails
z Often engineered for the highest possible performance at the lowest cost
z Performance may not be an important consideration
z They are most likely to have power constraints.
Misconceptions of real-time
systems
Real-time computing is equivalent to fast
computing.

Real-time programming is assembly coding.

‘‘Real-time’’ is performance engineering.

Real-time systems function in a static


environment (or closed system).
Real-time Systems
A real-time system is one where the timing of a
result is just as important as the result itself.
A correct answer produced too late is just as bad
as an incorrect answer or no answer at all.
Timeliness is the single most important aspect of a
real-time system.
“A real-time system is one in which the
correctness of the computations not only depends
upon the logical correctness of the computation but
also upon the time in which the result is produced.
If the timing constraints are not met, system failure
is said to have occurred.
Why meeting deadline?
Relative Deadline

Release Time Deadline Time

Hard Deadline:
Time to press the brake
Time to light up the engine
Soft Deadline:
Time to display the MPEG frame
Time to hand off the wireless connection
Firm Deadline
Time to take a shot
Real-Time scheduling algorithms
We use real-time scheduling algorithms every
day.
Dynamic priority scheduling algorithms
How do you plan your days to do the homework and exams?
Earliest Deadline First algorithm [Liu and Layland 1973]
Static priority scheduling algorithms
Do you prioritize your works?
Rate-Monotonic algorithm [Liu and Layland 1973]
The algorithms should schedule the tasks to
meeting the requirements.
Real-time Systems
The distinction between systems can obviously
become fuzzy.
At one end of the software spectrum are non-real-time
systems where all deadlines can be missed.
At the other end are hard real-time systems where
every deadline must be met.
Operating Systems
Embedded Systems Real-Time Systems
A/ROSE Nucleus
Inferno (distributed OS originally from On Time
Bell Labs)
ROM-DOS OS-9 by Microware
Embedded Linux OSEK
Rockbox (Free Software operating Phoenix-RTOS
system for music player devices)
Minix version 3
QNX
Windows XP Embedded RTAI
Windows CE RTEMS
.NET Micro Framework RTKE by Philips
Operating System Embedded (OSE) RTLinux
Real-Time Systems Salvo
ChorusOS ThreadX
eCos TRON (also ITRON, BTRON,
embOS (Segger) CTRON, MTRON, etc.)
FreeRTOS µCLinux
Inferno (distributed OS originally VRTX
from Bell Labs) VxWorks by Wind River Systems
INTEGRITY XMK (eXtreme Minimal Kernel)
LUnix written in 6502 Xenomai
LynxOS and many more
MenuetOS
MontaVista Linux
What Is eCos ?
Stands for “Embedded Configurable Operating
System”
Developed and maintained by RedHat.
eCos features:
Not Linux-based
Minimum footprint: about 50KB
Single address space
Real-time support
Support ROMFS, RAMFS and JFFS2
SMP support
eCos History
1996 Cygnus started eCos project.
1998 eCos 1.1 released (first public release.)
1999 Red Hat acquired Cygnus Solutions.
2000 eCos 1.3.1 released under Red Hat eCos
Public License.
2000 Red Hat announce the availability of
Redboot
2002 eCos 2.0-alpha released under GPL+
exception.
2002 original members of eCos team formed
eCosCentric Limited in Cambridge.
eCos History
2002 Red Hat announced their withdrawal
from RTOS market, laid off entire eCos
team.
2003 eCos 2.0-final was released.
2003 eCosCentric announced eCosPro
Developer‘s Kit.
2004 Red Hat announce intention to
assign copy right of the portions of the
original source base to FSF.
eCos Architecture
Applications

Libraries Compatibility
Math C POSIX µITRON

Target Networkin File


Independent Kernel
g Stack System

RedBoot
RedBoot Hardware Abstract Layer (HAL) Device Drivers
ROM
ROM interrupt exception flas seria networkin
monitor
monitor vectors
s s h l g
Target Hardware
eCos Core Component
z HAL: a software layer that gives general access
to the hardware.
z Kernel: interrupt and exception handling, thread
and synchronization support, scheduler
implementation, timer, counter and alarm.
z ISO C and Math libraries: Standard compatibility
with function calls
z Device driver: Serial, Ethernet, Flash ROM etc.
z GDB support: provides target software for
communicating with a GDB host.
Kernel Benchmark
Timing benchmarks generated on the Model 4205
MPC7455/57 processor board running at 600 MHz
and configured with a 2 Mbyte L3 cache:

Function Average Time (usec)


Thread Switch 0.98
Put or Get Mailbox 0.47
Mailbox Put/Get 1.27
Post Semaphore 0.22
Wait Semaphore 0.26
Post/Wait Semaphore 1.33
Wait for Flag [AND] 0.35
POSIX Standard
Portable Operating
System Interface for
Computer
POSIX.1 ISO 9945-1
Environments
Shell and Utility POSIX.2 ISO 9945-2
Realtime API POSIX.1b IEEE 1003.1b

Operating Security API POSIX.1e IEEE 1003.1e

Operating Security
Commands
POSIX.2c IEEE 1003.2c

z eCos contains support for partial POSIX


Specification (ISO/IEC 9945-1:1996 POSIX.1)
ISO C In eCos
eCos provides a math library, which
implements the mathematical functions
from the ISO C library

There are 4 compatibility modes:


ANSI/POSIX 1003.1;
IEEE-754;
X/Open Portability Guide issue 3 (XPG3);
System V Interface Definition Edition 3
eCos vs. Linux

Components Linux eCos


MMU O X
Memory map Virtual & Physical Single address space
License GPL eCos license
ISO C library O Separate Math lib
POSIX Not fully support
TCL/TK O X
Real-time X (selected boards only)
Device driver In the kernel Separate from kernel
Minimal footprint About 2MB About 50KB
Redboot Architecture
The Features of Redboot
Based on eCos HAL
Boot scripting support
Simple command line interface
Support flash & network booting
Support BOOTP, DHCP
Support TFTP, X/Y-modem for program
download
Support GDB for remote debugging via serial or
Ethernet connections
Installation and Development
Environment
Install cygwin under Windows
http://www.cygwin.com/setup.exe
Select additional packages: gcc, make, sharutils, tcltk, wget

Installing eCos
Under cygwin bash shell:
wget --passive-ftp ftp://ecos.sourceware.org/pub/ecos/ecos-install.tcl
Select GNU tools for target
Architecture TARGET
ARM (including StrongARM, XScale) arm-elf
Intel x86 i386-elf
MIPS32 mipsisa32-elf
PowerPC powerpc-eabi
Renesas SuperH sh-elf
History of µC/OS
Started by Jean Labrosse in
early 1990’s
The first paper for µC/OS II was
published on Embedded Systems
Programming (ESP) in May and
June 1992.
25,000 copies has been sold for
the first and second edition.
Source codes are freely available.
Advantages and Disadvantages of
Real-Time Kernels
A real-time kernel (RTOS) allows real-time applications to be designed and
expanded easily.
Functions can be added without requiring major changes to the software.

The use of RTOS simplifies the design process by splitting the application
code into separate tasks.

With a preemptive RTOS, all time-critical events are handled as quickly


and as efficiently as possible.

An RTOS allows you to make better use of your resources by providing


you with valuable services – semaphores, mailboxes, queues, time delays,
timeouts, etc.
- Extra cost of the kernel.
- More ROM/RAM space.
- 2 to 4 percent additional CPU overhead.
- Cost of the RTOS: $70 ~ $30,000 !
- The maintenance cost: $100 ~ $5,000 per year !
Real-Time Systems Summary
Foreground/Background Non-
Non-Preemptive Kernel Preemptive Kernel
MAX(Longest instruction, User int. MAX(Longest instruction, User MAX(Longest instruction,
Interrupt Latency
disable) + int. disable, Kernel int. disable) + User int. disable, Kernel int.
(Time)
Vector to ISR Vector to ISR disable) + Vector to ISR

Interrupt latency +
Interrupt response
Int. latency + Save CPU’
CPU’s context Int. latency + Save CPU’
CPU’s context Save CPU’
CPU’s context +
(Time)
Kernel ISR entry function

Find highest priority task +


Interrupt recovery Restore background’
background’s context + Restore task’
task’s context + Restore highest priority task’
task’s
(Time) Return from int. Return from int. context + Return from
interrupt

Longest task +
Task response Find highest priority task +
Background Find highest priority task +
(Time) Context switch
Context switch
Application code + Application code +
ROM size Application code
Kernel code Kernel code

Application code + Application code +


Kernel RAM + Kernel RAM +
RAM size Application code
SUM(Task stacks + SUM(Task stacks +
MAX(ISR stack)) MAX(ISR stack))

Services available? Application code must provide Yes Yes


RTLinux v.s. Linux
Defects of Linux
Linux scheduling algorithms are not designed for real-time tasks.
Linux will “batch” operations to make more efficient use of the hardware.
Linux scheduling is unpredictable.
Linux processes are heavyweight processes.
It can take several hundred microseconds to finish a context switch.
Linux Timer resolution is coarse, 10 ms.
Linux Kernel is Non-preemptible .
Even the lowest priority task is running.
Linux will make high priority tasks wait for low priority tasks to release resources.
Linux disables interrupts used for coarse-grained synchronization.
“Coarse grained” synchronization means that there are long intervals when one
task has exclusive use of some data.
Linux uses virtual memory.
Linux reorders requests for efficiency (e.g., for disk I/O).
RTLinux
z RT-Linux is an operating system in which a small
real-time kernel coexists with the POSIX-like
Linux kernel.
z RTLinux is module oriented.
z Scheduler.
z The “earliest deadline first” scheduler.
z Rate-monotonic scheduler.

z The module that implements RT-FIFOs.


z RTLinux decouples the mechanisms of the real-
time kernel from the mechanisms of the general
purpose kernel.
z Each can be optimized independently.
z The RT kernel can be kept small and simple.
RTLinux Features
z Real-time scheduling algorithm.
z Predictable delays.
z By its small size and limited operations.

z Finer timer resolution.


z Preemptible kernel.
z The RTLinux executive is itself nonpreemptible.
z Its routine are very small and fast, this does not cause big delays.
z Interrupts from Linux are disabled.

z No virtual memory.
Applications
Linux, RTLinux, and RTAI
Linux RTLinux RTAI
Alpha, ARM, i386, MIPS, PowerPC, i386, PPC, ARM, Alpha, i386, MIPS, PPC, ARM,
Hardware Sparc,
Sparc, SuperH,
SuperH, Etrax,
Etrax, m68k, PA-
PA-RISC MIPS m68k-
m68k-nommu

Multi-processor Yes Yes Yes


SCHED_FIFO, SCHED_RR, SCHED_FIFO, EDF, and
Scheduling SCHED_OTHER RM
Fixed priority

UNIX-
UNIX-processes &
Processes Pthreads Lightweight processes
Pthreads

Priorities
(0-
(0-100) (0-
(0-1,000,000) 0x3fffFfff-
0x3fffFfff-0)
lower - higher

Memory protection Yes No Yes

Dynamic memory Yes No Yes


Semaphores, Mutexes,
Mutexes,
Inter-process Semaphores, Mutexes,
Mutexes, Condition-
Condition-var.,
var., Semaphores, Mutexes,
Mutexes, Condition-
Condition-var.,
var., FIFO, Mailbox,
communication shared-
- mem,
shared mem , signals, pipes. Condition-
Condition var FIFO
- var.,
., shared-
shared-mem,
mem, net_rpc,
net_rpc,
Pqueues.
Pqueues.
Lessons Learned
Operating systems allocate/manage
resource AND consume resource.

No one operating system is suitable for


every application.

The system performance is a result of


hardware design and software design.
No HW design can be application blind.
So does SW design.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy