blob: b202de8824894a0bf436edb89e707f21e39325bb [file] [log] [blame]
Neil Horman5bc14212011-11-22 05:10:51 +00001/*
2 * netprio_cgroup.h Control Group Priority set
3 *
4 *
5 * Authors: Neil Horman <nhorman@tuxdriver.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 */
13
14#ifndef _NETPRIO_CGROUP_H
15#define _NETPRIO_CGROUP_H
Neil Horman5bc14212011-11-22 05:10:51 +000016#include <linux/cgroup.h>
17#include <linux/hardirq.h>
18#include <linux/rcupdate.h>
19
Neil Horman5bc14212011-11-22 05:10:51 +000020
Daniel Wagner51e4e7f2012-09-12 16:12:03 +020021#if IS_ENABLED(CONFIG_NETPRIO_CGROUP)
Neil Horman5bc14212011-11-22 05:10:51 +000022struct netprio_map {
23 struct rcu_head rcu;
24 u32 priomap_len;
25 u32 priomap[];
26};
27
Neil Horman8c215222011-11-23 15:52:58 -050028struct cgroup_netprio_state {
29 struct cgroup_subsys_state css;
30 u32 prioidx;
31};
32
Neil Horman5bc14212011-11-22 05:10:51 +000033#ifndef CONFIG_NETPRIO_CGROUP
34extern int net_prio_subsys_id;
35#endif
36
John Fastabend406a3c62012-07-20 10:39:25 +000037extern void sock_update_netprioidx(struct sock *sk, struct task_struct *task);
Neil Horman5bc14212011-11-22 05:10:51 +000038
Neil Horman2b73bc62012-02-10 05:43:38 +000039#if IS_BUILTIN(CONFIG_NETPRIO_CGROUP)
40
41static inline u32 task_netprioidx(struct task_struct *p)
Neil Horman5bc14212011-11-22 05:10:51 +000042{
Neil Horman2b73bc62012-02-10 05:43:38 +000043 struct cgroup_netprio_state *state;
44 u32 idx;
45
46 rcu_read_lock();
47 state = container_of(task_subsys_state(p, net_prio_subsys_id),
48 struct cgroup_netprio_state, css);
49 idx = state->prioidx;
50 rcu_read_unlock();
51 return idx;
52}
53
54#elif IS_MODULE(CONFIG_NETPRIO_CGROUP)
55
56static inline u32 task_netprioidx(struct task_struct *p)
57{
58 struct cgroup_netprio_state *state;
59 int subsys_id;
60 u32 idx = 0;
61
62 rcu_read_lock();
63 subsys_id = rcu_dereference_index_check(net_prio_subsys_id,
64 rcu_read_lock_held());
65 if (subsys_id >= 0) {
66 state = container_of(task_subsys_state(p, subsys_id),
67 struct cgroup_netprio_state, css);
68 idx = state->prioidx;
69 }
70 rcu_read_unlock();
71 return idx;
Neil Horman5bc14212011-11-22 05:10:51 +000072}
Daniel Wagner51e4e7f2012-09-12 16:12:03 +020073#endif
Neil Horman5bc14212011-11-22 05:10:51 +000074
Daniel Wagner51e4e7f2012-09-12 16:12:03 +020075#else /* !CONFIG_NETPRIO_CGROUP */
Neil Horman5bc14212011-11-22 05:10:51 +000076
Neil Horman2b73bc62012-02-10 05:43:38 +000077static inline u32 task_netprioidx(struct task_struct *p)
78{
79 return 0;
80}
81
John Fastabend406a3c62012-07-20 10:39:25 +000082#define sock_update_netprioidx(sk, task)
Daniel Wagner51e4e7f2012-09-12 16:12:03 +020083
84#endif /* CONFIG_NETPRIO_CGROUP */
Neil Horman5bc14212011-11-22 05:10:51 +000085
86#endif /* _NET_CLS_CGROUP_H */