CS591 (Spring 2001) The Linux Kernel: Debugging. CS591 (Spring 2001) Accessing the “Black Box” n Kernel code: n Not always executed in context of a process.

Slides:



Advertisements
Similar presentations
Tutorial 3 - Linux Interrupt Handling -
Advertisements

CS 6560 Operating System Design Lecture 7: Kernel Synchronization Kernel Time Management.
The Process Control Block From: A Process Control Block (PCB, also called Task Control Block or Task Struct) is.
Process Description and Control
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
OS Spring’03 Introduction Operating Systems Spring 2003.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Architecture of the 8051 INTERNAL DATA BUS Oscillator & Timing Programmable I/O (32 Pins) 80C51 CPU 64K byte Expansion Control Serial I/O 4K Program Memory.
OS Spring’04 Introduction Operating Systems Spring 2004.
Computer System Laboratory
Debugging techniques in Linux Debugging Techniques in Linux Chetan Kumar S Wipro Technologies.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
NT Kernel CS Spring Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
Time Management.  Time management is concerned with OS facilities and services which measure real time, and is essential to the operation of timesharing.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Lab 13 Department of Computer Science and Information Engineering National Taiwan University Lab13 – Interrupt + Timer 2014/12/23 1 /16.
Sogang University Advanced Operating Systems (Enhanced Device Driver Operations) Advanced Operating Systems (Enhanced Device Driver Operations) Sang Gue.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
4P13 Week 2 & 3 Talking Points 1. Kernel Processes 2.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Real Time Interrupts Section Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
System Hardware FPU – Floating Point Unit –Handles floating point and extended integer calculations 8284/82C284 Clock Generator (clock) –Synchronizes the.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
Time Sources and Timing David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Copyright © Curt Hill More on Operating Systems Continuation of Introduction.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
Ch6. Flow of Time Ch7. Getting Hold of Memory 홍원의.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
CSNB334 Advanced Operating Systems 3. Kernel Structure and Organization Lecturer: Abdul Rahim Ahmad.
Lecture 7 Interrupt ,Trap and System Call
Of Privilege, Traps, Interrupts & Exceptions Prof. Sirer CS 316 Cornell University.
Timers and Time Management Ok-Kyun Ha
Linux Kernel Development - Robert Love
Microprocessor Systems Design I
Time Sources and Timing
Anton Burtsev February, 2017
Discussions on hw5 Objectives:
CS 3305 System Calls Lecture 7.
Time Sources and Timing
Discussions on hw5 Objectives:
Processor Fundamentals
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Midterm Review Brian Kocoloski
Wireless Embedded Systems
Time Sources and Timing
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Process Description and Control in Unix
Interrupts and System Calls
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

CS591 (Spring 2001) The Linux Kernel: Debugging

CS591 (Spring 2001) Accessing the “Black Box” n Kernel code: n Not always executed in context of a process. n Not easily traced or executed under a conventional debugger. n Hard to step through (& set breakpoints in) a kernel that must be run to keep the system alive. n How, then, can we debug kernel code?

CS591 (Spring 2001) Debugging by Printing printf ’s are a common way of monitoring values of variables in application programs. Cannot use printf in the kernel as it’s part of the standard C library. printk is the kernel equivalent: n Messages can be classified according to their loglevel. e.g. printk(KERN_DEBUG “I have an IQ of 6000.\n”); Details found in kernel/printk.c.

CS591 (Spring 2001) Using /proc Filesystem n See Rubini page 74. Can use /proc virtual filesystem to create file nodes for reading kernel data. Entries in /proc can be configured like any file and can refer to devices too! Reading a /proc entry causes data to be generated. This is different than reading a file whose contents existed before the read call. Try doing ‘ls –l /proc’ to see the file sizes.

