netprio_cgroup.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #if IS_ENABLED(CONFIG_NETPRIO_CGROUP)
  19. struct netprio_map {
  20. struct rcu_head rcu;
  21. u32 priomap_len;
  22. u32 priomap[];
  23. };
  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. #endif
  62. #else /* !CONFIG_NETPRIO_CGROUP */
  63. static inline u32 task_netprioidx(struct task_struct *p)
  64. {
  65. return 0;
  66. }
  67. #define sock_update_netprioidx(sk)
  68. #endif /* CONFIG_NETPRIO_CGROUP */
  69. #endif /* _NET_CLS_CGROUP_H */