]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
5091faa4 MG |
2 | #ifdef CONFIG_SCHED_AUTOGROUP |
3 | ||
029632fb PZ |
4 | #include <linux/kref.h> |
5 | #include <linux/rwsem.h> | |
4eb5aaa3 | 6 | #include <linux/sched/autogroup.h> |
029632fb | 7 | |
5091faa4 | 8 | struct autogroup { |
c1ad41f1 IM |
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 | */ | |
5091faa4 MG |
14 | struct kref kref; |
15 | struct task_group *tg; | |
16 | struct rw_semaphore lock; | |
17 | unsigned long id; | |
18 | int nice; | |
19 | }; | |
20 | ||
029632fb PZ |
21 | extern void autogroup_init(struct task_struct *init_task); |
22 | extern void autogroup_free(struct task_group *tg); | |
23 | ||
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 | ||
5091faa4 | 31 | static inline struct task_group * |
029632fb PZ |
32 | autogroup_task_group(struct task_struct *p, struct task_group *tg) |
33 | { | |
316c1608 | 34 | int enabled = READ_ONCE(sysctl_sched_autogroup_enabled); |
c1ad41f1 IM |
35 | |
36 | if (enabled && task_wants_autogroup(p, tg)) | |
029632fb PZ |
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); | |
5091faa4 MG |
43 | |
44 | #else /* !CONFIG_SCHED_AUTOGROUP */ | |
45 | ||
46 | static inline void autogroup_init(struct task_struct *init_task) { } | |
47 | static inline void autogroup_free(struct task_group *tg) { } | |
f4493771 MG |
48 | static inline bool task_group_is_autogroup(struct task_group *tg) |
49 | { | |
50 | return 0; | |
51 | } | |
5091faa4 MG |
52 | |
53 | static inline struct task_group * | |
54 | autogroup_task_group(struct task_struct *p, struct task_group *tg) | |
55 | { | |
56 | return tg; | |
57 | } | |
58 | ||
59 | #ifdef CONFIG_SCHED_DEBUG | |
60 | static inline int autogroup_path(struct task_group *tg, char *buf, int buflen) | |
61 | { | |
62 | return 0; | |
63 | } | |
64 | #endif | |
65 | ||
66 | #endif /* CONFIG_SCHED_AUTOGROUP */ |