task.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 void init_idle_bootup_task(struct task_struct *idle);
  27. extern int sched_fork(unsigned long clone_flags, struct task_struct *p);
  28. extern void sched_dead(struct task_struct *p);
  29. void __noreturn do_task_dead(void);
  30. extern void proc_caches_init(void);
  31. extern void release_task(struct task_struct * p);
  32. #ifdef CONFIG_HAVE_COPY_THREAD_TLS
  33. extern int copy_thread_tls(unsigned long, unsigned long, unsigned long,
  34. struct task_struct *, unsigned long);
  35. #else
  36. extern int copy_thread(unsigned long, unsigned long, unsigned long,
  37. struct task_struct *);
  38. /* Architectures that haven't opted into copy_thread_tls get the tls argument
  39. * via pt_regs, so ignore the tls argument passed via C. */
  40. static inline int copy_thread_tls(
  41. unsigned long clone_flags, unsigned long sp, unsigned long arg,
  42. struct task_struct *p, unsigned long tls)
  43. {
  44. return copy_thread(clone_flags, sp, arg, p);
  45. }
  46. #endif
  47. extern void flush_thread(void);
  48. #ifdef CONFIG_HAVE_EXIT_THREAD
  49. extern void exit_thread(struct task_struct *tsk);
  50. #else
  51. static inline void exit_thread(struct task_struct *tsk)
  52. {
  53. }
  54. #endif
  55. extern void do_group_exit(int);
  56. extern void exit_files(struct task_struct *);
  57. extern void exit_itimers(struct signal_struct *);
  58. extern long _do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *, unsigned long);
  59. extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *);
  60. struct task_struct *fork_idle(int);
  61. extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
  62. extern long kernel_wait4(pid_t, int *, int, struct rusage *);
  63. extern void free_task(struct task_struct *tsk);
  64. /* sched_exec is called by processes performing an exec */
  65. #ifdef CONFIG_SMP
  66. extern void sched_exec(void);
  67. #else
  68. #define sched_exec() {}
  69. #endif
  70. #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
  71. extern void __put_task_struct(struct task_struct *t);
  72. static inline void put_task_struct(struct task_struct *t)
  73. {
  74. if (atomic_dec_and_test(&t->usage))
  75. __put_task_struct(t);
  76. }
  77. struct task_struct *task_rcu_dereference(struct task_struct **ptask);
  78. struct task_struct *try_get_task_struct(struct task_struct **ptask);
  79. #ifdef CONFIG_ARCH_WANTS_DYNAMIC_TASK_STRUCT
  80. extern int arch_task_struct_size __read_mostly;
  81. #else
  82. # define arch_task_struct_size (sizeof(struct task_struct))
  83. #endif
  84. #ifdef CONFIG_VMAP_STACK
  85. static inline struct vm_struct *task_stack_vm_area(const struct task_struct *t)
  86. {
  87. return t->stack_vm_area;
  88. }
  89. #else
  90. static inline struct vm_struct *task_stack_vm_area(const struct task_struct *t)
  91. {
  92. return NULL;
  93. }
  94. #endif
  95. /*
  96. * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
  97. * subscriptions and synchronises with wait4(). Also used in procfs. Also
  98. * pins the final release of task.io_context. Also protects ->cpuset and
  99. * ->cgroup.subsys[]. And ->vfork_done.
  100. *
  101. * Nests both inside and outside of read_lock(&tasklist_lock).
  102. * It must not be nested with write_lock_irq(&tasklist_lock),
  103. * neither inside nor outside.
  104. */
  105. static inline void task_lock(struct task_struct *p)
  106. {
  107. spin_lock(&p->alloc_lock);
  108. }
  109. static inline void task_unlock(struct task_struct *p)
  110. {
  111. spin_unlock(&p->alloc_lock);
  112. }
  113. #endif /* _LINUX_SCHED_TASK_H */