blob: 50ab8c26ab59b7ebe840e50d6f696d16f32969b8 [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;
Neil Horman8c215222011-11-23 15:52:58 -050030};
31
Zefan Li6ffd4642013-04-08 20:03:47 +000032extern void sock_update_netprioidx(struct sock *sk);
Neil Horman5bc14212011-11-22 05:10:51 +000033
Neil Horman2b73bc62012-02-10 05:43:38 +000034#if IS_BUILTIN(CONFIG_NETPRIO_CGROUP)
35
36static inline u32 task_netprioidx(struct task_struct *p)
Neil Horman5bc14212011-11-22 05:10:51 +000037{
Tejun Heo88d642f2012-11-22 07:32:47 -080038 struct cgroup_subsys_state *css;
Neil Horman2b73bc62012-02-10 05:43:38 +000039 u32 idx;
40
41 rcu_read_lock();
Tejun Heo88d642f2012-11-22 07:32:47 -080042 css = task_subsys_state(p, net_prio_subsys_id);
43 idx = css->cgroup->id;
Neil Horman2b73bc62012-02-10 05:43:38 +000044 rcu_read_unlock();
45 return idx;
46}
47
48#elif IS_MODULE(CONFIG_NETPRIO_CGROUP)
49
50static inline u32 task_netprioidx(struct task_struct *p)
51{
Daniel Wagner8a8e04d2012-09-12 16:12:07 +020052 struct cgroup_subsys_state *css;
Neil Horman2b73bc62012-02-10 05:43:38 +000053 u32 idx = 0;
54
55 rcu_read_lock();
Daniel Wagner8a8e04d2012-09-12 16:12:07 +020056 css = task_subsys_state(p, net_prio_subsys_id);
57 if (css)
Tejun Heo88d642f2012-11-22 07:32:47 -080058 idx = css->cgroup->id;
Neil Horman2b73bc62012-02-10 05:43:38 +000059 rcu_read_unlock();
60 return idx;
Neil Horman5bc14212011-11-22 05:10:51 +000061}
Daniel Wagner51e4e7f2012-09-12 16:12:03 +020062#endif
Neil Horman5bc14212011-11-22 05:10:51 +000063
Daniel Wagner51e4e7f2012-09-12 16:12:03 +020064#else /* !CONFIG_NETPRIO_CGROUP */
Neil Horman5bc14212011-11-22 05:10:51 +000065
Neil Horman2b73bc62012-02-10 05:43:38 +000066static inline u32 task_netprioidx(struct task_struct *p)
67{
68 return 0;
69}
70
Zefan Li6ffd4642013-04-08 20:03:47 +000071#define sock_update_netprioidx(sk)
Daniel Wagner51e4e7f2012-09-12 16:12:03 +020072
73#endif /* CONFIG_NETPRIO_CGROUP */
Neil Horman5bc14212011-11-22 05:10:51 +000074
75#endif /* _NET_CLS_CGROUP_H */