Commit | Line | Data |
---|---|---|
84bf557f MT |
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 | ||
11 | #define QUEUE_THRESHOLD 16384 | |
12 | #define DQCOUNT_INVALID -1 | |
805a5a23 MT |
13 | #define DTIME_INVALID U64_MAX |
14 | #define MAX_PROB U64_MAX | |
84bf557f MT |
15 | #define PIE_SCALE 8 |
16 | ||
17 | /* parameters used */ | |
18 | struct pie_params { | |
19 | psched_time_t target; /* user specified target delay in pschedtime */ | |
20 | u32 tupdate; /* timer frequency (in jiffies) */ | |
21 | u32 limit; /* number of packets that can be enqueued */ | |
22 | u32 alpha; /* alpha and beta are between 0 and 32 */ | |
23 | u32 beta; /* and are used for shift relative to 1 */ | |
24 | bool ecn; /* true if ecn is enabled */ | |
25 | bool bytemode; /* to scale drop early prob based on pkt size */ | |
26 | u8 dq_rate_estimator; /* to calculate delay using Little's law */ | |
27 | }; | |
28 | ||
29 | /* variables used */ | |
30 | struct pie_vars { | |
31 | u64 prob; /* probability but scaled by u64 limit. */ | |
32 | psched_time_t burst_time; | |
33 | psched_time_t qdelay; | |
34 | psched_time_t qdelay_old; | |
35 | u64 dq_count; /* measured in bytes */ | |
36 | psched_time_t dq_tstamp; /* drain rate */ | |
37 | u64 accu_prob; /* accumulated drop probability */ | |
38 | u32 avg_dq_rate; /* bytes per pschedtime tick,scaled */ | |
39 | u32 qlen_old; /* in bytes */ | |
40 | u8 accu_prob_overflows; /* overflows of accu_prob */ | |
41 | }; | |
42 | ||
43 | /* statistics gathering */ | |
44 | struct pie_stats { | |
45 | u32 packets_in; /* total number of packets enqueued */ | |
46 | u32 dropped; /* packets dropped due to pie_action */ | |
47 | u32 overlimit; /* dropped due to lack of space in queue */ | |
48 | u32 maxq; /* maximum queue size */ | |
49 | u32 ecn_mark; /* packets marked with ECN */ | |
50 | }; | |
51 | ||
52 | /* private skb vars */ | |
53 | struct pie_skb_cb { | |
54 | psched_time_t enqueue_time; | |
55 | }; | |
56 | ||
57 | static inline void pie_params_init(struct pie_params *params) | |
58 | { | |
59 | params->alpha = 2; | |
60 | params->beta = 20; | |
61 | params->tupdate = usecs_to_jiffies(15 * USEC_PER_MSEC); /* 15 ms */ | |
62 | params->limit = 1000; /* default of 1000 packets */ | |
63 | params->target = PSCHED_NS2TICKS(15 * NSEC_PER_MSEC); /* 15 ms */ | |
64 | params->ecn = false; | |
65 | params->bytemode = false; | |
66 | params->dq_rate_estimator = false; | |
67 | } | |
68 | ||
69 | static inline void pie_vars_init(struct pie_vars *vars) | |
70 | { | |
71 | vars->dq_count = DQCOUNT_INVALID; | |
72 | vars->dq_tstamp = DTIME_INVALID; | |
73 | vars->accu_prob = 0; | |
74 | vars->avg_dq_rate = 0; | |
75 | /* default of 150 ms in pschedtime */ | |
76 | vars->burst_time = PSCHED_NS2TICKS(150 * NSEC_PER_MSEC); | |
77 | vars->accu_prob_overflows = 0; | |
78 | } | |
79 | ||
80 | static inline struct pie_skb_cb *get_pie_cb(const struct sk_buff *skb) | |
81 | { | |
82 | qdisc_cb_private_validate(skb, sizeof(struct pie_skb_cb)); | |
83 | return (struct pie_skb_cb *)qdisc_skb_cb(skb)->data; | |
84 | } | |
85 | ||
86 | static inline psched_time_t pie_get_enqueue_time(const struct sk_buff *skb) | |
87 | { | |
88 | return get_pie_cb(skb)->enqueue_time; | |
89 | } | |
90 | ||
91 | static inline void pie_set_enqueue_time(struct sk_buff *skb) | |
92 | { | |
93 | get_pie_cb(skb)->enqueue_time = psched_get_time(); | |
94 | } | |
95 | ||
96 | #endif |