[ofw] [PATCH] use compiler intrinsics instead of complib 4 of 5

Smith, Stan stan.smith at intel.com
Tue Dec 28 15:07:32 PST 2010


Use compiler intrinsics and Ndis routines instead of complib routines for performance & debug.

cl_memclr --> NdisZeroMemory
cl_memcpy --> NdisMoveMemory
cl_memcmp --> memcmp
cl_memset --> memset

signed-off-by: stan smith <stan.smith at intel.com>

--- A/ulp/ipoib_NDIS6_CM/kernel/ipoib_port.cpp  Tue Dec 28 14:54:15 2010
+++ B/ulp/ipoib_NDIS6_CM/kernel/ipoib_port.cpp  Tue Dec 28 14:22:20 2010
@@ -645,7 +645,7 @@
        IN              const   void* const                                     p_key1,
        IN              const   void* const                                     p_key2 )
 {
-       return cl_memcmp( p_key1, p_key2, sizeof(ib_gid_t) );
+       return memcmp( p_key1, p_key2, sizeof(ib_gid_t) );
 }


@@ -1044,7 +1044,7 @@
 __ib_mgr_construct(
        IN                              ipoib_port_t* const                     p_port )
 {
-       cl_memclr( &p_port->ib_mgr, sizeof(ipoib_ib_mgr_t) );
+       NdisZeroMemory( &p_port->ib_mgr, sizeof(ipoib_ib_mgr_t) );
 }


@@ -1184,7 +1184,7 @@
        }

        /* Allocate the QP. */
-       cl_memclr( &qp_create, sizeof(qp_create) );
+       NdisZeroMemory( &qp_create, sizeof(qp_create) );
        qp_create.qp_type = IB_QPT_UNRELIABLE_DGRM;
        qp_create.rq_depth = p_port->p_adapter->params.rq_depth;
        qp_create.rq_sge = 2;   /* To support buffers spanning pages. */
@@ -1779,7 +1779,7 @@
         * Dereference the port object since the receive is no longer outstanding.
         */
        ipoib_port_deref( p_port, ref_get_recv );
-       IPOIB_EXIT(  IPOIB_DBG_RECV );
+       IPOIB_EXIT( IPOIB_DBG_RECV );
 }


