From nobody  Thu Jul  3 05:57:18 1997
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.5/8.8.5) id FAA08386;
          Thu, 3 Jul 1997 05:57:18 -0700 (PDT)
Message-Id: <199707031257.FAA08386@hub.freebsd.org>
Date: Thu, 3 Jul 1997 05:57:18 -0700 (PDT)
From: itojun@itojun.org
To: freebsd-gnats-submit@freebsd.org
Subject: vxget() in /sys/dev/vx/if_vx.c needs rework
X-Send-Pr-Version: www-1.0

>Number:         4020
>Category:       kern
>Synopsis:       vxget() in /sys/dev/vx/if_vx.c needs rework
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    itojun
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jul  3 06:00:01 PDT 1997
>Closed-Date:    Tue Sep 30 22:59:30 PDT 1997
>Last-Modified:  Tue Sep 30 23:01:08 PDT 1997
>Originator:     Jun-ichiro Itoh
>Release:        2.2.1-RELEASE
>Organization:
>Environment:
libretto30
>Description:
vxget() in if_vx.c almost always store packet into multiple mbufs.
It makes upper-layer protocol processing slightly slower.
The code looks awful (I'm not attacking the author, sorry) and
can be simplified/can be made more readable.

it would be better if:
	packet > MHLEN to be put into single external mbuf
	otherwise store into single internal mbuf


The problem still remains in the latest source in CVS branch.

>How-To-Repeat:
none
>Fix:
I'll try it later if nobody does it.
>Release-Note:
>Audit-Trail:

From: itojun@itojun.org
To: FreeBSD-gnats-submit@freebsd.org
Cc:  Subject: Re: kern/4020: vxget() in /sys/dev/vx/if_vx.c needs rework
Date: Fri, 04 Jul 1997 01:34:13 +0900

 	how about this?
 	(if_vx.c- is based on 2.2.1-RELEASE source code)
 
 itojun
 
 
 ---
 *** if_vx.c-	Fri Jul  4 09:39:38 1997
 --- if_vx.c	Fri Jul  4 10:33:36 1997
 ***************
 *** 820,832 ****
   }
   
   static struct mbuf *
 ! vxget(sc, totlen)
       struct vx_softc *sc;
 !     u_int totlen;
   {
       struct ifnet *ifp = &sc->arpcom.ac_if;
 !     struct mbuf *top, **mp, *m;
 !     int len;
       int sh;
   
       m = sc->mb[sc->next_mb];
 --- 820,831 ----
   }
   
   static struct mbuf *
 ! vxget(sc, len)
       struct vx_softc *sc;
 !     u_int len;
   {
       struct ifnet *ifp = &sc->arpcom.ac_if;
 !     struct mbuf *m;
       int sh;
   
       m = sc->mb[sc->next_mb];
 ***************
 *** 845,854 ****
           m->m_flags = M_PKTHDR;
       }
       m->m_pkthdr.rcvif = ifp;
 !     m->m_pkthdr.len = totlen;
 !     len = MHLEN;
 !     top = 0;
 !     mp = &top;
   
       /*
        * We read the packet at splhigh() so that an interrupt from another
 --- 844,850 ----
           m->m_flags = M_PKTHDR;
       }
       m->m_pkthdr.rcvif = ifp;
 !     m->m_pkthdr.len = len;
   
       /*
        * We read the packet at splhigh() so that an interrupt from another
 ***************
 *** 857,902 ****
        */
       sh = splhigh();
   
 !     while (totlen > 0) {
 !         if (top) {
 !             m = sc->mb[sc->next_mb];
 !             sc->mb[sc->next_mb] = 0;
 !             if (m == 0) {
 !                 MGET(m, M_DONTWAIT, MT_DATA);
 !                 if (m == 0) {
 !                     splx(sh);
 !                     m_freem(top);
 !                     return 0;
 !                 }
 !             } else {
 !                 sc->next_mb = (sc->next_mb + 1) % MAX_MBS;
 !             }
 !             len = MLEN;
 !         }
 !         if (totlen >= MINCLSIZE) {
 !         MCLGET(m, M_DONTWAIT);
 !         if (m->m_flags & M_EXT)
 !             len = MCLBYTES;
 !         }
 !         len = min(totlen, len);
 !         if (len > 3) {
 !             len &= ~3;
 !             insl(BASE + VX_W1_RX_PIO_RD_1, mtod(m, u_int32_t *),
 !                 len / 4);
 !         } else
 !             insb(BASE + VX_W1_RX_PIO_RD_1, mtod(m, u_int8_t *),
 !                 len);
 !         m->m_len = len;
 !         totlen -= len;
 !         *mp = m;
 !         mp = &m->m_next;
       }
   
       outw(BASE +VX_COMMAND, RX_DISCARD_TOP_PACK);
   
       splx(sh);
   
 !     return top;
   }
   
   
 --- 853,881 ----
        */
       sh = splhigh();
   
 !     if (MHLEN < len) {
 ! 	/* assumes ETHERMTU < MCLBYTES */
 ! 	MCLGET(m, M_DONTWAIT);
 ! 	if (! (m->m_flags & M_EXT)) {
 ! 	    m_freem(m);
 ! 	    goto fail;
 ! 	}
 !     }
 !     m->m_len = len;
 !     insl(BASE + VX_W1_RX_PIO_RD_1, mtod(m, u_int32_t *), len / 4);
 !     if (len & 3) {
 ! 	insb(BASE + VX_W1_RX_PIO_RD_1, mtod(m, u_int8_t *) + (len & ~3),
 ! 	    len & 3);
       }
   
       outw(BASE +VX_COMMAND, RX_DISCARD_TOP_PACK);
   
       splx(sh);
 +     return m;
   
 ! fail:
 !     splx(sh);
 !     return NULL;
   }
   
   
Responsible-Changed-From-To: freebsd-bugs->itojun 
Responsible-Changed-By: davidg 
Responsible-Changed-When: Fri Jul 25 16:36:08 PDT 1997 
Responsible-Changed-Why:  
Assigned to itojun. I have no problem with the proposed change as long as 
the test is changed from (MHLEN < len) to (len > MHLEN). 

From: Jun-ichiro Itoh <itojun@itojun.org>
To: freebsd-gnats-submit@freebsd.org, itojun@itojun.org
Cc:  Subject: Re: kern/4020: vxget() in /sys/dev/vx/if_vx.c needs rework
Date: Tue, 05 Aug 1997 13:12:42 +0900

 just to announce the current situation.
 i've got my patch reviewed by the author, however my main
 machine crushed (motherboard dead?) so i can't patch/test/commit it
 myself right now. pls hold for few days.
 
 itojun
State-Changed-From-To: open->closed 
State-Changed-By: itojun 
State-Changed-When: Tue Sep 30 22:59:30 PDT 1997 
State-Changed-Why:  

finally committed as src/sys/dev/vx/if_vx.c, 1.10 -> 1.11. 
(RELENG_2_2 1.2.2.3 -> 1.2.2.4) 
sorry that it took too much time. 
>Unformatted:
