Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 2 | #ifdef CONFIG_SCHED_AUTOGROUP |
| 3 | |
| 4 | struct autogroup { |
Ingo Molnar | c1ad41f | 2012-12-11 10:23:45 +0100 | [diff] [blame] | 5 | /* |
Ingo Molnar | 97fb7a0 | 2018-03-03 14:01:12 +0100 | [diff] [blame] | 6 | * 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 Molnar | c1ad41f | 2012-12-11 10:23:45 +0100 | [diff] [blame] | 9 | */ |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 10 | struct kref kref; |
| 11 | struct task_group *tg; |
| 12 | struct rw_semaphore lock; |
| 13 | unsigned long id; |
| 14 | int nice; |
| 15 | }; |
| 16 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 17 | extern void autogroup_init(struct task_struct *init_task); |
| 18 | extern void autogroup_free(struct task_group *tg); |
| 19 | |
| 20 | static inline bool task_group_is_autogroup(struct task_group *tg) |
| 21 | { |
| 22 | return !!tg->autogroup; |
| 23 | } |
| 24 | |
| 25 | extern bool task_wants_autogroup(struct task_struct *p, struct task_group *tg); |
| 26 | |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 27 | static inline struct task_group * |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 28 | autogroup_task_group(struct task_struct *p, struct task_group *tg) |
| 29 | { |
Jason Low | 316c1608d | 2015-04-28 13:00:20 -0700 | [diff] [blame] | 30 | int enabled = READ_ONCE(sysctl_sched_autogroup_enabled); |
Ingo Molnar | c1ad41f | 2012-12-11 10:23:45 +0100 | [diff] [blame] | 31 | |
| 32 | if (enabled && task_wants_autogroup(p, tg)) |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 33 | return p->signal->autogroup->tg; |
| 34 | |
| 35 | return tg; |
| 36 | } |
| 37 | |
| 38 | extern int autogroup_path(struct task_group *tg, char *buf, int buflen); |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 39 | |
| 40 | #else /* !CONFIG_SCHED_AUTOGROUP */ |
| 41 | |
| 42 | static inline void autogroup_init(struct task_struct *init_task) { } |
| 43 | static inline void autogroup_free(struct task_group *tg) { } |
Mike Galbraith | f449377 | 2011-01-13 04:54:50 +0100 | [diff] [blame] | 44 | static inline bool task_group_is_autogroup(struct task_group *tg) |
| 45 | { |
| 46 | return 0; |
| 47 | } |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 48 | |
| 49 | static inline struct task_group * |
| 50 | autogroup_task_group(struct task_struct *p, struct task_group *tg) |
| 51 | { |
| 52 | return tg; |
| 53 | } |
| 54 | |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 55 | static inline int autogroup_path(struct task_group *tg, char *buf, int buflen) |
| 56 | { |
| 57 | return 0; |
| 58 | } |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 59 | |
| 60 | #endif /* CONFIG_SCHED_AUTOGROUP */ |