blob: 90d69f2c5eafd2a1d96d42cbc99b6ec3cc6ea3f5 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Ingo Molnard90a2f12021-11-20 10:39:20 +01002#ifndef _KERNEL_SCHED_AUTOGROUP_H
3#define _KERNEL_SCHED_AUTOGROUP_H
4
Mike Galbraith5091faa2010-11-30 14:18:03 +01005#ifdef CONFIG_SCHED_AUTOGROUP
6
7struct autogroup {
Ingo Molnarc1ad41f2012-12-11 10:23:45 +01008 /*
Ingo Molnar97fb7a02018-03-03 14:01:12 +01009 * Reference doesn't mean how many threads attach to this
10 * autogroup now. It just stands for the number of tasks
11 * which could use this autogroup.
Ingo Molnarc1ad41f2012-12-11 10:23:45 +010012 */
Mike Galbraith5091faa2010-11-30 14:18:03 +010013 struct kref kref;
14 struct task_group *tg;
15 struct rw_semaphore lock;
16 unsigned long id;
17 int nice;
18};
19
Peter Zijlstra029632f2011-10-25 10:00:11 +020020extern void autogroup_init(struct task_struct *init_task);
21extern void autogroup_free(struct task_group *tg);
22
23static inline bool task_group_is_autogroup(struct task_group *tg)
24{
25 return !!tg->autogroup;
26}
27
28extern bool task_wants_autogroup(struct task_struct *p, struct task_group *tg);
29
Mike Galbraith5091faa2010-11-30 14:18:03 +010030static inline struct task_group *
Peter Zijlstra029632f2011-10-25 10:00:11 +020031autogroup_task_group(struct task_struct *p, struct task_group *tg)
32{
Zhen Nic8eaf6a2022-01-28 17:50:25 +080033 extern unsigned int sysctl_sched_autogroup_enabled;
Jason Low316c1608d2015-04-28 13:00:20 -070034 int enabled = READ_ONCE(sysctl_sched_autogroup_enabled);
Ingo Molnarc1ad41f2012-12-11 10:23:45 +010035
36 if (enabled && task_wants_autogroup(p, tg))
Peter Zijlstra029632f2011-10-25 10:00:11 +020037 return p->signal->autogroup->tg;
38
39 return tg;
40}
41
42extern int autogroup_path(struct task_group *tg, char *buf, int buflen);
Mike Galbraith5091faa2010-11-30 14:18:03 +010043
44#else /* !CONFIG_SCHED_AUTOGROUP */
45
46static inline void autogroup_init(struct task_struct *init_task) { }
47static inline void autogroup_free(struct task_group *tg) { }
Mike Galbraithf4493772011-01-13 04:54:50 +010048static inline bool task_group_is_autogroup(struct task_group *tg)
49{
50 return 0;
51}
Mike Galbraith5091faa2010-11-30 14:18:03 +010052
53static inline struct task_group *
54autogroup_task_group(struct task_struct *p, struct task_group *tg)
55{
56 return tg;
57}
58
Mike Galbraith5091faa2010-11-30 14:18:03 +010059static inline int autogroup_path(struct task_group *tg, char *buf, int buflen)
60{
61 return 0;
62}
Mike Galbraith5091faa2010-11-30 14:18:03 +010063
64#endif /* CONFIG_SCHED_AUTOGROUP */
Ingo Molnard90a2f12021-11-20 10:39:20 +010065
66#endif /* _KERNEL_SCHED_AUTOGROUP_H */