Kernel Tracing David Ferry, Chris Gill, Brian Kocoloski

Slides:



Advertisements
Similar presentations
CSE451 Processes Spring 2001 Gary Kimura Lecture #4 April 2, 2001.
Advertisements

Process Description and Control A process is sometimes called a task, it is a program in execution.
Cortex-M3 Debugging System
Implementing Processes and Process Management Brian Bershad.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Tami Meredith, Ph.D. CSCI  Devices need CPU access  E.g., NIC has a full buffer it needs to empty  These device needs are often asynchronous.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Course Introduction David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO 1E81.
Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.
How & When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO
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
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
Kernel Tracing David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Processes 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
Process Management Process Concept Why only the global variables?
How & When The Kernel Runs
Midterm Review Chris Gill CSE 422S - Operating Systems Organization
Time Sources and Timing
Midterm Review David Ferry, Chris Gill
Lecture Topics: 11/1 Processes Process Management
Department of Computer Science and Engineering
Kernel Tracing David Ferry, Chris Gill
Processes David Ferry, Chris Gill
Time Sources and Timing
Semester Review Chris Gill CSE 422S - Operating Systems Organization
Processes in Unix, Linux, and Windows
Interrupts and Interrupt Handling
Light-weight Contexts: An OS Abstraction for Safety and Performance
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Lecture Topics: 11/1 General Operating System Concepts Processes
Architectural Support for OS
Processes Hank Levy 1.
System Calls David Ferry CSCI 3500 – Operating Systems
Top Half / Bottom Half Processing
Processes and Process Management
Kernel Synchronization I
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Overview of the Lab 2 Assignment: Multicore Real-Time Tasks
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Midterm Review Brian Kocoloski
How & When The Kernel Runs
Kernel Synchronization II
Time Sources and Timing
Processes David Ferry CSCI 3500 – Operating Systems
Program Execution in Linux
Userspace Synchronization
Kernel Memory Chris Gill, David Ferry, Brian Kocoloski
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
CS510 Operating System Foundations
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Architectural Support for OS
Scheduling Classes and Real-Time Scheduling in Linux
Department of Computer Science and Engineering
Process Description and Control in Unix
Processes Hank Levy 1.
Process Description and Control in Unix
Interrupts and Interrupt Handling
Processes David Ferry, Chris Gill, Brian Kocoloski
Lecture 12 Input/Output (programmer view)
Dynamic Binary Translators and Instrumenters
Scheduling of Regular Tasks in Linux
Presentation transcript:

Kernel Tracing David Ferry, Chris Gill, Brian Kocoloski CSE 422S - Operating Systems Organization Washington University in St. Louis St. Louis, MO 63143

Things Happen: Kernel Oops vs Panic A kernel panic is unrecoverable and results in an instant halt An oops communicates something bad happened but the kernel tries to continue executing An oops means the kernel is not totally broken, but is probably in an inconsistent state An oops in interrupt context, the idle task (pid 0), or the init task (pid 1) results in a panic How to figure out what went wrong? "Kernel-panic" by Kevin http://flickr.com/photos/kevincollins/74279815/ CSE 422S –Operating Systems Organization

CSE 422S –Operating Systems Organization Debugging Can take two forms Correctness debugging e.g., your kernel is panic’ing when you load a kernel module Performance debugging e.g., you parallelized a program to run on 4 cores rather than 1, but did not see 4x speedup … CSE 422S –Operating Systems Organization

CSE 422S –Operating Systems Organization Source: https://opensourceforu.com/2011/01/understanding-a-kernel-oops/ CSE 422S –Operating Systems Organization

CSE 422S –Operating Systems Organization Important Bits BUG: unable to handle kernel NULL pointer dereference You probably have a pointer that was never set to allocated memory e.g: int * ptr = NULL; *ptr = x; Instruction pointer (sometimes called “program counter”) Address of instruction that generated BUG is stored in a special register On x86_64: RIP On ARM: R15 Linux will map this instruction back to the function where this instruction occurred In the previous example: my_oops_init CSE 422S –Operating Systems Organization

Kernel Correctness Debugging Debugging in the kernel is much more complicated than debugging in userspace You don’t have simple to use debuggers (though some like kgdb do exist) You don’t get graceful kill signals like segfaults Small errors can bring down the machine (question: why?) CSE 422S –Operating Systems Organization

Simplest “Tracer”: printk() printk() prints information to the system log Messages stored in circular buffer Can be read with dmesg Eight possible log levels (set with dmesg –n) Example: printk(KERN_ALERT “bad thing %ld”, bad_thing); Uses same format as printf() Note there is no comma after log level (KERN_ALERT) CSE 422S –Operating Systems Organization

