Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 1 | #ifdef CONFIG_SCHED_AUTOGROUP |
| 2 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 3 | #include <linux/kref.h> |
| 4 | #include <linux/rwsem.h> |
| 5 | |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 6 | struct autogroup { |
Yong Zhang | 800d4d3 | 2011-02-20 15:08:14 +0800 | [diff] [blame] | 7 | /* |
| 8 | * reference doesn't mean how many thread attach to this |
| 9 | * autogroup now. It just stands for the number of task |
| 10 | * could use this autogroup. |
| 11 | */ |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 12 | struct kref kref; |
| 13 | struct task_group *tg; |
| 14 | struct rw_semaphore lock; |
| 15 | unsigned long id; |
| 16 | int nice; |
| 17 | }; |
| 18 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 19 | extern void autogroup_init(struct task_struct *init_task); |
| 20 | extern void autogroup_free(struct task_group *tg); |
| 21 | |
| 22 | static inline bool task_group_is_autogroup(struct task_group *tg) |
| 23 | { |
| 24 | return !!tg->autogroup; |
| 25 | } |
| 26 | |
| 27 | extern bool task_wants_autogroup(struct task_struct *p, struct task_group *tg); |
| 28 | |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 29 | static inline struct task_group * |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 30 | autogroup_task_group(struct task_struct *p, struct task_group *tg) |
| 31 | { |
| 32 | int enabled = ACCESS_ONCE(sysctl_sched_autogroup_enabled); |
| 33 | |
| 34 | if (enabled && task_wants_autogroup(p, tg)) |
| 35 | return p->signal->autogroup->tg; |
| 36 | |
| 37 | return tg; |
| 38 | } |
| 39 | |
| 40 | extern int autogroup_path(struct task_group *tg, char *buf, int buflen); |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 41 | |
| 42 | #else /* !CONFIG_SCHED_AUTOGROUP */ |
| 43 | |
| 44 | static inline void autogroup_init(struct task_struct *init_task) { } |
| 45 | static inline void autogroup_free(struct task_group *tg) { } |
Mike Galbraith | f449377 | 2011-01-13 04:54:50 +0100 | [diff] [blame] | 46 | static inline bool task_group_is_autogroup(struct task_group *tg) |
| 47 | { |
| 48 | return 0; |
| 49 | } |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 50 | |
| 51 | static inline struct task_group * |
| 52 | autogroup_task_group(struct task_struct *p, struct task_group *tg) |
| 53 | { |
| 54 | return tg; |
| 55 | } |
| 56 | |
| 57 | #ifdef CONFIG_SCHED_DEBUG |
| 58 | static inline int autogroup_path(struct task_group *tg, char *buf, int buflen) |
| 59 | { |
| 60 | return 0; |
| 61 | } |
| 62 | #endif |
| 63 | |
| 64 | #endif /* CONFIG_SCHED_AUTOGROUP */ |