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

アトミック操作
|機能単位|主なヘッダやソース|備考|h
|整数|&ogfileone(include/linux/atomic.h);&br;&ogfile(asm/atomic.h);|asm/atomic.h はプロセッサ毎に定義されています。asm/atomic.h は linux/atomic.h で include されます。直接 include しない方が良いでしょう。|
|ビット|&ogfile(include/asm/bitops.h);|asm/bitops.h はプロセッサ毎に定義されています。ヘッダファイルに atomic かどうか書かれています。atomic な関数・マクロは &ogdefs(set_bit(),set_bit);, &ogdefs(clear_bit(),clear_bit);, &ogdefs(clear_bit_unlock(),clear_bit_unlock);, &ogdefs(change_bit(),change_bit);, &ogdefs(test_and_set_bit(),test_and_set_bit);, &ogdefs(test_and_set_bit_lock(),test_and_set_bit_lock);, &ogdefs(test_and_clear_bit(),test_and_clear_bit);, &ogdefs(test_and_change_bit(),test_and_change_bit);, &ogdefs(test_bit() atomic 関数と混在可,test_bit); です。asm/bitops.h は linux/bitops.h で include されます。直接 include しない方が良いでしょう。|
|整数|&ogfileone(linux/atomic.h,include/linux/atomic.h);&br;&ogfile(asm/atomic.h);|asm/atomic.h はプロセッサ毎に定義されています。asm/atomic.h は linux/atomic.h で include されます。|
|ビット|&ogfile(asm/bitops.h,include/asm/bitops.h);|asm/bitops.h はプロセッサ毎に定義されています。ヘッダファイルに atomic かどうか書かれています。atomic な関数・マクロは &ogdefs(set_bit(),set_bit);, &ogdefs(clear_bit(),clear_bit);, &ogdefs(clear_bit_unlock(),clear_bit_unlock);, &ogdefs(change_bit(),change_bit);, &ogdefs(test_and_set_bit(),test_and_set_bit);, &ogdefs(test_and_set_bit_lock(),test_and_set_bit_lock);, &ogdefs(test_and_clear_bit(),test_and_clear_bit);, &ogdefs(test_and_change_bit(),test_and_change_bit);, &ogdefs(test_bit() atomic 関数と混在可,test_bit); です。asm/bitops.h は linux/bitops.h で include されます。|

バリア同期
バリア指示・同期
|機能単位|主なヘッダやソース|備考|h
|バリア|&ogfile(include/linux/compiler.h);&br;&ogfile(include/asm/barrier.h);|linux/compiler.h は linux/kernel.h より include されます。asm/barrier.h は linux/atomic.h から include されます。|
|バリア|&ogfile(linux/compiler.h,include/linux/compiler.h);&br;&ogfile(asm/barrier.h,include/asm/barrier.h);|linux/compiler.h は linux/kernel.h より include されます。asm/barrier.h は linux/atomic.h から include されます。|
排他制御
|機能単位|主なヘッダやソース|備考|h
|Spin Lock|&ogfileone(include/linux/spinlock.h);|使い分けのドキュメントは &ogfiledirect(Documentation/locking/spinlocks.txt);, &ogfiledirect(Documentation/DocBook/kernel-locking/index.html);|
|Semaphore|&ogfileone(include/linux/semaphore.h);||
|Mutex|&ogfileone(include/linux/mutex.h);||
|Spin Lock|&ogfileone(linux/spinlock.h,include/linux/spinlock.h);|使い分けのドキュメントは &ogfiledirect(Documentation/locking/spinlocks.txt);, &ogfiledirect(Documentation/DocBook/kernel-locking/index.html);|
|Semaphore|&ogfileone(linux/semaphore.h,include/linux/semaphore.h);||
|Mutex|&ogfileone(linux/mutex.h,include/linux/mutex.h);||

同期制御、状態変化待ち
|機能単位|主なヘッダやソース|備考|h
|Condition|&ogfileone(include/linux/wait.h);||
|Completion|&ogfileone(include/linux/completion.h);||
|Condition|&ogfileone(linux/wait.h,include/linux/wait.h);||
|Completion|&ogfileone(linux/completion.h,include/linux/completion.h);||

割り込み処理
割り込みハンドラ登録・設定
|機能単位|主なヘッダやソース|備考|h
|IRQ class|&ogfileone(include/linux/interrupt.h);||
|IRQ class|&ogfileone(linux/interrupt.h,include/linux/interrupt.h);||

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

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

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

論理-物理マップ、DMA 転送、コピー
|機能単位|主なヘッダやソース|h
|User - Kernel Copy||
|Virt - Phy map convert||
|DMA map Scatter Gather||

スレッド・軽量処理
|機能単位|主なヘッダやソース|h
|kthread||
|work queue||
|tasklet||

接続切断通知
|機能単位|主なヘッダやソース|h
|UEvent||
|switch (Android)||

リファレンスカウンタ
|機能単位|主なヘッダやソース|h
|kref||

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

ノード形成
|機能単位|主なヘッダやソース|備考|h
|VFS(character)|||
|VFS(block)|||
|procfs|||
|sysfs|||
|debugfs|||

モジュールロード、アンロード、シンボル解決
|機能単位|主なヘッダやソース|備考|h
|Module insmod rmmod|||
|Symbol lookup|||

基本的なドライバ
|機能単位|主なヘッダやソース|h
|Null, Zero, Full, Mem drivers||

基本的なファイルシステムノード
|機能単位|主なヘッダやソース|備考|h
|pipe|||
|eventfd|||
|signalfd|||
|timerfd|||


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