Operating System Functions and Hardware Support Overview

Chapter 1 Notes:

What is an Operating system? (page 3-6)

  • Software that runs in kernel mode (Semi True)

  • two main functions unrelated, providing application programmers a clean abstract set of resources instead of the messy hardware ones and managing these hardware resources.

  • Practice Question answer: An operating system must provide the users with an extended machine, and it must manage the I/O devices and other system resources. To some extent, these are different functions.

  • Keywords, Extended Machine & Systems Resource Manager

Operating system functions vs hardware support? (Page 3-28)

Operating System Functions

  • Extended Machine Abstraction: Operating system abstracts the hardware complexity and provides a cleaner, simpler user interface via virtual machines or extended machine abstractions

  • Resource Management: Operating Systems manage hardware resources by multiplexing them in time( sharing resources among multiple users or processes overtime) and space(dividing resources among multiple users or processes)

  • Utility Services: Operating systems provide various utility services such as program execution, I/O operations, file system manipulation, communication, and error detection.

Hardware Support:

  • Processor: The role of the processor and its relationship with the operating system are crucial, particularly in terms of executing the command set that the operating system provides.

  • Memory: Operating systems manage multiple types of memory hardware, including RAM and caches. This involves tasks such as memory allocation, paging, and segmentation.

  • I/O Devices: Operating systems handle the complexity of I/O devices through drivers that abstract the hardware specifics into a uniform interface that the OS can interact with more simply

In my words:

OS turn the complexity of 0 and 1’s of the hardware into actual interactive interfaces

Privileged Instructions? (page 71)

  • Privileged instructions are those that can only be executed by the operating system while running in kernel mode.  This mode provides full access to the hardware and is protected to ensure that user applications cannot perform harmful operations.

  • Typically used in I/O devices in kernel not user mode. Everyone may have different access.

  • These restrictions are set by system administrators based on some policies, which need to be enforced so that user level programs cannot interfere with them. (Example Problem Answer)

Architecture overview: cache (coherence, consistency), interrupt handling, exception handling, I/O paradigms – programmed I/O vs. interrupt driven, DMA?

Cache (coherence) – protocol for managing the multiple caches of a multiprocessing system so that no inconsistencies occur between them. It ensures that any copy of data stored in local caches is kept up to date when changes are made to the stored data in any particular cache.

Cache (Consistency) – deals with ensuring that the data in the cache is consistent with the data in the main memory. When a processor updates data in its cache, there might be a delay before those changes are written back to the main memory. During this delay other processors that access the same data directly from main memory might see old data, leading to inconsistencies. Achieve by write-through(Writes to caches are immediately written to the main memory as well) and using barriers or fences.

Interrupt Handling – signals indicating an event such as an I/O request completion

12VO3-jf2cfJ64N7PardyMU8UEIq3ApS0mXqh_mnpd0gvQVFGLK2CR0kox2EdqVn5wPo5jBm6Krwd9kNrA1_VLQYGMbqpApLi7PTIBD2-SmwEpj3B-QM-xf_PFDCGs12FFKhYnlviTXw28mr

Exception Handling – Error conditions generated while the CPU is executing instructions. 

I/O Paradigms 

Programmed I/O 

  • Definition: where the CPU is actively involved in every step of the I/O process. In this method, the CPU executes a program that gives it direct control over I/O operations. The steps typically involve the CPU checking the device status, waiting until the device is ready, and then writing or reading data directly to or from the device register. 

  • Pro/Con: Simple to implement and understand as it involves straightforward programming for small amounts of data without delay. CPU intensive & not scalable with systems with high volume data

Interrupt-driven I/O 

  • Definition – frees up the CPU from the direct management of I/O operations by allowing I/O devices to signal the CPU only when they are ready to exchange data. This is achieved through the use of hardware interrupts that notify the CPU when an I/O device is ready for attention. 

  • Pro/Con: Efficient use of CPU is better for high volume. More complex and potential for interrupt

  • Direct Memory Access (DMA), which allows devices to transfer data directly to/from memory without CPU intervention

Implementation of system calls, function calls?

System Calls:

  • primary method through which a user program interacts with the operating system. When a user program needs to perform an operation that requires access to hardware resources or sensitive system functions (like reading a file or opening a network socket), it must ask the operating system to perform these operations on its behalf. This is done through system calls.

  • Purpose: The primary purpose of system calls is to provide a controlled interface to the operating system’s services, ensuring that programs do not directly access hardware or sensitive data, preserving system stability, security, and multi-user/process isolation.

  • Examples: Opening a file, creating a process, writing data to a hardware device, setting system parameters, etc.

