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