autogroup.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _KERNEL_SCHED_AUTOGROUP_H
  3. #define _KERNEL_SCHED_AUTOGROUP_H
  4. #ifdef CONFIG_SCHED_AUTOGROUP
  5. struct autogroup {
  6. /*
  7. * Reference doesn't mean how many threads attach to this
  8. * autogroup now. It just stands for the number of tasks
  9. * which could use this autogroup.
  10. */
  11. struct kref kref;
  12. struct task_group *tg;
  13. struct rw_semaphore lock;
  14. unsigned long id;
  15. int nice;
  16. };
  17. extern void autogroup_init(struct task_struct *init_task);
  18. extern void autogroup_free(struct task_group *tg);
  19. static inline bool task_group_is_autogroup(struct task_group *tg)
  20. {
  21. return !!tg->autogroup;
  22. }
  23. extern bool task_wants_autogroup(struct task_struct *p, struct task_group *tg);
  24. static inline struct task_group *
  25. autogroup_task_group(struct task_struct *p, struct task_group *tg)
  26. {
  27. extern unsigned int sysctl_sched_autogroup_enabled;
  28. int enabled = READ_ONCE(sysctl_sched_autogroup_enabled);
  29. if (enabled && task_wants_autogroup(p, tg))
  30. return p->signal->autogroup->tg;
  31. return tg;
  32. }
  33. extern int autogroup_path(struct task_group *tg, char *buf, int buflen);
  34. #else /* !CONFIG_SCHED_AUTOGROUP */
  35. static inline void autogroup_init(struct task_struct *init_task) { }
  36. static inline void autogroup_free(struct task_group *tg) { }
  37. static inline bool task_group_is_autogroup(struct task_group *tg)
  38. {
  39. return 0;
  40. }
  41. static inline struct task_group *
  42. autogroup_task_group(struct task_struct *p, struct task_group *tg)
  43. {
  44. return tg;
  45. }
  46. static inline int autogroup_path(struct task_group *tg, char *buf, int buflen)
  47. {
  48. return 0;
  49. }
  50. #endif /* CONFIG_SCHED_AUTOGROUP */
  51. #endif /* _KERNEL_SCHED_AUTOGROUP_H */