auto_group.h 1.5 KB

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