Linux Kernel の見取り図

Linux_bigmap_for_driver_developer.png

標準ライブラリ

機能単位主なヘッダやソース備考
型定義linux/types.h
コンパイラは inttypes.h, stdint.h を提供しています。
定数、最大、最小linux/kernel.h
linux/stddef.h
linux/limits.h
linux/sizes.h
uapi/linux/limits.h は linux/limits.h で include します。
構造体オフセットlinux/stddef.h
linux/kernel.h
メンバーからそれを保持する構造体へ変換するマクロ container_of() もここに含めます。
文字linux/ctype.hlinux/ctype.h は1バイト文字(いわゆるASCII)のみ対応です。
文字列・メモリlinux/string.h
linux/glob.h
linux/string_helpers.h
linux/textsearch.h
linux/textsearch_fsm.h
linux/ihex.h
文字列変換linux/kernel.h
linux/parser.h
linux/kernel.h の中で strtoxxx は kstrtoxxx (たとえばkstrtoul() という関数になっています。
書式フォーマットlinux/kernel.hscnprintf() など
計算(数値)linux/kernel.h
linux/math64.h
asm/div64.h
linux/gcd.h
linux/lcm.h
linux/log2.h
linux/mpi.h
asm/div64.h は linux/math64.h から include されます。プロセッサ語長が 32 bit の場合、64bit (long long) 型に対して除算または剰余演算子を使うとリンクに失敗します。64bit 除算ライブラリ do_div() などを使用して下さい。
計算(ビット)linux/bcd.h
linux/bitops.h
asm/bitops.h
linux/bitrev.h
linux/bitmap.h
asm-generic/bitops/const_hweight.h
asm-generic/bitops/ffs.h
asm-generic/bitops/fls.h
asm-generic/bitops/find.h
linux/crc-ccitt.h
linux/crc-itu-t.h
linux/crc-t10dif.h
linux/crc16.h
linux/crc32.h
linux/crc32c.h
linux/crc7.h
linux/crc8.h
asm/bitops.h, asm-generic/bitops/const_hweight.h, asm-generic/bitops/ffs.h, asm-generic/bitops/fls.h, asm-generic/bitops/find.h は linux/bitops.h で include されます。直接 include しないで下さい。
bitops.h はプロセッサ毎に定義されています。
asm-generic/bitops/const_hweight.h はビットを数え上げる計算です。ファイル名に const がついていますが、即値と変数両方に使えるマクロです。gcc の組み込み関数 __builtin_constant_p() を使用して静的な定数と変数に対する計算をそれぞれ最適化しています。
エンディアン変換linux/byteorder/generic.h
linux/swab.h
linux/byteorder/generic.h は関数一覧として挙げてあります。実際は各アーキテクチャに最適な変換処理を利用するので asm/byteorder.h をインクルードします。
アルゴリズムinclude/linux/average.h
include/linux/bch.h
include/linux/bpf.h
include/linux/bsearch.h
include/linux/btree.h
include/linux/circ_buf.h
include/linux/cordic.h
include/linux/plist.h
include/linux/sort.h
include/linux/range.h
include/linux/rbtree.h
include/linux/rslib.h
include/linux/crypto.h
include/linux/cryptohash.h
include/linux/cryptouser.h
include/linux/hash.h
include/linux/hashtable.h
include/linux/jhash.h
圧縮include/linux/lz4.h
include/linux/lzo.h
include/linux/xz.h
include/linux/zlib.h

リンク・リスト

機能単位主なヘッダやソース備考
リスト操作include/linux/list.hリンク・リスト・メンバーからそれを保持する構造体へ変換するマクロ list_entry()container_of() と同じです。リスト操作に関連するならば list_entry() を使用して下さい。

アトミック操作

機能単位主なヘッダやソース備考
整数linux/atomic.h
asm/atomic.h
asm/atomic.h はプロセッサ毎に定義されています。asm/atomic.h は linux/atomic.h で include されます。
ビットasm/bitops.hasm/bitops.h はプロセッサ毎に定義されています。ヘッダファイルに atomic かどうか書かれています。atomic な関数・マクロは set_bit(), clear_bit(), clear_bit_unlock(), change_bit(), test_and_set_bit(), test_and_set_bit_lock(), test_and_clear_bit(), test_and_change_bit(), test_bit() atomic 関数と混在可 です。asm/bitops.h は linux/bitops.h で include されます。

バリア指示・同期

機能単位主なヘッダやソース備考
バリアlinux/compiler.h
asm/barrier.h
linux/compiler.h は linux/kernel.h より include されます。asm/barrier.h は linux/atomic.h から include されます。

排他制御

機能単位主なヘッダやソース備考
Spin Locklinux/spinlock.h使い分けのドキュメントは Documentation/locking/spinlocks.txt, Documentation/DocBook/kernel-locking/index.html
Semaphorelinux/semaphore.h
Mutexlinux/mutex.h

同期制御、状態変化待ち

機能単位主なヘッダやソース備考
Conditionlinux/wait.h
Completionlinux/completion.h

割り込みハンドラ登録・設定

機能単位主なヘッダやソース備考
IRQ classlinux/interrupt.h

時間待ち、タイマー

機能単位主なヘッダやソース備考
Sleeplinux/delay.hsleep の代表的な関数は msleep() です。実行中のタスクを再スケジュールします。CPU 資源を無駄にしません。割り込み処理中では使えません。
単に別の task に実行を渡す(いわゆる 0 秒待ちをする)場合は schedule() を使用します。
Delaylinux/delay.hdelay 関数は ndelay(), udelay(), mdelay() があります。これらは CPU を空走させて時間待ちを実現します。割り込みハンドラの中でも使えます。しかし、割り込み応答性能を悪化させます。
Timerinclude/linux/timer.h

時刻

機能単位主なヘッダやソース備考
jiffieslinux/jiffies.hjiffies の時間的前後関係を判定する場合は、linux/jiffies.h に定義された比較関数・マクロを使用して下さい。
Timelinux/time.h
linux/timekeeping.h
linux/sched.h
linux/sched.h の中に local_clock(), sched_clock() などの時刻関数が入っています。

メモリ確保

機能単位主なヘッダやソース備考
任意サイズlinux/slab.h
ページ単位linux/gfp.h
linux/mm.h
ページ確保: linux/gfp.h:alloc_page() 、ページ・アドレス取得: linux/mm.h:page_address() となっています。

論理-物理マップ、DMA 転送、コピー

機能単位主なヘッダやソース
User - Kernel Copy
Virt - Phy map convert
DMA map Scatter Gather

スレッド・軽量処理

機能単位主なヘッダやソース
kthread
work queue
tasklet

接続切断通知

機能単位主なヘッダやソース
UEvent
switch (Android)

リファレンスカウンタ

機能単位主なヘッダやソース
kref

Kernel Object

機能単位主なヘッダやソース備考
KObject
KSet

ノード形成

機能単位主なヘッダやソース備考
VFS(character)
VFS(block)
procfs
sysfs
debugfs

モジュールロード、アンロード、シンボル解決

機能単位主なヘッダやソース備考
Module insmod rmmod
Symbol lookup

基本的なドライバ

機能単位主なヘッダやソース
Null, Zero, Full, Mem drivers

基本的なファイルシステムノード

機能単位主なヘッダやソース備考
pipe
eventfd
signalfd
timerfd

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS