2012/12/17(月)preemptive kernel

Linux kernel configurationの、Preemption Modeについて。
kernel configしてみると、以下の選択肢が現れる。通常Desktop程度までだろう。
Real-time kernelにすると、割り込みレイテンシを短くすることができる、らしい。
( ) No Forced Preemption (Server)
( ) Voluntary Kernel Preemption (Desktop)
( ) Preemptible Kernel (Low-Latency Desktop)
(X) Complete Preemption (Real-Time)
で、コレを使ったときや、手動で設定すると、割り込みハンドラ中にもdispatchができてしまうようだ。


CONFIG_PREEMPT_RT:
This option further reduces the scheduling latency of the kernel by replacing almost every spinlock used by the kernel with preemptible mutexes and thus making all but the most critical kernel code involuntarily preemptible.
The remaining handful of lowlevel non-preemptible codepaths are short and have a deterministic latency of a couple of tens of microseconds (depending on the hardware).
This also allows applications to run more 'smoothly' even when the system is under load, at the cost of lower throughput and runtime overhead to kernel code.

(According to profiles, when this mode is selected then even during kernel-intense workloads the system is in an immediately preemptible state more than 95% of the time.)

Select this if you are building a kernel for a desktop, embedded or real-time system with guaranteed latency requirements of 100 usecs or lower.

Symbol: PREEMPT_RT [=y]
Prompt: Complete Preemption (Real-Time)
  Defined at kernel/Kconfig.preempt:56
  Depends on: <choice>
  Location:
    -> Kernel options
      -> Preemption Mode (<choice> [=y])
  Selects: PREEMPT_SOFTIRQS [=y] && PREEMPT_HARDIRQS [=y] && PREEMPT_RCU [=PREEMPT_RCU] && RT_MUTEXES [=y]

"Complete Preemption"
CONFIG_PREEMPT_HARDIRQS:
This option reduces the latency of the kernel by 'threading' hardirqs.
This means that all (or selected) hardirqs will run in their own kernel thread context.
While this helps latency, this feature can also reduce performance.

The threading of hardirqs can also be controlled via the
/proc/sys/kernel/hardirq_preemption runtime flag and the hardirq-preempt=0/1 boot-time option.
Per-irq threading can be enabled/disable via the /proc/irq/<IRQ>/<handler>/threaded runtime flags.

Symbol: PREEMPT_HARDIRQS [=y]
Prompt: Thread Hardirqs
  Defined at kernel/Kconfig.preempt:105
  Depends on: GENERIC_HARDIRQS_NO__DO_IRQ [=y]

CONFIG_PREEMPT_SOFTIRQS:
This option reduces the latency of the kernel by 'threading' soft interrupts.
This means that all softirqs will execute in softirqd's context.
While this helps latency, it can also reduce performance.

 The threading of softirqs can also be controlled via
 /proc/sys/kernel/softirq_preemption runtime flag and the sofirq-preempt=0/1 boot-time option.