Module 1 By Shruthi R Assistant Professor Dept of ECE, NIE, Mysuru QNX- Shruthi R 1 Computer System Organization Understanding how a computer system is organized is crucial to grasping the OS's role. A typical computer system is fundamentally composed of four interdependent components, each with a distinct function, working in concert to enable computation. Hardware 1 This is the physical foundation, encompassing the Central Processing Unit (CPU) for execution, Memory (RAM) for temporary data storage, and Input/Output (I/O) Devices like keyboards, mice, printers, and monitors. These provide the raw computational power and interaction points. Operating System System and Application Programs 2 3 4 As we've discussed, the OS acts as the sophisticated resource manager. It's responsible for allocating hardware resources to various programs and users, ensuring fair access and preventing conflicts. It's the unseen hand that keeps everything running smoothly. Application Programs These are the programs you use daily, ranging from compilers (which translate code), web browsers, to games and productivity software. They rely on the OS to access hardware and perform their functions. Users The final layer consists of the entities interacting with the system. This includes human users, other machines (like sensors), or even other computers communicating over a network. Their commands initiate the system's activities. The interaction flow is hierarchical: User sends commands → Applications process them → OS interprets and manages requests → Hardware executes the instructions. This layered approach ensures efficiency and abstraction. preencoded.png Hierarchical View of the OS To better understand how an operating system functions, it's often conceptualized as a series of hierarchical layers. Each layer performs specific functions and interacts with the layers immediately above and below it, providing a structured approach to system design and operation. Hardware Layer (Bottom) This is the foundational layer, comprising the physical components of the computer system: CPU, memory, storage devices, and I/O devices. It's the raw physical machine that executes instructions. Kernel Layer (Core) The kernel is the core of the operating system. It resides in memory and has direct control over the hardware. Its responsibilities include resource management (CPU scheduling, memory management), inter-process communication, and managing device drivers. System Calls & APIs (Middle) This layer provides the interface between user applications and the kernel. System calls are special functions that allow programs to request services from the kernel (e.g., read a file, create a process). APIs (Application Programming Interfaces) simplify these calls for programmers. User Interface (Top) The topmost layer is what the user directly interacts with. This can be a Graphical User Interface (GUI) with icons and windows (like Windows or macOS) or a Command Line Interface (CLI) where users type commands (common in Linux servers). This layered model demonstrates how complex functionalities are built upon simpler ones, ensuring modularity, security, and easier maintenance within the operating system. Unix Architecture preencoded.png Architecture Key Components in Any OS Architecture 1. Kernel – The core part managing CPU, memory, and device communication. 2. Process Management – Handles process creation, scheduling, and termination. 3. Memory Management – Allocates and deallocates memory. 4. File System – Manages file storage and retrieval. 5. Device Drivers – Interfaces between hardware and software. 6. User Interface – CLI or GUI to interact with users. QNX- Shruthi R 4 Roles of OS • Policy Enforcer: Controls application execution, prevents errors & misuse • Kernel (Core): • Provides basic hardware control • Runs in system mode (protected) • Applications run in user mode Main Functions of General-Purpose Operating Systems • Manages processor, memory, I/O devices, disks, networks • Provides API (Application Programming Interface) for applications Service Access Methods • System Call: Traps → switch to system mode → execute → return • Message Passing: Process sends request message → OS executes → reply sent back preencoded.png Real time operating systems (RTOS) ➢Operating system responsibilities ✓Managing system resources ✓Managing host application software’s. ➢RTOS additional functionalities ✓To run applications with very precise timing. ✓Provide output that has high degree of reliability. • RTOS are used in environments where a large number of events, mostly external to the computer system, must be accepted and processed in a short time or within certain deadlines. • Deadline: it is the largest value of response time for which the system can function perfectly ❑RTOS ➔reactive ❑Delay in computation➔ failure in the system preencoded.png Real Time Operating System Theoretical Definition: an OS where correctness depends not just on logical results, but also on timing deadlines. A task must complete within its deadline, otherwise it’s considered a failure. In practice, industries don’t just care about “deadlines” in isolation — they care about the mechanisms that enforce predictability, such as: 1. Deterministic Scheduling 1. Fixed-priority or deadline-driven (Rate Monotonic, EDF) 2. Predictable scheduling - guarantees deadlines 2. Memory Management (MMU) 1. Static allocation or simple MMU use Academia → RTOS = meeting timing deadlines Industry → RTOS = deterministic behavior (scheduling, MMU, bounded response) 2. Avoids paging/swapping delays - more deterministic 3. Interrupt Latency & Context Switching 1. Optimized for very low latency and fast switching 2. e.g., FreeRTOS, VxWorks (µs vs ms in general OS) 4. Deterministic Response 1. Every system call, interrupt, and scheduler decision has bounded WCET preencoded.png Aspect Operating System (OS) Real-Time Operating System (RTOS) Goal Provide user convenience, multitasking, throughput, and resource sharing. Provide deterministic and predictable execution to meet strict timing deadlines. Scheduling Focuses on fairness and efficiency (e.g., Round Robin, Multilevel Queue, Completely Fair Scheduler). Focuses on predictability (e.g., Fixed Priority, Rate Monotonic, Earliest Deadline First). Response Time Response time varies depending on system load; not guaranteed. Provides bounded response time (low latency and predictable behavior). Task Priority Priorities exist but not always strictly enforced (e.g., a background task may delay a foreground task). Strict priority-based scheduling; highpriority tasks always preempt lower ones. Memory Uses dynamic allocation, paging, and Management swapping; can introduce delays. Reliability Suitable for applications where delays are acceptable (word processing, web browsing, servers). Examples Windows, Linux, macOS, Android. Often static allocation or simple MMU use to avoid unpredictable delays. Suitable for safety-critical and timesensitive applications (avionics, automotive ECUs, medical devices, robotics). FreeRTOS, VxWorks, QNX, RTLinux, µC/OS-II. preencoded.png Types of Kernel Operating System 1. Monolithic Systems : Entire operating system in a single large kernel. a. All basic services (process mgmt, memory, file systems, device drivers) are part of one program. b. Examples: Early UNIX, MS-DOS, Linux (with modular extensions). 2. Microkernel Systems: Kernel provides only minimal functionality: a. Interprocess communication (IPC), b. CPU scheduling, c. Basic memory management. d. Examples: Minix, Mach (basis for macOS/iOS), QNX. 3. Hybrid Systems: Combination of monolithic and microkernel. a. Examples: Windows NT and successors, macOS (XNU kernel). 4. Modular (Object-Oriented) Kernels: Kernel structured as dynamically loadable modules. a. Examples: Modern Linux (Loadable Kernel Modules), Solaris. 5. Virtual Machines: OS provides an abstraction of the hardware, Multiple virtual machines run on one physical machine. a. Examples: VMware, VirtualBox, Java Virtual Machine. preencoded.png Dual-mode operation When system is executing on behalf of user application, the system is in user mode. ➢When a user application requests a service from OS, it must transit from user to kernel mode to fulfill the request. ➢Whenever a trap or interrupt occurs, the hardware switches from user mode to kernel mode. ➢Whenever the OS gains control of the computer, it is in kernel mode. ➢ The system always switches to user mode before passing control to user program. ✓This allows protection to OS. QNX- Shruthi R 10 Privileged & Non-Privileged Instructions ➢Instructions to be executed only in kernel mode → Privileged Instructions. ➢Instructions to be executed only in user mode → Non-Privileged Instructions. ➢If an attempt is made to execute privileged instructions in user mode, the hardware does not execute it but rather treats it as an illegal and traps it to the OS. QNX- Shruthi R 11 QNX Architecture QNX- Shruthi R 12 What is QNX ??? ✓QNX is a commercial and real-time operating system ✓Owned by Blackberry Limited. ✓It is a Unix-like operating system. ✓Microkernel based real time OS. ✓One of the first commercially successful microkernel operating systems. ✓Originally developed by Quantum Software Systems which was later renamed QNX Software Systems. QNX- Shruthi R 13 Why use QNX ??? ✓Performance :Because of the advanced microkernel architecture, QNX is designed to maximize silicon advancements and deliver unprecedented real-time performance for all time. ✓Safety: QNX ensures safety through its microkernel architecture, which isolates faults and limits the impact of failures. ✓Scalability: The fully-managed microkernel RTOS can be used across all product lines, the developers can focus on value-added features, not OS maintenance. ✓Reliability: The QNX microkernel architecture protects the OS and system from component failure and delivers exceptional performance. Where is it used??? • Its target system types are mission-critical applications in various industries like automotive, medical, smartphones, consumer, industrial, embedded systems and safety. QNX- Shruthi R 14 Architecture of OS Monolithic Executive Microkernel QNX- Shruthi R 15 Executive Architecture Traditional Real –Time Execuitve ➢Are designed for speed and predictability, so they often lack advanced features ➢All modules share the same address space and are effectively, one big problem. ➢Scheduler, drivers, apps all live in the same memory map. ➢Example: Driver writes to address 0x1000, accidentally overwrites part of scheduler → system crash. ➢Limitation ➢Limited Functionality ➢Complex Development and Debugging ➢Resource Constraints QNX- Shruthi R 16 Executive Architecture • User Interface • Provides the way users interact with the system, e.g., command-line, GUI, or control screens. • Scheduler • Decides which process or task runs at a given time, ensuring real-time deadlines are met. • Memory Allocator • Manages memory allocation and deallocation to tasks, ensuring no memory conflicts occur. • Network Stack • Provides communication over networks (TCP/IP, UDP, etc.), handling data transfer between systems. • Applications • These are the actual programs running on top of the executive, such as control algorithms or user-level services. • Serial Driver • Provides support for serial communication ports (UART, RS-232, etc.) often used for sensors or debugging. • Disk Driver QNX- Shruthi R • Manages interaction with disk hardware for reading/writing data. 17 Monolithic Architecture • All OS services operate in kernel space • Applications are processes in protected memory space • The entire OS is one large program that runs in a single address space; this is considered a traditional approach. • All components within it are tightly integrated and share the same memory. • This includes process management, memory management, file systems, device drivers, and networking. Single address space Structure ☺ ☺ Tightly coupled components ☺ Direct function calls ☺ Performance ☻Driver development becomes complex ☻Debugging is difficult ☻Direct function calls ☻Performance QNX- Shruthi R 18 Monolithic Architecture In a traditional Monolithic kernel OS: – the kernel contains the OS kernel functionality and all drivers, so driver development is complex and debugging can be painful. – applications are processes in protected memory space, so the kernel is protected from applications and applications are protected from each other SUMMARY ✓ Each application is treated as a process with its own protected memory space. ✓ This protection ensures that applications cannot directly affect the kernel or other applications. ✓ If an application crashes, it typically does not crash the whole system, but a kernel module crash can. ✓ This architecture prioritizes performance (due to less context switching), but compromises on safety and modularity compared to microkernel designs. ✓ As all functions provided by OS are put together in single layer, the size of the kernel increases and in turn size of OS also increased. QNX- Shruthi R 19 Microkernel Architecture • In QNX Microkernel (multiple address spaces): • Scheduler lives in kernel space. • Driver lives in its own process space. • It is an operating system (OS) design approach emphasizing minimalism and modularity. • the core idea is to minimize the number of functionalities that run within the kernel itself, keeping it as small and simple as possible. • the OS consists of the kernel, called procnto, and a set of cooperating processes. • the processes are separate from the kernel so if something goes wrong in a process it would not affect the kernel. ✓ Kernel (procnto) ✓ Cooperating Processes ✓ Separation of Kernel and Processes QNX- Shruthi R ✓ Fault Isolation 20 procnto In QNX Neutrino RTOS, procnto is the heart of the OS, but it's not just the microkernel it’s a combination of two distinct architectural components: 1. Neutrino Microkernel 1. Accessed using kernel calls 2. Responsibilities: 1. Thread scheduling – managing which thread runs on which core and when. 2. Interrupt handling – responding to hardware events. 3. Inter-process communication (IPC) – fast message-passing mechanism. 4. Synchronization primitives – like mutexes, semaphores. 2. Process Manager 1. Accessed using IPC. 2. Reached by messages and has threads to handle messages. 3. Responsibilities: 1. Process creation and termination 2. Memory management and allocation 3. File descriptor management KERNEL + PROCESS QNX- Shruthi RMANAGER = procnto 21 QNX- Shruthi R 22 Benefits and system overhead of microkernel Benefits ✓Resilience & Reliability ✓Ease of Configuration & Reconfiguration ✓Ease of Debugging ✓Ease of Development ✓Scalability Trade-Offs – Costs: ▪ System Overhead • more context switches • more copies of data QNX- Shruthi R 23 QNX- Shruthi R 24 Process & Threads QNX- Shruthi R 25 Process Concept • Process– is an instance of a program in execution. • Is an active entity • Is the execution of those instructions after being loaded from the disk into memory • A single program can create many processes when run multiple times Example: ✓ When we open a .exe or binary file multiple times, multiple instances begin (multiple processes are created). ✓Double clicking on Google chrome browser instantiates a process. When another window of it is opened another process is created. QNX- Shruthi R 26 Continued … • A process is an independent program in execution. It has: ➢Its own memory space (code, data, heap, stack) ➢System resources (file descriptors, open files) ➢At least one thread (usually the main thread) ➢Timers • Each process isolated from other processes. • Each process is identified by QNX- Shruthi R a process id (pid) 27 Continued … There are a few process creation calls:– ✓fork() ➢create a copy of the calling process ✓exec*() ➢load a program from storage to transform the calling process ✓posix_spawn(), spawn*() ➢load a new program creating a new process for it QNX- Shruthi R 28 Threads ✓ Separate stream of execution within a single process. ✓ Threads in a process can execute different parts of the program code. ✓ Threads provides concurrency within a process with less overhead. ✓ Basic unit of CPU utilization. ✓ Threads in a process are not isolated from each other ✓ Process creates a thread through system call. ✓ A thread is the smallest unit of CPU execution within a process. “Threads run code, processes own resources” • Multiple threads in a process can run concurrently, sharing the same memory but operating independently. ✓ Shares process memory (code, data, heap) ✓ Each thread has its own stack, program counter, and registers QNX- Shruthi R 29 Continued … QNX- Shruthi R 30 Continued … QNX- Shruthi R 31 Process Thread Processes are heavy weight operations Threads are lighter weight operations Each process has its own memory space Threads use the memory of the process they belong to Inter-thread communication can be faster Inter-process communication is slow as than inter-process communication processes have different memory because threads of the same process addresses share memory Context switching between processes is Context switching between threads of the more expensive same process is less expensive Processes don’t share memory with other Threads share memory with other threads processes of the same process QNX- Shruthi R 32 Microkernel ✓Microkernel is the core of your system ✓Programs do not interact with the microkernel directly, instead, they use special C library routines known as kernel calls (Camel Case format). Ex: MsgSend(), ThreadCreate(), TimerCreate() • Kernel calls act as the interface between a process and the operating system. ✓Most of the other sub-systems, including user applications, communicate with each other using the message passing provided by the microkernel through kernel calls. QNX- Shruthi R 33 Kernel calls • When a thread makes a kernel call: QNX- Shruthi R 34 Microkernel Call Behavior and Thread Context When a thread makes a kernel call in QNX: 1. Execution Mode Switch: ▪ The thread transitions from user mode to microkernel (kernel) mode, enabling access to system-level operations. 2. Context Changes: ▪ The thread gains elevated privileges, procnto address space becomes visible, uses a kernelspace stack instead of its regular stack 3. Thread Identity Remains: ▪ Despite the context switch, it remains the same thread ▪ Keeps its priority and scheduling properties. ▪ Can still be pre-empted, interrupted, or managed by the scheduler. “much like making a normal (user-space) library call” QNX- Shruthi R 35 Continued … 1. Microkernel is external driven: This means the microkernel responds to events rather than constantly running tasks on its own and hence updates the states. It mainly waits for and reacts to: • Kernel calls: When user programs request system-level services (e.g., MsgSend(), ThreadCreate()). • Interrupts: Signals from hardware (like a timer or network interface). • Faults: Errors like memory violations. 2. Has three microkernel threads per CPU core: i. an interrupt service thread (IST) for interprocessor interrupts (IPIs) ii. an IST for timer interrupts. iii. an idle thread for when no other thread needs to run QNX- Shruthi R 36 QNX- Shruthi R 37 QNX- Shruthi R 38
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )