netprio_cgroup.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #ifndef _NETPRIO_CGROUP_H
  14. #define _NETPRIO_CGROUP_H
  15. #include <linux/cgroup.h>
  16. #include <linux/hardirq.h>
  17. #include <linux/rcupdate.h>
  18. struct netprio_map {
  19. struct rcu_head rcu;
  20. u32 priomap_len;
  21. u32 priomap[];
  22. };
  23. #ifdef CONFIG_CGROUPS
  24. struct cgroup_netprio_state {
  25. struct cgroup_subsys_state css;
  26. u32 prioidx;
  27. };
  28. #ifndef CONFIG_NETPRIO_CGROUP
  29. extern int net_prio_subsys_id;
  30. #endif
  31. extern void sock_update_netprioidx(struct sock *sk);
  32. #if IS_BUILTIN(CONFIG_NETPRIO_CGROUP)
  33. static inline u32 task_netprioidx(struct task_struct *p)
  34. {
  35. struct cgroup_netprio_state *state;
  36. u32 idx;
  37. rcu_read_lock();
  38. state = container_of(task_subsys_state(p, net_prio_subsys_id),
  39. struct cgroup_netprio_state, css);
  40. idx = state->prioidx;
  41. rcu_read_unlock();
  42. return idx;
  43. }
  44. #elif IS_MODULE(CONFIG_NETPRIO_CGROUP)
  45. static inline u32 task_netprioidx(struct task_struct *p)
  46. {
  47. struct cgroup_netprio_state *state;
  48. int subsys_id;
  49. u32 idx = 0;
  50. rcu_read_lock();
  51. subsys_id = rcu_dereference_index_check(net_prio_subsys_id,
  52. rcu_read_lock_held());
  53. if (subsys_id >= 0) {
  54. state = container_of(task_subsys_state(p, subsys_id),
  55. struct cgroup_netprio_state, css);
  56. idx = state->prioidx;
  57. }
  58. rcu_read_unlock();
  59. return idx;
  60. }
  61. #else
  62. static inline u32 task_netprioidx(struct task_struct *p)
  63. {
  64. return 0;
  65. }
  66. #endif /* CONFIG_NETPRIO_CGROUP */
  67. #else
  68. #define sock_update_netprioidx(sk)
  69. #endif
  70. #endif /* _NET_CLS_CGROUP_H */