autogroup.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifdef CONFIG_SCHED_AUTOGROUP
  3. #include <linux/kref.h>
  4. #include <linux/rwsem.h>
  5. #include <linux/sched/autogroup.h>
  6. struct autogroup {
  7. /*
  8. * reference doesn't mean how many thread attach to this
  9. * autogroup now. It just stands for the number of task
  10. * could use this autogroup.
  11. */
  12. struct kref kref;
  13. struct task_group *tg;
  14. struct rw_semaphore lock;
  15. unsigned long id;
  16. int nice;
  17. };
  18. extern void autogroup_init(struct task_struct *init_task);
  19. extern void autogroup_free(struct task_group *tg);
  20. static inline bool task_group_is_autogroup(struct task_group *tg)
  21. {
  22. return !!tg->autogroup;
  23. }
  24. extern bool task_wants_autogroup(struct task_struct *p, struct task_group *tg);
  25. static inline struct task_group *
  26. autogroup_task_group(struct task_struct *p, struct task_group *tg)
  27. {
  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 */