@@ -2599,7 +2599,7 @@
                if( p_src )
                {
                        /* Don't report loopback traffic - we requested SW loopback. */
-                       if( !cl_memcmp( &p_port->p_adapter->params.conf_mac,
+                       if( !memcmp( &p_port->p_adapter->params.conf_mac,
                                &p_src->mac, sizeof(p_port->p_adapter->params.conf_mac) ) )
                        {
                                /*
@@ -3070,7 +3070,7 @@
         */
        if( *pp_src )
        {
-               if( cl_memcmp( &(*pp_src)->dgid, &p_ib_arp->src_hw.gid, sizeof(ib_gid_t) ) )
+               if( memcmp( &(*pp_src)->dgid, &p_ib_arp->src_hw.gid, sizeof(ib_gid_t) ) )
                {
                        /*
                         * GIDs for the endpoint are different.  The ARP must
@@ -3112,7 +3112,7 @@
        if( !*pp_src )
        {
                /* Copy the src GID to allow aligned access */
-               cl_memcpy( &gid, &p_ib_arp->src_hw.gid, sizeof(ib_gid_t) );
+               NdisMoveMemory( &gid, &p_ib_arp->src_hw.gid, sizeof(ib_gid_t) );
                status = ipoib_mac_from_guid( gid.unicast.interface_id,
                                                                          p_port->p_adapter->params.guid_mask,
                                                                          &mac );
@@ -3162,7 +3162,7 @@

        (*pp_src)->cm_flag = cm_capable;

-       CL_ASSERT( !cl_memcmp(
+       CL_ASSERT( !memcmp(
                &(*pp_src)->dgid, &p_ib_arp->src_hw.gid, sizeof(ib_gid_t) ) );
        CL_ASSERT( ipoib_is_voltaire_router_gid( &(*pp_src)->dgid ) ||
                (*pp_src)->qpn == ipoib_addr_get_qpn( &p_ib_arp->src_hw ) );
@@ -3204,9 +3204,9 @@
        p_arp->src_hw = (*pp_src)->mac;
        p_arp->src_ip = p_ib_arp->src_ip;

-       if( cl_memcmp( &p_ib_arp->dst_hw, &null_hw, sizeof(ipoib_hw_addr_t) ) )
+       if( memcmp( &p_ib_arp->dst_hw, &null_hw, sizeof(ipoib_hw_addr_t) ) )
        {
-               if( cl_memcmp( &p_dst->dgid, &p_ib_arp->dst_hw.gid, sizeof(ib_gid_t) ) )
+               if( memcmp( &p_dst->dgid, &p_ib_arp->dst_hw.gid, sizeof(ib_gid_t) ) )
                {
                        /*
                         * We received bcast ARP packet that means the remote port
@@ -3240,7 +3240,7 @@
        }
        else /* we got ARP request */
        {
-               cl_memclr( &p_arp->dst_hw, sizeof(mac_addr_t) );
+               NdisZeroMemory( &p_arp->dst_hw, sizeof(mac_addr_t) );
                p_arp->dst_ip = p_ib_arp->dst_ip;
        }

@@ -4504,7 +4504,7 @@
                // BUGBUG: need to add support for extension headers
                prot = ((ipv6_hdr_t *) p_ip_hdr)->next_header;
                hdr_size = sizeof(ipv6_hdr_t);
-                IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_SEND,("Got IPV6 Header\n" ) );
+               IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_SEND,("Got IPV6 Header\n" ) );
        }
        else //IPv4
        {
@@ -4845,14 +4845,14 @@
        //TODO: in this case we limited IP size to 20, but it can be bigger, according to GetIpPayloadPtr
        if ( ethertype == ETH_PROT_TYPE_IPV6 )
        {
-               cl_memcpy( &s_buf->p_send_buf->ipv6.hdr, p_ip_hdr , sizeof(ipv6_hdr_t) );
+               NdisMoveMemory( &s_buf->p_send_buf->ipv6.hdr, p_ip_hdr , sizeof(ipv6_hdr_t) );
        }
        else
        {
-               cl_memcpy( &s_buf->p_send_buf->ip.hdr, p_ip_hdr , sizeof(ip_hdr_t) );
+               NdisMoveMemory( &s_buf->p_send_buf->ip.hdr, p_ip_hdr , sizeof(ip_hdr_t) );
        }

-       cl_memcpy(
+       NdisMoveMemory(
                &s_buf->p_send_buf->ip.prot.udp.hdr, p_udp_hdr, sizeof(udp_hdr_t) );

        cl_perf_start( FilterDhcp );
@@ -4931,7 +4931,7 @@
        }

        p_ib_dhcp = &s_buf->p_send_buf->ip.prot.udp.dhcp;
-       cl_memcpy( p_ib_dhcp, p_dhcp, buf_len );
+       NdisMoveMemory( p_ib_dhcp, p_dhcp, buf_len );

        /* Now scan through the options looking for the client identifier. */
        p_option = &p_ib_dhcp->options[4];
@@ -4975,7 +4975,7 @@
                if( p_cid )
                {
                        /* do we need to replace it ?  len eq ETH MAC sz 'and' MAC is mine */
-                       if( p_cid[1] == HW_ADDR_LEN+1 && !cl_memcmp( &p_cid[3],
+                       if( p_cid[1] == HW_ADDR_LEN+1 && !memcmp( &p_cid[3],
                                &s_buf->p_port->p_adapter->params.conf_mac.addr, HW_ADDR_LEN ) )
                        {
                                /* Make sure there's room to extend it.  22 is the size of
@@ -5020,10 +5020,13 @@
                p_cid[coIPoIB_CID_TotalLen]= DHCP_OPT_END;

                // Copy the default prefix for ALL DHCP messages
-               cl_memcpy( &p_cid[2], &coIBDefaultDHCPPrefix[0], sizeof coIBDefaultDHCPPrefix);
+               NdisMoveMemory( &p_cid[2],
+                                               &coIBDefaultDHCPPrefix[0],
+                                               sizeof coIBDefaultDHCPPrefix );
                // Copy the GUID into the last 8 bytes of the CID field
-               cl_memcpy( &p_cid[2+ sizeof(coIBDefaultDHCPPrefix)],&s_buf->p_port->p_adapter->guids.port_guid.guid ,
-                       sizeof(s_buf->p_port->p_adapter->guids.port_guid.guid) );
+               NdisMoveMemory( &p_cid[2+ sizeof(coIBDefaultDHCPPrefix)],
+                                               &s_buf->p_port->p_adapter->guids.port_guid.guid,
+                                               sizeof(s_buf->p_port->p_adapter->guids.port_guid.guid) );

                p_ib_dhcp->htype = DHCP_HW_TYPE_IB;

@@ -5151,7 +5154,7 @@
        p_ib_arp->src_ip = p_arp->src_ip;
        ipoib_print_arp_hdr( p_ib_arp );

-       if( cl_memcmp( &p_arp->dst_hw, &null_hw, sizeof(mac_addr_t) ) )
+       if( memcmp( &p_arp->dst_hw, &null_hw, sizeof(mac_addr_t) ) )
        {
                /* Get the endpoint referenced by the dst_hw address. */
                net32_t qpn = 0;
@@ -5214,7 +5217,7 @@
        }
        else
        {
-               cl_memclr( &p_ib_arp->dst_hw, sizeof(ipoib_hw_addr_t) );
+               NdisZeroMemory( &p_ib_arp->dst_hw, sizeof(ipoib_hw_addr_t) );
        }

 #if 0 //DBG
@@ -6673,7 +6676,7 @@

        IPOIB_ENTER( IPOIB_DBG_ENDPT );

-       cl_memcpy( &key, &mac, sizeof(mac_addr_t) );
+       NdisMoveMemory( &key, &mac, sizeof(mac_addr_t) );

        cl_obj_lock( &p_port->obj );

@@ -6712,7 +6715,7 @@

        IPOIB_ENTER( IPOIB_DBG_ENDPT );

-       cl_memcpy( &key, &mac, sizeof(mac_addr_t) );
+       NdisMoveMemory( &key, &mac, sizeof(mac_addr_t) );

        cl_obj_lock( &p_port->obj );

@@ -6800,7 +6803,7 @@

        IPOIB_ENTER( IPOIB_DBG_ENDPT );

-       if( !cl_memcmp( &mac, &p_port->p_adapter->params.conf_mac, sizeof(mac) ) )
+       if( !memcmp( &mac, &p_port->p_adapter->params.conf_mac, sizeof(mac) ) )
        {
                /* Discard loopback traffic. */
                IPOIB_PRINT(TRACE_LEVEL_WARNING, IPOIB_DBG_ENDPT,
@@ -6810,7 +6813,7 @@
        }

        key = 0;
-       cl_memcpy( &key, &mac, sizeof(mac_addr_t) );
+       NdisMoveMemory( &key, &mac, sizeof(mac_addr_t) );

        cl_obj_lock( &p_port->obj );

@@ -6861,7 +6864,7 @@
        cl_obj_lock( &p_port->obj );

        key = 0;
-       cl_memcpy( &key, &mac, sizeof(mac_addr_t) );
+       NdisMoveMemory( &key, &mac, sizeof(mac_addr_t) );
        p_item = cl_qmap_get( &p_port->endpt_mgr.mac_endpts, key );
        if( p_item == cl_qmap_end( &p_port->endpt_mgr.mac_endpts ) )
        {
@@ -6992,7 +6995,7 @@

        p_endpt->mac = mac;
        key = 0;
-       cl_memcpy( &key, &mac, sizeof(mac_addr_t) );
+       NdisMoveMemory( &key, &mac, sizeof(mac_addr_t) );
        p_qitem = cl_qmap_insert( &p_port->endpt_mgr.mac_endpts,
                                                          key,
                                                          &p_endpt->mac_item );
@@ -7064,7 +7067,7 @@
        }

        /* Add the broadcast endpoint to the endpoint map. */
-       cl_memset( &bcast_mac, 0xFF, sizeof(bcast_mac) );
+       memset( &bcast_mac, 0xFF, sizeof(bcast_mac) );
        status = __endpt_mgr_insert_locked( p_port, bcast_mac, p_endpt );

        IPOIB_EXIT( IPOIB_DBG_INIT );
@@ -7086,7 +7089,7 @@
        IPOIB_ENTER( IPOIB_DBG_ENDPT );

        key = 0;
-       cl_memcpy( &key, &mac, sizeof(mac_addr_t) );
+       NdisMoveMemory( &key, &mac, sizeof(mac_addr_t) );

        /* Remove the endpoint from the maps so further requests don't find it. */
        cl_obj_lock( &p_port->obj );
@@ -7305,7 +7308,7 @@
                return IB_INSUFFICIENT_MEMORY;
        }

-       cl_memclr( &av_attr, sizeof(ib_av_attr_t) );
+       NdisZeroMemory( &av_attr, sizeof(ib_av_attr_t) );
        av_attr.port_num = p_port->port_num;
        av_attr.sl = 0;
        IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_ENDPT,
@@ -7364,13 +7367,13 @@
        info.p_attr = &member_rec;

        /* Query requires only the MGID. */
-       cl_memclr( &member_rec, sizeof(ib_member_rec_t) );
+       NdisZeroMemory( &member_rec, sizeof(ib_member_rec_t) );
        member_rec.mgid = bcast_mgid_template;

     member_rec.mgid.raw[4] = (uint8_t) (p_port->p_adapter->guids.port_guid.pkey >> 8) ;
        member_rec.mgid.raw[5] = (uint8_t) p_port->p_adapter->guids.port_guid.pkey;
        member_rec.pkey = cl_hton16(p_port->p_adapter->guids.port_guid.pkey);
-       cl_memclr( &query, sizeof(ib_query_req_t) );
+       NdisZeroMemory( &query, sizeof(ib_query_req_t) );
        query.query_type = IB_QUERY_USER_DEFINED;
        query.p_query_input = &info;
        query.port_guid = p_port->p_adapter->guids.port_guid.guid;
@@ -7511,7 +7514,7 @@
        }

        /* Join the broadcast group. */
-       cl_memclr( &mcast_req, sizeof(mcast_req) );
+       NdisZeroMemory( &mcast_req, sizeof(mcast_req) );
        /* Copy the results of the Get to use as parameters. */
        mcast_req.member_rec = *p_member_rec;

@@ -7575,7 +7578,7 @@
        IPOIB_ENTER( IPOIB_DBG_INIT );

        /* Join the broadcast group. */
-       cl_memclr( &mcast_req, sizeof(mcast_req) );
+       NdisZeroMemory( &mcast_req, sizeof(mcast_req) );
        mcast_req.create = TRUE;
        /*
         * Create requires pkey, qkey, SL, flow label, traffic class, joing state
@@ -7672,7 +7675,7 @@
         * synchronize with send/receive callbacks.
         */
        CL_ASSERT( p_port->ib_mgr.h_qp );
-       cl_memclr( &qp_mod, sizeof(ib_qp_mod_t) );
+       NdisZeroMemory( &qp_mod, sizeof(ib_qp_mod_t) );
        qp_mod.req_state = IB_QPS_ERROR;
        status = p_port->p_adapter->p_ifc->modify_qp( p_port->ib_mgr.h_qp, &qp_mod );
        if( status != IB_SUCCESS )
@@ -7797,7 +7800,7 @@
        if( !p_port->p_local_endpt )
        {
                ib_port_info_t  port_info;
-               cl_memclr(&port_info, sizeof(port_info));
+               NdisZeroMemory(&port_info, sizeof(port_info));
                port_info.base_lid = p_port->base_lid;
                status = __endpt_mgr_add_local( p_port, &port_info );
                if( status != IB_SUCCESS )
@@ -7880,7 +7883,7 @@
                cl_spinlock_release( &p_port->recv_lock );

                CL_ASSERT( p_port->ib_mgr.h_qp );
-               cl_memclr( &qp_mod, sizeof(ib_qp_mod_t) );
+               NdisZeroMemory( &qp_mod, sizeof(ib_qp_mod_t) );
                qp_mod.req_state = IB_QPS_ERROR;
                status = p_port->p_adapter->p_ifc->modify_qp( p_port->ib_mgr.h_qp, &qp_mod );
                IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_INIT,
@@ -7950,7 +7953,7 @@
         * Move the QP to RESET.  This allows us to reclaim any
         * unflushed receives.
         */
-       cl_memclr( &qp_mod, sizeof(ib_qp_mod_t) );
+       NdisZeroMemory( &qp_mod, sizeof(ib_qp_mod_t) );
        qp_mod.req_state = IB_QPS_RESET;
        status = p_port->p_adapter->p_ifc->modify_qp( p_port->ib_mgr.h_qp, &qp_mod );
        if( status != IB_SUCCESS )
@@ -8046,7 +8049,7 @@
         * This allows us to do a create request that should always succeed since
         * the required parameters are known.
         */
-       cl_memclr( &mcast_req, sizeof(mcast_req) );
+       NdisZeroMemory( &mcast_req, sizeof(mcast_req) );
        mcast_req.create = TRUE;

        /* Copy the settings from the broadcast group. */
@@ -8075,7 +8078,7 @@
                mcast_req.member_rec.mgid.raw[2] = 0x14;
                mcast_req.member_rec.mgid.raw[3] = 0x05;
                /* Now copy the MAC address into the last 6 bytes of the GID. */
-               cl_memcpy( &mcast_req.member_rec.mgid.raw[10], mac.addr, 6 );
+               NdisMoveMemory( &mcast_req.member_rec.mgid.raw[10], mac.addr, 6 );
        }

        mcast_req.mcast_context = p_port;
@@ -8379,7 +8382,7 @@
        if (CurrLength == ETH_OFFSET) {
                ASSERT(FALSE);
                IsRegularFlow = FALSE;
-               memcpy(pCopiedData, pSrc, ETH_OFFSET);
+               NdisMoveMemory(pCopiedData, pSrc, ETH_OFFSET);
                pCopiedData += ETH_OFFSET;
                FullBuffers++;
                // First buffer was only ethernet
@@ -8395,7 +8398,7 @@

                //IMPORTANT: we de-facto replace ETH header by IPoIB header here
                //TODO: This is not good practice to change data we got from NDIS
-               memcpy (pLsoData->LsoBuffers[0].pData, ipoib_hdr, sizeof (ipoib_hdr_t));
+               NdisMoveMemory (pLsoData->LsoBuffers[0].pData, ipoib_hdr, sizeof (ipoib_hdr_t));

                CurrLength -= ETH_OFFSET;
                pSrc = pSrc + ETH_OFFSET;
@@ -8422,10 +8425,10 @@
                // if(IsRegularFlow = TRUE ) ==> ETH and IP in the same buffer
                // TCP will start at next buffer
                if(IsRegularFlow){
-                       memcpy(pCopiedData, pSrc-ETH_OFFSET ,ETH_OFFSET+IpHeaderLen);
+                       NdisMoveMemory(pCopiedData, pSrc-ETH_OFFSET ,ETH_OFFSET+IpHeaderLen);
                        pCopiedData += (ETH_OFFSET + IpHeaderLen);
                } else {
-                       memcpy(pCopiedData, pSrc,IpHeaderLen);
+                       NdisMoveMemory(pCopiedData, pSrc,IpHeaderLen);
                        pCopiedData += IpHeaderLen;
                }

@@ -8443,7 +8446,7 @@
                if (IsRegularFlow) {
                        pLsoData->LsoBuffers[0].Len += IpHeaderLen;
                } else {
-                       memcpy(pCopiedData, pSrc, IpHeaderLen);
+                       NdisMoveMemory(pCopiedData, pSrc, IpHeaderLen);
                        pCopiedData += IpHeaderLen;
                }

@@ -8467,7 +8470,7 @@
                pLsoData->LsoBuffers[0].Len += TcpHeaderLen;
        }
        else{
-               memcpy(pCopiedData, pSrc, TcpHeaderLen);
+               NdisMoveMemory(pCopiedData, pSrc, TcpHeaderLen);
                pCopiedData += TcpHeaderLen;
        }
        if (CurrLength == TcpHeaderLen) {
@@ -8518,7 +8521,7 @@

                if( p_endpt->h_mcast &&
                        (!p_endpt->is_mcast_listener) &&
-                       ( cl_memcmp( &p_endpt->mac, &DEFAULT_MCAST_GROUP, sizeof(mac_addr_t) ) &&
+                       ( memcmp( &p_endpt->mac, &DEFAULT_MCAST_GROUP, sizeof(mac_addr_t) ) &&
                         (!p_endpt->is_in_use) ))
                {
                        cl_qmap_remove_item( &p_port->endpt_mgr.mac_endpts,
@@ -8729,7 +8732,7 @@
                                ("Failed to query IP options buffer address.\n") );
                        return NDIS_STATUS_FAILURE;
                }
-               cl_memcpy( p_buf, p_ip_hdr, sizeof( ip_hdr_t ) );
+               NdisMoveMemory( p_buf, p_ip_hdr, sizeof( ip_hdr_t ) );
                if( p_options && options_len )
                {
                        __copy_ip_options( &p_buf[sizeof(ip_hdr_t)],
@@ -8740,7 +8743,7 @@
        }
        else
        {       /*options probably in the same buffer */
-               cl_memcpy( p_buf, p_ip_hdr, buf_len );
+               NdisMoveMemory( p_buf, p_ip_hdr, buf_len );
                options_len = ip_hdr_len - sizeof( ip_hdr_t );
                if( options_len )
                {
@@ -8816,7 +8819,7 @@
                                p_buf += sizeof( ipoib_hdr_t );
                                ++ds_idx;

-                               cl_memcpy( p_buf, p_ip_hdr, sizeof( ip_hdr_t ) );
+                               NdisMoveMemory( p_buf, p_ip_hdr, sizeof( ip_hdr_t ) );
                                if( p_options && options_len )
                                {
                                        /* copy ip options if needed */
@@ -8912,7 +8915,7 @@
                return;
        if( copy_all )
        {
-               cl_memcpy( p_dst, p_src, options_len );
+               NdisMoveMemory( p_dst, p_src, options_len );
                return;
        }
        do
@@ -8935,7 +8938,7 @@
                if( copied_length && (copied_length % 4) )
                {
                        uint32_t align = 4 - (copied_length % 4);
-                       cl_memset( p_dst, 0x1, (size_t)align );
+                       memset( p_dst, 0x1, (size_t)align );
                        p_dst += align;
                        copied_length += align;
                }
@@ -8943,7 +8946,7 @@

                if( *p_src & 0x80 )
                {
-                       cl_memcpy( p_dst, p_src, option_length );
+                       NdisMoveMemory( p_dst, p_src, option_length );
                        p_dst += option_length;
                        copied_length += option_length;
                }
@@ -8958,8 +8961,8 @@
        /* padding the rest */
        if( options_len > copied_length )
        {
-               cl_memclr( p_dst, ( options_len - copied_length ) );
+               NdisZeroMemory( p_dst, ( options_len - copied_length ) );
        }
        return;
 }
-#endif
\ No newline at end of file
+#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ipoib_port.cpp.patch
Type: application/octet-stream
Size: 15739 bytes
Desc: ipoib_port.cpp.patch
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20101228/198e5aab/attachment.obj>


More information about the ofw mailing list