rte_red.h(3)

πŸŽ€ rte_red.h πŸŽ€

okay so welcome to rte_red.h, a DPDK header, and bestie we are going to get through it together. it's giving big-brain queue management energy and honestly? obsessed. πŸ’…


🌸 NAME 🌸

rte_red.h β€” the header that hands you RTE Random Early Detection (RED), aka the whole queue-vibes situation.

also, for the record: Definition in file rte_red.h. yes ma'am, it cites itself. main character behavior. πŸ‘‘

✨ SYNOPSIS ✨

#include <stdint.h>
#include <limits.h>
#include <rte_debug.h>
#include <rte_cycles.h>
#include <rte_branch_prediction.h>

🫢 Data Structures

the three structs you're gonna be hanging with:

  • struct rte_red_params
  • struct rte_red_config
  • struct rte_red

🫢 Macros

  • #define RTE_RED_SCALING 10
  • #define RTE_RED_S (1 << 22)
  • #define RTE_RED_MAX_TH_MAX 1023
  • #define RTE_RED_WQ_LOG2_MIN 1
  • #define RTE_RED_WQ_LOG2_MAX 12
  • #define RTE_RED_MAXP_INV_MIN 1
  • #define RTE_RED_MAXP_INV_MAX 255
  • #define RTE_RED_2POW16 (1<<16)

🫢 Functions

  • int rte_red_rt_data_init (struct rte_red *red) β€” Initialises run-time data.
  • int rte_red_config_init (struct rte_red_config *red_cfg, const uint16_t wq_log2, const uint16_t min_th, const uint16_t max_th, const uint16_t maxp_inv) β€” Configures a single RED configuration parameter structure.
  • static uint32_t rte_fast_rand (void) β€” Generate random number for RED.
  • static uint16_t __rte_red_calc_qempty_factor (uint8_t wq_log2, uint16_t m) β€” calculate factor to scale average queue size when queue becomes empty
  • static int rte_red_enqueue_empty (const struct rte_red_config *red_cfg, struct rte_red *red, const uint64_t time) β€” Updates queue average in condition when queue is empty.
  • static int __rte_red_drop (const struct rte_red_config *red_cfg, struct rte_red *red) β€” make a decision to drop or enqueue a packet based on mark probability criteria
  • static int rte_red_enqueue_nonempty (const struct rte_red_config *red_cfg, struct rte_red *red, const unsigned q) β€” Decides if new packet should be enqueued or dropped in queue non-empty case.
  • static int rte_red_enqueue (const struct rte_red_config *red_cfg, struct rte_red *red, const unsigned q, const uint64_t time) β€” Decides if new packet should be enqueued or dropped. Updates run time data based on new queue size value. Based on new queue average and RED configuration parameters gives verdict whether to enqueue or drop the packet.
  • static void rte_red_mark_queue_empty (struct rte_red *red, const uint64_t time) β€” Callback to records time that queue became empty.

🫢 Variables

  • uint32_t rte_red_rand_val

πŸ’œ Detailed Description πŸ’œ

okay so this is the RTE Random Early Detection (RED) party, and you're invited. πŸŽ‰

Definition in file rte_red.h.


πŸ¦‹ Macro Definition Documentation πŸ¦‹

πŸ’– #define RTE_RED_SCALING 10

Fraction size for fixed-point. so like, how many bits live on the fractional side of the decimal point. πŸ“

Definition at line 23 of file rte_red.h.

πŸ’– #define RTE_RED_S (1 << 22)

Packet size multiplied by number of leaf queues. big number, big responsibilities. 😭

Definition at line 24 of file rte_red.h.

πŸ’– #define RTE_RED_MAX_TH_MAX 1023

Max threshold limit in fixed point format. that's the ceiling, literally. πŸ’…

Definition at line 25 of file rte_red.h.

πŸ’– #define RTE_RED_WQ_LOG2_MIN 1

Min inverse filter weight value. floor edition. 🧚

Definition at line 26 of file rte_red.h.

πŸ’– #define RTE_RED_WQ_LOG2_MAX 12

Max inverse filter weight value. ceiling edition. 🌈

Definition at line 27 of file rte_red.h.

πŸ’– #define RTE_RED_MAXP_INV_MIN 1

Min inverse mark probability value.

Definition at line 28 of file rte_red.h.

