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