Hi,

the buffer sizes allocated in the tty layer are too small for todays use 
cases like l2tp and virtio-console. Also, the watermarks used by ppp are 
way to small and do not scale with the line speed.

This patch

- makes 115200 the default speed for buffer sizing in ttymalloc(). A lot 
of devices call ttymalloc(0) so this affects quite a few of them.

- increases the buffer size for 9600 < baud <= 115200 from 1k to 4k

- makes ppp use the lo/hi watermarks from the tty layer which are adjusted 
according to speed + buffer size. The previous fixed values of 100 and 400 
were way too small

- make pty call ttymalloc with baud == 1000000, which is the common value 
used in the tree for "fast".


A slightly different variant of these changes were suggested and tested by 
Sergey Ryazanov. They result in significant speed-up when sending data 
with l2tp. I have also seen similar speed-up with the viocon driver.

I am looking for OKs, comments, additional testers (especially normal ppp 
(not l2tp)).

Cheers,
Stefan


diff --git sys/kern/tty.c sys/kern/tty.c
index b276061..c9230be 100644
--- sys/kern/tty.c
+++ sys/kern/tty.c
@@ -2330,8 +2330,13 @@ ttymalloc(int baud)
 
        tp = malloc(sizeof(struct tty), M_TTYS, M_WAITOK|M_ZERO);
 
-       if (baud <= 115200)
+       if (baud == 0)
+               baud = 115200;
+
+       if (baud <= 9600)
                tp->t_qlen = 1024;
+       else if (baud <= 115200)
+               tp->t_qlen = 4096;
        else
                tp->t_qlen = 8192;
        clalloc(&tp->t_rawq, tp->t_qlen, 1);
diff --git sys/kern/tty_pty.c sys/kern/tty_pty.c
index 40b2db2..de009b8 100644
--- sys/kern/tty_pty.c
+++ sys/kern/tty_pty.c
@@ -193,7 +193,7 @@ check_pty(int minor)
        if (!pt_softc[minor]) {
                pti = malloc(sizeof(struct pt_softc), M_DEVBUF,
                    M_WAITOK|M_ZERO);
-               pti->pt_tty = ttymalloc(0);
+               pti->pt_tty = ttymalloc(1000000);
                ptydevname(minor, pti);
                pt_softc[minor] = pti;
        }
@@ -235,7 +235,7 @@ ptsopen(dev_t dev, int flag, int devtype, struct proc *p)
 
        pti = pt_softc[minor(dev)];
        if (!pti->pt_tty) {
-               tp = pti->pt_tty = ttymalloc(0);
+               tp = pti->pt_tty = ttymalloc(1000000);
        } else
                tp = pti->pt_tty;
        if ((tp->t_state & TS_ISOPEN) == 0) {
@@ -245,7 +245,7 @@ ptsopen(dev_t dev, int flag, int devtype, struct proc *p)
                tp->t_oflag = TTYDEF_OFLAG;
                tp->t_lflag = TTYDEF_LFLAG;
                tp->t_cflag = TTYDEF_CFLAG;
-               tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
+               tp->t_ispeed = tp->t_ospeed = 1000000;
                ttsetwater(tp);         /* would be done in xxparam() */
        } else if (tp->t_state&TS_XCLUDE && suser(p, 0) != 0)
                return (EBUSY);
@@ -412,7 +412,7 @@ ptcopen(dev_t dev, int flag, int devtype, struct proc *p)
 
        pti = pt_softc[minor(dev)];
        if (!pti->pt_tty) {
-               tp = pti->pt_tty = ttymalloc(0);
+               tp = pti->pt_tty = ttymalloc(1000000);
        } else
                tp = pti->pt_tty;
        if (tp->t_oproc)
diff --git sys/net/ppp_tty.c sys/net/ppp_tty.c
index 186d4c7..94d9d4e 100644
--- sys/net/ppp_tty.c
+++ sys/net/ppp_tty.c
@@ -155,9 +155,6 @@ struct pool ppp_pkts;
 /* This is a NetBSD-1.0 or later kernel. */
 #define CCOUNT(q)      ((q)->c_cc)
 
-#define PPP_LOWAT      100     /* Process more output when < LOWAT on queue */
-#define        PPP_HIWAT       400     /* Don't start a new packet if HIWAT on 
queue */
-
 /*
  * Line specific open routine for async tty devices.
  * Attach the given tty to the first available ppp unit.
@@ -499,7 +496,7 @@ pppasyncstart(struct ppp_softc *sc)
     int s;
 
     idle = 0;
-    while (CCOUNT(&tp->t_outq) < PPP_HIWAT) {
+    while (CCOUNT(&tp->t_outq) < tp->t_hiwat) {
        /*
         * See if we have an existing packet partly sent.
         * If not, get a new packet and start sending it.
@@ -706,7 +703,7 @@ pppstart_internal(struct tty *tp, int force)
      * or been disconnected from the ppp unit, then tell if_ppp.c that
      * we need more output.
      */
-    if ((CCOUNT(&tp->t_outq) < PPP_LOWAT || force)
+    if ((CCOUNT(&tp->t_outq) < tp->t_lowat || force)
        && !((tp->t_state & TS_CARR_ON) == 0 && (tp->t_cflag & CLOCAL) == 0)
        && sc != NULL && tp == (struct tty *) sc->sc_devp) {
        ppp_restart(sc);

Reply via email to