1 #ifndef __NET_SCHED_RED_H
2 #define __NET_SCHED_RED_H
4 #include <linux/types.h>
109 #define RED_ONE_PERCENT ((u32)DIV_ROUND_CLOSEST(1ULL<<32, 100))
111 #define MAX_P_MIN (1 * RED_ONE_PERCENT)
112 #define MAX_P_MAX (50 * RED_ONE_PERCENT)
113 #define MAX_P_ALPHA(val) min(MAX_P_MIN, val / 4)
115 #define RED_STAB_SIZE 256
116 #define RED_STAB_MASK (RED_STAB_SIZE - 1)
153 static inline u32 red_maxp(
u8 Plog)
155 return Plog < 32 ? (~0U >> Plog) : ~0
U;
158 static inline void red_set_vars(
struct red_vars *
v)
169 static inline void red_set_parms(
struct red_parms *
p,
171 u8 Scell_log,
u8 *stab,
u32 max_P)
173 int delta = qth_max - qth_min;
184 max_P = red_maxp(Plog);
188 max_p_delta = max_P /
delta;
189 max_p_delta =
max(max_p_delta, 1
U);
207 static inline int red_is_idling(
const struct red_vars *
v)
212 static inline void red_start_of_idle_period(
struct red_vars *
v)
217 static inline void red_end_of_idle_period(
struct red_vars *
v)
222 static inline void red_restart(
struct red_vars *
v)
224 red_end_of_idle_period(v);
229 static inline unsigned long red_calc_qavg_from_idle_time(
const struct red_parms *p,
259 return v->
qavg >> shift;
270 if (us_idle < (v->
qavg >> 1))
271 return v->
qavg - us_idle;
277 static inline unsigned long red_calc_qavg_no_idle_time(
const struct red_parms *p,
293 static inline unsigned long red_calc_qavg(
const struct red_parms *p,
297 if (!red_is_idling(v))
298 return red_calc_qavg_no_idle_time(p, v, backlog);
300 return red_calc_qavg_from_idle_time(p, v);
309 static inline int red_mark_probability(
const struct red_parms *p,
338 static inline int red_cmp_thresh(
const struct red_parms *p,
unsigned long qavg)
340 if (qavg < p->qth_min)
354 static inline int red_action(
const struct red_parms *p,
358 switch (red_cmp_thresh(p, qavg)) {
365 if (red_mark_probability(p, v, qavg)) {
367 v->
qR = red_random(p);
371 v->
qR = red_random(p);
390 if (red_is_idling(v))
391 qavg = red_calc_qavg_from_idle_time(p, v);
402 max_p_delta =
max(max_p_delta, 1
U);