task.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #ifndef _LINUX_SCHED_TASK_H
  2. #define _LINUX_SCHED_TASK_H
  3. /*
  4. * Interface between the scheduler and various task lifetime (fork()/exit())
  5. * functionality:
  6. */
  7. #include <linux/sched.h>
  8. struct task_struct;
  9. struct rusage;
  10. union thread_union;
  11. /*
  12. * This serializes "schedule()" and also protects
  13. * the run-queue from deletions/modifications (but
  14. * _adding_ to the beginning of the run-queue has
  15. * a separate lock).
  16. */
  17. extern rwlock_t tasklist_lock;
  18. extern spinlock_t mmlist_lock;
  19. extern union thread_union init_thread_union;
  20. extern struct task_struct init_task;
  21. #ifdef CONFIG_PROVE_RCU
  22. extern int lockdep_tasklist_lock_is_held(void);
  23. #endif /* #ifdef CONFIG_PROVE_RCU */
  24. extern asmlinkage void schedule_tail(struct task_struct *prev);
  25. extern void init_idle(struct task_struct *idle, int cpu);
  26. extern int sched_fork(unsigned long clone_flags, struct task_struct *p);
  27. extern void sched_dead(struct task_struct *p);
  28. void __noreturn do_task_dead(void);
  29. extern void proc_caches_init(void);
  30. extern void release_task(struct task_struct * p);
  31. #ifdef CONFIG_HAVE_COPY_THREAD_TLS
  32. extern int copy_thread_tls(unsigned long, unsigned long, unsigned long,
  33. struct task_struct *, unsigned long);
  34. #else
  35. extern int copy_thread(unsigned long, unsigned long, unsigned long,
  36. struct task_struct *);
  37. /* Architectures that haven't opted into copy_thread_tls get the tls argument
  38. * via pt_regs, so ignore the tls argument passed via C. */
  39. static inline int copy_thread_tls(
  40. unsigned long clone_flags, unsigned long sp, unsigned long arg,
  41. struct task_struct *p, unsigned long tls)
  42. {
  43. return copy_thread(clone_flags, sp, arg, p);
  44. }
  45. #endif
  46. extern void flush_thread(void);
  47. #ifdef CONFIG_HAVE_EXIT_THREAD
  48. extern void exit_thread(struct task_struct *tsk);
  49. #else
  50. static inline void exit_thread(struct task_struct *tsk)
  51. {
  52. }
  53. #endif
  54. extern void do_group_exit(int);
  55. extern void exit_files(struct task_struct *);
  56. extern void exit_itimers(struct signal_struct *);
  57. extern long _do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *, unsigned long);
  58. extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *);
  59. struct task_struct *fork_idle(int);
  60. extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
  61. extern long kernel_wait4(pid_t, int *, int, struct rusage *);
  62. extern void free_task(struct task_struct *tsk);
  63. /* sched_exec is called by processes performing an exec */
  64. #ifdef CONFIG_SMP
  65. extern void sched_exec(void);
  66. #else
  67. #define sched_exec() {}
  68. #endif
  69. #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
  70. extern void __put_task_struct(struct task_struct *t);
  71. static inline void put_task_struct(struct task_struct *t)
  72. {
  73. if (atomic_dec_and_test(&t->usage))
  74. __put_task_struct(t);
  75. }
  76. struct task_struct *task_rcu_dereference(struct task_struct **ptask);
  77. #ifdef CONFIG_ARCH_WANTS_DYNAMIC_TASK_STRUCT
  78. extern int arch_task_struct_size __read_mostly;
  79. #else
  80. # define arch_task_struct_size (sizeof(struct task_struct))
  81. #endif
  82. #ifdef CONFIG_VMAP_STACK
  83. static inline struct vm_struct *task_stack_vm_area(const struct task_struct *t)
  84. {
  85. return t->stack_vm_area;
  86. }
  87. #else
  88. static inline struct vm_struct *task_stack_vm_area(const struct task_struct *t)
  89. {
  90. return NULL;
  91. }
  92. #endif
  93. /*
  94. * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
  95. * subscriptions and synchronises with wait4(). Also used in procfs. Also
  96. * pins the final release of task.io_context. Also protects ->cpuset and
  97. * ->cgroup.subsys[]. And ->vfork_done.
  98. *
  99. * Nests both inside and outside of read_lock(&tasklist_lock).
  100. * It must not be nested with write_lock_irq(&tasklist_lock),
  101. * neither inside nor outside.
  102. */
  103. static inline void task_lock(struct task_struct *p)
  104. {
  105. spin_lock(&p->alloc_lock);
  106. }
  107. static inline void task_unlock(struct task_struct *p)
  108. {
  109. spin_unlock(&p->alloc_lock);
  110. }
  111. #endif /* _LINUX_SCHED_TASK_H */