Other Debugging Mechanisms int some_function(…) { // <code you know is correct> // <code never reached> } CSE 422S –Operating Systems Organization

Other Debugging Mechanisms int some_function(…) { // <code you know is correct> // <code that must have a bug> // <code never reached> } CSE 422S –Operating Systems Organization

Other Debugging Mechanisms int some_function(…) { printk(“Value of some variable: %d\n”, var); // stop executing code to avoid // triggering bug while (1) {} Sits in a loop forever, but will never relinquish the CPU (Linux generally does not preempt tasks executing kernel code) CSE 422S –Operating Systems Organization

Other Debugging Mechanisms int some_function(…) { printk(“Value of some variable: %d\n”, var); // stop executing code to avoid // triggering bug while (1) { schedule(); } Relinquishes the current CPU, giving it back to Linux to run other tasks CSE 422S –Operating Systems Organization

Performance Debugging The more interesting type of debugging We’ll look at two things today: monitoring system calls executed by a process (fyi: this is something a rootkit or sandboxer might also want to do ) Monitoring preemption and scheduling operations experienced by a process CSE 422S –Operating Systems Organization

System Call Tracing: Strace Allows one userspace process (tracer) to inspect the system calls made by another thread (tracee). Tracer calls ptrace() on tracee Tracee halts at every system call, system call return, and signal (except SIGKILL) Tracer records info, and releases tracee to continue Note: Tracing is per-thread Seriously warps program timing CSE 422S –Operating Systems Organization

CSE 422S –Operating Systems Organization strace ./program CSE 422S –Operating Systems Organization

CSE 422S –Operating Systems Organization strace ./program strace KERNEL CSE 422S –Operating Systems Organization

strace ./program strace fork KERNEL ./program <kernel creates new process> KERNEL ./program CSE 422S –Operating Systems Organization

ptrace (PTRACE_TRACEME) strace ./program strace fork <kernel creates new process> <kernel begins intercepting syscalls of ./program> KERNEL ptrace (PTRACE_TRACEME) ./program CSE 422S –Operating Systems Organization

ptrace (PTRACE_ATTACH) fork strace ./program strace ptrace (PTRACE_ATTACH) fork <kernel begins forwarding syscalls of ./program to strace> <kernel creates new process> <kernel begins intercepting syscalls of ./program> KERNEL ptrace (PTRACE_TRACEME) ./program CSE 422S –Operating Systems Organization

ptrace (PTRACE_ATTACH) fork strace ./program strace ptrace (PTRACE_ATTACH) fork <kernel begins forwarding syscalls of ./program to strace> <kernel creates new process> <kernel stops ./program and wakes up strace> <kernel begins intercepting syscalls of ./program> KERNEL ptrace (PTRACE_TRACEME) open (…) ./program CSE 422S –Operating Systems Organization

ptrace (PTRACE_ATTACH) Inspect open system call strace ./program strace ptrace (PTRACE_ATTACH) Inspect open system call fork <kernel begins forwarding syscalls of ./program to strace> <kernel creates new process> <kernel stops ./program and wakes up strace> <kernel begins intercepting syscalls of ./program> KERNEL ptrace (PTRACE_TRACEME) open (…) ./program CSE 422S –Operating Systems Organization

ptrace (PTRACE_ATTACH) Inspect open system call ptrace (PTRACE_CONT) strace ./program strace ptrace (PTRACE_ATTACH) Inspect open system call ptrace (PTRACE_CONT) fork <kernel begins forwarding syscalls of ./program to strace> <kernel creates new process> <kernel stops ./program and wakes up strace> <kernel stops strace, executes system calls and wakes up ./program> <kernel begins intercepting syscalls of ./program> KERNEL ptrace (PTRACE_TRACEME) open (…) ./program CSE 422S –Operating Systems Organization

ptrace (PTRACE_ATTACH) Inspect open system call ptrace (PTRACE_CONT) strace ./program strace ptrace (PTRACE_ATTACH) Inspect open system call ptrace (PTRACE_CONT) fork <kernel begins forwarding syscalls of ./program to strace> <kernel creates new process> <kernel stops ./program and wakes up strace> <kernel stops strace, executes system calls and wakes up ./program> <kernel begins intercepting syscalls of ./program> KERNEL ptrace (PTRACE_TRACEME) open (…) ./program CSE 422S –Operating Systems Organization

Ftrace – the Function Tracer Tracing beyond system calls; many features: Event tracepoints (scheduler, interrupts, etc.) Trace any kernel function Call graphs Kernel stack size Latency tracing How long interrupts disabled How long preemption disabled Has a user interface called trace-cmd Very nice graphical trace browser called Kernelshark CSE 422S –Operating Systems Organization

CSE 422S –Operating Systems Organization Ftrace Internals When tracing is enabled, the kernel maintains: Per-CPU ring buffer for holding events Per-CPU kernel thread that empties ring buffer If readers can’t keep up, data is lost (dropped) Tracepoints in kernel: Kernel maintains list of tracepoint locations Locations normally converted to no-ops (ftrace_make_nop()) Trace code is runtime-patched into kernel code when activated (ftrace_make_call()) CSE 422S –Operating Systems Organization

CSE 422S –Operating Systems Organization Today’s Studio By the end of the studio, you will understand how to perform basic analysis of program and kernel interaction What system calls are made? Where and when does the kernel schedule processes? You will use strace to inspect system calls made by a program strace ./dense_mm 100 &> dense100trace.txt strace ./dense_mm 300 &> dense300trace.txt You will use ftrace and kernelshark to inspect scheduling behavior CSE 422S –Operating Systems Organization