Neil Horman | 5bc1421 | 2011-11-22 05:10:51 +0000 | [diff] [blame] | 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 |
Neil Horman | 5bc1421 | 2011-11-22 05:10:51 +0000 | [diff] [blame] | 16 | #include <linux/cgroup.h> |
| 17 | #include <linux/hardirq.h> |
| 18 | #include <linux/rcupdate.h> |
| 19 | |
Neil Horman | 5bc1421 | 2011-11-22 05:10:51 +0000 | [diff] [blame] | 20 | |
Daniel Wagner | 51e4e7f | 2012-09-12 16:12:03 +0200 | [diff] [blame] | 21 | #if IS_ENABLED(CONFIG_NETPRIO_CGROUP) |
Neil Horman | 5bc1421 | 2011-11-22 05:10:51 +0000 | [diff] [blame] | 22 | struct netprio_map { |
| 23 | struct rcu_head rcu; |
| 24 | u32 priomap_len; |
| 25 | u32 priomap[]; |
| 26 | }; |
| 27 | |
Neil Horman | 8c21522 | 2011-11-23 15:52:58 -0500 | [diff] [blame] | 28 | struct cgroup_netprio_state { |
| 29 | struct cgroup_subsys_state css; |
Neil Horman | 8c21522 | 2011-11-23 15:52:58 -0500 | [diff] [blame] | 30 | }; |
| 31 | |
John Fastabend | 406a3c6 | 2012-07-20 10:39:25 +0000 | [diff] [blame] | 32 | extern void sock_update_netprioidx(struct sock *sk, struct task_struct *task); |
Neil Horman | 5bc1421 | 2011-11-22 05:10:51 +0000 | [diff] [blame] | 33 | |
Neil Horman | 2b73bc6 | 2012-02-10 05:43:38 +0000 | [diff] [blame] | 34 | #if IS_BUILTIN(CONFIG_NETPRIO_CGROUP) |
| 35 | |
| 36 | static inline u32 task_netprioidx(struct task_struct *p) |
Neil Horman | 5bc1421 | 2011-11-22 05:10:51 +0000 | [diff] [blame] | 37 | { |
Tejun Heo | 88d642f | 2012-11-22 07:32:47 -0800 | [diff] [blame] | 38 | struct cgroup_subsys_state *css; |
Neil Horman | 2b73bc6 | 2012-02-10 05:43:38 +0000 | [diff] [blame] | 39 | u32 idx; |
| 40 | |
| 41 | rcu_read_lock(); |
Tejun Heo | 88d642f | 2012-11-22 07:32:47 -0800 | [diff] [blame] | 42 | css = task_subsys_state(p, net_prio_subsys_id); |
| 43 | idx = css->cgroup->id; |
Neil Horman | 2b73bc6 | 2012-02-10 05:43:38 +0000 | [diff] [blame] | 44 | rcu_read_unlock(); |
| 45 | return idx; |
| 46 | } |
| 47 | |
| 48 | #elif IS_MODULE(CONFIG_NETPRIO_CGROUP) |
| 49 | |
| 50 | static inline u32 task_netprioidx(struct task_struct *p) |
| 51 | { |
Daniel Wagner | 8a8e04d | 2012-09-12 16:12:07 +0200 | [diff] [blame] | 52 | struct cgroup_subsys_state *css; |
Neil Horman | 2b73bc6 | 2012-02-10 05:43:38 +0000 | [diff] [blame] | 53 | u32 idx = 0; |
| 54 | |
| 55 | rcu_read_lock(); |
Daniel Wagner | 8a8e04d | 2012-09-12 16:12:07 +0200 | [diff] [blame] | 56 | css = task_subsys_state(p, net_prio_subsys_id); |
| 57 | if (css) |
Tejun Heo | 88d642f | 2012-11-22 07:32:47 -0800 | [diff] [blame] | 58 | idx = css->cgroup->id; |
Neil Horman | 2b73bc6 | 2012-02-10 05:43:38 +0000 | [diff] [blame] | 59 | rcu_read_unlock(); |
| 60 | return idx; |
Neil Horman | 5bc1421 | 2011-11-22 05:10:51 +0000 | [diff] [blame] | 61 | } |
Daniel Wagner | 51e4e7f | 2012-09-12 16:12:03 +0200 | [diff] [blame] | 62 | #endif |
Neil Horman | 5bc1421 | 2011-11-22 05:10:51 +0000 | [diff] [blame] | 63 | |
Daniel Wagner | 51e4e7f | 2012-09-12 16:12:03 +0200 | [diff] [blame] | 64 | #else /* !CONFIG_NETPRIO_CGROUP */ |
Neil Horman | 5bc1421 | 2011-11-22 05:10:51 +0000 | [diff] [blame] | 65 | |
Neil Horman | 2b73bc6 | 2012-02-10 05:43:38 +0000 | [diff] [blame] | 66 | static inline u32 task_netprioidx(struct task_struct *p) |
| 67 | { |
| 68 | return 0; |
| 69 | } |
| 70 | |
John Fastabend | 406a3c6 | 2012-07-20 10:39:25 +0000 | [diff] [blame] | 71 | #define sock_update_netprioidx(sk, task) |
Daniel Wagner | 51e4e7f | 2012-09-12 16:12:03 +0200 | [diff] [blame] | 72 | |
| 73 | #endif /* CONFIG_NETPRIO_CGROUP */ |
Neil Horman | 5bc1421 | 2011-11-22 05:10:51 +0000 | [diff] [blame] | 74 | |
| 75 | #endif /* _NET_CLS_CGROUP_H */ |