πŸ’– #define RTE_RED_MAXP_INV_MAX 255

Max inverse mark probability value.

Definition at line 29 of file rte_red.h.

πŸ’– #define RTE_RED_2POW16 (1<<16)

2 power 16. it's 65536 babe, and it's iconic. ✨

Definition at line 30 of file rte_red.h.


πŸ”₯ Function Documentation πŸ”₯

πŸ’… int rte_red_rt_data_init (struct rte_red * red)

Initialises run-time data. give the runtime struct its little life. 🫢

Parameters

  • red [in,out] β€” data pointer to RED runtime data

Returns

Operation status

Return values

  • 0 β€” success
  • !0 β€” error

πŸ’… int rte_red_config_init (struct rte_red_config * red_cfg, const uint16_t wq_log2, const uint16_t min_th, const uint16_t max_th, const uint16_t maxp_inv)

Configures a single RED configuration parameter structure. one struct, four numbers, zero drama. ✨

Parameters

  • red_cfg [in,out] β€” config pointer to a RED configuration parameter structure
  • wq_log2 [in] β€” log2 of the filter weight, valid range is: RTE_RED_WQ_LOG2_MIN <= wq_log2 <= RTE_RED_WQ_LOG2_MAX
  • min_th [in] β€” queue minimum threshold in number of packets
  • max_th [in] β€” queue maximum threshold in number of packets
  • maxp_inv [in] β€” inverse maximum mark probability

Returns

Operation status

Return values

  • 0 β€” success
  • !0 β€” error

πŸ’… static uint32_t rte_fast_rand (void) [inline], [static]

Generate random number for RED. the implementation is based on:

http://software.intel.com/en-us/articles/fast-random-number-generator-on-the-intel-pentiumr-4-processor/

ngl the fun bit: a 10 bit shift has been found through empirical tests (was 16). they really said "let's just try it and see" and it ate. πŸ’€

Returns

Random number between 0 and (2^22 - 1)

Definition at line 116 of file rte_red.h.

πŸ’… static uint16_t __rte_red_calc_qempty_factor (uint8_t wq_log2, uint16_t m) [inline], [static]

calculate factor to scale average queue size when queue becomes empty. math time bestie, grab a snack. πŸ“

Parameters

  • wq_log2 [in] β€” where EWMA filter weight wq = 1/(2 ^ wq_log2)
  • m [in] β€” exponent in the computed value (1 - wq) ^ m

Returns

computed value

Return values

  • ((1 - wq) ^ m) scaled in fixed-point format

okay the derivation, and I'm gonna quote it because it's lowkey poetry:

Basic math tells us that: a^b = 2^(b * log2(a) )

in our case: a = (1-Wq) b = m Wq = 1/ (2^log2n)

So we are computing this equation: factor = 2 ^ ( m * log2(1-Wq))

First we are computing: n = m * log2(1-Wq)

To avoid dealing with signed numbers log2 values are positive but they should be negative because (1-Wq) is always < 1. Contents of log2 table values are also scaled for precision.

The tricky part is computing 2^n, for this I split n into integer part and fraction part. f - is fraction part of n n - is integer part of original n

Now using basic math we compute 2^n: 2^(f+n) = 2^f * 2^n 2^f - we use lookup table 2^n - can be replaced with bit shift right operations

Definition at line 133 of file rte_red.h.

πŸ’… static int rte_red_enqueue_empty (const struct rte_red_config * red_cfg, struct rte_red * red, const uint64_t time) [inline], [static]

Updates queue average in condition when queue is empty. Note: packet is never dropped in this particular case. πŸ™ˆ so relax.

Parameters

  • red_cfg [in] β€” config pointer to a RED configuration parameter structure
  • red [in,out] β€” data pointer to RED runtime data
  • time [in] β€” current time stamp

Returns

Operation status

Return values

  • 0 β€” enqueue the packet
  • 1 β€” drop the packet based on max threshold criterion
  • 2 β€” drop the packet based on mark probability criterion

We compute avg but we don't compare avg against min_th or max_th, nor calculate drop probability. that's literally not this function's job, mind your business. πŸ’…

m is the number of packets that might have arrived while the queue was empty. In this case we have time stamps provided by scheduler in byte units (bytes transmitted on network port). Such time stamp translates into time units as port speed is fixed but such approach simplifies the code.

