drivers

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
drivers [2016/07/31 08:17] admindrivers [2018/05/18 09:53] (current) – [Debugging] admin
Line 15: Line 15:
   * kmalloc is the primary allocator in the Linux kernel, for objects from 8 bytes to 128KB. The allocated area is guaranteed to be physically contiguous.   * kmalloc is the primary allocator in the Linux kernel, for objects from 8 bytes to 128KB. The allocated area is guaranteed to be physically contiguous.
   * vmalloc provides virtually contiguous memory zones that may not be physically contiguous. The resulting virtual addresses are higher than the top of physical memory. vmalloc cannot be used when the real physical address is needed, e.g. for DMA, and cannot be used at interrupt time. Allocation of large areas is possible, since physical memory fragmentation is not an issue.   * vmalloc provides virtually contiguous memory zones that may not be physically contiguous. The resulting virtual addresses are higher than the top of physical memory. vmalloc cannot be used when the real physical address is needed, e.g. for DMA, and cannot be used at interrupt time. Allocation of large areas is possible, since physical memory fragmentation is not an issue.
 +  * kzalloc
 +  * kcalloc
 +  * dma_alloc_coherent
 +  * dma_alloc_sg
 +  * contiguous memory algorithms (CMA, ION)
  
 Debugging features: Debugging features:
Line 24: Line 29:
 An issue with I/O memory accesses is memory reordering, which may require memory barriers (rmb(), wmb(), mw()). An issue with I/O memory accesses is memory reordering, which may require memory barriers (rmb(), wmb(), mw()).
  
 +===== User space memory handling =====
 User-space applications can access physical addresses directly through /dev/mem. User-space applications can access physical addresses directly through /dev/mem.
 +
 +  * Process heap (sbrk, brk)
 +  * Direct/Abstract (mmap)
 +  * Allocators (malloc, calloc, realloc, free)
 +
  
 ====== Modules ====== ====== Modules ======
Line 62: Line 73:
 ====== Sleeping ====== ====== Sleeping ======
  
 +  /* dynamic declaration */
   wait_queue_head_t queue;   wait_queue_head_t queue;
   init_waitqueue_head(&queue);   init_waitqueue_head(&queue);
 +  /* blocking */
   wait_event_interruptible(queue, condition);   wait_event_interruptible(queue, condition);
 +  /* unblocking - if condition is still false, nothing happens;
 +     if the condition is true, the process in the wait queue is
 +     awakaned and its state set to TASK_RUNNING */
   wake_up_interruptible(&queue);   wake_up_interruptible(&queue);
      
Line 72: Line 88:
 Top half and botton half processing: Top half and botton half processing:
   * Top half. The real interrupt handler. Schedules a bottom half to handle it.   * Top half. The real interrupt handler. Schedules a bottom half to handle it.
-  * Bottom half, implemented as:  +  * Bottom half, implemented the available work deferring mechanisms:  
-    * softirqs, executed with all i/r enabled. **They run in interrupt context.** A softirq handler can run simultaneously on multiple CPUs. They are executed once all i/r handlers have completed, before the scheduler resumes (sleeping not allowed). HI and TASKLET softirqs are used to executed tasklets. +    * SoftIRQs, executed with all i/r enabled. **They run in interrupt context.** A softirq handler can run simultaneously on multiple CPUs. They are executed once all i/r handlers have completed, before the scheduler resumes (sleeping not allowed). HI and TASKLET softirqs are used to execute tasklets. 
-    * tasklets, executed with all i/r enabled. **They run in interrupt context.** A taklet is guaranteed to execute on a single CPU at a time. Implemented as a function, and easily usable by individual device drivers. The interrupt handler can schedule the execution of a tasklet with tasklet_schedule() or tasklet_hi_schedule(). +    * Tasklets, executed with all i/r enabled. They are built on top of softirqs. **They run in interrupt context.** A taklet is guaranteed to execute on a single CPU at a time. Implemented as a function, and easily usable by individual device drivers. The interrupt handler can schedule the execution of a tasklet with tasklet_schedule() or tasklet_hi_schedule(). 
-    * work queues, not limited to handling interrupts. **They run in process context (kernel thread).** All i/r enabled, and sleeping is allowed. A workqueue is registered with INIT_WORK and triggered with queue_work().+    * Workqueues, not limited to handling interrupts. **They run in process context (kernel thread).** All i/r enabled, and sleeping is allowed. A workqueue is registered with INIT_WORK and triggered with queue_work().
  
  
Line 93: Line 109:
  
 Threaded interrupts are executed inside a thread (allows to block inside the handler). There is support for interrupt handler execution priority. Threaded interrupts are executed inside a thread (allows to block inside the handler). There is support for interrupt handler execution priority.
 +
 +UIO allows the handling from interrupt in user space.
  
 ====== Concurrency ====== ====== Concurrency ======
  
 The kernel lock validator is an useful tool to detect violations of locking rules during system life. Alternatives to locking are the use of lock-free algorithms (e.g. read copy update, RCU) or atomic operations (.e.g. atomic_set/atomic_read). The kernel lock validator is an useful tool to detect violations of locking rules during system life. Alternatives to locking are the use of lock-free algorithms (e.g. read copy update, RCU) or atomic operations (.e.g. atomic_set/atomic_read).
 +===== Semaphores =====
 ===== Mutexes ===== ===== Mutexes =====
  
Line 122: Line 141:
   * Kernel markers   * Kernel markers
   * LTTng with LTTV   * LTTng with LTTV
 +  * printk
 +  * kernel configs
 +  * debugfs/sysfs
 +  * ftrace
 +  * Kdb
 +  * Kgdb
 +  * jtag + gdb
 +  * emulation (QEmu)
  
 +Userspace:
 +  * printf
 +  * strace
 +  * ltrace
 +  * valgrind
 +  * gdb
 ====== Userspace drivers ====== ====== Userspace drivers ======
 http://2net.co.uk/slides/ew2016-userspace-drivers-slides.pdf http://2net.co.uk/slides/ew2016-userspace-drivers-slides.pdf
  
  
  • drivers.1469953064.txt.gz
  • Last modified: 10 years ago
  • by admin