Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef __NET_SCHED_PIE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define __NET_SCHED_PIE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/ktime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <net/inet_ecn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define MAX_PROB	(U64_MAX >> BITS_PER_BYTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define DTIME_INVALID	U64_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define QUEUE_THRESHOLD	16384
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define DQCOUNT_INVALID	-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define PIE_SCALE	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * struct pie_params - contains pie parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * @target:		target delay in pschedtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * @tudpate:		interval at which drop probability is calculated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * @limit:		total number of packets that can be in the queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * @alpha:		parameter to control drop probability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * @beta:		parameter to control drop probability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * @ecn:		is ECN marking of packets enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * @bytemode:		is drop probability scaled based on pkt size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * @dq_rate_estimator:	is Little's law used for qdelay calculation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct pie_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	psched_time_t target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	u32 tupdate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	u32 limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	u32 alpha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	u32 beta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	u8 ecn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	u8 bytemode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	u8 dq_rate_estimator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * struct pie_vars - contains pie variables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * @qdelay:		current queue delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * @qdelay_old:		queue delay in previous qdelay calculation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * @burst_time:		burst time allowance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * @dq_tstamp:		timestamp at which dq rate was last calculated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * @prob:		drop probability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * @accu_prob:		accumulated drop probability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * @dq_count:		number of bytes dequeued in a measurement cycle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @avg_dq_rate:	calculated average dq rate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @backlog_old:	queue backlog during previous qdelay calculation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) struct pie_vars {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	psched_time_t qdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	psched_time_t qdelay_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	psched_time_t burst_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	psched_time_t dq_tstamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u64 prob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u64 accu_prob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	u64 dq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	u32 avg_dq_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	u32 backlog_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * struct pie_stats - contains pie stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * @packets_in:	total number of packets enqueued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * @dropped:	packets dropped due to pie action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * @overlimit:	packets dropped due to lack of space in queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * @ecn_mark:	packets marked with ECN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * @maxq:	maximum queue size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) struct pie_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	u32 packets_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	u32 dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	u32 overlimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	u32 ecn_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	u32 maxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * struct pie_skb_cb - contains private skb vars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * @enqueue_time:	timestamp when the packet is enqueued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * @mem_usage:		size of the skb during enqueue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) struct pie_skb_cb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	psched_time_t enqueue_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	u32 mem_usage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static inline void pie_params_init(struct pie_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	params->target = PSCHED_NS2TICKS(15 * NSEC_PER_MSEC);	/* 15 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	params->tupdate = usecs_to_jiffies(15 * USEC_PER_MSEC);	/* 15 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	params->limit = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	params->alpha = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	params->beta = 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	params->ecn = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	params->bytemode = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	params->dq_rate_estimator = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static inline void pie_vars_init(struct pie_vars *vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	vars->burst_time = PSCHED_NS2TICKS(150 * NSEC_PER_MSEC); /* 150 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	vars->dq_tstamp = DTIME_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	vars->accu_prob = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	vars->dq_count = DQCOUNT_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	vars->avg_dq_rate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static inline struct pie_skb_cb *get_pie_cb(const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	qdisc_cb_private_validate(skb, sizeof(struct pie_skb_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return (struct pie_skb_cb *)qdisc_skb_cb(skb)->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static inline psched_time_t pie_get_enqueue_time(const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return get_pie_cb(skb)->enqueue_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static inline void pie_set_enqueue_time(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	get_pie_cb(skb)->enqueue_time = psched_get_time();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) bool pie_drop_early(struct Qdisc *sch, struct pie_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		    struct pie_vars *vars, u32 backlog, u32 packet_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) void pie_process_dequeue(struct sk_buff *skb, struct pie_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			 struct pie_vars *vars, u32 backlog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			       u32 backlog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #endif