Lines Matching +full:static +full:- +full:beta

1 /* SPDX-License-Identifier: GPL-2.0 */
22 ------------------
26 avg = (1-W)*avg + W*current_queue_len,
28 W is the filter time constant (chosen as 2^(-Wlog)), it controls
32 if (avg > th_max) -> packet marked (dropped).
33 if (avg < th_min) -> packet passes.
36 Pb = max_P * (avg - th_min)/(th_max-th_min)
42 max_P is chosen as a number, so that max_P/(th_max-th_min)
48 -----------------------------
50 qth_min - bytes (should be < qth_max/2)
51 qth_max - bytes (should be at least 2*qth_min and less limit)
52 Wlog - bits (<32) log(1/W).
53 Plog - bits (<32)
57 max_P = (qth_max-qth_min)/2^Plog;
65 Lookup table for log((1-W)^(t/t_ave).
71 -----------------
76 L + 1 - th_min/S < (1-(1-W)^L)/W
81 -1 33
82 -2 35
83 -3 39
84 -4 46
85 -5 57
86 -6 75
87 -7 101
88 -8 135
89 -9 190
101 * decrease max_p : max_p *= beta;
103 * target :[qth_min + 0.4*(qth_min - qth_max),
104 * qth_min + 0.6*(qth_min - qth_max)].
106 * beta : 0.9
108 * max_P between 0.01 and 0.5 (1% - 50%) [ Its no longer a negative power of two ]
117 #define RED_STAB_MASK (RED_STAB_SIZE - 1)
135 u32 qth_delta; /* max_th - min_th */
136 u32 target_min; /* min_th + 0.4*(max_th - min_th) */
137 u32 target_max; /* min_th + 0.6*(max_th - min_th) */
154 static inline u32 red_maxp(u8 Plog) in red_maxp()
159 static inline void red_set_vars(struct red_vars *v) in red_set_vars()
163 * it might result in an unreasonable qavg for a while. --TGR in red_set_vars()
165 v->qavg = 0; in red_set_vars()
167 v->qcount = -1; in red_set_vars()
170 static inline bool red_check_params(u32 qth_min, u32 qth_max, u8 Wlog, in red_check_params()
191 static inline int red_get_flags(unsigned char qopt_flags, in red_get_flags()
203 return -EINVAL; in red_get_flags()
218 static inline int red_validate_flags(unsigned char flags, in red_validate_flags()
223 return -EINVAL; in red_validate_flags()
229 static inline void red_set_parms(struct red_parms *p, in red_set_parms()
233 int delta = qth_max - qth_min; in red_set_parms()
236 WRITE_ONCE(p->qth_min, qth_min << Wlog); in red_set_parms()
237 WRITE_ONCE(p->qth_max, qth_max << Wlog); in red_set_parms()
238 WRITE_ONCE(p->Wlog, Wlog); in red_set_parms()
239 WRITE_ONCE(p->Plog, Plog); in red_set_parms()
242 p->qth_delta = delta; in red_set_parms()
245 max_P *= delta; /* max_P = (qth_max - qth_min)/2^Plog */ in red_set_parms()
247 WRITE_ONCE(p->max_P, max_P); in red_set_parms()
250 p->max_P_reciprocal = reciprocal_value(max_p_delta); in red_set_parms()
253 * [min_th + 0.4*(min_th - max_th), in red_set_parms()
254 * min_th + 0.6*(min_th - max_th)]. in red_set_parms()
257 p->target_min = qth_min + 2*delta; in red_set_parms()
258 p->target_max = qth_min + 3*delta; in red_set_parms()
260 WRITE_ONCE(p->Scell_log, Scell_log); in red_set_parms()
261 p->Scell_max = (255 << Scell_log); in red_set_parms()
264 memcpy(p->Stab, stab, sizeof(p->Stab)); in red_set_parms()
267 static inline int red_is_idling(const struct red_vars *v) in red_is_idling()
269 return v->qidlestart != 0; in red_is_idling()
272 static inline void red_start_of_idle_period(struct red_vars *v) in red_start_of_idle_period()
274 v->qidlestart = ktime_get(); in red_start_of_idle_period()
277 static inline void red_end_of_idle_period(struct red_vars *v) in red_end_of_idle_period()
279 v->qidlestart = 0; in red_end_of_idle_period()
282 static inline void red_restart(struct red_vars *v) in red_restart()
285 v->qavg = 0; in red_restart()
286 v->qcount = -1; in red_restart()
289 static inline unsigned long red_calc_qavg_from_idle_time(const struct red_parms *p, in red_calc_qavg_from_idle_time()
292 s64 delta = ktime_us_delta(ktime_get(), v->qidlestart); in red_calc_qavg_from_idle_time()
293 long us_idle = min_t(s64, delta, p->Scell_max); in red_calc_qavg_from_idle_time()
308 * v->qavg *= (1-W)^m in red_calc_qavg_from_idle_time()
316 shift = p->Stab[(us_idle >> p->Scell_log) & RED_STAB_MASK]; in red_calc_qavg_from_idle_time()
319 return v->qavg >> shift; in red_calc_qavg_from_idle_time()
323 * (1-W)^m ~= 1-mW + ... in red_calc_qavg_from_idle_time()
328 us_idle = (v->qavg * (u64)us_idle) >> p->Scell_log; in red_calc_qavg_from_idle_time()
330 if (us_idle < (v->qavg >> 1)) in red_calc_qavg_from_idle_time()
331 return v->qavg - us_idle; in red_calc_qavg_from_idle_time()
333 return v->qavg >> 1; in red_calc_qavg_from_idle_time()
337 static inline unsigned long red_calc_qavg_no_idle_time(const struct red_parms *p, in red_calc_qavg_no_idle_time()
342 * NOTE: v->qavg is fixed point number with point at Wlog. in red_calc_qavg_no_idle_time()
346 * qavg = qavg*(1-W) + backlog*W; in red_calc_qavg_no_idle_time()
348 * --ANK (980924) in red_calc_qavg_no_idle_time()
350 return v->qavg + (backlog - (v->qavg >> p->Wlog)); in red_calc_qavg_no_idle_time()
353 static inline unsigned long red_calc_qavg(const struct red_parms *p, in red_calc_qavg()
364 static inline u32 red_random(const struct red_parms *p) in red_random()
366 return reciprocal_divide(get_random_u32(), p->max_P_reciprocal); in red_random()
369 static inline int red_mark_probability(const struct red_parms *p, in red_mark_probability()
376 (0..1/max_P)*(qth_max-qth_min) in red_mark_probability()
385 max_P*(qavg - qth_min)/(qth_max-qth_min) < rnd/qcount in red_mark_probability()
387 Any questions? --ANK (980924) in red_mark_probability()
389 return !(((qavg - p->qth_min) >> p->Wlog) * v->qcount < v->qR); in red_mark_probability()
398 static inline int red_cmp_thresh(const struct red_parms *p, unsigned long qavg) in red_cmp_thresh()
400 if (qavg < p->qth_min) in red_cmp_thresh()
402 else if (qavg >= p->qth_max) in red_cmp_thresh()
414 static inline int red_action(const struct red_parms *p, in red_action()
420 v->qcount = -1; in red_action()
424 if (++v->qcount) { in red_action()
426 v->qcount = 0; in red_action()
427 v->qR = red_random(p); in red_action()
431 v->qR = red_random(p); in red_action()
436 v->qcount = -1; in red_action()
444 static inline void red_adaptative_algo(struct red_parms *p, struct red_vars *v) in red_adaptative_algo()
449 qavg = v->qavg; in red_adaptative_algo()
453 /* v->qavg is fixed point number with point at Wlog */ in red_adaptative_algo()
454 qavg >>= p->Wlog; in red_adaptative_algo()
456 if (qavg > p->target_max && p->max_P <= MAX_P_MAX) in red_adaptative_algo()
457 p->max_P += MAX_P_ALPHA(p->max_P); /* maxp = maxp + alpha */ in red_adaptative_algo()
458 else if (qavg < p->target_min && p->max_P >= MAX_P_MIN) in red_adaptative_algo()
459 p->max_P = (p->max_P/10)*9; /* maxp = maxp * Beta */ in red_adaptative_algo()
461 max_p_delta = DIV_ROUND_CLOSEST(p->max_P, p->qth_delta); in red_adaptative_algo()
463 p->max_P_reciprocal = reciprocal_value(max_p_delta); in red_adaptative_algo()