Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __NET_GEN_STATS_H
0003 #define __NET_GEN_STATS_H
0004 
0005 #include <linux/gen_stats.h>
0006 #include <linux/socket.h>
0007 #include <linux/rtnetlink.h>
0008 #include <linux/pkt_sched.h>
0009 
0010 /* Throughput stats.
0011  * Must be initialized beforehand with gnet_stats_basic_sync_init().
0012  *
0013  * If no reads can ever occur parallel to writes (e.g. stack-allocated
0014  * bstats), then the internal stat values can be written to and read
0015  * from directly. Otherwise, use _bstats_set/update() for writes and
0016  * gnet_stats_add_basic() for reads.
0017  */
0018 struct gnet_stats_basic_sync {
0019     u64_stats_t bytes;
0020     u64_stats_t packets;
0021     struct u64_stats_sync syncp;
0022 } __aligned(2 * sizeof(u64));
0023 
0024 struct net_rate_estimator;
0025 
0026 struct gnet_dump {
0027     spinlock_t *      lock;
0028     struct sk_buff *  skb;
0029     struct nlattr *   tail;
0030 
0031     /* Backward compatibility */
0032     int               compat_tc_stats;
0033     int               compat_xstats;
0034     int               padattr;
0035     void *            xstats;
0036     int               xstats_len;
0037     struct tc_stats   tc_stats;
0038 };
0039 
0040 void gnet_stats_basic_sync_init(struct gnet_stats_basic_sync *b);
0041 int gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock,
0042               struct gnet_dump *d, int padattr);
0043 
0044 int gnet_stats_start_copy_compat(struct sk_buff *skb, int type,
0045                  int tc_stats_type, int xstats_type,
0046                  spinlock_t *lock, struct gnet_dump *d,
0047                  int padattr);
0048 
0049 int gnet_stats_copy_basic(struct gnet_dump *d,
0050               struct gnet_stats_basic_sync __percpu *cpu,
0051               struct gnet_stats_basic_sync *b, bool running);
0052 void gnet_stats_add_basic(struct gnet_stats_basic_sync *bstats,
0053               struct gnet_stats_basic_sync __percpu *cpu,
0054               struct gnet_stats_basic_sync *b, bool running);
0055 int gnet_stats_copy_basic_hw(struct gnet_dump *d,
0056                  struct gnet_stats_basic_sync __percpu *cpu,
0057                  struct gnet_stats_basic_sync *b, bool running);
0058 int gnet_stats_copy_rate_est(struct gnet_dump *d,
0059                  struct net_rate_estimator __rcu **ptr);
0060 int gnet_stats_copy_queue(struct gnet_dump *d,
0061               struct gnet_stats_queue __percpu *cpu_q,
0062               struct gnet_stats_queue *q, __u32 qlen);
0063 void gnet_stats_add_queue(struct gnet_stats_queue *qstats,
0064               const struct gnet_stats_queue __percpu *cpu_q,
0065               const struct gnet_stats_queue *q);
0066 int gnet_stats_copy_app(struct gnet_dump *d, void *st, int len);
0067 
0068 int gnet_stats_finish_copy(struct gnet_dump *d);
0069 
0070 int gen_new_estimator(struct gnet_stats_basic_sync *bstats,
0071               struct gnet_stats_basic_sync __percpu *cpu_bstats,
0072               struct net_rate_estimator __rcu **rate_est,
0073               spinlock_t *lock,
0074               bool running, struct nlattr *opt);
0075 void gen_kill_estimator(struct net_rate_estimator __rcu **ptr);
0076 int gen_replace_estimator(struct gnet_stats_basic_sync *bstats,
0077               struct gnet_stats_basic_sync __percpu *cpu_bstats,
0078               struct net_rate_estimator __rcu **ptr,
0079               spinlock_t *lock,
0080               bool running, struct nlattr *opt);
0081 bool gen_estimator_active(struct net_rate_estimator __rcu **ptr);
0082 bool gen_estimator_read(struct net_rate_estimator __rcu **ptr,
0083             struct gnet_stats_rate_est64 *sample);
0084 #endif