Articles in the kernel category

  1. "[Linux] Generate kernel crash dump"

    Steps

    1. Make sure following configs are on/off for current kernel
    # CONFIG_KASAN is not set
    CONFIG_RELOCATABLE=y
    CONFIG_KEXEC=y
    CONFIG_CRASH_DUMP=y
    CONFIG_DEBUG_INFO=y
    CONFIG_MAGIC_SYSRQ=y
    CONFIG_PROC_VMCORE=y
    
    1. Install kexec and crash tool
    $ sudo apt install kexec-tools makedumpfile crash
    
    1. Add 'crashkernel' parameter to grub
    $ sudo vi /etc/default/grub
    GRUB_CMDLINE_LINUX_DEFAULT="crashkernel …
  2. "[Design Pattern] Summary"

    Singleton

    • private constructor

      class Foo {
      private:
          Foo();
      }
      
    • a get_xxx() method looks like:

      static Foo *g_foo = NULL;
      Foo *get_foo() {
          if (!g_foo)
              g_foo = create_foo();
          return g_foo;
      }
      

    Factory Method

    • also known as 'Virtual Constructor'
    • delegate class instantiation to subclass
      +----------------+            +-----------------+
      |    Product     |            |    Creator      |
      +----------------+            +-----------------+
              A                     |                 |
              |                     +-----------------+
              |                     |+factoryMethod() |
              |                     +-----------------+
              |                              A
              |                              |
              |                              |
      +-----------------+           +-----------------+
      | ConcreteProduct |<-------<x>| ConcreteCreator |
      +-----------------+           +-----------------+
                                    |                 |
                                    +-----------------+
                                    |+factoryMethod() |
                                    +-----------------+
      

    Observer

    • also known as 'Publish …
  3. "[ARM] CPU registers and modes"

    Registers

    1. r0 ~ r7: general registers
    2. r8 ~ r12: banked registers (in fiq mode)
    3. r13 / sp: stack pointer register
    4. r14 / lr: link register
    5. r15 / pc: program counter register

    CPU modes

    1. (usr) user mode
    2. (sys) system mode
    3. (svc) supervisor mode
    4. (abt) abort mode
    5. (und) undefined mode
    6. (irq) interrupt mode
    7. (fiq) fast interrupt mode …
  4. "[Linux] Speedup Linux clone"

    Background

    In Nov. 2015, kernel.org announced that Fastly(a CDN provider) offered CDN service to provide fast download for Linux kernel releases.

    How to use this feature

    1. Download Linux bundle

      $ wget -c --no-check-certificate https://cdn.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/clone.bundle
      

      In Shanghai …

  5. "[Kernel] Kernel and module debugging with gdb"

    What is a loadable module

    • Module entry routine is tagged with __init attribute.
    • __init is to identify code that can be discarded after the the module is loaded so as to not waste any kernel space.
    • Module exit routine is tagged with __exit attribute.
    • __exit is to identify code that …
  6. "[Linux] Module.symvers"

    What is Module.symvers

    • Module.symvers is a plain text file which is generated after kernel building.
    • It records CRC values of all the exported symbols in both vmlinux and modules.

    What Module.symvers is used for

    • Module.symvers is used as a simple ABI consistency check.
    • Before a module …
  7. "[Kernel] Linux GPIO Subsystem"

    Kernel GPIO Interface

    bool gpio_is_valid(int number);
     int gpio_request(unsigned gpio, const char *label);
    void gpio_free(unsigned gpio);
     int gpio_direction_input(unsigned gpio);
     int gpio_direction_output(unsigned gpio, int value);
     int gpio_get_value(unsigned gpio);
    void gpio_set_value(unsigned gpio, int value);
     int gpio_export(unsigned gpio, bool direction_may_change);
    void gpio_unexport(unsigned gpio);
     int gpio_to_irq …