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