8
How & When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO [email protected] 1 CSE 522S – Advanced Operating Systems

How When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO

Embed Size (px)

DESCRIPTION

Kernel Execution: Boot System Boot Initialize System Idle Task (pid 0) Creates Init, which creates all other threads ksoftirq Init (pid 1) migration The kernel only runs deterministically at boot time. Otherwise, the kernel is entirely event driven. Power On Bootloader loads kernel Initial kernel never returns 3CSE 522S – Advanced Operating Systems Kernel threads are scheduled as any other process. Kernel entry point: start_kernel() in /init/main.c

Citation preview

Page 1: How  When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO

CSE 522S – Advanced Operating Systems 1

How & When The Kernel Runs

David Ferry, Chris GillDepartment of Computer Science and Engineering

Washington University, St. Louis [email protected]

Page 2: How  When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO

CSE 522S – Advanced Operating Systems 2

Traditional View of Process Execution

However, the kernel is not traditional!

Creation

Ready Running

Waiting

TerminateBlocked

Preempted

Scheduled

Unblocked

Page 3: How  When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO

CSE 522S – Advanced Operating Systems 3

Kernel Execution: Boot

SystemBoot

InitializeSystem

Idle Task(pid 0)

Creates Init, whichcreates all other threads

ksoftirqInit

(pid 1) migration

The kernel only runs deterministically at boot time. Otherwise, the kernel is entirely event driven.

Power On

Bootloaderloads kernel

Initial kernelnever returns

Kernel threads are scheduled as any other process.

Kernel entry point:start_kernel() in /init/main.c

Page 4: How  When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO

CSE 522S – Advanced Operating Systems 4

Kernel Execution: ThreadsKernel threads perform background operations, e.g.

– [ksoftirq] does delayed interrupt handling– [migrate] does inter-processor load balancing– [kworker] handles misc. tasks

Kernel threads are almost just like user threads:– are scheduled– can be preempted– runs in kernel context– has no process memory space

Page 5: How  When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO

CSE 522S – Advanced Operating Systems 5

Kernel Execution: Event Driven

Runs insyscall

context

InterruptHandler

Runs ininterruptcontext

Software/hardwareInterrupt arrives Returns control

Hardwareinterrupt

Softwareinterrupt

Returns control

• Interrupt context is unpreemptible• Syscall context is preemptible (though may disable preemption)• Return path may return control to kernel, userspace, or call schedule()

Kernelpreemption

Page 6: How  When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO

CSE 522S – Advanced Operating Systems 6

System Calls

• The syscall interface is a single integer1. User loads syscall number into register2. May load syscall arguments into other registers3. Executes syscall trap (software exception)4. Trap is caught by the kernel5. Puts arguments on kernel stack (asmlinkage)6. Kernel looks up syscall number in the interrupt

vector7. Jumps to syscall routine specified in interrupt table

Page 7: How  When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO

CSE 522S – Advanced Operating Systems 7

System Calls on ARM

• The syscall interface is a single integer1. User loads syscall number into register R72. May load syscall arguments into R0-R63. Executes SWI instruction(software exception)4. Trap is caught by the kernel5. Control jumps to function vector_swi() in

arch/arm/kernel/entry-common.S6. Control eventually jumps to a C function inside the

kernel

Page 8: How  When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO

CSE 522S – Advanced Operating Systems 8

Class Notes

• Please do studios in groups of 2 or 3• Meet in Urbauer 115 next time