4

現在のプロセスが Linux システムで実行されている CPU を知りたいのですが、2 つの選択肢があります —

  1. on_cpu構造体でフィールドを取得するtask_structか、
  2. cpustructのフィールドを取得しますthread_info

2 つのフィールドをプローブするカーネル モジュール プログラミングを作成し、以下の結果を取得します。

[ 3991.419185] the field 'on_cpu' in task_struct is :1
[ 3991.419187] the field 'cpu' in thread_info is :0
[ 3991.419199] the field 'on_cpu' in task_struct is :1
[ 3991.419200] the field 'cpu' in thread_info is :0
[ 3991.419264] the field 'on_cpu' in task_struct is :1
[ 3991.419266] the field 'cpu' in thread_info is :1
[ 3991.419293] the field 'on_cpu' in task_struct is :1
[ 3991.419294] the field 'cpu' in thread_info is :1
[ 3991.419314] the field 'on_cpu' in task_struct is :1
[ 3991.419315] the field 'cpu' in thread_info is :1
[ 3991.419494] the field 'on_cpu' in task_struct is :1
[ 3991.419495] the field 'cpu' in thread_info is :0
[ 3991.419506] the field 'on_cpu' in task_struct is :1
[ 3991.419507] the field 'cpu' in thread_info is :1

2 つのフィールドの正しい意味がわかりません。

4

1 に答える 1

1

cpuフィールドはthread_info、プロセスが実行されている CPU の番号を指定します。これはあなたが探しているものです。

on_cpuフラグはtask_struct、コンテキストの切り替え時に実際にはロックであり、コンテキストの切り替え中に割り込みを有効にして、ランキューのロックを解除することで高いレイテンシーを回避します。基本的に 0 の場合、タスクを別の CPU に移動できます。

于 2012-11-22T14:30:01.930 に答える