autogroup.h 1.4 KB

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