blob: b96419974a1f0e88cf3e0a7b203bde1fcff89b2c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Mike Galbraith5091faa2010-11-30 14:18:03 +01002#ifdef CONFIG_SCHED_AUTOGROUP
3
4struct autogroup {
Ingo Molnarc1ad41f2012-12-11 10:23:45 +01005 /*
Ingo Molnar97fb7a02018-03-03 14:01:12 +01006 * Reference doesn't mean how many threads attach to this
7 * autogroup now. It just stands for the number of tasks
8 * which could use this autogroup.
Ingo Molnarc1ad41f2012-12-11 10:23:45 +01009 */
Mike Galbraith5091faa2010-11-30 14:18:03 +010010 struct kref kref;
11 struct task_group *tg;
12 struct rw_semaphore lock;
13 unsigned long id;
14 int nice;
15};
16
Peter Zijlstra029632f2011-10-25 10:00:11 +020017extern void autogroup_init(struct task_struct *init_task);
18extern void autogroup_free(struct task_group *tg);
19
20static inline bool task_group_is_autogroup(struct task_group *tg)
21{
22 return !!tg->autogroup;
23}
24
25extern bool task_wants_autogroup(struct task_struct *p, struct task_group *tg);
26
Mike Galbraith5091faa2010-11-30 14:18:03 +010027static inline struct task_group *
Peter Zijlstra029632f2011-10-25 10:00:11 +020028autogroup_task_group(struct task_struct *p, struct task_group *tg)
29{
Jason Low316c1608d2015-04-28 13:00:20 -070030 int enabled = READ_ONCE(sysctl_sched_autogroup_enabled);
Ingo Molnarc1ad41f2012-12-11 10:23:45 +010031
32 if (enabled && task_wants_autogroup(p, tg))
Peter Zijlstra029632f2011-10-25 10:00:11 +020033 return p->signal->autogroup->tg;
34
35 return tg;
36}
37
38extern int autogroup_path(struct task_group *tg, char *buf, int buflen);
Mike Galbraith5091faa2010-11-30 14:18:03 +010039
40#else /* !CONFIG_SCHED_AUTOGROUP */
41
42static inline void autogroup_init(struct task_struct *init_task) { }
43static inline void autogroup_free(struct task_group *tg) { }
Mike Galbraithf4493772011-01-13 04:54:50 +010044static inline bool task_group_is_autogroup(struct task_group *tg)
45{
46 return 0;
47}
Mike Galbraith5091faa2010-11-30 14:18:03 +010048
49static inline struct task_group *
50autogroup_task_group(struct task_struct *p, struct task_group *tg)
51{
52 return tg;
53}
54
Mike Galbraith5091faa2010-11-30 14:18:03 +010055static inline int autogroup_path(struct task_group *tg, char *buf, int buflen)
56{
57 return 0;
58}
Mike Galbraith5091faa2010-11-30 14:18:03 +010059
60#endif /* CONFIG_SCHED_AUTOGROUP */