netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/4] pie: minor improvements
@ 2020-03-04 18:55 Leslie Monis
  2020-03-04 18:55 ` [PATCH net-next v2 1/4] pie: use term backlog instead of qlen Leslie Monis
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Leslie Monis @ 2020-03-04 18:55 UTC (permalink / raw)
  To: netdev; +Cc: davem, tahiliani, gautamramk

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.

Leslie Monis (4):
  pie: use term backlog instead of qlen
  pie: remove unnecessary type casting
  pie: remove pie_vars->accu_prob_overflows
  pie: realign comment

 include/net/pie.h      | 31 +++++++++++++---------------
 net/sched/sch_fq_pie.c |  1 -
 net/sched/sch_pie.c    | 47 +++++++++++++++++-------------------------
 3 files changed, 33 insertions(+), 46 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 1/4] pie: use term backlog instead of qlen
  2020-03-04 18:55 [PATCH net-next v2 0/4] pie: minor improvements Leslie Monis
@ 2020-03-04 18:55 ` Leslie Monis
  2020-03-04 18:56 ` [PATCH net-next v2 2/4] pie: remove unnecessary type casting Leslie Monis
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Leslie Monis @ 2020-03-04 18:55 UTC (permalink / raw)
  To: netdev; +Cc: davem, tahiliani, gautamramk

Remove ambiguity by using the term backlog instead of qlen when
representing the queue length in bytes.

Signed-off-by: Mohit P. Tahiliani <tahiliani@nitk.edu.in>
Signed-off-by: Gautam Ramakrishnan <gautamramk@gmail.com>
Signed-off-by: Leslie Monis <lesliemonis@gmail.com>
---
 include/net/pie.h   | 10 +++++-----
 net/sched/sch_pie.c | 22 +++++++++++-----------
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/include/net/pie.h b/include/net/pie.h
index fd5a37cb7993..24f68c1e9919 100644
--- a/include/net/pie.h
+++ b/include/net/pie.h
@@ -46,7 +46,7 @@ struct pie_params {
  * @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
+ * @backlog_old:		queue backlog during previous qdelay calculation
  * @accu_prob_overflows:	number of times accu_prob overflows
  */
 struct pie_vars {
@@ -58,7 +58,7 @@ struct pie_vars {
 	u64 accu_prob;
 	u64 dq_count;
 	u32 avg_dq_rate;
-	u32 qlen_old;
+	u32 backlog_old;
 	u8 accu_prob_overflows;
 };
 
@@ -127,12 +127,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
diff --git a/net/sched/sch_pie.c b/net/sched/sch_pie.c
index 915bcdb59a9f..8a2f9f11c86f 100644
--- a/net/sched/sch_pie.c
+++ b/net/sched/sch_pie.c
@@ -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;
@@ -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
@@ -215,7 +215,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;
@@ -231,7 +231,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)
@@ -244,7 +244,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;
 	}
@@ -283,7 +283,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;
@@ -307,7 +307,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 */
@@ -322,7 +322,7 @@ 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 {
@@ -330,10 +330,10 @@ void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,
 		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
@@ -409,7 +409,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
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 2/4] pie: remove unnecessary type casting
  2020-03-04 18:55 [PATCH net-next v2 0/4] pie: minor improvements Leslie Monis
  2020-03-04 18:55 ` [PATCH net-next v2 1/4] pie: use term backlog instead of qlen Leslie Monis
@ 2020-03-04 18:56 ` Leslie Monis
  2020-03-04 18:56 ` [PATCH net-next v2 3/4] pie: remove pie_vars->accu_prob_overflows Leslie Monis
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Leslie Monis @ 2020-03-04 18:56 UTC (permalink / raw)
  To: netdev; +Cc: davem, tahiliani, gautamramk

In function pie_calculate_probability(), the variables alpha and
beta are of type u64. The variables qdelay, qdelay_old and
params->target are of type psched_time_t (which is also u64).
The explicit type casting done when calculating the value for
the variable delta is redundant and not required.

Signed-off-by: Mohit P. Tahiliani <tahiliani@nitk.edu.in>
Signed-off-by: Gautam Ramakrishnan <gautamramk@gmail.com>
Signed-off-by: Leslie Monis <lesliemonis@gmail.com>
---
 net/sched/sch_pie.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/sched/sch_pie.c b/net/sched/sch_pie.c
index 8a2f9f11c86f..198cfa34a00a 100644
--- a/net/sched/sch_pie.c
+++ b/net/sched/sch_pie.c
@@ -363,8 +363,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;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 3/4] pie: remove pie_vars->accu_prob_overflows
  2020-03-04 18:55 [PATCH net-next v2 0/4] pie: minor improvements Leslie Monis
  2020-03-04 18:55 ` [PATCH net-next v2 1/4] pie: use term backlog instead of qlen Leslie Monis
  2020-03-04 18:56 ` [PATCH net-next v2 2/4] pie: remove unnecessary type casting Leslie Monis