Check that m will fit into 16-bit unsigned integer. no overflow girlies. 🫢

Definition at line 196 of file rte_red.h.

πŸ’… static int __rte_red_drop (const struct rte_red_config * red_cfg, struct rte_red * red) [inline], [static]

make a decision to drop or enqueue a packet based on mark probability criteria. Drop probability (Sally Floyd and Van Jacobson):

pb = (1 / maxp_inv) * (avg - min_th) / (max_th - min_th) pa = pb / (2 - count * pb)

and then:

           (1 / maxp_inv) * (avg - min_th)
          ---------------------------------
                   max_th - min_th

pa = ----------------------------------------------------------
      2 - count * (1 / maxp_inv) * (avg - min_th) / (max_th - min_th)

and again:

                     avg - min_th

pa = -----------------------------------------------------------
     2 * (max_th - min_th) * maxp_inv - count * (avg - min_th)

We define pa_const as: pa_const = 2 * (max_th - min_th) * maxp_inv. Then:

                avg - min_th

pa = -----------------------------------
     pa_const - count * (avg - min_th)

Parameters

  • red_cfg [in] β€” config pointer to structure defining RED parameters
  • red [in,out] β€” data pointer to RED runtime data

Returns

operation status

Return values

  • 0 β€” enqueue the packet
  • 1 β€” drop the packet

Definition at line 274 of file rte_red.h.

πŸ’… static int rte_red_enqueue_nonempty (const struct rte_red_config * red_cfg, struct rte_red * red, const unsigned q) [inline], [static]

Decides if new packet should be enqueued or dropped in queue non-empty case. yeah, the other case. 🌸

Parameters

  • red_cfg [in] β€” config pointer to a RED configuration parameter structure
  • red [in,out] β€” data pointer to RED runtime data
  • q [in] β€” current queue size (measured in packets)

Returns

Operation status

Return values

  • 0 β€” enqueue the packet
  • 1 β€” drop the packet based on max threshold criterion
  • 2 β€” drop the packet based on mark probability criterion

EWMA filter (Sally Floyd and Van Jacobson):

avg = (1 - wq) * avg + wq * q
avg = avg + q * wq - avg * wq

We select: wq = 2^(-n). Let scaled version of avg be: avg_s = avg * 2^(N+n). We get: avg_s = avg_s + q * 2^N - avg_s * 2^(-n)

By using shift left/right operations, we get:

avg_s = avg_s + (q << N) - (avg_s >> n)
avg_s += (q << N) - (avg_s >> n)

bit shifts doing the absolute most, we love to see it. πŸ”₯

Definition at line 313 of file rte_red.h.

πŸ’… static int rte_red_enqueue (const struct rte_red_config * red_cfg, struct rte_red * red, const unsigned q, const uint64_t time) [inline], [static]

Decides if new packet should be enqueued or dropped. Updates run time data based on new queue size value. Based on new queue average and RED configuration parameters gives verdict whether to enqueue or drop the packet. the judge, the jury, the whole courtroom. πŸ‘‘

Parameters

  • red_cfg [in] β€” config pointer to a RED configuration parameter structure
  • red [in,out] β€” data pointer to RED runtime data
  • q [in] β€” updated queue size in packets
  • time [in] β€” current time stamp

Returns

Operation status

Return values

  • 0 β€” enqueue the packet
  • 1 β€” drop the packet based on max threshold criteria
  • 2 β€” drop the packet based on mark probability criteria

Definition at line 375 of file rte_red.h.

πŸ’… static void rte_red_mark_queue_empty (struct rte_red * red, const uint64_t time) [inline], [static]

Callback to records time that queue became empty. writing down the moment, for the memories. πŸŽ€

Parameters

  • red [in,out] β€” data pointer to RED runtime data
  • time [in] β€” current time stamp

Definition at line 397 of file rte_red.h.


🌟 Variable Documentation 🌟

πŸ’œ uint32_t rte_red_rand_val [extern]

Externs. that's it, that's the whole note. humble. πŸ™ˆ


πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for DPDK from the source code. not a human, just doxygen doing its lil thing. πŸ€–βœ¨


and that's the whole page bestie!! this was Version 25.11.0, dated Fri Jan 30 2026, and it was rte_red.h(3) the entire time. you ate that. periodt. πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from