Rocking the blogosphere

Linux Kernel Development notes

These are some really rough notes about some of the content that I found interesting in “Linux Kernel Development” (Second Edition) by Robert Love:

  • Chapter 3: Process Management
  • Chapter 4: Process Scheduling
    • Basically about the 2.6 kernel’s O(1) scheduler
    • struct runqueue (has since been renamed to struct rq) and struct prio_array
    • The main scheduler function is schedule().
    • Recalculating time slices - swapping the active and expired priority arrays - happens here.
    • Finding the highest priority runnable task is done quickly and cleverly by searching a 140-bit priority array for the first set bit - this happes here.
    • Dynamic priority = static priority + bonus for interactivity or a penalty for processor hog - effective_prio()
    • Wait queues - wait_queue_head_t (the book has a typo here, listing wake_queue_head_t); create statically with DECLARE_WAITQUEUE() or dynamically with init_waitqueue_head(). Wake up processes waiting on a given wait queue with wake_up().
    • Load balancing among CPUs on multiprocessing systems happens via load_balance(), which is called:
      • by schedule() when the current runqueue is empty
      • by timer; every 1 ms when system idle and every 200 ms otherwise
    • Preemption (including kernel preemption) and context switching - context\_switch(), which makes use of the architecture-dependent routines switch\_mm() and switch_to() (super-fun inline assembler!)
    • Real-time scheduling policies - SCHED\_FIFO and SCHED\_RR - defined in include/linux/sched.h. The difference is SCHED\_RR gets a limited timeslice but SCHED\_FIFO can run indefinitely. Both are always scheduled over SCHED\_NORMAL tasks. Linux has soft real-time behavior.
    • Schedule-related system calls - priority and policy-related calls, including processor affinity calls
  • Chapter 5: System Calls
    • x86: int $0x80 -> system_call() (arch/i386/kernel/entry.S) -> sys_call_table (the book says that this resides in the same file as system_call() but in my 2.6.20 tree it’s in another file called syscall_table.S). This file mentions 319 system calls for i386.
    • copy_to_user(), copy_from_user()
  • Chapter 6: Interrupts and Interrupt Handlers
    • Top halves and bottom halves
    • Registering and freeing an interrupt handler - request_irq(), free_irq(). Since the publication of the book, the kernel has added a typedef irq_handler_t which specifies the required function signature for a handler (patch). The book mentions a regs parameter that might not be long for this world, and indeed, it was removed in 2.6.19 (according to LWN here and here).
    • fast interrupt handler - run with all interrupts disabled on the current processor instead of just the current interrupt. The book describes the SA_INTERRUPT flag, but according to LWN’s 2.6 kernel API page, in 2.6.18 this (along with other SA_* flags) was deprecated in favor of the more aptly named IRQF_DISABLED (see include/linux/interrupt.h)
    • Code for a real-life interrupt handler - rtc_interrupt()
    • Implementation of interrupt handling - do_IRQ(), handle_irq_event(), ret_from_intr()
    • /proc/interrupts
    • Disabling and enabling interrupts - local_irq_disable(), local_irq_enable(), local_irq_save(), local_irq_restore() (include/linux/irqflags.h and include/asm-i386/irqflags.h)
    • Disabling a specific interrupt line - disable_irq(), disable_irq_nosync(), enable_irq(), synchronize_irq() (kernel/irq/manage.c)
    • Getting status - in_interrupt(), in_irq() (include/linux/hardirq.h)
  • Chapter 7: Bottom Halves and Deferring Work
  • Chapter 8: Kernel Synchronization Introduction
  • Chapter 9: Kernel Synchronization Methods
  • Chapter 10: Timers and Time Management
  • Chapter 11: Memory Management
  • Chapter 16: Modules
  • Chapter 17: kobjects and sysfs

Popularity: 13% [?]

No comments yet. Be the first.

Leave a reply