xref: /linux/include/net/gen_stats.h (revision 67c9e6270f3013e4d86ec57c4e7f27459f2a0652)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NET_GEN_STATS_H
3 #define __NET_GEN_STATS_H
4 
5 #include <linux/gen_stats.h>
6 #include <linux/socket.h>
7 #include <linux/rtnetlink.h>
8 #include <linux/pkt_sched.h>
9 
10 /* Note: this used to be in include/uapi/linux/gen_stats.h */
11 struct gnet_stats_basic_packed {
12 	__u64	bytes;
13 	__u64	packets;
14 	struct u64_stats_sync syncp;
15 };
16 
17 struct gnet_stats_basic_cpu {
18 	struct gnet_stats_basic_packed bstats;
19 	struct u64_stats_sync syncp;
20 } __aligned(2 * sizeof(u64));
21 
22 struct net_rate_estimator;
23 
24 struct gnet_dump {
25 	spinlock_t *      lock;
26 	struct sk_buff *  skb;
27 	struct nlattr *   tail;
28 
29 	/* Backward compatibility */
30 	int               compat_tc_stats;
31 	int               compat_xstats;
32 	int               padattr;
33 	void *            xstats;
34 	int               xstats_len;
35 	struct tc_stats   tc_stats;
36 };
37 
38 void gnet_stats_basic_packed_init(struct gnet_stats_basic_packed *b);
39 int gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock,
40 			  struct gnet_dump *d, int padattr);
41 
42 int gnet_stats_start_copy_compat(struct sk_buff *skb, int type,
43 				 int tc_stats_type, int xstats_type,
44 				 spinlock_t *lock, struct gnet_dump *d,
45 				 int padattr);
46 
47 int gnet_stats_copy_basic(const seqcount_t *running,
48 			  struct gnet_dump *d,
49 			  struct gnet_stats_basic_cpu __percpu *cpu,
50 			  struct gnet_stats_basic_packed *b);
51 void gnet_stats_add_basic(const seqcount_t *running,
52 			  struct gnet_stats_basic_packed *bstats,
53 			  struct gnet_stats_basic_cpu __percpu *cpu,
54 			  struct gnet_stats_basic_packed *b);
55 int gnet_stats_copy_basic_hw(const seqcount_t *running,
56 			     struct gnet_dump *d,
57 			     struct gnet_stats_basic_cpu __percpu *cpu,
58 			     struct gnet_stats_basic_packed *b);
59 int gnet_stats_copy_rate_est(struct gnet_dump *d,
60 			     struct net_rate_estimator __rcu **ptr);
61 int gnet_stats_copy_queue(struct gnet_dump *d,
62 			  struct gnet_stats_queue __percpu *cpu_q,
63 			  struct gnet_stats_queue *q, __u32 qlen);
64 void gnet_stats_add_queue(struct gnet_stats_queue *qstats,
65 			  const struct gnet_stats_queue __percpu *cpu_q,
66 			  const struct gnet_stats_queue *q);
67 int gnet_stats_copy_app(struct gnet_dump *d, void *st, int len);
68 
69 int gnet_stats_finish_copy(struct gnet_dump *d);
70 
71 int gen_new_estimator(struct gnet_stats_basic_packed *bstats,
72 		      struct gnet_stats_basic_cpu __percpu *cpu_bstats,
73 		      struct net_rate_estimator __rcu **rate_est,
74 		      spinlock_t *lock,
75 		      seqcount_t *running, struct nlattr *opt);
76 void gen_kill_estimator(struct net_rate_estimator __rcu **ptr);
77 int gen_replace_estimator(struct gnet_stats_basic_packed *bstats,
78 			  struct gnet_stats_basic_cpu __percpu *cpu_bstats,
79 			  struct net_rate_estimator __rcu **ptr,
80 			  spinlock_t *lock,
81 			  seqcount_t *running, struct nlattr *opt);
82 bool gen_estimator_active(struct net_rate_estimator __rcu **ptr);
83 bool gen_estimator_read(struct net_rate_estimator __rcu **ptr,
84 			struct gnet_stats_rate_est64 *sample);
85 #endif
86