@ 2020-03-04 18:56 ` Leslie Monis
  2020-03-04 18:56 ` [PATCH net-next v2 4/4] pie: realign comment Leslie Monis
  2020-03-04 20:49 ` [PATCH net-next v2 0/4] pie: minor improvements Jakub Kicinski
  4 siblings, 0 replies; 7+ messages in thread
From: Leslie Monis @ 2020-03-04 18:56 UTC (permalink / raw)
  To: netdev; +Cc: davem, tahiliani, gautamramk

The variable pie_vars->accu_prob is used as an accumulator for
probability values. Since probabilty values are scaled using the
MAX_PROB macro denoting (2^64 - 1), pie_vars->accu_prob is
likely to overflow as it is of type u64.

The variable pie_vars->accu_prob_overflows counts the number of
times the variable pie_vars->accu_prob overflows.

The MAX_PROB macro needs to be equal to at least (2^39 - 1) in
order to do precise calculations without any underflow. Thus
MAX_PROB can be reduced to (2^56 - 1) without affecting the
precision in calculations drastically. Doing so will eliminate
the need for the variable pie_vars->accu_prob_overflows as the
variable pie_vars->accu_prob will never overflow.

Removing the variable pie_vars->accu_prob_overflows also reduces
the size of the structure pie_vars to exactly 64 bytes.

Signed-off-by: Mohit P. Tahiliani <tahiliani@nitk.edu.in>
Signed-off-by: Gautam Ramakrishnan <gautamramk@gmail.com>
Signed-off-by: Leslie Monis <lesliemonis@gmail.com>
---
 include/net/pie.h      |  5 +----
 net/sched/sch_fq_pie.c |  1 -
 net/sched/sch_pie.c    | 21 ++++++---------------
 3 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/include/net/pie.h b/include/net/pie.h
index 24f68c1e9919..1c645b76a2ed 100644
--- a/include/net/pie.h
+++ b/include/net/pie.h
@@ -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
@@ -47,7 +47,6 @@ struct pie_params {
  * @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
- * @accu_prob_overflows:	number of times accu_prob overflows
  */
 struct pie_vars {
 	psched_time_t qdelay;
@@ -59,7 +58,6 @@ struct pie_vars {
 	u64 dq_count;
 	u32 avg_dq_rate;
 	u32 backlog_old;
-	u8 accu_prob_overflows;
 };
 
 /**
@@ -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)
diff --git a/net/sched/sch_fq_pie.c b/net/sched/sch_fq_pie.c
index 214657eb3dfd..a9da8776bf5b 100644
--- a/net/sched/sch_fq_pie.c
+++ b/net/sched/sch_fq_pie.c
@@ -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;
diff --git a/net/sched/sch_pie.c b/net/sched/sch_pie.c
index 198cfa34a00a..f52442d39bf5 100644
--- a/net/sched/sch_pie.c
+++ b/net/sched/sch_pie.c
@@ -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;
 	}
 
@@ -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);
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 4/4] pie: realign comment
  2020-03-04 18:55 [PATCH net-next v2 0/4] pie: minor improvements Leslie Monis
                   ` (2 preceding siblings ...)
  2020-03-04 18:56 ` [PATCH net-next v2 3/4] pie: remove pie_vars->accu_prob_overflows Leslie Monis
@ 2020-03-04 18:56 ` Leslie Monis
  2020-03-04 20:49 ` [PATCH net-next v2 0/4] pie: minor improvements Jakub Kicinski
  4 siblings, 0 replies; 7+ messages in thread
From: Leslie Monis @ 2020-03-04 18:56 UTC (permalink / raw)
  To: netdev; +Cc: davem, tahiliani, gautamramk

Realign a comment after the change introduced by the
previous patch.

Signed-off-by: Leslie Monis <lesliemonis@gmail.com>
---
 include/net/pie.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/net/pie.h b/include/net/pie.h
index 1c645b76a2ed..3fe2361e03b4 100644
--- a/include/net/pie.h
+++ b/include/net/pie.h
@@ -38,15 +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
- * @backlog_old:		queue backlog during previous qdelay calculation
+ * @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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 0/4] pie: minor improvements
  2020-03-04 18:55 [PATCH net-next v2 0/4] pie: minor improvements Leslie Monis
                   ` (3 preceding siblings ...)
  2020-03-04 18:56 ` [PATCH net-next v2 4/4] pie: realign comment Leslie Monis
@ 2020-03-04 20:49 ` Jakub Kicinski
  2020-03-04 21:26   ` David Miller
  4 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2020-03-04 20:49 UTC (permalink / raw)
  To: Leslie Monis; +Cc: netdev, davem, tahiliani, gautamramk

On Thu,  5 Mar 2020 00:25:58 +0530 Leslie Monis wrote:
> 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.

I was wondering if patch 3 changes make user-visible changes but it
seems those should be only slight accuracy adjustments, so LGTM. FWIW:

Reviewed-by: Jakub Kicinski <kuba@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 0/4] pie: minor improvements
  2020-03-04 20:49 ` [PATCH net-next v2 0/4] pie: minor improvements Jakub Kicinski
@ 2020-03-04 21:26   ` David Miller
  0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2020-03-04 21:26 UTC (permalink / raw)
  To: kuba; +Cc: lesliemonis, netdev, tahiliani, gautamramk

From: Jakub Kicinski <kuba@kernel.org>
Date: Wed, 4 Mar 2020 12:49:17 -0800

> On Thu,  5 Mar 2020 00:25:58 +0530 Leslie Monis wrote:
>> 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.
> 
> I was wondering if patch 3 changes make user-visible changes but it
> seems those should be only slight accuracy adjustments, so LGTM. FWIW:
> 
> Reviewed-by: Jakub Kicinski <kuba@kernel.org>

Series applied, thanks everyone.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-03-04 21:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-04 18:55 [PATCH net-next v2 0/4] pie: minor improvements Leslie Monis
2020-03-04 18:55 ` [PATCH net-next v2 1/4] pie: use term backlog instead of qlen Leslie Monis
2020-03-04 18:56 ` [PATCH net-next v2 2/4] pie: remove unnecessary type casting Leslie Monis
2020-03-04 18:56 ` [PATCH net-next v2 3/4] pie: remove pie_vars->accu_prob_overflows Leslie Monis
2020-03-04 18:56 ` [PATCH net-next v2 4/4] pie: realign comment Leslie Monis
2020-03-04 20:49 ` [PATCH net-next v2 0/4] pie: minor improvements Jakub Kicinski
2020-03-04 21:26   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).