netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ethernet: optimize memcpy and memset
@ 2007-08-17 23:29 Stephen Hemminger
  2007-08-25  5:35 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2007-08-17 23:29 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev

The ethernet header management only needs to handle a fixed
size address (6 bytes). If the memcpy/memset are changed to
be passed a constant length, then compiler can optimize for
this case (and if it is smart eliminate string instructions).

Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>

--- a/net/ethernet/eth.c	2007-08-17 12:08:51.000000000 -0400
+++ b/net/ethernet/eth.c	2007-08-17 12:16:33.000000000 -0400
@@ -91,10 +91,10 @@ int eth_header(struct sk_buff *skb, stru
 
 	if (!saddr)
 		saddr = dev->dev_addr;
-	memcpy(eth->h_source, saddr, dev->addr_len);
+	memcpy(eth->h_source, saddr, ETH_ALEN);
 
 	if (daddr) {
-		memcpy(eth->h_dest, daddr, dev->addr_len);
+		memcpy(eth->h_dest, daddr, ETH_ALEN);
 		return ETH_HLEN;
 	}
 
@@ -103,7 +103,7 @@ int eth_header(struct sk_buff *skb, stru
 	 */
 
 	if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
-		memset(eth->h_dest, 0, dev->addr_len);
+		memset(eth->h_dest, 0, ETH_ALEN);
 		return ETH_HLEN;
 	}
 
@@ -135,7 +135,7 @@ int eth_rebuild_header(struct sk_buff *s
 		       "%s: unable to resolve type %X addresses.\n",
 		       dev->name, (int)eth->h_proto);
 
-		memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
+		memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
 		break;
 	}
 
@@ -233,8 +233,8 @@ int eth_header_cache(struct neighbour *n
 		return -1;
 
 	eth->h_proto = type;
-	memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
-	memcpy(eth->h_dest, neigh->ha, dev->addr_len);
+	memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
+	memcpy(eth->h_dest, neigh->ha, ETH_ALEN);
 	hh->hh_len = ETH_HLEN;
 	return 0;
 }
@@ -251,7 +251,7 @@ void eth_header_cache_update(struct hh_c
 			     unsigned char *haddr)
 {
 	memcpy(((u8 *) hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)),
-	       haddr, dev->addr_len);
+	       haddr, ETH_ALEN);
 }
 
 /**
@@ -271,7 +271,7 @@ static int eth_mac_addr(struct net_devic
 		return -EBUSY;
 	if (!is_valid_ether_addr(addr->sa_data))
 		return -EADDRNOTAVAIL;
-	memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+	memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
 	return 0;
 }
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ethernet: optimize memcpy and memset
  2007-08-17 23:29 [PATCH] ethernet: optimize memcpy and memset Stephen Hemminger
@ 2007-08-25  5:35 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2007-08-25  5:35 UTC (permalink / raw)
  To: shemminger; +Cc: netdev

From: Stephen Hemminger <shemminger@linux-foundation.org>
Date: Fri, 17 Aug 2007 16:29:50 -0700

> The ethernet header management only needs to handle a fixed
> size address (6 bytes). If the memcpy/memset are changed to
> be passed a constant length, then compiler can optimize for
> this case (and if it is smart eliminate string instructions).
> 
> Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-25  5:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-17 23:29 [PATCH] ethernet: optimize memcpy and memset Stephen Hemminger
2007-08-25  5:35 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).