1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21051408fSIngo Molnar #ifdef CONFIG_SCHED_AUTOGROUP 31051408fSIngo Molnar 41051408fSIngo Molnar #include <linux/kref.h> 51051408fSIngo Molnar #include <linux/rwsem.h> 64eb5aaa3SIngo Molnar #include <linux/sched/autogroup.h> 71051408fSIngo Molnar 81051408fSIngo Molnar struct autogroup { 91051408fSIngo Molnar /* 10*97fb7a0aSIngo Molnar * Reference doesn't mean how many threads attach to this 11*97fb7a0aSIngo Molnar * autogroup now. It just stands for the number of tasks 12*97fb7a0aSIngo Molnar * which could use this autogroup. 131051408fSIngo Molnar */ 141051408fSIngo Molnar struct kref kref; 151051408fSIngo Molnar struct task_group *tg; 161051408fSIngo Molnar struct rw_semaphore lock; 171051408fSIngo Molnar unsigned long id; 181051408fSIngo Molnar int nice; 191051408fSIngo Molnar }; 201051408fSIngo Molnar 211051408fSIngo Molnar extern void autogroup_init(struct task_struct *init_task); 221051408fSIngo Molnar extern void autogroup_free(struct task_group *tg); 231051408fSIngo Molnar 241051408fSIngo Molnar static inline bool task_group_is_autogroup(struct task_group *tg) 251051408fSIngo Molnar { 261051408fSIngo Molnar return !!tg->autogroup; 271051408fSIngo Molnar } 281051408fSIngo Molnar 291051408fSIngo Molnar extern bool task_wants_autogroup(struct task_struct *p, struct task_group *tg); 301051408fSIngo Molnar 311051408fSIngo Molnar static inline struct task_group * 321051408fSIngo Molnar autogroup_task_group(struct task_struct *p, struct task_group *tg) 331051408fSIngo Molnar { 341051408fSIngo Molnar int enabled = READ_ONCE(sysctl_sched_autogroup_enabled); 351051408fSIngo Molnar 361051408fSIngo Molnar if (enabled && task_wants_autogroup(p, tg)) 371051408fSIngo Molnar return p->signal->autogroup->tg; 381051408fSIngo Molnar 391051408fSIngo Molnar return tg; 401051408fSIngo Molnar } 411051408fSIngo Molnar 421051408fSIngo Molnar extern int autogroup_path(struct task_group *tg, char *buf, int buflen); 431051408fSIngo Molnar 441051408fSIngo Molnar #else /* !CONFIG_SCHED_AUTOGROUP */ 451051408fSIngo Molnar 461051408fSIngo Molnar static inline void autogroup_init(struct task_struct *init_task) { } 471051408fSIngo Molnar static inline void autogroup_free(struct task_group *tg) { } 481051408fSIngo Molnar static inline bool task_group_is_autogroup(struct task_group *tg) 491051408fSIngo Molnar { 501051408fSIngo Molnar return 0; 511051408fSIngo Molnar } 521051408fSIngo Molnar 531051408fSIngo Molnar static inline struct task_group * 541051408fSIngo Molnar autogroup_task_group(struct task_struct *p, struct task_group *tg) 551051408fSIngo Molnar { 561051408fSIngo Molnar return tg; 571051408fSIngo Molnar } 581051408fSIngo Molnar 591051408fSIngo Molnar static inline int autogroup_path(struct task_group *tg, char *buf, int buflen) 601051408fSIngo Molnar { 611051408fSIngo Molnar return 0; 621051408fSIngo Molnar } 631051408fSIngo Molnar 641051408fSIngo Molnar #endif /* CONFIG_SCHED_AUTOGROUP */ 65