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