Function Calls:

  • are used within a program to execute specific functions that do not necessarily need direct interaction with the operating system. These are the standard methods in programming languages to modularize code and make it reusable and organized

  • Purpose: Function calls are designed to reduce code redundancy, improve code clarity, and encapsulate functionality, making programs easier to write, debug, and maintain..

  • Examples: Calculating the sum of an array, sorting a list of numbers, displaying a message on the screen (using standard library functions that may internally use system calls).

Distinction: The key distinction is that function calls are about structuring and executing program logic, while system calls are about requesting services from the operating system.

Architecture Designs: Monolithic, Microkernels, Virtual Machines, Layered.

Monolithic:

  • Definition: traditional architecture used in many early operating systems. In this model, nearly all of the operating system functionality (including scheduling, file system management, memory management, and device drivers) is integrated tightly into a single, large kernel

  • Pro:  high performance, simpler design.

  • Con: Poor reliability and security since a big one in one part of the kernel can potentially affect the entire system. Difficult to maintain and update due to its large size and complexity.

MicroKernels:

  • Definition: minimalist approach by running only the most fundamental services in the kernel, such as communication between processes (IPC), and basic scheduling. Other services like device drivers, file system management, and network protocols are run in user space.

  • Pro: Increased system stability and security because faults in one service can be isolated without crashing the system. Easier to maintain, new services can be added without altering the kernel

  • Con: Slower than monolithics due to the overhead of inter-process communication. More complex to develop and debug due to the interactions across user and kernel space.

Virtual Machines:

  • Definition: abstraction of the entire physical computer, including its processor, memory, and other resources. They allow multiple operating systems to run concurrently on a single physical machine.

  • Pro: Flexibility and security as each virtual machine is isolated from the others. Ability to utilize hardware more efficiently by dynamically allocating resources to different VM/s based on demand.

  • Cons: Resource overhead associated with running multiple operating systems concurrently. Complexity in managing and securing the hypervisor

Layered Systems:

  • Definition: organize the OS into a hierarchy of layers, where each layer provides services to the layer above it and serves as a client to the layer below.

  • Pro: Modularity allows easier debugging and system verification, as each layer can be designed and tested independently. Enhanced security and reliability, as layers can restrict interactions to only neighboring layers.

  • Cons: potential performance overhead due to layering and abstraction. Complexity in designing layers properly.



Chapter 2 Study:

Processes and multiprogramming:

Process – Is a program in execution. Each process has its own memory space, including code, data and the process stack. If there are multiple processes then the OS using multiprogramming, allowing more than one process to reside in the main memory at the same time.

Multiprogramming – OS keeps several jobs in memory at the same time, selecting one to run and swapping it out if it becomes idle due to waiting for an I/O operation.

Process state, control block and queueing diagrams:

Process state – new, ready, running, waiting or terminated. These gates help the OS manage processes efficiently.

Process Control Block (PCB) – each process is represented by a PCB, which contains important information about the process, such as its process state, program counter, CPU registers, memory limits, list of open files, and other execution parameters.

Queueing Diagrams – These are used to visualize the flow of processes through various states. Processes are placed in different queues depending on their state. ex: ready queue, I/O Queue.

Threads: thread state, control block. Threading models: user-level, kernel-level, hybrid

Threads – threads are the smallest sequence of programmed instructions that can be managed independently by a scheduler. In operating systems, threads are typically part of a process.

Thread State – new, ready, running, waiting, and terminated

Control Block – Each thread has a thread control block that contains thread specific information like the thread’s state, its stack pointer, and its counter.

Threading Models 

  • User-Level Threads: Managed by a user-level library, fast context switch, not known by the OS.

  • Kernel-Level Threads: Managed by the OS, slower context switch, fully managed by the OS.

  • Hybrid – Combines user & kernel-level threading which provides flexibility.

Scheduling: Short-term schedulers, Starvation

Short-term Schedulers: Decide which of the ready, in-memory processes are to be executed (called dispatching) using a short-term scheduler.

Starvation: Occurs when a process is never allocated to the CPU( often due to poor scheduling algorithms) while others are processed.

Non-Preemptive vs. Preemptive Scheduling

Non-Preemptive Scheduling: Once a process enters the running state, it continues until it either terminates or switches to the waiting state voluntarily.

Preemptive Scheduling: The scheduler may forcibly remove a process from running state to allow another process to execute. This method is useful for ensuring responsive and fair computing environments.

Short-Term Schedulers:

FIFO (First in, First out): Processes are dispatched according to their arrival time on the ready queue. The first process to arrive is the first to be executed. FIFO is simple but can lead to poor performance for short tasks that follow long ones

SJF (Shortest Job First): This scheduler picks the process that has the smallest next CPU burst time. It is efficient in terms of average waiting time for a given set of processes, but can lead to starvation of longer processes.

