xref: /openbmc/linux/kernel/sched/autogroup.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2*d90a2f16SIngo Molnar #ifndef _KERNEL_SCHED_AUTOGROUP_H
3*d90a2f16SIngo Molnar #define _KERNEL_SCHED_AUTOGROUP_H
4*d90a2f16SIngo Molnar 
51051408fSIngo Molnar #ifdef CONFIG_SCHED_AUTOGROUP
61051408fSIngo Molnar 
71051408fSIngo Molnar struct autogroup {
81051408fSIngo Molnar 	/*
997fb7a0aSIngo Molnar 	 * Reference doesn't mean how many threads attach to this
1097fb7a0aSIngo Molnar 	 * autogroup now. It just stands for the number of tasks
1197fb7a0aSIngo Molnar 	 * which could use this autogroup.
121051408fSIngo Molnar 	 */
131051408fSIngo Molnar 	struct kref		kref;
141051408fSIngo Molnar 	struct task_group	*tg;
151051408fSIngo Molnar 	struct rw_semaphore	lock;
161051408fSIngo Molnar 	unsigned long		id;
171051408fSIngo Molnar 	int			nice;
181051408fSIngo Molnar };
191051408fSIngo Molnar 
201051408fSIngo Molnar extern void autogroup_init(struct task_struct *init_task);
211051408fSIngo Molnar extern void autogroup_free(struct task_group *tg);
221051408fSIngo Molnar 
task_group_is_autogroup(struct task_group * tg)231051408fSIngo Molnar static inline bool task_group_is_autogroup(struct task_group *tg)
241051408fSIngo Molnar {
251051408fSIngo Molnar 	return !!tg->autogroup;
261051408fSIngo Molnar }
271051408fSIngo Molnar 
281051408fSIngo Molnar extern bool task_wants_autogroup(struct task_struct *p, struct task_group *tg);
291051408fSIngo Molnar 
301051408fSIngo Molnar static inline struct task_group *
autogroup_task_group(struct task_struct * p,struct task_group * tg)311051408fSIngo Molnar autogroup_task_group(struct task_struct *p, struct task_group *tg)
321051408fSIngo Molnar {
33c8eaf6acSZhen Ni 	extern unsigned int sysctl_sched_autogroup_enabled;
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 
autogroup_init(struct task_struct * init_task)461051408fSIngo Molnar static inline void autogroup_init(struct task_struct *init_task) {  }
autogroup_free(struct task_group * tg)471051408fSIngo Molnar static inline void autogroup_free(struct task_group *tg) { }
task_group_is_autogroup(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 *
autogroup_task_group(struct task_struct * p,struct task_group * tg)541051408fSIngo Molnar autogroup_task_group(struct task_struct *p, struct task_group *tg)
551051408fSIngo Molnar {
561051408fSIngo Molnar 	return tg;
571051408fSIngo Molnar }
581051408fSIngo Molnar 
autogroup_path(struct task_group * tg,char * buf,int buflen)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*d90a2f16SIngo Molnar 
66*d90a2f16SIngo Molnar #endif /* _KERNEL_SCHED_AUTOGROUP_H */
67