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.

2012/12/05(水)TLB miss hit対策

論理-物理アドレスの変換は、ハードウェア(MMU)の力を借りて実現しています。
この機構、アーキテクチャによって異なりますが、
一般的*1
4KByte/pageを単位として管理されているようです。

*1 : 狭い視野なので、一般じゃないかも

hugetlb

libhugetlbfs
コレを使うことで、実行ファイル(ELFファイル)の読み出し先にhugepageを割り当て、
TLB miss hitを軽減することができます。
リンカの設定や、実行時の処理・PRELOAD処理が必要となり、アプリの起動時間が解析・転送時間だけ
遅れますが、CPU cacheに載らない範囲のランダムアクセスが多い場合には有効ではないでしょうか。

余力と根気があれば、例を踏まえて追記したいと思います。
(ぐぐれば ベンチマークを掲載しているWEB pageもございます)