CS591 (Spring 2001) Debugging System Faults n Oops Messages: n Usually generated by kernel when dereferencing invalid address. n What about other hardware detected faults? n Processor status is dumped to screen, including CPU register values. Generated by arch/*/kernel/traps.c. Can check /var/log/messages to see fn before oops message. Can ‘cat /proc/ksyms’ to see address of function where PC was (value in EIP register) at time of fault.

CS591 (Spring 2001) Other Debugging Methods n Using a debugger: e.g. gdb vmlinux /proc/kcore enables symbols to be examined in the uncompressed kernel image. n Assumes kernel built with symbols not stripped (-g option). Will be huge! kcore is a core file representing the “executing kernel”. It is as large as all physical memory. n You cannot run the kernel image being debugged – it will seg fault! Hence this method is only good for symbol examination. Other methods: kgdb, remote debugging.

CS591 (Spring 2001) Message Logging defines the loglevels. n 8 loglevels available. If priority of message is less than console_loglevel priority, printk message is displayed. If klogd and syslogd are running, messages are logged in /var/log/messages. /etc/syslog.conf tells syslogd how to handle messages.

CS591 (Spring 2001) The Linux Kernel: The Flow of Time

CS591 (Spring 2001) “What time is it?” n Need timing measurements to: Keep track of current time and date for use by e.g. gettimeofday(). n Maintain timers that notify the kernel or a user program that an interval of time has elapsed. n Timing measurements are performed by several hardware circuits, based on fixed frequency oscillators and counters.

CS591 (Spring 2001) Hardware Clocks n Real-Time Clock (RTC): n Often integrated with CMOS RAM on separate chip from CPU: e.g., Motorola n Issues periodic interrupts on IRQ line (IRQ 8) at programmed frequency (e.g., Hz). n In Linux, used to derive time and date. Kernel accesses RTC through 0x70 and 0x71 I/O ports.

CS591 (Spring 2001) Timestamp Counter (TSC) n Intel Pentium (and up), AMD K6 etc incorporate a TSC. n Processor’s CLK pin receives a signal from an external oscillator e.g., 400 MHz crystal. n TSC register is incremented at each clock signal. Using rdtsc assembly instruction can obtain 64-bit timing value. n Most accurate timing method on above platforms.

CS591 (Spring 2001) The “PIT”s n Programmable Interrupt Timers (PITs): n e.g., 8254 chip. n PIT issues timer interrupts at programmed frequency. In Linux, PC-based 8254 is programmed to interrupt Hz (=100) times per second on IRQ 0. Hz defined in PIT is accessed on ports 0x40-0x43. n Provides the system “heartbeat” or “clock tick”.

CS591 (Spring 2001) “This’ll only take a jiffy” jiffies is incremented every timer interrupt. n Number of clock ticks since OS was booted. n Scheduling and preemption done at granularities of time-slices calculated in units of jiffies.

CS591 (Spring 2001) Timer Interrupt Handler n Every timer interrupt: n Update jiffies. Update time and date (in secs &  secs since 1970). n Determine how long a process has been executing and preempt it, if it finishes its allocated timeslice. n Update resource usage statistics. n Invoke functions for elapsed interval timers.

CS591 (Spring 2001) PIT Interrupt Service Routine n Signal on IRQ 0 is generated: timer_interrupt() is invoked w/ interrupts disabled ( SA_INTERRUPT flag is set to denote this). do_timer() is ultimately executed: Simply increments jiffies & allocates other tasks to “bottom half handlers”. Bottom half (bh) handlers update time and date, statistics, execute fns after specific elapsed intervals and invoke schedule() if necessary, for rescheduling processes.

CS591 (Spring 2001) Updating Time and Date lost_ticks ( lost_ticks_system ) store total (system) “ticks” since update to xtime, which stores approximate current time. This is needed since bh handlers run at convenient time and we need to keep track of when exactly they run to accurately update date & time. TIMER_BH refers to the queue of bottom halves invoked as a consequence of do_timer().

CS591 (Spring 2001) Task Queues n Often necessary to schedule kernel tasks at a later time without using interrupts. n Solution: Task Queues and kernel timers. n A task queue is a list of bottom half handlers, each represented by a function pointer and argument. From : struct tq_struct { struct tq_struct *next; int sync; /* always 0 initially. */ void (*routine)(void *); void *data; }

CS591 (Spring 2001) Predefined Task Queues tq_scheduler : bottom half tasks in this queue are executed whenever the scheduler runs. n Both scheduler and bottom halves run in context of process being scheduled out. tq_timer : executed every timer tick at “interrupt time”. tq_immediate : executed either on return from syscall or when scheduler is run.

CS591 (Spring 2001) Useful Task Queue Functions n void queue_task (struct tq_struct *task, task_queue *list); n Each queued task is removed from its queue after it is executed. n A task must be re-queued if needed repeatedly. n void run_task_queue (task_queue *list); n Not needed unless custom task queues are implemented. Fn is called by do_bottom_half() for predefined task queues.

CS591 (Spring 2001) Task Queue Example struct wait_queue *waitq=null; void wakeup_function(void *data) { wakeup_interruptible(&waitq); } void foo() { struct tq_struct bh; bh.next=null; bh.sync=0; bh.routine=wakeup_function; bh.data=(void *)some_data; queue_task(&bh,&tq_scheduler); interruptible_sleep_on(&waitq); }

CS591 (Spring 2001) Kernel Timers n Like task queues but timer bottom halves execute at predefined times. From : struct timer_list { struct timer_list *next; struct timer_list *prev; unsigned long expires; /* timeout in jiffies. */ unsigned long data; void (*function)(unsigned long); }

CS591 (Spring 2001) Useful Kernel Timer Functions n void init_timer(struct timer_list *timer); Zeroes prev & next pointers in doubly-linked timer queue. n void add_timer(struct timer_list *timer); n Adds timer bottom half to kernel timer queue. n int del_timer(struct timer_list *timer); n Removes timer before it expires.

CS591 (Spring 2001) Kernel Timer Example struct wait_queue *waitq=null; void wakeup_function(unsigned long data) { wakeup_interruptible(&waitq); } void foo() { struct timer_list bh; init_timer(&bh); bh.function=wakeup_function; bh.data=(unsigned long)some_data; bh.expires=jiffies+10*HZ; /* in 10 seconds. */ add_timer(&bh); interruptible_sleep_on(&waitq); }