Advertisement
brightprogrammer

kernel_task_struct.c

Oct 28th, 2021
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.96 KB | None | 0 0
  1.   struct task_struct {
  2.       volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */
  3.       void *stack;
  4.       atomic_t usage;
  5.       unsigned int flags; /* per process flags, defined below */
  6.       unsigned int ptrace;
  7.  
  8.   #ifdef CONFIG_SMP
  9.       struct llist_node wake_entry;
  10.       int on_cpu;
  11.   #endif
  12.       int on_rq;
  13.  
  14.       int prio, static_prio, normal_prio;
  15.       unsigned int rt_priority;
  16.       const struct sched_class *sched_class;
  17.       struct sched_entity se;
  18.       struct sched_rt_entity rt;
  19.   #ifdef CONFIG_CGROUP_SCHED
  20.       struct task_group *sched_task_group;
  21.   #endif
  22.  
  23.   #ifdef CONFIG_PREEMPT_NOTIFIERS
  24.       /* list of struct preempt_notifier: */
  25.       struct hlist_head preempt_notifiers;
  26.   #endif
  27.  
  28.       /*
  29.        * fpu_counter contains the number of consecutive context switches
  30.        * that the FPU is used. If this is over a threshold, the lazy fpu
  31.        * saving becomes unlazy to save the trap. This is an unsigned char
  32.        * so that after 256 times the counter wraps and the behavior turns
  33.        * lazy again; this to deal with bursty apps that only use FPU for
  34.        * a short time
  35.        */
  36.       unsigned char fpu_counter;
  37.   #ifdef CONFIG_BLK_DEV_IO_TRACE
  38.       unsigned int btrace_seq;
  39.   #endif
  40.  
  41.       unsigned int policy;
  42.       int nr_cpus_allowed;
  43.       cpumask_t cpus_allowed;
  44.  
  45.   #ifdef CONFIG_PREEMPT_RCU
  46.       int rcu_read_lock_nesting;
  47.       char rcu_read_unlock_special;
  48.       struct list_head rcu_node_entry;
  49.   #endif /* #ifdef CONFIG_PREEMPT_RCU */
  50.   #ifdef CONFIG_TREE_PREEMPT_RCU
  51.       struct rcu_node *rcu_blocked_node;
  52.   #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
  53.   #ifdef CONFIG_RCU_BOOST
  54.       struct rt_mutex *rcu_boost_mutex;
  55.   #endif /* #ifdef CONFIG_RCU_BOOST */
  56.  
  57.   #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
  58.       struct sched_info sched_info;
  59.   #endif
  60.  
  61.       struct list_head tasks;
  62.   #ifdef CONFIG_SMP
  63.       struct plist_node pushable_tasks;
  64.   #endif
  65.  
  66.       struct mm_struct *mm, *active_mm;
  67.   #ifdef CONFIG_COMPAT_BRK
  68.       unsigned brk_randomized:1;
  69.   #endif
  70.   #if defined(SPLIT_RSS_COUNTING)
  71.       struct task_rss_stat    rss_stat;
  72.   #endif
  73.   /* task state */
  74.       int exit_state;
  75.       int exit_code, exit_signal;
  76.       int pdeath_signal;  /*  The signal sent when the parent dies  */
  77.       unsigned int jobctl;    /* JOBCTL_*, siglock protected */
  78.       /* ??? */
  79.       unsigned int personality;
  80.       unsigned did_exec:1;
  81.       unsigned in_execve:1;   /* Tell the LSMs that the process is doing an
  82.                    * execve */
  83.       unsigned in_iowait:1;
  84.  
  85.       /* task may not gain privileges */
  86.       unsigned no_new_privs:1;
  87.  
  88.       /* Revert to default priority/policy when forking */
  89.       unsigned sched_reset_on_fork:1;
  90.       unsigned sched_contributes_to_load:1;
  91.  
  92.       pid_t pid;
  93.       pid_t tgid;
  94.  
  95.   #ifdef CONFIG_CC_STACKPROTECTOR
  96.       /* Canary value for the -fstack-protector gcc feature */
  97.       unsigned long stack_canary;
  98.   #endif
  99.       /*
  100.        * pointers to (original) parent process, youngest child, younger sibling,
  101.        * older sibling, respectively.  (p->father can be replaced with
  102.        * p->real_parent->pid)
  103.        */
  104.       struct task_struct __rcu *real_parent; /* real parent process */
  105.       struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
  106.       /*
  107.        * children/sibling forms the list of my natural children
  108.        */
  109.       struct list_head children;  /* list of my children */
  110.       struct list_head sibling;   /* linkage in my parent's children list */
  111.       struct task_struct *group_leader;   /* threadgroup leader */
  112.  
  113.       /*
  114.        * ptraced is the list of tasks this task is using ptrace on.
  115.        * This includes both natural children and PTRACE_ATTACH targets.
  116.        * p->ptrace_entry is p's link on the p->parent->ptraced list.
  117.        */
  118.       struct list_head ptraced;
  119.       struct list_head ptrace_entry;
  120.  
  121.       /* PID/PID hash table linkage. */
  122.       struct pid_link pids[PIDTYPE_MAX];
  123.       struct list_head thread_group;
  124.  
  125.       struct completion *vfork_done;      /* for vfork() */
  126.       int __user *set_child_tid;      /* CLONE_CHILD_SETTID */
  127.       int __user *clear_child_tid;        /* CLONE_CHILD_CLEARTID */
  128.  
  129.       cputime_t utime, stime, utimescaled, stimescaled;
  130.       cputime_t gtime;
  131.   #ifndef CONFIG_VIRT_CPU_ACCOUNTING
  132.       cputime_t prev_utime, prev_stime;
  133.   #endif
  134.       unsigned long nvcsw, nivcsw; /* context switch counts */
  135.       struct timespec start_time;         /* monotonic time */
  136.       struct timespec real_start_time;    /* boot based time */
  137.   /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
  138.       unsigned long min_flt, maj_flt;
  139.  
  140.       struct task_cputime cputime_expires;
  141.       struct list_head cpu_timers[3];
  142.  
  143.   /* process credentials */
  144.       const struct cred __rcu *real_cred; /* objective and real subjective task
  145.                        * credentials (COW) */
  146.       const struct cred __rcu *cred;  /* effective (overridable) subjective task
  147.                        * credentials (COW) */
  148.       char comm[TASK_COMM_LEN]; /* executable name excluding path
  149.                        - access with [gs]et_task_comm (which lock
  150.                          it with task_lock())
  151.                        - initialized normally by setup_new_exec */
  152.   /* file system info */
  153.       int link_count, total_link_count;
  154.   #ifdef CONFIG_SYSVIPC
  155.   /* ipc stuff */
  156.       struct sysv_sem sysvsem;
  157.   #endif
  158.   #ifdef CONFIG_DETECT_HUNG_TASK
  159.   /* hung task detection */
  160.       unsigned long last_switch_count;
  161.   #endif
  162.   /* CPU-specific state of this task */
  163.       struct thread_struct thread;
  164.   /* filesystem information */
  165.       struct fs_struct *fs;
  166.   /* open file information */
  167.       struct files_struct *files;
  168.   /* namespaces */
  169.       struct nsproxy *nsproxy;
  170.   /* signal handlers */
  171.       struct signal_struct *signal;
  172.       struct sighand_struct *sighand;
  173.  
  174.       sigset_t blocked, real_blocked;
  175.       sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
  176.       struct sigpending pending;
  177.  
  178.       unsigned long sas_ss_sp;
  179.       size_t sas_ss_size;
  180.       int (*notifier)(void *priv);
  181.       void *notifier_data;
  182.       sigset_t *notifier_mask;
  183.       struct callback_head *task_works;
  184.  
  185.       struct audit_context *audit_context;
  186.   #ifdef CONFIG_AUDITSYSCALL
  187.       kuid_t loginuid;
  188.       unsigned int sessionid;
  189.   #endif
  190.       struct seccomp seccomp;
  191.  
  192.   /* Thread group tracking */
  193.       u32 parent_exec_id;
  194.       u32 self_exec_id;
  195.   /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
  196.    * mempolicy */
  197.       spinlock_t alloc_lock;
  198.  
  199.       /* Protection of the PI data structures: */
  200.       raw_spinlock_t pi_lock;
  201.  
  202.   #ifdef CONFIG_RT_MUTEXES
  203.       /* PI waiters blocked on a rt_mutex held by this task */
  204.       struct plist_head pi_waiters;
  205.       /* Deadlock detection and priority inheritance handling */
  206.       struct rt_mutex_waiter *pi_blocked_on;
  207.   #endif
  208.  
  209.   #ifdef CONFIG_DEBUG_MUTEXES
  210.       /* mutex deadlock detection */
  211.       struct mutex_waiter *blocked_on;
  212.   #endif
  213.   #ifdef CONFIG_TRACE_IRQFLAGS
  214.       unsigned int irq_events;
  215.       unsigned long hardirq_enable_ip;
  216.       unsigned long hardirq_disable_ip;
  217.       unsigned int hardirq_enable_event;
  218.       unsigned int hardirq_disable_event;
  219.       int hardirqs_enabled;
  220.       int hardirq_context;
  221.       unsigned long softirq_disable_ip;
  222.       unsigned long softirq_enable_ip;
  223.       unsigned int softirq_disable_event;
  224.       unsigned int softirq_enable_event;
  225.       int softirqs_enabled;
  226.       int softirq_context;
  227.   #endif
  228.   #ifdef CONFIG_LOCKDEP
  229.   # define MAX_LOCK_DEPTH 48UL
  230.       u64 curr_chain_key;
  231.       int lockdep_depth;
  232.       unsigned int lockdep_recursion;
  233.       struct held_lock held_locks[MAX_LOCK_DEPTH];
  234.       gfp_t lockdep_reclaim_gfp;
  235.   #endif
  236.  
  237.   /* journalling filesystem info */
  238.       void *journal_info;
  239.  
  240.   /* stacked block device info */
  241.       struct bio_list *bio_list;
  242.  
  243.   #ifdef CONFIG_BLOCK
  244.   /* stack plugging */
  245.       struct blk_plug *plug;
  246.   #endif
  247.  
  248.   /* VM state */
  249.       struct reclaim_state *reclaim_state;
  250.  
  251.       struct backing_dev_info *backing_dev_info;
  252.  
  253.       struct io_context *io_context;
  254.  
  255.       unsigned long ptrace_message;
  256.       siginfo_t *last_siginfo; /* For ptrace use.  */
  257.       struct task_io_accounting ioac;
  258.   #if defined(CONFIG_TASK_XACCT)
  259.       u64 acct_rss_mem1;  /* accumulated rss usage */
  260.       u64 acct_vm_mem1;   /* accumulated virtual memory usage */
  261.       cputime_t acct_timexpd; /* stime + utime since last update */
  262.   #endif
  263.   #ifdef CONFIG_CPUSETS
  264.       nodemask_t mems_allowed;    /* Protected by alloc_lock */
  265.       seqcount_t mems_allowed_seq;    /* Seqence no to catch updates */
  266.       int cpuset_mem_spread_rotor;
  267.       int cpuset_slab_spread_rotor;
  268.   #endif
  269.   #ifdef CONFIG_CGROUPS
  270.       /* Control Group info protected by css_set_lock */
  271.       struct css_set __rcu *cgroups;
  272.       /* cg_list protected by css_set_lock and tsk->alloc_lock */
  273.       struct list_head cg_list;
  274.   #endif
  275.   #ifdef CONFIG_FUTEX
  276.       struct robust_list_head __user *robust_list;
  277.   #ifdef CONFIG_COMPAT
  278.       struct compat_robust_list_head __user *compat_robust_list;
  279.   #endif
  280.       struct list_head pi_state_list;
  281.       struct futex_pi_state *pi_state_cache;
  282.   #endif
  283.   #ifdef CONFIG_PERF_EVENTS
  284.       struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
  285.       struct mutex perf_event_mutex;
  286.       struct list_head perf_event_list;
  287.   #endif
  288.   #ifdef CONFIG_NUMA
  289.       struct mempolicy *mempolicy;    /* Protected by alloc_lock */
  290.       short il_next;
  291.       short pref_node_fork;
  292.   #endif
  293.       struct rcu_head rcu;
  294.  
  295.       /*
  296.        * cache last used pipe for splice
  297.        */
  298.       struct pipe_inode_info *splice_pipe;
  299.  
  300.       struct page_frag task_frag;
  301.  
  302.   #ifdef  CONFIG_TASK_DELAY_ACCT
  303.       struct task_delay_info *delays;
  304.   #endif
  305.   #ifdef CONFIG_FAULT_INJECTION
  306.       int make_it_fail;
  307.   #endif
  308.       /*
  309.        * when (nr_dirtied >= nr_dirtied_pause), it's time to call
  310.        * balance_dirty_pages() for some dirty throttling pause
  311.        */
  312.       int nr_dirtied;
  313.       int nr_dirtied_pause;
  314.       unsigned long dirty_paused_when; /* start of a write-and-pause period */
  315.  
  316.   #ifdef CONFIG_LATENCYTOP
  317.       int latency_record_count;
  318.       struct latency_record latency_record[LT_SAVECOUNT];
  319.   #endif
  320.       /*
  321.        * time slack values; these are used to round up poll() and
  322.        * select() etc timeout values. These are in nanoseconds.
  323.        */
  324.       unsigned long timer_slack_ns;
  325.       unsigned long default_timer_slack_ns;
  326.  
  327.   #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  328.       /* Index of current stored address in ret_stack */
  329.       int curr_ret_stack;
  330.       /* Stack of return addresses for return function tracing */
  331.       struct ftrace_ret_stack *ret_stack;
  332.       /* time stamp for last schedule */
  333.       unsigned long long ftrace_timestamp;
  334.       /*
  335.        * Number of functions that haven't been traced
  336.        * because of depth overrun.
  337.        */
  338.       atomic_t trace_overrun;
  339.       /* Pause for the tracing */
  340.       atomic_t tracing_graph_pause;
  341.   #endif
  342.   #ifdef CONFIG_TRACING
  343.       /* state flags for use by tracers */
  344.       unsigned long trace;
  345.       /* bitmask and counter of trace recursion */
  346.       unsigned long trace_recursion;
  347.   #endif /* CONFIG_TRACING */
  348.   #ifdef CONFIG_MEMCG /* memcg uses this to do batch job */
  349.       struct memcg_batch_info {
  350.           int do_batch;   /* incremented when batch uncharge started */
  351.           struct mem_cgroup *memcg; /* target memcg of uncharge */
  352.           unsigned long nr_pages; /* uncharged usage */
  353.           unsigned long memsw_nr_pages; /* uncharged mem+swap usage */
  354.       } memcg_batch;
  355.   #endif
  356.   #ifdef CONFIG_HAVE_HW_BREAKPOINT
  357.       atomic_t ptrace_bp_refcnt;
  358.   #endif
  359.   #ifdef CONFIG_UPROBES
  360.       struct uprobe_task *utask;
  361.   #endif
  362.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement