Skip to content

Commit

Permalink
Merge branch 'pie-minor-improvements'
Browse files Browse the repository at this point in the history
Leslie Monis says:

====================
pie: minor improvements

This patch series includes the following minor changes with
respect to the PIE/FQ-PIE qdiscs:

 - Patch 1 removes some ambiguity by using the term "backlog"
           instead of "qlen" when referring to the queue length
           in bytes.
 - Patch 2 removes redundant type casting on two expressions.
 - Patch 3 removes the pie_vars->accu_prob_overflows variable
           without affecting the precision in calculations and
           makes the size of the pie_vars structure exactly 64
           bytes.
 - Patch 4 realigns a comment affected by a change in patch 3.

Changes from v1 to v2:
 - Kept 8 as the argument to prandom_bytes() instead of changing it
   to 7 as suggested by David Miller.
====================

Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Mar 4, 2020
2 parents ef71037 + 5c5840e commit f6f8ef9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 46 deletions.
31 changes: 14 additions & 17 deletions include/net/pie.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <net/inet_ecn.h>
#include <net/pkt_sched.h>

#define MAX_PROB U64_MAX
#define MAX_PROB (U64_MAX >> BITS_PER_BYTE)
#define DTIME_INVALID U64_MAX
#define QUEUE_THRESHOLD 16384
#define DQCOUNT_INVALID -1
Expand Down Expand Up @@ -38,16 +38,15 @@ struct pie_params {

/**
* struct pie_vars - contains pie variables
* @qdelay: current queue delay
* @qdelay_old: queue delay in previous qdelay calculation
* @burst_time: burst time allowance
* @dq_tstamp: timestamp at which dq rate was last calculated
* @prob: drop probability
* @accu_prob: accumulated drop probability
* @dq_count: number of bytes dequeued in a measurement cycle
* @avg_dq_rate: calculated average dq rate
* @qlen_old: queue length during previous qdelay calculation
* @accu_prob_overflows: number of times accu_prob overflows
* @qdelay: current queue delay
* @qdelay_old: queue delay in previous qdelay calculation
* @burst_time: burst time allowance
* @dq_tstamp: timestamp at which dq rate was last calculated
* @prob: drop probability
* @accu_prob: accumulated drop probability
* @dq_count: number of bytes dequeued in a measurement cycle
* @avg_dq_rate: calculated average dq rate
* @backlog_old: queue backlog during previous qdelay calculation
*/
struct pie_vars {
psched_time_t qdelay;
Expand All @@ -58,8 +57,7 @@ struct pie_vars {
u64 accu_prob;
u64 dq_count;
u32 avg_dq_rate;
u32 qlen_old;
u8 accu_prob_overflows;
u32 backlog_old;
};

/**
Expand Down Expand Up @@ -107,7 +105,6 @@ static inline void pie_vars_init(struct pie_vars *vars)
vars->accu_prob = 0;
vars->dq_count = DQCOUNT_INVALID;
vars->avg_dq_rate = 0;
vars->accu_prob_overflows = 0;
}

static inline struct pie_skb_cb *get_pie_cb(const struct sk_buff *skb)
Expand All @@ -127,12 +124,12 @@ static inline void pie_set_enqueue_time(struct sk_buff *skb)
}

bool pie_drop_early(struct Qdisc *sch, struct pie_params *params,
struct pie_vars *vars, u32 qlen, u32 packet_size);
struct pie_vars *vars, u32 backlog, u32 packet_size);

void pie_process_dequeue(struct sk_buff *skb, struct pie_params *params,
struct pie_vars *vars, u32 qlen);
struct pie_vars *vars, u32 backlog);

void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,
u32 qlen);
u32 backlog);

#endif
1 change: 0 additions & 1 deletion net/sched/sch_fq_pie.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ static int fq_pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
out:
q->stats.dropped++;
sel_flow->vars.accu_prob = 0;
sel_flow->vars.accu_prob_overflows = 0;
__qdisc_drop(skb, to_free);
qdisc_qstats_drop(sch);
return NET_XMIT_CN;
Expand Down
47 changes: 19 additions & 28 deletions net/sched/sch_pie.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct pie_sched_data {
};

bool pie_drop_early(struct Qdisc *sch, struct pie_params *params,
struct pie_vars *vars, u32 qlen, u32 packet_size)
struct pie_vars *vars, u32 backlog, u32 packet_size)
{
u64 rnd;
u64 local_prob = vars->prob;
Expand All @@ -51,7 +51,7 @@ bool pie_drop_early(struct Qdisc *sch, struct pie_params *params,
/* If we have fewer than 2 mtu-sized packets, disable pie_drop_early,
* similar to min_th in RED
*/
if (qlen < 2 * mtu)
if (backlog < 2 * mtu)
return false;

/* If bytemode is turned on, use packet size to compute new
Expand All @@ -62,27 +62,19 @@ bool pie_drop_early(struct Qdisc *sch, struct pie_params *params,
else
local_prob = vars->prob;

if (local_prob == 0) {
if (local_prob == 0)
vars->accu_prob = 0;
vars->accu_prob_overflows = 0;
}

if (local_prob > MAX_PROB - vars->accu_prob)
vars->accu_prob_overflows++;

vars->accu_prob += local_prob;
else
vars->accu_prob += local_prob;

if (vars->accu_prob_overflows == 0 &&
vars->accu_prob < (MAX_PROB / 100) * 85)
if (vars->accu_prob < (MAX_PROB / 100) * 85)
return false;
if (vars->accu_prob_overflows == 8 &&
vars->accu_prob >= MAX_PROB / 2)
if (vars->accu_prob >= (MAX_PROB / 2) * 17)
return true;

prandom_bytes(&rnd, 8);
if (rnd < local_prob) {
if ((rnd >> BITS_PER_BYTE) < local_prob) {
vars->accu_prob = 0;
vars->accu_prob_overflows = 0;
return true;
}

Expand Down Expand Up @@ -129,7 +121,6 @@ static int pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
out:
q->stats.dropped++;
q->vars.accu_prob = 0;
q->vars.accu_prob_overflows = 0;
return qdisc_drop(skb, sch, to_free);
}

Expand Down Expand Up @@ -215,7 +206,7 @@ static int pie_change(struct Qdisc *sch, struct nlattr *opt,
}

void pie_process_dequeue(struct sk_buff *skb, struct pie_params *params,
struct pie_vars *vars, u32 qlen)
struct pie_vars *vars, u32 backlog)
{
psched_time_t now = psched_get_time();
u32 dtime = 0;
Expand All @@ -231,7 +222,7 @@ void pie_process_dequeue(struct sk_buff *skb, struct pie_params *params,

vars->dq_tstamp = now;

if (qlen == 0)
if (backlog == 0)
vars->qdelay = 0;

if (dtime == 0)
Expand All @@ -244,7 +235,7 @@ void pie_process_dequeue(struct sk_buff *skb, struct pie_params *params,
* we have enough packets to calculate the drain rate. Save
* current time as dq_tstamp and start measurement cycle.
*/
if (qlen >= QUEUE_THRESHOLD && vars->dq_count == DQCOUNT_INVALID) {
if (backlog >= QUEUE_THRESHOLD && vars->dq_count == DQCOUNT_INVALID) {
vars->dq_tstamp = psched_get_time();
vars->dq_count = 0;
}
Expand Down Expand Up @@ -283,7 +274,7 @@ void pie_process_dequeue(struct sk_buff *skb, struct pie_params *params,
* dq_count to 0 to re-enter the if block when the next
* packet is dequeued
*/
if (qlen < QUEUE_THRESHOLD) {
if (backlog < QUEUE_THRESHOLD) {
vars->dq_count = DQCOUNT_INVALID;
} else {
vars->dq_count = 0;
Expand All @@ -307,7 +298,7 @@ void pie_process_dequeue(struct sk_buff *skb, struct pie_params *params,
EXPORT_SYMBOL_GPL(pie_process_dequeue);

void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,
u32 qlen)
u32 backlog)
{
psched_time_t qdelay = 0; /* in pschedtime */
psched_time_t qdelay_old = 0; /* in pschedtime */
Expand All @@ -322,18 +313,18 @@ void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,
vars->qdelay_old = vars->qdelay;

if (vars->avg_dq_rate > 0)
qdelay = (qlen << PIE_SCALE) / vars->avg_dq_rate;
qdelay = (backlog << PIE_SCALE) / vars->avg_dq_rate;
else
qdelay = 0;
} else {
qdelay = vars->qdelay;
qdelay_old = vars->qdelay_old;
}

/* If qdelay is zero and qlen is not, it means qlen is very small,
/* If qdelay is zero and backlog is not, it means backlog is very small,
* so we do not update probabilty in this round.
*/
if (qdelay == 0 && qlen != 0)
if (qdelay == 0 && backlog != 0)
update_prob = false;

/* In the algorithm, alpha and beta are between 0 and 2 with typical
Expand Down Expand Up @@ -363,8 +354,8 @@ void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,
}

/* alpha and beta should be between 0 and 32, in multiples of 1/16 */
delta += alpha * (u64)(qdelay - params->target);
delta += beta * (u64)(qdelay - qdelay_old);
delta += alpha * (qdelay - params->target);
delta += beta * (qdelay - qdelay_old);

oldprob = vars->prob;

Expand Down Expand Up @@ -409,7 +400,7 @@ void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,
vars->prob -= vars->prob / 64;

vars->qdelay = qdelay;
vars->qlen_old = qlen;
vars->backlog_old = backlog;

/* We restart the measurement cycle if the following conditions are met
* 1. If the delay has been low for 2 consecutive Tupdate periods
Expand Down

0 comments on commit f6f8ef9

Please sign in to comment.