Round Robin (RR): Each process gets a small unit of CPU time(time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.

  • Advantage is that it offers excellent response time for processes.

Priority Scheduling: Processes are scheduled based on priority. A process with higher priority (Lower priority number) is executed first.

  • Challenge, Lower priority processes may suffer starvation

Shortest Process Next (SPN): Similar to SJF but preemptive. The scheduler always chooses the process that has the shortest estimated remaining processing time.

Multiple Queues / Multilevel Scheduling: Ready queue is divided into several separate queues, each with its own scheduling algorithm. Often used in combination with priority scheduling where each level has a different priority.

Guaranteed Scheduling: Each process gets a certain percentage of the CPU, based on the number of processes.

Fair Share Scheduling: Resources are divided among groups (not individual processes), ensuring that each group receives a fair share of the resources.

Lottery Scheduling: Assigns each process a certain number of lottery tickets and randomly draws a ticket to decide which process to run. Can be either Preemptive or non- preemptive. This method allows for probabilistic fairness over time.

Real-Time Scheduling:

Soft Real-Time: Not critical but highly desirable to meet timing constraints. Task can run late without catastrophic consequences.

Hard Real-Time: Must meet strict timing constraints. Missing a deadline could lead to system failure. Often used in embedded systems, such as those in medical devices or automotive controls.

Multiprocessor Scheduling.

Smart Scheduling: Scheduling decisions are based on the ongoing monitoring of system parameters to optimize performance and resource usage.

Affinity Scheduling: Attempts to keep processes within the same processor set to minimize cache misses or migration between CPU’s

Two-Level Scheduling: Separates the scheduling into two distinct levels; high-level scheduler selects a batch of processes based on some criteria, and a low level scheduler does the actual process scheduling.

Space Sharing: Each process is assigned to a certain portion of the processors, where it will run exclusively.

Gang Scheduling: A set of related processes is scheduled to run on a set of processors at the same time, on a one to one basis.


Chapter 3:

Memory Management without Logical Addressing – No Memory Abstraction: 

Early systems lacked memory abstraction, which meant each program directly accessed physical memory addresses without any form of isolation between processes

Address binding time: compile, load, execution: 

Address binding can occur at different times, such as at compile time, load time, or execution time, which influences how and when memory addresses are allocated and can be modified

Compile Time: If memory location is known a prior, absolute code can be generated; it must be known where the program will reside in memory

Load Time: If it is not known at compile time where the program will reside, the compiler must generate relocatable code that will be adjusted to bind memory locations during loading.

Execution Time: Binding delayed until runtime if the process can be moved during its execution. This flexibility is necessary for paging and segmentation.

Memory Relocation – Static vs Dynamic Relocation:

Static Relocation: The binding of instructions and data to memory addresses is fixed and cannot change throughout the execution.

Dynamic Relocation: Addresses are bound to memory locations at run time, allowing processes to be moved in and out of memory, which is crucial for implementing swapping and for systems that support multitasking with one user process running while another is waiting for I/O. and Advanced memory management techniques like paging

Contiguous Memory Management:

Tracking Free Space: The operating system must track which parts of memory are in use and which parts are free, typically using data structures such as free lists, bitmaps, or linked lists.

Internal and External Fragmentation

Internal Fragmentation: Occurs when allocated memory may contain unused space

. This happens when the memory allocated is slightly larger than the requested memory.

External Fragmentation: Free memory space is broken into small blocks and is scattered all over, making it difficult to allocate contiguous blocks of memory even though there might be enough free memory. This type of fragmentation is common in systems where processes are loaded and removed from memory frequently, causing the free memory space to be broken into non-contiguous pieces.

Summary: Internal Fragmentation occurs when a process needs more space than the size of allocated memory block or uses less space. External Fragmentation occurs when a process is removed from the main memory.

Compaction:

The process of moving all free/empty memory to one large block and all occupied memory to another area in memory. Compaction is a solution to external fragmentation but is costly in terms of CPU time.

Logical vs Physical Address space:

Logical Address Space: Logical address is rendered by CPU

Physical Address Space: Physical address is like a location that is present in the main memory. It is a collection of all logical addresses rendered by the CPU

Virtual Memory:

Memory Management Unit (MMU): A hardware device that handles the translation of virtual addresses to physical addresses.

Paging: Memory management scheme that eliminates the need for contiguous allocation of physical memory, thus minimizing external fragmentation. The virtual address space of a process is divided into blocks called pages.

Address Translation and Page Table Structure: 

  • Translation of virtual addresses to physical addresses via page tables, 

  • Page Table, which stores mappings from virtual pages to physical frames.

Multi-level Page Tables: Hierarchical paging that reduces the memory needed for page tables by dividing the virtual address space into multiple levels.

Inverted Page Tables: Space-efficient page table structure that has one entry for each page of physical memory, mapping physical addresses to virtual addresses/pages.

Translation Lookaside Buffers (TLB): A cache that keeps recent translations of virtual addresses to physical addresses to speed up the translation process