xref: /openbmc/linux/include/net/gen_stats.h (revision 29cbcd85)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef __NET_GEN_STATS_H
31da177e4SLinus Torvalds #define __NET_GEN_STATS_H
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds #include <linux/gen_stats.h>
61da177e4SLinus Torvalds #include <linux/socket.h>
71da177e4SLinus Torvalds #include <linux/rtnetlink.h>
81da177e4SLinus Torvalds #include <linux/pkt_sched.h>
91da177e4SLinus Torvalds 
1050dc9a85SAhmed S. Darwish /* Throughput stats.
1150dc9a85SAhmed S. Darwish  * Must be initialized beforehand with gnet_stats_basic_sync_init().
1250dc9a85SAhmed S. Darwish  *
1350dc9a85SAhmed S. Darwish  * If no reads can ever occur parallel to writes (e.g. stack-allocated
1450dc9a85SAhmed S. Darwish  * bstats), then the internal stat values can be written to and read
1550dc9a85SAhmed S. Darwish  * from directly. Otherwise, use _bstats_set/update() for writes and
1650dc9a85SAhmed S. Darwish  * gnet_stats_add_basic() for reads.
1750dc9a85SAhmed S. Darwish  */
1850dc9a85SAhmed S. Darwish struct gnet_stats_basic_sync {
1950dc9a85SAhmed S. Darwish 	u64_stats_t bytes;
2050dc9a85SAhmed S. Darwish 	u64_stats_t packets;
2122e0f8b9SJohn Fastabend 	struct u64_stats_sync syncp;
22001c96dbSEric Dumazet } __aligned(2 * sizeof(u64));
2322e0f8b9SJohn Fastabend 
241c0d32fdSEric Dumazet struct net_rate_estimator;
251c0d32fdSEric Dumazet 
26fd2c3ef7SEric Dumazet struct gnet_dump {
271da177e4SLinus Torvalds 	spinlock_t *      lock;
281da177e4SLinus Torvalds 	struct sk_buff *  skb;
291e90474cSPatrick McHardy 	struct nlattr *   tail;
301da177e4SLinus Torvalds 
3125985edcSLucas De Marchi 	/* Backward compatibility */
321da177e4SLinus Torvalds 	int               compat_tc_stats;
331da177e4SLinus Torvalds 	int               compat_xstats;
349854518eSNicolas Dichtel 	int               padattr;
351da177e4SLinus Torvalds 	void *            xstats;
361da177e4SLinus Torvalds 	int               xstats_len;
371da177e4SLinus Torvalds 	struct tc_stats   tc_stats;
381da177e4SLinus Torvalds };
391da177e4SLinus Torvalds 
4050dc9a85SAhmed S. Darwish void gnet_stats_basic_sync_init(struct gnet_stats_basic_sync *b);
418aae218fSJoe Perches int gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock,
429854518eSNicolas Dichtel 			  struct gnet_dump *d, int padattr);
431da177e4SLinus Torvalds 
448aae218fSJoe Perches int gnet_stats_start_copy_compat(struct sk_buff *skb, int type,
451da177e4SLinus Torvalds 				 int tc_stats_type, int xstats_type,
469854518eSNicolas Dichtel 				 spinlock_t *lock, struct gnet_dump *d,
479854518eSNicolas Dichtel 				 int padattr);
481da177e4SLinus Torvalds 
49*29cbcd85SAhmed S. Darwish int gnet_stats_copy_basic(struct gnet_dump *d,
5050dc9a85SAhmed S. Darwish 			  struct gnet_stats_basic_sync __percpu *cpu,
51*29cbcd85SAhmed S. Darwish 			  struct gnet_stats_basic_sync *b, bool running);
52*29cbcd85SAhmed S. Darwish void gnet_stats_add_basic(struct gnet_stats_basic_sync *bstats,
5350dc9a85SAhmed S. Darwish 			  struct gnet_stats_basic_sync __percpu *cpu,
54*29cbcd85SAhmed S. Darwish 			  struct gnet_stats_basic_sync *b, bool running);
55*29cbcd85SAhmed S. Darwish int gnet_stats_copy_basic_hw(struct gnet_dump *d,
5650dc9a85SAhmed S. Darwish 			     struct gnet_stats_basic_sync __percpu *cpu,
57*29cbcd85SAhmed S. Darwish 			     struct gnet_stats_basic_sync *b, bool running);
588aae218fSJoe Perches int gnet_stats_copy_rate_est(struct gnet_dump *d,
591c0d32fdSEric Dumazet 			     struct net_rate_estimator __rcu **ptr);
6064015853SJohn Fastabend int gnet_stats_copy_queue(struct gnet_dump *d,
61b0ab6f92SJohn Fastabend 			  struct gnet_stats_queue __percpu *cpu_q,
62b0ab6f92SJohn Fastabend 			  struct gnet_stats_queue *q, __u32 qlen);
63448e163fSSebastian Andrzej Siewior void gnet_stats_add_queue(struct gnet_stats_queue *qstats,
64448e163fSSebastian Andrzej Siewior 			  const struct gnet_stats_queue __percpu *cpu_q,
65448e163fSSebastian Andrzej Siewior 			  const struct gnet_stats_queue *q);
668aae218fSJoe Perches int gnet_stats_copy_app(struct gnet_dump *d, void *st, int len);
671da177e4SLinus Torvalds 
688aae218fSJoe Perches int gnet_stats_finish_copy(struct gnet_dump *d);
691da177e4SLinus Torvalds 
7050dc9a85SAhmed S. Darwish int gen_new_estimator(struct gnet_stats_basic_sync *bstats,
7150dc9a85SAhmed S. Darwish 		      struct gnet_stats_basic_sync __percpu *cpu_bstats,
721c0d32fdSEric Dumazet 		      struct net_rate_estimator __rcu **rate_est,
7351a9f5aeSVlad Buslov 		      spinlock_t *lock,
74*29cbcd85SAhmed S. Darwish 		      bool running, struct nlattr *opt);
751c0d32fdSEric Dumazet void gen_kill_estimator(struct net_rate_estimator __rcu **ptr);
7650dc9a85SAhmed S. Darwish int gen_replace_estimator(struct gnet_stats_basic_sync *bstats,
7750dc9a85SAhmed S. Darwish 			  struct gnet_stats_basic_sync __percpu *cpu_bstats,
781c0d32fdSEric Dumazet 			  struct net_rate_estimator __rcu **ptr,
7951a9f5aeSVlad Buslov 			  spinlock_t *lock,
80*29cbcd85SAhmed S. Darwish 			  bool running, struct nlattr *opt);
811c0d32fdSEric Dumazet bool gen_estimator_active(struct net_rate_estimator __rcu **ptr);
821c0d32fdSEric Dumazet bool gen_estimator_read(struct net_rate_estimator __rcu **ptr,
831c0d32fdSEric Dumazet 			struct gnet_stats_rate_est64 *sample);
841da177e4SLinus Torvalds #endif
85