1 __setup
在include/linux/init.h文件中定义
#define __setup_param(str, unique_id, fn, early) \
static const char __setup_str_##unique_id[] __initconst \
__aligned(1) = str; \
static struct obs_kernel_param __setup_##unique_id \
__used __section(.init.setup) \
__attribute__((aligned((sizeof(long))))) \
= { __setup_str_##unique_id, fn, early }
#define __setup(str, fn) \
__setup_param(str, fn, fn, 0)
__setup在kernel启动时用来读取、解析cmdline。str可以当成一个变量,fn是用来处理str变量的函数
ldb.c kernel_imx\drivers\video\mxc文件使用到这个宏
static int __init ldb_setup(char *options)
{
if (!strcmp(options, "spl0"))
g_ldb_mode = LDB_SPL_DI0;
else if (!strcmp(options, "spl1"))
g_ldb_mode = LDB_SPL_DI1;
else if (!strcmp(options, "dul0"))
g_ldb_mode = LDB_DUL_DI0;
else if (!strcmp(options, "dul1"))
g_ldb_mode = LDB_DUL_DI1;
else if (!strcmp(options, "sin0"))
g_ldb_mode = LDB_SIN0;
else if (!strcmp(options, "sin1"))
g_ldb_mode = LDB_SIN1;
else if (!strcmp(options, "sep0"))
g_ldb_mode = LDB_SEP0;
else if (!strcmp(options, "sep1"))
g_ldb_mode = LDB_SEP1;
return 1;
}
__setup("ldb=", ldb_setup);
当前使用的cmdline部分内容为
bootargs=console=ttymxc0,115200 androidboot.console=ttymxc0 vmalloc=400M init=/init video=mxcfb0:dev=ldb,LDB-1080P60,if=RGB24,bpp=32 ldb=spl0
ldb=spl0,那么ldb_setup的参数就是spl0。宏的展开
__setup("ldb=", ldb_setup);
__setup_param("ldb=", ldb_setup, ldb_setup, 0) //定义两个变量
static const char __setup_str_ldb_setup[] __initconst __aligned(1) = "ldb="; //字符串数组
static struct obs_kernel_param __setup_ldb_setup __used __section(.init.setup) //结构体 __attribute__((aligned((sizeof(long))))) = {
__setup_str_ldb_setup, ldb_setup, 0
}
2 early_param
定义如下,除了__setup_param的最后一个参数,其他的跟__setup的定义是一样的,定义两个变量,参数不同。
#define early_param(str, fn) /
__setup_param(str, fn, fn, 1)
early_param和__setup定义的变量都是在main.c (kernel_imx\init) start_kernel函数中处理的。
parse_early_param(); //处理early_param定义的变量,实际最后还是调用了parse_args函数,参数不一样
parse_args("Booting kernel", static_command_line, __start___param,
__stop___param - __start___param,
&unknown_bootoption);//处理 __setup定义的变量
3 MACHINE_START
4 __attribute__编译属性 section
本节内容从__attribute__编译属性—section转载
__attribute__ 是gcc编译属性,主要用于改变所声明或定义的函数或数据的特性,它有很多子项,用于改变作用对象的特性。比如对函数,noline将禁止进行内联扩展、noreturn表示没有返回值、pure表明函数除返回值外,不会通过其它(如全局变量、指针)对函数外部产生任何影响。内核中出现比较多是section, section对代码段起作用。
目前支持以下变量属性
• address (addr)
• aligned (alignment)
• boot
• deprecated
• fillupper
• far
• mode (mode)
• near
• noload
• packed
• persistent
• reverse (alignment)
• section ("section-name")
• secure
• sfr (address)
• space (space)
• transparent_union
• unordered
• unused
• weak
__attribute__的section子项的使用格式为:
__attribute__((section("section_name")))
其作用是将作用的函数或数据放入指定名为"section_name"输入段。
输入段和输出段是相对于要生成最终的elf或binary时的Link过程说的,Link过程的输入大都是由源代码编绎生成的目标文件.o,那么这些.o文件中包含的段相对link过程来说就是输入段,而Link的输出一般是可执行文件elf或库等,这些输出文件中也包含有段,这些输出文件中的段就叫做输出段。输入段和输出段本来没有什么必然的联系,是互相独立,只是在Link过程中,Link程序会根据一定的规则(这些规则其实来源于Link Script),将不同的输入段重新组合到不同的输出段中,即使是段的名字,输入段和输出段可以完全不同。
int var __attribute__((section(".xdata"))) = 0;
这样定义的变量var将被放入名为.xdata的输入段,(注意:attribute这种用法中的括号很严格,这里的几个括号好象一个也不能少。)__attribute__的section属性只指定对象的输入段,它并不能影响所指定对象最终会放在可执行文件的什么段。
__init 宏最常用的地方是驱动模块初始化函数的定义处,其目的是将驱动模块的初始化函数放入名叫.init.text的输入段。对于__initdata来说,用于数据定义,目的是将数据放入名叫.init.data的输入段。
4.1 initcall宏定义
源码
#define __define_initcall(level,fn,id) \
static initcall_t __initcall_##fn##id __used \
__attribute__((__section__(".initcall" level ".init"*强调内容*))) = fn
其用来定义类型为initcall_t的static函数指针,函数指针的名称由参数fn和id决定:_initcall##fn##id,这就是函数指针的名称,它其实是一个变量名称。从该名称的定义方法我们其学到了宏定义的一种高级用法,即利用宏的参数产生名称,这要借助于”##”这一符号组合的作用。
这一函数指针变量放入什么输入段呢,请看__attribute__ ((__section__ (“.initcall” levle “.init”))),输入段的名称由level决定,如果level=”1”,则输入段是.initcall1.init,如果level=”3s”,则输入段是.initcall3s.init。这一函数指针变量就是放在用这种方法决定的输入段中的。
5 current
kernel中current是一个宏,返回当前进程task_struct结构的指针。参考文档
定义如下,
/* arch/arm/include/asm/current.h */
static inline struct task_struct *get_current(void)
{
return current_thread_info()->task;
}
// current宏
#define current (get_current())
sp为当前进程内核栈栈顶地址
/* arch/arm/include/asm/thread_info.h */
static inline struct thread_info *current_thread_info(void)
{
register unsigned long sp asm ("sp");
return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
}
每个进程在内核态下都会开辟一个内核栈,一般就是8KB,一般把thread_info这个结构体和内核栈放在一起,这样内核就可以很方便从ESP寄存器中获取当前CPU上正在运行的thread_info。具体的位置是thread_info结构保存在8K起始位置,如下图所示:
无论esp是指向哪里,只要将其低13位屏蔽掉,总能找到8K的起始地址,也就是图中的0x015fa000,这样我们就找到了thread_info,而task也就是tast_struct结构休是thread_info的成员,thread_info->task就是当前进程task_struct结构体指针。
上图是以x86架构画的图,arm cpu也是一样的处理逻辑,只是 将esp改成sp
struct thread_info结构体
struct thread_info {
unsigned long flags; /* low level flags */
int preempt_count; /* 0 => preemptable, <0 => bug */
mm_segment_t addr_limit; /* address limit */
struct task_struct *task; /* main task structure */
struct exec_domain *exec_domain; /* execution domain */
__u32 cpu; /* cpu */
__u32 cpu_domain; /* cpu domain */
struct cpu_context_save cpu_context; /* cpu context */
__u32 syscall; /* syscall number */
__u8 used_cp[16]; /* thread used copro */
unsigned long tp_value;
struct crunch_state crunchstate;
union fp_state fpstate __attribute__((aligned(8)));
union vfp_state vfpstate;
#ifdef CONFIG_ARM_THUMBEE
unsigned long thumbee_state; /* ThumbEE Handler Base register */
#endif
struct restart_block restart_block;
};
内核做的大部分动作是代表一个特定进程的,可以将内核看作是一个特殊的进程,应用层的是普通进程。在一个系统调用执行期间,例如 open 或者 read, 当前进程是发出调用的进程。内核代码可以通过使用 current 来使用进程特定的信息,此时的current是发出调用的进程的task_struct指针。
6 关于打开设备结点(struct inode和struct file)
当在应用层多个终端或者文件上同时打开同一个设备结点,如:/dev/stdin时,fd = open(“/dev/stdin”, O_RDWR)
返回的fd不总是同一个值,由当前终端决定,有可能相同,也有可能不同,也就是说fd是不确定的,由系统的环境决定。
但是在kernel所有打开的结点都指向同一个inode(struct inode),也就是说,无论应用层打开多少次,在kernel看来都是同一个文件。其调用的方法、使用的数据都是一致的。但是每次打开结点文件,kernel都会分配一个struct file *filp,file是与上层应用的文件描述符想对应的,在一个进程(无论是否在一个进程、线程),多次打开结点,会分配多个struct file结构体,并返回不同的fd。
不仅是结点文件,普通文件同样适用。
总结:应用层多次打开文件,kernel只分配一次struct inode,多次分配struct file,返回多个不同的fd
7 struct page
struct page 表示一个内存页框,是内存管理的最小单位,通常一个页框的大小是4K,kernel会为每个内存页框分配一个struct page结构体。下面是struct page部分代码
struct page {
/* First double word block */
unsigned long flags; /* 体系结构无关的标记,用于描述页的属性,flags中的每一个bit,定义了page的一种属性 */
struct address_space *mapping; /* a: 如果mapping = 0,说明该page属于交换缓存(swap cache);当需要使用地址空间时会指定交换分区的地址空间swapper_space。
b: 如果mapping != 0,bit[0] = 0,说明该page属于页缓存或文件映射,mapping指向文件的地址空间address_space。
c: 如果mapping != 0,bit[0] != 0,说明该page为匿名映射,mapping指向struct anon_vma对象。
通过mapping恢复anon_vma的方法:anon_vma = (struct anon_vma *)(mapping - PAGE_MAPPING_ANON)。
*/
/* Second double word */
struct {
union {
pgoff_t index; /* Our offset within mapping.在映射的虚拟空间(vma_area)内的偏移;一个文件可能只映射一部分,
假设映射了1M的空间,index指的是在1M空间内的偏移,而不是在整个文件内的偏移 */
void *freelist; /* slub first free object */
};
union {
#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
/* Used for cmpxchg_double in slub */
unsigned long counters;
#else
/*
* Keep _count separate from slub cmpxchg_double data.
* As the rest of the double word is protected by
* slab_lock but _count is not.
*/
unsigned counters;
#endif
struct {
union {
/*
被页表映射的次数,也就是说该page同时被多少个进程共享。初始值为-1,如果只被一个进程的页表映射了,该值为0 。
如果该page处于伙伴系统中,该值为PAGE_BUDDY_MAPCOUNT_VALUE(-128),内核通过判断该值是否为PAGE_BUDDY_MAPCOUNT_VALUE
来确定该page是否属于伙伴系统
*/
atomic_t _mapcount;
struct {
unsigned inuse:16;
unsigned objects:15;
unsigned frozen:1;
};
};
atomic_t _count; /* 表示内核中引用该页的次数。当值为0时,表示page当前没有使用者,那么这个page可以被释放,
否则的话表示这个page有使用者。_mapcount表示的是映射次数,而_count表示的是使用次数;
被映射了不一定在使用,但要使用必须先映射
*/
};
};
};
/* Third double word block */
union {
struct list_head lru; /* Pageout list, eg. active_list
* protected by zone->lru_lock !
*/
struct { /* slub per cpu partial pages */
struct page *next; /* Next partial slab */
#ifdef CONFIG_64BIT
int pages; /* Nr of partial slabs left */
int pobjects; /* Approximate # of objects */
#else
short int pages;
short int pobjects;
#endif
};
};
/* Remainder is not double word aligned */
union {
unsigned long private; /* Mapping-private opaque data:
* usually used for buffer_heads
* if PagePrivate set; used for
* swp_entry_t if PageSwapCache;
* indicates order in the buddy
* system if PG_buddy is set.
*/
#if defined(WANT_PAGE_VIRTUAL)
void *virtual; /* Kernel virtual address (NULL if not kmapped, ie. highmem)指向本页框的内核虚拟地址,
virtual只用于高端内存中的页,这是因为高端内存的页,无法简单的通过该页的物理地址计算出线性地址。
当然如果高端内存还没有映射到kernel时,地址为空 */
#endif /* WANT_PAGE_VIRTUAL */
}
8 struct mm_struct
转载
task_struct,叫做进程描述符,而mm_struct 叫做内存描述符,描述linux下进程的地址空间的所有的信息。
一个进程的虚拟地址空间主要由两个数据结构来描述。一个是最高层次的:mm_struct,一个是较高层次的:vm_area_struct。最高层次的mm_struct结构描述了一个进程的整个虚拟地址空间。较高层次的结构vm_area_truct描述了虚拟地址空间的一个区间(简称虚拟区)。每个进程只有一个mm_struct结构,在每个进程的task_struct结构中,有一个指向该进程的结构。下面来看下mm_struct在内核中的位置。
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/719f2c80191a77c954a9ee84a0ce5e96.png)
图8-1 进程的地址空间的分布
mm_struct保存了一个进程代码段(start_code ~ end_code)、DATA段(start_data ~ end_data)、BSS段、堆(start_brk ~ brk)栈(stack_start ~ stack_end)、mmap(mmap_base是维护共享映射区的起始地址) 地址。这些地址通过页表转换可以找到对应的物理地址。task_struct用mm、active_mm变量来指向当前进程的mm_struct结构体。
每一个进程都会有自己独立的mm_struct,这样每一个进程都会有自己独立的地址空间,这样才能互不干扰。当进程之间的地址空间被共享的时候,我们可以理解为这个时候是多个进程使用一份地址空间,这就是线程。
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/e49c3d06c89ff8cab71646b6fe70b1ef.png)
图 8-2 进程虚拟地址空间
多个进程的地址空间分布如 图8-2 一样,每一个进程的用户空间在32位的平台上就是上面这个图的情况,对于物理内存当中的内核kernel,是只存在一份,所有的进程是用来共享的,内核当中会利用PCB(进程控制块)来管理不同的进程。
struct mm_struct {
struct vm_area_struct * mmap; /* list of VMAs, 链表,每个vm_area_struct虚拟内存区间,就是mm_struct的一段 */
struct rb_root mm_rb; /* 红黑树,跟mmap一样用来组织各个段,使用的算法不一样,用红黑树来管理 */
struct vm_area_struct * mmap_cache; /* 用来保存最后使用的 vm_area_struct,如果下次还要使用就不用从链表中找 */
#ifdef CONFIG_MMU
unsigned long (*get_unmapped_area) (struct file *filp,
unsigned long addr, unsigned long len,
unsigned long pgoff, unsigned long flags);
void (*unmap_area) (struct mm_struct *mm, unsigned long addr);
#endif
unsigned long mmap_base; /* base of mmap area, mmap的起始地址*/
unsigned long task_size; /* size of task vm space 当前进程虚拟地址空间大小 */
unsigned long cached_hole_size; /* if non-zero, the largest hole below free_area_cache */
unsigned long free_area_cache; /* first hole of size cached_hole_size or larger */
pgd_t * pgd; /* pgt区间是用来维护页表的目录,每一个进程的都有自己的页表目录,需要注意进程的页目录和内核的页目录
是不一样的,当程序调度器调度程序运行的时候,这个时候这个地址就会转换成为物理地址,linux一般采用
三级页表进行转换。 */
atomic_t mm_users; /* How many users with user space? 进程数量值(在多线程的情况下尤为适用) */
atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) 引用计数 */
int map_count; /* number of VMAs mmap链表中个数 */
spinlock_t page_table_lock; /* Protects page tables and some counters 页表锁 */
struct rw_semaphore mmap_sem;
struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
* together off init_mm.mmlist, and are protected
* by mmlist_lock,通过mmlist将当前mm_struct添加到系统全局的mm_struct链表中
*/
unsigned long hiwater_rss; /* High-watermark of RSS usage */
unsigned long hiwater_vm; /* High-water virtual memory usage */
//进程地址空间的大小,锁住无法换页的个数,共享文件内存映射的页数,可执行内存映射中的页数
unsigned long total_vm; /* Total pages mapped */
unsigned long locked_vm; /* Pages that have PG_mlocked set */
unsigned long pinned_vm; /* Refcount permanently increased */
unsigned long shared_vm; /* Shared pages (files) */
unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE */
//用户态堆栈的页数
unsigned long stack_vm; /* VM_GROWSUP/DOWN */
unsigned long reserved_vm; /* VM_RESERVED|VM_IO pages */
unsigned long def_flags;
unsigned long nr_ptes; /* Page table pages */
//维护代码段和数据段
unsigned long start_code, end_code, start_data, end_data;
//维护堆和栈
unsigned long start_brk, brk, start_stack;
//维护命令行参数,命令行参数的起始地址和最后地址,以及环境变量的起始地址和最后地址
unsigned long arg_start, arg_end, env_start, env_end;
unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
/*
* Special counters, in some configurations protected by the
* page_table_lock, in other configurations by being atomic.
*/
struct mm_rss_stat rss_stat;
struct linux_binfmt *binfmt;
cpumask_var_t cpu_vm_mask_var;
/* Architecture-specific MM context */
mm_context_t context;
/* Swap token stuff */
/*
* Last value of global fault stamp as seen by this process.
* In other words, this value gives an indication of how long
* it has been since this task got the token.
* Look at mm/thrash.c
*/
unsigned int faultstamp;
unsigned int token_priority;
unsigned int last_interval;
unsigned long flags; /* Must use atomic bitops to access the bits */
struct core_state *core_state; /* coredumping support */
#ifdef CONFIG_AIO
spinlock_t ioctx_lock;
struct hlist_head ioctx_list;
#endif
#ifdef CONFIG_MM_OWNER
/*
* "owner" points to a task that is regarded as the canonical
* user/owner of this mm. All of the following must be true in
* order for it to be changed:
*
* current == mm->owner
* current->mm != mm
* new_owner->mm == mm
* new_owner->alloc_lock is held
*/
struct task_struct __rcu *owner;
#endif
/* store ref to file /proc/<pid>/exe symlink points to */
struct file *exe_file;
unsigned long num_exe_file_vmas;
#ifdef CONFIG_MMU_NOTIFIER
struct mmu_notifier_mm *mmu_notifier_mm;
#endif
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
pgtable_t pmd_huge_pte; /* protected by page_table_lock */
#endif
#ifdef CONFIG_CPUMASK_OFFSTACK
struct cpumask cpumask_allocation;
#endif
};
9 struct task_struct
https://blog.csdn.net/peiyao456/article/details/54407343?ref=myread
struct task_struct {
volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped volatile关键字是降低编译器对代码的优化,state变量一直从变量的内存中读取内容而不是寄存器 */
void *stack; //用来维护进程的内核栈
atomic_t usage;
unsigned int flags; /* per process flags, defined below */
unsigned int ptrace;
#ifdef CONFIG_SMP
struct llist_node wake_entry;
int on_cpu;
#endif
int on_rq;
//优先级,用于进程调度
/*
static_prio 用来保存静态优先级,可以调用nice系统直接来修改取值范围为100~139
rt_priority 用来保存实时优先级,取值范围为0~99
prio 用来保存动态优先级
normal_prio 它的值取决于静态优先级和调度策略
*/
int prio, static_prio, normal_prio;
unsigned int rt_priority;
const struct sched_class *sched_class;
struct sched_entity se;
struct sched_rt_entity rt;
#ifdef CONFIG_CGROUP_SCHED
struct task_group *sched_task_group;
#endif
#ifdef CONFIG_PREEMPT_NOTIFIERS
/* list of struct preempt_notifier: */
struct hlist_head preempt_notifiers;
#endif
/*
* fpu_counter contains the number of consecutive context switches
* that the FPU is used. If this is over a threshold, the lazy fpu
* saving becomes unlazy to save the trap. This is an unsigned char
* so that after 256 times the counter wraps and the behavior turns
* lazy again; this to deal with bursty apps that only use FPU for
* a short time
*/
unsigned char fpu_counter;
#ifdef CONFIG_BLK_DEV_IO_TRACE
unsigned int btrace_seq;
#endif
unsigned int policy;
cpumask_t cpus_allowed;
#ifdef CONFIG_PREEMPT_RCU
int rcu_read_lock_nesting;
char rcu_read_unlock_special;
struct list_head rcu_node_entry;
#endif /* #ifdef CONFIG_PREEMPT_RCU */
#ifdef CONFIG_TREE_PREEMPT_RCU
struct rcu_node *rcu_blocked_node;
#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
#ifdef CONFIG_RCU_BOOST
struct rt_mutex *rcu_boost_mutex;
#endif /* #ifdef CONFIG_RCU_BOOST */
#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
struct sched_info sched_info;
#endif
struct list_head tasks;
#ifdef CONFIG_SMP
struct plist_node pushable_tasks;
#endif
//进程地址空间,mm指定mm_struct链表,active_mm指定mm_struct红黑树
struct mm_struct *mm, *active_mm;
#ifdef CONFIG_COMPAT_BRK
unsigned brk_randomized:1;
#endif
#if defined(SPLIT_RSS_COUNTING)
struct task_rss_stat rss_stat;
#endif
/* task state */
int exit_state;
int exit_code, exit_signal;
int pdeath_signal; /* The signal sent when the parent dies */
unsigned int jobctl; /* JOBCTL_*, siglock protected */
/* ??? */
unsigned int personality;
unsigned did_exec:1;
unsigned in_execve:1; /* Tell the LSMs that the process is doing an
* execve */
unsigned in_iowait:1;
/* task may not gain privileges */
unsigned no_new_privs:1;
/* Revert to default priority/policy when forking */
unsigned sched_reset_on_fork:1;
unsigned sched_contributes_to_load:1;
#ifdef CONFIG_GENERIC_HARDIRQS
/* IRQ handler threads */
unsigned irq_thread:1;
#endif
pid_t pid; //进程的标识符
pid_t tgid; //线程组标识符
#ifdef CONFIG_CC_STACKPROTECTOR
/* Canary value for the -fstack-protector gcc feature */
unsigned long stack_canary;
#endif
/* 进程之间的亲属关系
* pointers to (original) parent process, youngest child, younger sibling,
* older sibling, respectively. (p->father can be replaced with
* p->real_parent->pid)
*/
struct task_struct __rcu *real_parent; /* real parent process */
struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
/*
* children/sibling forms the list of my natural children
*/
struct list_head children; /* list of my children */
struct list_head sibling; /* linkage in my parent's children list */
struct task_struct *group_leader; /* threadgroup leader */
/*
* ptraced is the list of tasks this task is using ptrace on.
* This includes both natural children and PTRACE_ATTACH targets.
* p->ptrace_entry is p's link on the p->parent->ptraced list.
*/
struct list_head ptraced;
struct list_head ptrace_entry;
/* PID/PID hash table linkage. */
struct pid_link pids[PIDTYPE_MAX];
struct list_head thread_group;
struct completion *vfork_done; /* for vfork() */
int __user *set_child_tid; /* CLONE_CHILD_SETTID */
int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
cputime_t utime, stime, utimescaled, stimescaled;
cputime_t gtime;
#ifndef CONFIG_VIRT_CPU_ACCOUNTING
cputime_t prev_utime, prev_stime;
#endif
unsigned long nvcsw, nivcsw; /* context switch counts */
struct timespec start_time; /* monotonic time */
struct timespec real_start_time; /* boot based time */
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
unsigned long min_flt, maj_flt;
struct task_cputime cputime_expires;
struct list_head cpu_timers[3];
/* process credentials */
const struct cred __rcu *real_cred; /* objective and real subjective task
* credentials (COW) */
const struct cred __rcu *cred; /* effective (overridable) subjective task
* credentials (COW) */
struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
char comm[TASK_COMM_LEN]; /* executable name excluding path
- access with [gs]et_task_comm (which lock
it with task_lock())
- initialized normally by setup_new_exec */
/* file system info */
int link_count, total_link_count;
#ifdef CONFIG_SYSVIPC
/* ipc stuff */
struct sysv_sem sysvsem;
#endif
#ifdef CONFIG_DETECT_HUNG_TASK
/* hung task detection */
unsigned long last_switch_count;
#endif
/* CPU-specific state of this task */
struct thread_struct thread;
/* filesystem information */
struct fs_struct *fs;
/* open file information */
struct files_struct *files;
/* namespaces */
struct nsproxy *nsproxy;
/* signal handlers */
struct signal_struct *signal;
struct sighand_struct *sighand;
sigset_t blocked, real_blocked;
sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
struct sigpending pending;
unsigned long sas_ss_sp;
size_t sas_ss_size;
int (*notifier)(void *priv);
void *notifier_data;
sigset_t *notifier_mask;
struct audit_context *audit_context;
#ifdef CONFIG_AUDITSYSCALL
uid_t loginuid;
unsigned int sessionid;
#endif
struct seccomp seccomp;
/* Thread group tracking */
u32 parent_exec_id;
u32 self_exec_id;
/* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
* mempolicy */
spinlock_t alloc_lock;
/* Protection of the PI data structures: */
raw_spinlock_t pi_lock;
#ifdef CONFIG_RT_MUTEXES
/* PI waiters blocked on a rt_mutex held by this task */
struct plist_head pi_waiters;
/* Deadlock detection and priority inheritance handling */
struct rt_mutex_waiter *pi_blocked_on;
#endif
#ifdef CONFIG_DEBUG_MUTEXES
/* mutex deadlock detection */
struct mutex_waiter *blocked_on;
#endif
#ifdef CONFIG_TRACE_IRQFLAGS
unsigned int irq_events;
unsigned long hardirq_enable_ip;
unsigned long hardirq_disable_ip;
unsigned int hardirq_enable_event;
unsigned int hardirq_disable_event;
int hardirqs_enabled;
int hardirq_context;
unsigned long softirq_disable_ip;
unsigned long softirq_enable_ip;
unsigned int softirq_disable_event;
unsigned int softirq_enable_event;
int softirqs_enabled;
int softirq_context;
#endif
#ifdef CONFIG_LOCKDEP
# define MAX_LOCK_DEPTH 48UL
u64 curr_chain_key;
int lockdep_depth;
unsigned int lockdep_recursion;
struct held_lock held_locks[MAX_LOCK_DEPTH];
gfp_t lockdep_reclaim_gfp;
#endif
/* journalling filesystem info */
void *journal_info;
/* stacked block device info */
struct bio_list *bio_list;
#ifdef CONFIG_BLOCK
/* stack plugging */
struct blk_plug *plug;
#endif
/* VM state */
struct reclaim_state *reclaim_state;
struct backing_dev_info *backing_dev_info;
struct io_context *io_context;
unsigned long ptrace_message;
siginfo_t *last_siginfo; /* For ptrace use. */
struct task_io_accounting ioac;
#if defined(CONFIG_TASK_XACCT)
u64 acct_rss_mem1; /* accumulated rss usage */
u64 acct_vm_mem1; /* accumulated virtual memory usage */
cputime_t acct_timexpd; /* stime + utime since last update */
#endif
#ifdef CONFIG_CPUSETS
nodemask_t mems_allowed; /* Protected by alloc_lock */
seqcount_t mems_allowed_seq; /* Seqence no to catch updates */
int cpuset_mem_spread_rotor;
int cpuset_slab_spread_rotor;
#endif
#ifdef CONFIG_CGROUPS
/* Control Group info protected by css_set_lock */
struct css_set __rcu *cgroups;
/* cg_list protected by css_set_lock and tsk->alloc_lock */
struct list_head cg_list;
#endif
#ifdef CONFIG_FUTEX
struct robust_list_head __user *robust_list;
#ifdef CONFIG_COMPAT
struct compat_robust_list_head __user *compat_robust_list;
#endif
struct list_head pi_state_list;
struct futex_pi_state *pi_state_cache;
#endif
#ifdef CONFIG_PERF_EVENTS
struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
struct mutex perf_event_mutex;
struct list_head perf_event_list;
#endif
#ifdef CONFIG_NUMA
struct mempolicy *mempolicy; /* Protected by alloc_lock */
short il_next;
short pref_node_fork;
#endif
struct rcu_head rcu;
/*
* cache last used pipe for splice
*/
struct pipe_inode_info *splice_pipe;
#ifdef CONFIG_TASK_DELAY_ACCT
struct task_delay_info *delays;
#endif
#ifdef CONFIG_FAULT_INJECTION
int make_it_fail;
#endif
/*
* when (nr_dirtied >= nr_dirtied_pause), it's time to call
* balance_dirty_pages() for some dirty throttling pause
*/
int nr_dirtied;
int nr_dirtied_pause;
unsigned long dirty_paused_when; /* start of a write-and-pause period */
#ifdef CONFIG_LATENCYTOP
int latency_record_count;
struct latency_record latency_record[LT_SAVECOUNT];
#endif
/*
* time slack values; these are used to round up poll() and
* select() etc timeout values. These are in nanoseconds.
*/
unsigned long timer_slack_ns;
unsigned long default_timer_slack_ns;
struct list_head *scm_work_list;
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
/* Index of current stored address in ret_stack */
int curr_ret_stack;
/* Stack of return addresses for return function tracing */
struct ftrace_ret_stack *ret_stack;
/* time stamp for last schedule */
unsigned long long ftrace_timestamp;
/*
* Number of functions that haven't been traced
* because of depth overrun.
*/
atomic_t trace_overrun;
/* Pause for the tracing */
atomic_t tracing_graph_pause;
#endif
#ifdef CONFIG_TRACING
/* state flags for use by tracers */
unsigned long trace;
/* bitmask and counter of trace recursion */
unsigned long trace_recursion;
#endif /* CONFIG_TRACING */
#ifdef CONFIG_CGROUP_MEM_RES_CTLR /* memcg uses this to do batch job */
struct memcg_batch_info {
int do_batch; /* incremented when batch uncharge started */
struct mem_cgroup *memcg; /* target memcg of uncharge */
unsigned long nr_pages; /* uncharged usage */
unsigned long memsw_nr_pages; /* uncharged mem+swap usage */
} memcg_batch;
#endif
#ifdef CONFIG_HAVE_HW_BREAKPOINT
atomic_t ptrace_bp_refcnt;
#endif
};