blob: dafc09f0fdbc86f8b87180cbee2e733694b89085 [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
Daniel Borkmann86f85152013-12-29 17:27:11 +010016
Neil Horman5bc14212011-11-22 05:10:51 +000017#include <linux/cgroup.h>
18#include <linux/hardirq.h>
19#include <linux/rcupdate.h>
20
Daniel Borkmann86f85152013-12-29 17:27:11 +010021#if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
Neil Horman5bc14212011-11-22 05:10:51 +000022struct netprio_map {
23 struct rcu_head rcu;
24 u32 priomap_len;
25 u32 priomap[];
26};
27
Joe Perches37830722013-07-31 17:31:39 -070028void sock_update_netprioidx(struct sock *sk);
Neil Horman5bc14212011-11-22 05:10:51 +000029
Daniel Borkmann86f85152013-12-29 17:27:11 +010030#if IS_BUILTIN(CONFIG_CGROUP_NET_PRIO)
Neil Horman2b73bc62012-02-10 05:43:38 +000031static inline u32 task_netprioidx(struct task_struct *p)
Neil Horman5bc14212011-11-22 05:10:51 +000032{
Tejun Heo88d642f2012-11-22 07:32:47 -080033 struct cgroup_subsys_state *css;
Neil Horman2b73bc62012-02-10 05:43:38 +000034 u32 idx;
35
36 rcu_read_lock();
Tejun Heo8af01f52013-08-08 20:11:22 -040037 css = task_css(p, net_prio_subsys_id);
Tejun Heo88d642f2012-11-22 07:32:47 -080038 idx = css->cgroup->id;
Neil Horman2b73bc62012-02-10 05:43:38 +000039 rcu_read_unlock();
40 return idx;
41}
Daniel Borkmann86f85152013-12-29 17:27:11 +010042#elif IS_MODULE(CONFIG_CGROUP_NET_PRIO)
Neil Horman2b73bc62012-02-10 05:43:38 +000043static inline u32 task_netprioidx(struct task_struct *p)
44{
Daniel Wagner8a8e04d2012-09-12 16:12:07 +020045 struct cgroup_subsys_state *css;
Neil Horman2b73bc62012-02-10 05:43:38 +000046 u32 idx = 0;
47
48 rcu_read_lock();
Tejun Heo8af01f52013-08-08 20:11:22 -040049 css = task_css(p, net_prio_subsys_id);
Daniel Wagner8a8e04d2012-09-12 16:12:07 +020050 if (css)
Tejun Heo88d642f2012-11-22 07:32:47 -080051 idx = css->cgroup->id;
Neil Horman2b73bc62012-02-10 05:43:38 +000052 rcu_read_unlock();
53 return idx;
Neil Horman5bc14212011-11-22 05:10:51 +000054}
Daniel Wagner51e4e7f2012-09-12 16:12:03 +020055#endif
Daniel Borkmann86f85152013-12-29 17:27:11 +010056#else /* !CONFIG_CGROUP_NET_PRIO */
Neil Horman2b73bc62012-02-10 05:43:38 +000057static inline u32 task_netprioidx(struct task_struct *p)
58{
59 return 0;
60}
61
Zefan Li6ffd4642013-04-08 20:03:47 +000062#define sock_update_netprioidx(sk)
Daniel Wagner51e4e7f2012-09-12 16:12:03 +020063
Daniel Borkmann86f85152013-12-29 17:27:11 +010064#endif /* CONFIG_CGROUP_NET_PRIO */
Neil Horman5bc14212011-11-22 05:10:51 +000065#endif /* _NET_CLS_CGROUP_H */