• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
task_group_is_autogroup(struct task_group * tg)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 *
autogroup_task_group(struct task_struct * p,struct task_group * tg)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 
autogroup_init(struct task_struct * init_task)46 static inline void autogroup_init(struct task_struct *init_task) {  }
autogroup_free(struct task_group * tg)47 static inline void autogroup_free(struct task_group *tg) { }
task_group_is_autogroup(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 *
autogroup_task_group(struct task_struct * p,struct task_group * tg)54 autogroup_task_group(struct task_struct *p, struct task_group *tg)
55 {
56 	return tg;
57 }
58 
autogroup_path(struct task_group * tg,char * buf,int buflen)59 static inline int autogroup_path(struct task_group *tg, char *buf, int buflen)
60 {
61 	return 0;
62 }
63 
64 #endif /* CONFIG_SCHED_AUTOGROUP */
65