Author: shurd
Date: Sat Sep 23 01:33:20 2017
New Revision: 323941
URL: https://svnweb.freebsd.org/changeset/base/323941

Log:
  Some small packet performance improvements
  
  If the packet is smaller than MTU, disable the TSO flags.
  Move TCP header parsing inside the IS_TSO?() test.
  Add a new IFLIB_NEED_ZERO_CSUM flag to indicate the checksums need to be 
zeroed before TX.
  
  Reviewed by:  sbruno
  Approved by:  sbruno (mentor)
  Sponsored by: Limelight Networks
  Differential Revision:        https://reviews.freebsd.org/D12442

Modified:
  head/sys/dev/e1000/if_em.c
  head/sys/net/iflib.c
  head/sys/net/iflib.h

Modified: head/sys/dev/e1000/if_em.c
==============================================================================
--- head/sys/dev/e1000/if_em.c  Fri Sep 22 22:19:56 2017        (r323940)
+++ head/sys/dev/e1000/if_em.c  Sat Sep 23 01:33:20 2017        (r323941)
@@ -483,7 +483,7 @@ static struct if_shared_ctx em_sctx_init = {
        .isc_vendor_info = em_vendor_info_array,
        .isc_driver_version = em_driver_version,
        .isc_driver = &em_if_driver,
-       .isc_flags = IFLIB_NEED_SCRATCH | IFLIB_TSO_INIT_IP,
+       .isc_flags = IFLIB_NEED_SCRATCH | IFLIB_TSO_INIT_IP | 
IFLIB_NEED_ZERO_CSUM,
 
        .isc_nrxd_min = {EM_MIN_RXD},
        .isc_ntxd_min = {EM_MIN_TXD},
@@ -511,7 +511,7 @@ static struct if_shared_ctx igb_sctx_init = {
        .isc_vendor_info = igb_vendor_info_array,
        .isc_driver_version = em_driver_version,
        .isc_driver = &em_if_driver,
-       .isc_flags = IFLIB_NEED_SCRATCH | IFLIB_TSO_INIT_IP,
+       .isc_flags = IFLIB_NEED_SCRATCH | IFLIB_TSO_INIT_IP | 
IFLIB_NEED_ZERO_CSUM,
 
        .isc_nrxd_min = {EM_MIN_RXD},
        .isc_ntxd_min = {EM_MIN_TXD},

Modified: head/sys/net/iflib.c
==============================================================================
--- head/sys/net/iflib.c        Fri Sep 22 22:19:56 2017        (r323940)
+++ head/sys/net/iflib.c        Sat Sep 23 01:33:20 2017        (r323941)
@@ -2696,6 +2696,10 @@ iflib_parse_header(iflib_txq_t txq, if_pkt_info_t pi, 
                pi->ipi_ehdrlen = ETHER_HDR_LEN;
        }
 
+       if (if_getmtu(txq->ift_ctx->ifc_ifp) >= pi->ipi_len) {
+               pi->ipi_csum_flags &= ~(CSUM_IP_TSO|CSUM_IP6_TSO);
+       }
+
        switch (pi->ipi_etype) {
 #ifdef INET
        case ETHERTYPE_IP:
@@ -2740,21 +2744,21 @@ iflib_parse_header(iflib_txq_t txq, if_pkt_info_t pi, 
                pi->ipi_ipproto = ip->ip_p;
                pi->ipi_flags |= IPI_TX_IPV4;
 
-               if (pi->ipi_csum_flags & CSUM_IP)
+               if ((sctx->isc_flags & IFLIB_NEED_ZERO_CSUM) && 
(pi->ipi_csum_flags & CSUM_IP))
                        ip->ip_sum = 0;
 
-               if (pi->ipi_ipproto == IPPROTO_TCP) {
-                       if (__predict_false(th == NULL)) {
-                               txq->ift_pullups++;
-                               if (__predict_false((m = m_pullup(m, (ip->ip_hl 
<< 2) + sizeof(*th))) == NULL))
-                                       return (ENOMEM);
-                               th = (struct tcphdr *)((caddr_t)ip + 
pi->ipi_ip_hlen);
-                       }
-                       pi->ipi_tcp_hflags = th->th_flags;
-                       pi->ipi_tcp_hlen = th->th_off << 2;
-                       pi->ipi_tcp_seq = th->th_seq;
-               }
                if (IS_TSO4(pi)) {
+                       if (pi->ipi_ipproto == IPPROTO_TCP) {
+                               if (__predict_false(th == NULL)) {
+                                       txq->ift_pullups++;
+                                       if (__predict_false((m = m_pullup(m, 
(ip->ip_hl << 2) + sizeof(*th))) == NULL))
+                                               return (ENOMEM);
+                                       th = (struct tcphdr *)((caddr_t)ip + 
pi->ipi_ip_hlen);
+                               }
+                               pi->ipi_tcp_hflags = th->th_flags;
+                               pi->ipi_tcp_hlen = th->th_off << 2;
+                               pi->ipi_tcp_seq = th->th_seq;
+                       }
                        if (__predict_false(ip->ip_p != IPPROTO_TCP))
                                return (ENXIO);
                        th->th_sum = in_pseudo(ip->ip_src.s_addr,
@@ -2785,15 +2789,15 @@ iflib_parse_header(iflib_txq_t txq, if_pkt_info_t pi, 
                pi->ipi_ipproto = ip6->ip6_nxt;
                pi->ipi_flags |= IPI_TX_IPV6;
 
-               if (pi->ipi_ipproto == IPPROTO_TCP) {
-                       if (__predict_false(m->m_len < pi->ipi_ehdrlen + 
sizeof(struct ip6_hdr) + sizeof(struct tcphdr))) {
-                               if (__predict_false((m = m_pullup(m, 
pi->ipi_ehdrlen + sizeof(struct ip6_hdr) + sizeof(struct tcphdr))) == NULL))
-                                       return (ENOMEM);
-                       }
-                       pi->ipi_tcp_hflags = th->th_flags;
-                       pi->ipi_tcp_hlen = th->th_off << 2;
-               }
                if (IS_TSO6(pi)) {
+                       if (pi->ipi_ipproto == IPPROTO_TCP) {
+                               if (__predict_false(m->m_len < pi->ipi_ehdrlen 
+ sizeof(struct ip6_hdr) + sizeof(struct tcphdr))) {
+                                       if (__predict_false((m = m_pullup(m, 
pi->ipi_ehdrlen + sizeof(struct ip6_hdr) + sizeof(struct tcphdr))) == NULL))
+                                               return (ENOMEM);
+                               }
+                               pi->ipi_tcp_hflags = th->th_flags;
+                               pi->ipi_tcp_hlen = th->th_off << 2;
+                       }
 
                        if (__predict_false(ip6->ip6_nxt != IPPROTO_TCP))
                                return (ENXIO);

Modified: head/sys/net/iflib.h
==============================================================================
--- head/sys/net/iflib.h        Fri Sep 22 22:19:56 2017        (r323940)
+++ head/sys/net/iflib.h        Sat Sep 23 01:33:20 2017        (r323941)
@@ -305,6 +305,10 @@ typedef enum {
  * Interface doesn't align IP header
  */
 #define IFLIB_DO_RX_FIXUP      0x40
+/*
+ * Driver needs csum zeroed for offloading
+ */
+#define IFLIB_NEED_ZERO_CSUM   0x80
 
 
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to