blob: ce40c810cd5c346c82e61ea40c0b817c1251c02a [file] [log] [blame]
Mike Galbraith5091faa2010-11-30 14:18:03 +01001#ifdef CONFIG_SCHED_AUTOGROUP
2
Peter Zijlstra029632f2011-10-25 10:00:11 +02003#include <linux/kref.h>
4#include <linux/rwsem.h>
Ingo Molnar4eb5aaa2017-02-08 18:51:29 +01005#include <linux/sched/autogroup.h>
Peter Zijlstra029632f2011-10-25 10:00:11 +02006
Mike Galbraith5091faa2010-11-30 14:18:03 +01007struct autogroup {
Ingo Molnarc1ad41f2012-12-11 10:23:45 +01008 /*
9 * reference doesn't mean how many thread attach to this
10 * autogroup now. It just stands for the number of task
11 * could use this autogroup.
12 */
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{
Jason Low316c1608d2015-04-28 13:00:20 -070033 int enabled = READ_ONCE(sysctl_sched_autogroup_enabled);
Ingo Molnarc1ad41f2012-12-11 10:23:45 +010034
35 if (enabled && task_wants_autogroup(p, tg))
Peter Zijlstra029632f2011-10-25 10:00:11 +020036 return p->signal->autogroup->tg;
37
38 return tg;
39}
40
41extern int autogroup_path(struct task_group *tg, char *buf, int buflen);
Mike Galbraith5091faa2010-11-30 14:18:03 +010042
43#else /* !CONFIG_SCHED_AUTOGROUP */
44
45static inline void autogroup_init(struct task_struct *init_task) { }
46static inline void autogroup_free(struct task_group *tg) { }
Mike Galbraithf4493772011-01-13 04:54:50 +010047static inline bool task_group_is_autogroup(struct task_group *tg)
48{
49 return 0;
50}
Mike Galbraith5091faa2010-11-30 14:18:03 +010051
52static inline struct task_group *
53autogroup_task_group(struct task_struct *p, struct task_group *tg)
54{
55 return tg;
56}
57
58#ifdef CONFIG_SCHED_DEBUG
59static inline int autogroup_path(struct task_group *tg, char *buf, int buflen)
60{
61 return 0;
62}
63#endif
64
65#endif /* CONFIG_SCHED_AUTOGROUP */