Presentation is loading. Please wait.

Presentation is loading. Please wait.

What Every Developer Should Know about the Kernel Dr. Michael L. Collard 1.

Similar presentations


Presentation on theme: "What Every Developer Should Know about the Kernel Dr. Michael L. Collard 1."— Presentation transcript:

1 What Every Developer Should Know about the Kernel Dr. Michael L. Collard www.sdml.info/collard www.sdml.info/collard/linux collard@cs.kent.edu 1

2 Virtual Addresses Process has a 4 GB virtual address space (32 bit) user space – your code, and the libraries you call (lower 3GB) – unique to your process kernel space – kernel code (upper 1 GB) – shared among all processes

3 Modes user mode – when you are executing your code, and the code of the libraries that you call – working in user space kernel mode – when you are directly executing the kernel code – working in kernel space

4 System Calls Processes enter and exit kernel mode through system calls syscall – fundamental interface between process and kernel Every system call has a unique number syscall is a wrapper around the assembly code for the call

5 ABI Application Binary Interface – technique used for syscall No need to link to kernel code Statically linked executable for one Linux kernel version will probably work on another Most compatibility problems are changes in the library API, not the ABI

6 System Call Process Process is in user mode The process calls syscall with the proper number of arguments, buffers, etc. Interrupt switches process into kernel mode Calls appropriate system call When finished, exits kernel mode Returns process back to user mode

7 User Space, Kernel Space, & Data Data in user space is per-process Data in kernel space is not visible to the process ( Data must be copied to/from user and kernel space Disadvantage: Copies must be made, heavily optimized Advantages: Keeps divide between user and kernel space, and system calls can return faster, e.g., write

8 Process Scheduling scheduler – divides CPU time among tasks Kernel has several scheduling algorithms, selected at boot time Although scheduling is viewed as a separate process, it is actually executed in every process – Goes to sleep, or blocks waiting for a device – -> calls scheduler routines to determine next process

9 Multitasking cooperative multitasking – When each process is done, it schedules the next – Works well with tasks mainly concerned with device I/O with lots of waiting and lots of scheduler calls – Problem: compute-intensive tasks preemptive multitasking – Interrupts task to start another, based on time slice (quantum) Linux uses a mix of cooperative and preemptive multitasking

10 Blocking, Preempting, and Yielding preempted – Kernel stops a process because: – its time slice expire, or for a higher-priority process yielded – Process gives up the CPU voluntarily – sched_yield system call, which most other system calls (read, write) call blocking – Process waiting for an event in Kernel mode – Cannot run until event occurs – Does not consume CPU – Does not get scheduled until an event occurs to wake it up

11 Preemption and Kernel Mode nonpreemptible kernel – Process running in kernel mode cannot be preempted until it returns to user mode – E.g., middle of system call, higher priority task must wait preemptible kernel – Introduced in Linux 2.6 – E.g., if a device driver hangs, doesn’t hang entire system

12 Linux Priority Scheme Resolves scheduling conflicts Goal: Every task gets a chance to run (no task starved for CPU time) “interactive” process behavior is given an inflated priority static priority – priority when process created effective priority - static priority + bonus (bonus is plus or minus) Will discuss “nice” later

13 Priorities Higher number is scheduled first Linux priorities for a normal process: 0 – 39 For “real-time” – 100 additional priorities: 41 – 139 Must also give scheduling policy

14 Standard Scheduling Policies Other – Process to run is based on dynamic priority, which is increased every time the process is ready to run, but that process was denied by the scheduler Batch – Similar to Other, but assumes processes are compute intensive (Linux 2.6.16)

15 Real-Time Scheduling Policies sched_getscheduler – 1 – 99 -> 41 - 139 FIFO (First In First Out) – First one ready, cannot be interrupted except by a higher-priority process RR (Round Robin) – enhancement of FIFO – If a process is preempted by a higher-priority process, it gets its remaining time back

16 Process States R Running – already running, or ready to run S Interruptible – blocked, waiting for an event, may be awakened by a signal D Uninterruptible – blocked, waiting for an event, may not be awakened by a signal T Stopped – stopped due to job control Z Zombie – exited, but waiting for parent process


Download ppt "What Every Developer Should Know about the Kernel Dr. Michael L. Collard 1."

Similar presentations


Ads by Google