Kernel Structure and Infrastructure David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO 63130.

Slides:



Advertisements
Similar presentations
Pointers.
Advertisements

Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
Symbol Table.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Part IV: Memory Management
Christo Wilson Project 2: User Programs in Pintos
Chris Riesbeck, Fall 2007 Dynamic Memory Allocation Today Dynamic memory allocation – mechanisms & policies Memory bugs.
Memory allocation CSE 2451 Matt Boggus. sizeof The sizeof unary operator will return the number of bytes reserved for a variable or data type. Determine:
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
Honors Compilers Addressing of Local Variables Mar 19 th, 2002.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
 200 Total Points ◦ 74 Points Writing Programs ◦ 60 Points Tracing Algorithms and determining results ◦ 36 Points Short Answer ◦ 30 Points Multiple Choice.
1 MT258 Computer Programming and Problem Solving Unit 7.
1 What is a Kernel The kernel of any operating system is the core of all the system’s software. The only thing more fundamental than the kernel is the.
Stack and Heap Memory Stack resident variables include:
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
CSC 660: Advanced Operating Systems
Win32 Programming Lesson 19: Introduction to DLLs.
Advanced Pointer Topics. Pointers to Pointers u A pointer variable is a variable that takes some memory address as its value. Therefore, you can have.
How & When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
Read-Copy-Update Synchronization in the Linux Kernel 1 David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis.
Linux Boot Process on the Raspberry Pi 2 1 David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis,
Interrupts and Interrupt Handling David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Getting Started with the Kernel. Obtaining the Kernel Source
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
Processes David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Kernel Synchronization David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Memory Management.
Linux Details: Device Drivers
Scheduling of Non-Real-Time Tasks in Linux (SCHED_NORMAL/SCHED_OTHER)
Linked Lists Chapter 6 Section 6.4 – 6.6
Midterm Review Chris Gill CSE 422S - Operating Systems Organization
Linking & Loading.
Chapter 8 Main Memory.
Processes David Ferry, Chris Gill
Program Execution in Linux
Semester Review Chris Gill CSE 422S - Operating Systems Organization
Main Memory Management
Chapter 8: Main Memory.
Kernel Synchronization II
System Structure and Process Model
Memory Allocation CS 217.
Kernel Structure and Infrastructure
Lecture Topics: 11/1 General Operating System Concepts Processes
Linux Details: Device Drivers
Operating System Chapter 7. Memory Management
Top Half / Bottom Half Processing
Kernel Synchronization I
Overview of the Lab 2 Assignment: Multicore Real-Time Tasks
Midterm Review Brian Kocoloski
Kernel Structure and Infrastructure
Semester Review Brian Kocoloski
Program Execution in Linux
Userspace Synchronization
Kernel Memory Chris Gill, David Ferry, Brian Kocoloski
Data Structures & Algorithms
CS703 - Advanced Operating Systems
Processes David Ferry, Chris Gill, Brian Kocoloski
Shared Memory David Ferry, Chris Gill
Presentation transcript:

Kernel Structure and Infrastructure David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO

Kernel vs. Application Coding Two major differences: – The core kernel must be a monolithic binary – The core kernel must be statically linked Thus, no standard libraries: – No malloc, pthreads, string handling, etc. – Partly because of chicken/egg situation – Also, standard libraries can be too slow No dynamic loading for the core kernel: – Early symbol addresses must be at fixed locations – Core kernel utilities must be efficient – Core kernel utilities must always be available CSE 522S – Advanced Operating Systems2

Two Big Problems 1.Programmers rely on library functions for efficiency and correctness – Chicken and egg problem: traditional libraries (like libc ) are built on top of kernel utilities – Kernel code has to be entirely self-contained 2.A totally static kernel would be enormous – About 20 million lines of code in 2015 – Most of this is hardware drivers that are never used on any given platform CSE 522S – Advanced Operating Systems3

First Solution: Kernel Libraries Kernel libraries re-implement a lot of the functionality programmers expect in user space – Are statically compiled into the kernel – Automatically available just by including relevant header – Built to be kernel-safe (sleeping, waiting, locking, etc. is done properly) Features: – Utilities: kmalloc, kthreads, string parsing, etc. – Containers: hash tables, binary trees etc. – Algorithms: sorting, compression Mostly found under /lib and /include/linux CSE 522S – Advanced Operating Systems4

Example: kmalloc() A unified kernel memory allocator to manage the kernel virtual memory space CSE 522S – Advanced Operating Systems5 Kernel Image Kernel Module Space (insmod) Userspace (mmap syscall) High Memory Like traditional malloc, but handles kernel concerns, such as how to allocate and where to allocate inside of virtual address space. E.g.: GFP_KERNEL - Normal kernel allocation, may block GFP_ATOMIC - Never blocks, for use in interrupt handlers and critical sections GFP_USER - Used when allocating space for user processes And many more... 0x0 0xfffffff

Example: Linked Lists A list-able struct must contain struct list_head struct list_head { struct list_head *next; struct list_head *prev; }; If you wanted a list of structs of type data : struct data{ int foo; int bar; struct list_head list; } CSE 522S – Advanced Operating Systems6

Example: Linked Lists Initializing a list dynamically: struct data *myList; myList = kmalloc(sizeof(*myList), GFP_KERNEL); myList->foo = 5; myList->bar = 10; INIT_LIST_HEAD(&myList->list); Or statically at compile time: static LIST_HEAD(data_list_head); CSE 522S – Advanced Operating Systems7

Example: Linked Lists Functions may take pointers to list nodes or pointers to the list head: Adding: struct data *new_data; list_add(&new_data->list, &data_list_head); Deleting: list_del(&new_data->list); kfree(new_data); //if dynamic CSE 522S – Advanced Operating Systems8

Example: Linked Lists Iterating: struct list_head ptr; list_for_each(ptr, data_list_head){ //ptr points to each list structure } struct data *data_ptr; list_for_each_entry(d_ptr, data_list_head, list){ //d_ptr points to each data structure } Also: list_for_each_entry_reverse() list_for_each_entry_safe() //for modifying list elements CSE 522S – Advanced Operating Systems9

Example: Linked Lists See also: – /include/linux/list.h – /include/linux/types.h Moral of the story: Always search for functionality before writing it yourself. CSE 522S – Advanced Operating Systems10

Second Solution: Loadable Kernel Modules Kernel modules are kernel code that can be loaded dynamically: – Can be loaded/unloaded whenever – Runs in kernel mode – Can access exported kernel variables and functions – Can export variables and functions to kernel or other modules CSE 522S – Advanced Operating Systems11

Module Implementation Must define: – An initialization function called on load – An exit function called on unload The init function must be self contained! – Must unwind actions if initialization cannot complete successfully – E.g. if you kmalloc() space but don’t free it, that physical memory is now lost forever. You can also pass parameters to modules at load time. CSE 522S – Advanced Operating Systems12

Exported Symbols Not all kernel symbols (functions/variables) are designed to be shared. A kernel subsystem exports symbols that are designed to be used outside of the subsystem. The set of exported symbols is the closest thing to a formal, intra-kernel API. Symbols are exported via the macros EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL() Modules should only use exported symbols CSE 522S – Advanced Operating Systems13