Commit | Line | Data |
---|---|---|
5bc1421e NH |
1 | /* |
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 | |
5bc1421e NH |
16 | #include <linux/cgroup.h> |
17 | #include <linux/hardirq.h> | |
18 | #include <linux/rcupdate.h> | |
19 | ||
5bc1421e | 20 | |
51e4e7fa | 21 | #if IS_ENABLED(CONFIG_NETPRIO_CGROUP) |
5bc1421e NH |
22 | struct netprio_map { |
23 | struct rcu_head rcu; | |
24 | u32 priomap_len; | |
25 | u32 priomap[]; | |
26 | }; | |
27 | ||
8c215228 NH |
28 | struct cgroup_netprio_state { |
29 | struct cgroup_subsys_state css; | |
30 | u32 prioidx; | |
31 | }; | |
32 | ||
406a3c63 | 33 | extern void sock_update_netprioidx(struct sock *sk, struct task_struct *task); |
5bc1421e | 34 | |
2b73bc65 NH |
35 | #if IS_BUILTIN(CONFIG_NETPRIO_CGROUP) |
36 | ||
37 | static inline u32 task_netprioidx(struct task_struct *p) | |
5bc1421e | 38 | { |
2b73bc65 NH |
39 | struct cgroup_netprio_state *state; |
40 | u32 idx; | |
41 | ||
42 | rcu_read_lock(); | |
43 | state = container_of(task_subsys_state(p, net_prio_subsys_id), | |
44 | struct cgroup_netprio_state, css); | |
45 | idx = state->prioidx; | |
46 | rcu_read_unlock(); | |
47 | return idx; | |
48 | } | |
49 | ||
50 | #elif IS_MODULE(CONFIG_NETPRIO_CGROUP) | |
51 | ||
52 | static inline u32 task_netprioidx(struct task_struct *p) | |
53 | { | |
8a8e04df | 54 | struct cgroup_subsys_state *css; |
2b73bc65 NH |
55 | u32 idx = 0; |
56 | ||
57 | rcu_read_lock(); | |
8a8e04df DW |
58 | css = task_subsys_state(p, net_prio_subsys_id); |
59 | if (css) | |
60 | idx = container_of(css, | |
61 | struct cgroup_netprio_state, css)->prioidx; | |
2b73bc65 NH |
62 | rcu_read_unlock(); |
63 | return idx; | |
5bc1421e | 64 | } |
51e4e7fa | 65 | #endif |
5bc1421e | 66 | |
51e4e7fa | 67 | #else /* !CONFIG_NETPRIO_CGROUP */ |
5bc1421e | 68 | |
2b73bc65 NH |
69 | static inline u32 task_netprioidx(struct task_struct *p) |
70 | { | |
71 | return 0; | |
72 | } | |
73 | ||
406a3c63 | 74 | #define sock_update_netprioidx(sk, task) |
51e4e7fa DW |
75 | |
76 | #endif /* CONFIG_NETPRIO_CGROUP */ | |
5bc1421e NH |
77 | |
78 | #endif /* _NET_CLS_CGROUP_H */ |