shithub: riscv

Download patch

ref: d13142b3daba5e76646cd36f718a1ff5ae9e25d4
parent: ce9cc8a358cad7be3561554a7ebfd06f7af5360f
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Dec 27 20:24:38 EST 2017

etheriwl, etherwpi: limit transmit queue buffer bloat to 48k (at 22Mbit ≅ 20ms)

--- a/sys/src/9/pc/etheriwl.c
+++ b/sys/src/9/pc/etheriwl.c
@@ -19,8 +19,12 @@
 #include "wifi.h"
 
 enum {
+	MaxQueue	= 24*1024,	/* total buffer is 2*MaxQueue: 48k at 22Mbit ≅ 20ms */
+
 	Ntxlog		= 8,
 	Ntx		= 1<<Ntxlog,
+	Ntxqmax		= MaxQueue/1500,
+
 	Nrxlog		= 8,
 	Nrx		= 1<<Nrxlog,
 
@@ -1666,7 +1670,7 @@
 txqready(void *arg)
 {
 	TXQ *q = arg;
-	return q->n < Ntx;
+	return q->n < Ntxqmax;
 }
 
 static char*
@@ -1680,11 +1684,11 @@
 
 	ilock(ctlr);
 	q = &ctlr->tx[qid];
-	while(q->n >= Ntx && !ctlr->broken){
+	while(q->n >= Ntxqmax && !ctlr->broken){
 		iunlock(ctlr);
 		qlock(q);
 		if(!waserror()){
-			tsleep(q, txqready, q, 10);
+			tsleep(q, txqready, q, 5);
 			poperror();
 		}
 		qunlock(q);
@@ -1929,6 +1933,7 @@
 	{   4,  20, RFlagCCK },
 	{  11,  55, RFlagCCK },
 	{  22, 110, RFlagCCK },
+
 	{  12, 0xd, 0 },
 	{  18, 0xf, 0 },
 	{  24, 0x5, 0 },
@@ -1945,6 +1950,7 @@
 	0x80 | 4,
 	0x80 | 11,
 	0x80 | 22,
+
 	0x80 | 12,
 	0x80 | 18,
 	0x80 | 24,
@@ -2026,12 +2032,12 @@
 				flags |= TFlagFullTxOp;
 		}
 	}
+	if(p >= wifi->rates)
+		rate = p - wifi->rates;
+	else
+		rate = 0;
 	qunlock(ctlr);
 
-	rate = 0;
-	if(p >= iwlrates && p < &iwlrates[nelem(ratetab)])
-		rate = p - iwlrates;
-
 	/* select first available antenna */
 	ant = ctlr->rfcfg.txantmask & 7;
 	ant |= (ant == 0);
@@ -2192,6 +2198,8 @@
 			error("wifi disabled by switch");
 
 		if(ctlr->wifi == nil){
+			qsetlimit(edev->oq, MaxQueue);
+
 			ctlr->wifi = wifiattach(edev, transmit);
 			/* tested with 2230, it has transmit issues using higher bit rates */
 			if(ctlr->type != Type2030)
--- a/sys/src/9/pc/etherwpi.c
+++ b/sys/src/9/pc/etherwpi.c
@@ -11,15 +11,20 @@
 #include "wifi.h"
 
 enum {
-	Nrxlog = 6,
-	Nrx    = 1<<Nrxlog,
-	Ntx    = 256,
+	MaxQueue	= 24*1024,	/* total buffer is 2*MaxQueue: 48k at 22Mbit ≅ 20ms */
 
-	Rbufsize = 3*1024,
-	Rdscsize = 8,
+	Ntxlog		= 8,
+	Ntx		= 1<<Ntxlog,
+	Ntxqmax		= MaxQueue/1500,
 
-	Tdscsize = 64,
-	Tcmdsize = 128,
+	Nrxlog		= 6,
+	Nrx		= 1<<Nrxlog,
+
+	Rbufsize	= 3*1024,
+	Rdscsize	= 8,
+
+	Tdscsize	= 64,
+	Tcmdsize	= 128,
 };
 
 /* registers */
@@ -956,7 +961,7 @@
 txqready(void *arg)
 {
 	TXQ *q = arg;
-	return q->n < Ntx;
+	return q->n < Ntxqmax;
 }
 
 static char*
@@ -971,11 +976,11 @@
 
 	ilock(ctlr);
 	q = &ctlr->tx[qid];
-	while(q->n >= Ntx && !ctlr->broken){
+	while(q->n >= Ntxqmax && !ctlr->broken){
 		iunlock(ctlr);
 		qlock(q);
 		if(!waserror()){
-			tsleep(q, txqready, q, 10);
+			tsleep(q, txqready, q, 5);
 			poperror();
 		}
 		qunlock(q);
@@ -1144,6 +1149,7 @@
 	0x80 | 72,
 	0x80 | 96,
 	0x80 | 108,
+
 	0x80 | 2,
 	0x80 | 4,
 	0x80 | 11,
@@ -1164,6 +1170,7 @@
 	{  72, 0xb },
 	{  96, 0x1 },
 	{ 108, 0x3 },
+
 	{   2,  10 },
 	{   4,  20 },
 	{  11,  55 },
@@ -1436,12 +1443,12 @@
 			p = wn->actrate;
 		}
 	}
+	if(p >= wifi->rates)
+		rate = p - wifi->rates;
+	else
+		rate = 0;
 	qunlock(ctlr);
 
-	rate = 0;
-	if(p >= wpirates && p < &wpirates[nelem(ratetab)])
-		rate = p - wpirates;
-
 	memset(p = c, 0, sizeof(c));
 	put16(p, BLEN(b)), p += 2;
 	put16(p, 0), p += 2;	/* lnext */
@@ -1582,6 +1589,8 @@
 			error("wifi disabled by switch");
 
 		if(ctlr->wifi == nil){
+			qsetlimit(edev->oq, MaxQueue);
+
 			ctlr->wifi = wifiattach(edev, transmit);
 			ctlr->wifi->rates = wpirates;
 		}