Kernel 内外のコンテキスト(Players inside/outside kernel)

Documentation/DocBook/kernel-hacking/basic-players.html に Linux において CPU が実行しているコンテキストについて書かれています。Documentation/DocBook/kernel-hacking/basic-players.html ではコンテキストを Players と呼んでいます。次の表は context (players) についてまとめたものです。

ContextDescription
User Space 実行中

running a process in user space
Userland のアプリケーションやコマンドを実行している状態です。system call、例外(trap)、プリエンプション、ハードウエア割り込みによって kernel 内の実行に移ります。kernel 内のコードは User 空間で実行されることはありません。
User Space と関連した kernel 内実行

running in kernel space, associated with a process (user context)
Userland のプロセスと関連した kernel 内の処理です。system call または例外によって kernel に実行が移った状態です。デバイスドライバを開発する立場であれば system call がきっかけで kernel 内に実行が移った状況だと考えて良いでしょう。system call の open(), close(), read(), write(), ioctl(), lseek(), mmap(), poll() などです。copy_from_user()copy_to_user() などでユーザーランドのアプリケーションと情報を交換できる状況です。
User Space と関連しない kernel 内実行

running in kernel space, not associated with a process (user context)
Userland のプロセスと関連していない kernel 内の処理です。kernel thread (kthread) 実行中、work queue /include/linux/workqueue.h に登録した関数を実行している最中です。work queue も __alloc_workqueue_key() にて kthread で実装されています。User Space と関連が無いのでユーザーランドのアプリケーションと情報は交換できません。上記の Userland に関連したコンテキスト、この項目に分類されるコンテキスト、次の softirq を起床するすることはできます。
softirq 実行中

not associated with any process,serving a softirq, tasklet, or timer
softirqsoftirq, tasklet, timer は bottom halves (省略されて bh) と総称されています。tasklet, timer ともsoftirq にて実装されています(TASKLET_SOFTIRQ, TIMER_SOFTIRQ)。
Linux Kernel のドキュメントでは User Space と関連しない kernel 内実行(not associated with any process) と書かれています。このことを確かめるため softirq 処理の中から (task_struct*)current->comm を読むと何らかの process 名が入っています。割り込みが発生した時点でたまたま実行していたコンテキスト上で softirq は実行されています。User Space と選べない・予測できない関連があると言うのが正しいです。
tasklet
timer
hardware 割り込み実行中

not associated with any process, serving a hardware interrupt

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