gen_stats.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __NET_GEN_STATS_H
  3. #define __NET_GEN_STATS_H
  4. #include <linux/gen_stats.h>
  5. #include <linux/socket.h>
  6. #include <linux/rtnetlink.h>
  7. #include <linux/pkt_sched.h>
  8. /* Throughput stats.
  9. * Must be initialized beforehand with gnet_stats_basic_sync_init().
  10. *
  11. * If no reads can ever occur parallel to writes (e.g. stack-allocated
  12. * bstats), then the internal stat values can be written to and read
  13. * from directly. Otherwise, use _bstats_set/update() for writes and
  14. * gnet_stats_add_basic() for reads.
  15. */
  16. struct gnet_stats_basic_sync {
  17. u64_stats_t bytes;
  18. u64_stats_t packets;
  19. struct u64_stats_sync syncp;
  20. } __aligned(2 * sizeof(u64));
  21. struct net_rate_estimator;
  22. struct gnet_dump {
  23. spinlock_t * lock;
  24. struct sk_buff * skb;
  25. struct nlattr * tail;
  26. /* Backward compatibility */
  27. int compat_tc_stats;
  28. int compat_xstats;
  29. int padattr;
  30. void * xstats;
  31. int xstats_len;
  32. struct tc_stats tc_stats;
  33. };
  34. void gnet_stats_basic_sync_init(struct gnet_stats_basic_sync *b);
  35. int gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock,
  36. struct gnet_dump *d, int padattr);
  37. int gnet_stats_start_copy_compat(struct sk_buff *skb, int type,
  38. int tc_stats_type, int xstats_type,
  39. spinlock_t *lock, struct gnet_dump *d,
  40. int padattr);
  41. int gnet_stats_copy_basic(struct gnet_dump *d,
  42. struct gnet_stats_basic_sync __percpu *cpu,
  43. struct gnet_stats_basic_sync *b, bool running);
  44. void gnet_stats_add_basic(struct gnet_stats_basic_sync *bstats,
  45. struct gnet_stats_basic_sync __percpu *cpu,
  46. struct gnet_stats_basic_sync *b, bool running);
  47. int gnet_stats_copy_basic_hw(struct gnet_dump *d,
  48. struct gnet_stats_basic_sync __percpu *cpu,
  49. struct gnet_stats_basic_sync *b, bool running);
  50. int gnet_stats_copy_rate_est(struct gnet_dump *d,
  51. struct net_rate_estimator __rcu **ptr);
  52. int gnet_stats_copy_queue(struct gnet_dump *d,
  53. struct gnet_stats_queue __percpu *cpu_q,
  54. struct gnet_stats_queue *q, __u32 qlen);
  55. void gnet_stats_add_queue(struct gnet_stats_queue *qstats,
  56. const struct gnet_stats_queue __percpu *cpu_q,
  57. const struct gnet_stats_queue *q);
  58. int gnet_stats_copy_app(struct gnet_dump *d, void *st, int len);
  59. int gnet_stats_finish_copy(struct gnet_dump *d);
  60. int gen_new_estimator(struct gnet_stats_basic_sync *bstats,
  61. struct gnet_stats_basic_sync __percpu *cpu_bstats,
  62. struct net_rate_estimator __rcu **rate_est,
  63. spinlock_t *lock,
  64. bool running, struct nlattr *opt);
  65. void gen_kill_estimator(struct net_rate_estimator __rcu **ptr);
  66. int gen_replace_estimator(struct gnet_stats_basic_sync *bstats,
  67. struct gnet_stats_basic_sync __percpu *cpu_bstats,
  68. struct net_rate_estimator __rcu **ptr,
  69. spinlock_t *lock,
  70. bool running, struct nlattr *opt);
  71. bool gen_estimator_active(struct net_rate_estimator __rcu **ptr);
  72. bool gen_estimator_read(struct net_rate_estimator __rcu **ptr,
  73. struct gnet_stats_rate_est64 *sample);
  74. #endif