static inline struct thread_info *current_thread_info(void) { return (struct thread_info *) (current_stack_pointer & ~(THREAD_SIZE - 1)); } current_stack_pointer 表示当前栈顶寄存器的值,对于 X86 就是 esp,在内核态的时候,current_stack_pointer 表示内核栈中的某一个位置 THREAD_SIZE 我们上面...
从而保证了init_thread_union是以8192对齐的。 对于一般的线程信息,uclinux内核是如何做到这一点的呢?在thread_info.h中有一个宏定义: /* thread information allocation */ #definealloc_thread_info(tsk) ((structthread_info *) / __get_free_pages(GFP_KERNEL, 1)) #definefree_thread_info(ti) free_pa...
thread_info和内核栈虽然共用了thread_union结构, 但是thread_info大小固定, 存储在联合体的开始部分, 而内核栈由高地址向低地址扩展, 当内核栈的栈顶到达thread_info的存储空间时, 则会发生栈溢出 系统的current指针指向了当前运行进程的thread_union(或者thread_info)的地 进程task_struct中的stack指针指向了进程的...
#defineget_current()(current_thread_info()->task)#define currentget_current() current 通过 get_current(),进而调用 current_thread_info()->task 我们看一看 current_thread_info 的定义: 代码语言:javascript 复制 staticinline struct thread_info*current_thread_info(void){return(struct thread_info*)(c...
/* current从thread_info的task域中提取并返回task_struct地址 */current_thread_info()->task; 进程状态 进程描述符(task_struct)的state域描述了进程的当前状态。每个进程比如处于这5中状态中的一种。 TASK_RUNNING(运行):进程是可执行的;或正在执行,或在运行队列中等待执行(就绪)。
#include <linux/thread_info.h> #define get_current() (current_thread_info()->task)//获取当前进程的线程task #define current get_current()//表示当前进程 #endif/* __ASM_GENERIC_CURRENT_H */ 1. 2. 3. 4. 5. 6. 7. 8. 9.
这个结构体保存了进程描述符中中频繁访问和需要快速访问的字段,内核依赖于该数据结构来获得当前进程的描述符(为了获取当前CPU上运行进程的task_struct结构,内核提供了current宏。 代码语言:javascript 复制 #defineget_current()(current_thread_info()->task)#define currentget_current() ...
#define get_current() (current_thread_info()->task) #define current get_current() 1. 2. 内核还需要存储每个进程的PCB信息, linux内核是支持不同体系的的, 但是不同的体系结构可能进程需要存储的信息不尽相同, 这就需要我们实现一种通用的方式, 我们将体系结构相关的部分和无关的部门进行分离,用一种通用...
后面通过current宏获取当前cpu // 的当前进程,就是这里的功劳 // 传统的current红灯是根据内核sp获取到thread_info,然后根据 // thread_info获取到task_struct // 不过x86平台上做了优化,通过没cpu变量实现 // 每次进程切换时都会将当前运行的进程写入到当前cpu的每cpu // 变量中,通过current宏获取时也是从每...
31current_thread_info->preempt.need_resched =0; 32} 当内核的某个路径设置重新调度标志(如时钟中断tick时),会调用到resched_curr 来设置重新调度标志:可以看到除了设置任务的flags的TIF_NEED_RESCHED标志外,还设置了preempt.need_resched为0。 如何清除重新调度标志: ...