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