netprio_cgroup.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. extern void sock_update_netprioidx(struct sock *sk, struct task_struct *task);
  29. #if IS_BUILTIN(CONFIG_NETPRIO_CGROUP)
  30. static inline u32 task_netprioidx(struct task_struct *p)
  31. {
  32. struct cgroup_netprio_state *state;
  33. u32 idx;
  34. rcu_read_lock();
  35. state = container_of(task_subsys_state(p, net_prio_subsys_id),
  36. struct cgroup_netprio_state, css);
  37. idx = state->prioidx;
  38. rcu_read_unlock();
  39. return idx;
  40. }
  41. #elif IS_MODULE(CONFIG_NETPRIO_CGROUP)
  42. static inline u32 task_netprioidx(struct task_struct *p)
  43. {
  44. struct cgroup_subsys_state *css;
  45. u32 idx = 0;
  46. rcu_read_lock();
  47. css = task_subsys_state(p, net_prio_subsys_id);
  48. if (css)
  49. idx = container_of(css,
  50. struct cgroup_netprio_state, css)->prioidx;
  51. rcu_read_unlock();
  52. return idx;
  53. }
  54. #endif
  55. #else /* !CONFIG_NETPRIO_CGROUP */
  56. static inline u32 task_netprioidx(struct task_struct *p)
  57. {
  58. return 0;
  59. }
  60. #define sock_update_netprioidx(sk, task)
  61. #endif /* CONFIG_NETPRIO_CGROUP */
  62. #endif /* _NET_CLS_CGROUP_H */