What are the values โ€‹โ€‹of the 'on_cpu' field in the struct task_struct and the 'cpu' field in the struct thread_info?

I want to know which processor of the current process is running on a Linux system, and I have two options -

  • get the on_cpu field in struct task_struct or
  • get the cpu field in struct thread_info .

I am writing kernel module programming to probe two fields and get the result below:

 [ 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 

and I do not know the correct meaning of these two fields.

+4
source share
1 answer

The cpu field in thread_info indicates the number of the CPU in which the process is running. This is what you are looking for.

The on_cpu flag in task_struct is actually a lock when switching contexts and requires interrupts to be enabled during context switching to avoid high latency while having an unlocked runqueue. Basically, when it is 0, the task can be transferred to another processor.

+1
source

Source: https://habr.com/ru/post/1447673/


All Articles