struct thread_info thread_info
是
first
member of the
struct task_struct
:
struct task_struct {
#ifdef CONFIG_THREAD_INFO_IN_TASK
/*
* For reasons of header soup (see current_thread_info()), this
* must be the first element of task_struct.
*/
struct thread_info thread_info;
#endif
struct
. 它本可以用类似的方法
¤t->thread_info
但如果
结构任务\u结构
是
至于
DECLARE_PER_CPU
每个CPU声明\u
这是因为在x86上,读取是通过一个特殊的段寄存器进行的。其他CPU架构必须使用一些完全不同的方法来访问每CPU值。
this_cpu_read
它不允许GCC以任何方式缓存它,但是当前线程信息是一个例外,因为当前线程总是在当前线程中运行,不管它在哪个CPU上。从
arch/x86/include/asm/percpu.h
:
/*
* this_cpu_read() makes gcc load the percpu variable every time it is
* accessed while this_cpu_read_stable() allows the value to be cached.
* this_cpu_read_stable() is more efficient and can be used if its value
* is guaranteed to be valid across cpus. The current users include
* get_current() and get_thread_info() both of which are actually
* per-thread variables implemented as per-cpu variables and thus
* stable for the duration of the respective task.
*/