Skip to contentSkip to conversation

net: packetengines: slight optimization of addr

PATCH Superseded Ding Tianhong 4 participants 8 messages Dec 28, 2013 – Dec 30, 2013

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 11/20 net: packetengines: slight optimization of addr

Use possibly more efficient ether_addr_equal
to instead of memcmp.

Cc "David S. Miller" <[email protected]>
---
 drivers/net/ethernet/packetengines/yellowfin.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/packetengines/yellowfin.c +6 -6
index d28593b..b83ac0e 100644
@@ -1097,12 +1097,12 @@ static int yellowfin_rx(struct net_device *dev)
 			if (status2 & 0x80) dev->stats.rx_dropped++;
 #ifdef YF_PROTOTYPE		/* Support for prototype hardware errata. */
 		} else if ((yp->flags & HasMACAddrBug)  &&
-			memcmp(le32_to_cpu(yp->rx_ring_dma +
-				entry*sizeof(struct yellowfin_desc)),
-				dev->dev_addr, 6) != 0 &&
-			memcmp(le32_to_cpu(yp->rx_ring_dma +
-				entry*sizeof(struct yellowfin_desc)),
-				"\377\377\377\377\377\377", 6) != 0) {
+			!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+						      entry * sizeof(struct yellowfin_desc)),
+							  dev->dev_addr) &&
+			!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+							  entry * sizeof(struct yellowfin_desc)),
+							  "\377\377\377\377\377\377")) {
 			if (bogus_rx++ == 0)
 				netdev_warn(dev, "Bad frame to %pM\n",
 					    buf_addr);
Signature · 1 line
1.7.1
#1 lore raw

Hello.

Quoted 16 lines · Ding Tianhong

Use possibly more efficient ether_addr_equal
to instead of memcmp.

Cc "David S. Miller" <[email protected]>
---
  drivers/net/ethernet/packetengines/yellowfin.c |   12 ++++++------
  1 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/packetengines/yellowfin.c +0 -0
index d28593b..b83ac0e 100644
@@ -1097,12 +1097,12 @@ static int yellowfin_rx(struct net_device *dev)
  			if (status2 & 0x80) dev->stats.rx_dropped++;
  #ifdef YF_PROTOTYPE		/* Support for prototype hardware errata. */

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1102

Quoted 10 lines
drivers/net/ethernet/packetengines/yellowfin.c +3 -6
  		} else if ((yp->flags & HasMACAddrBug)  &&
-			memcmp(le32_to_cpu(yp->rx_ring_dma +
-				entry*sizeof(struct yellowfin_desc)),
-				dev->dev_addr, 6) != 0 &&
-			memcmp(le32_to_cpu(yp->rx_ring_dma +
-				entry*sizeof(struct yellowfin_desc)),
-				"\377\377\377\377\377\377", 6) != 0) {
+			!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+						      entry * sizeof(struct yellowfin_desc)),
+							  dev->dev_addr) &&

Previous line was aligned correctly, the above line should start under
le32_to_cpu.

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1104

Quoted 2 lines
drivers/net/ethernet/packetengines/yellowfin.c +2 -0
+			!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+							  entry * sizeof(struct yellowfin_desc)),

Start the continuation lines under 'yp', please.

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1105

Quoted 1 line
drivers/net/ethernet/packetengines/yellowfin.c +1 -0
+							  "\377\377\377\377\377\377")) {

This line should start under le32_to_cpu.

WBR, Sergei

#2 lore raw
Quoted 36 lines · Sergei Shtylyov

Hello.

Quoted 16 lines · Ding Tianhong

Use possibly more efficient ether_addr_equal
to instead of memcmp.

Cc "David S. Miller" <[email protected]>
---
  drivers/net/ethernet/packetengines/yellowfin.c |   12 ++++++------
  1 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/packetengines/yellowfin.c +0 -0
index d28593b..b83ac0e 100644
@@ -1097,12 +1097,12 @@ static int yellowfin_rx(struct net_device *dev)
              if (status2 & 0x80) dev->stats.rx_dropped++;
  #ifdef YF_PROTOTYPE        /* Support for prototype hardware errata. */

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1102

Quoted 10 lines
drivers/net/ethernet/packetengines/yellowfin.c +3 -6
          } else if ((yp->flags & HasMACAddrBug)  &&
-            memcmp(le32_to_cpu(yp->rx_ring_dma +
-                entry*sizeof(struct yellowfin_desc)),
-                dev->dev_addr, 6) != 0 &&
-            memcmp(le32_to_cpu(yp->rx_ring_dma +
-                entry*sizeof(struct yellowfin_desc)),
-                "\377\377\377\377\377\377", 6) != 0) {
+            !ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+                              entry * sizeof(struct yellowfin_desc)),
+                              dev->dev_addr) &&

Previous line was aligned correctly, the above line should start under le32_to_cpu.

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1104

Quoted 2 lines
drivers/net/ethernet/packetengines/yellowfin.c +2 -0
+            !ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+                              entry * sizeof(struct yellowfin_desc)),
Quoted 8 lines

Start the continuation lines under 'yp', please.

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1105

Quoted 1 line
drivers/net/ethernet/packetengines/yellowfin.c +1 -0
+                              "\377\377\377\377\377\377")) {

This line should start under le32_to_cpu.

WBR, Sergei

Hi sergei:
you mean this way?

	!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
				      entry * sizeof(struct yellowfin_desc)),
			  dev->dev_addr) &&

	!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
				      entry * sizeof(struct yellowfin_desc)),
			  "\377\377\377\377\377\377")) {

Regards
Ding

Quoted 5 lines
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 48 lines · Ding Tianhong
Quoted 36 lines · Sergei Shtylyov

Hello.

Quoted 16 lines · Ding Tianhong

Use possibly more efficient ether_addr_equal
to instead of memcmp.

Cc "David S. Miller" <[email protected]>
---
  drivers/net/ethernet/packetengines/yellowfin.c |   12 ++++++------
  1 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/packetengines/yellowfin.c +0 -0
index d28593b..b83ac0e 100644
@@ -1097,12 +1097,12 @@ static int yellowfin_rx(struct net_device *dev)
              if (status2 & 0x80) dev->stats.rx_dropped++;
  #ifdef YF_PROTOTYPE        /* Support for prototype hardware errata. */

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1102

Quoted 10 lines
drivers/net/ethernet/packetengines/yellowfin.c +3 -6
          } else if ((yp->flags & HasMACAddrBug)  &&
-            memcmp(le32_to_cpu(yp->rx_ring_dma +
-                entry*sizeof(struct yellowfin_desc)),
-                dev->dev_addr, 6) != 0 &&
-            memcmp(le32_to_cpu(yp->rx_ring_dma +
-                entry*sizeof(struct yellowfin_desc)),
-                "\377\377\377\377\377\377", 6) != 0) {
+            !ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+                              entry * sizeof(struct yellowfin_desc)),
+                              dev->dev_addr) &&

Previous line was aligned correctly, the above line should start under le32_to_cpu.

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1104

Quoted 2 lines
drivers/net/ethernet/packetengines/yellowfin.c +2 -0
+            !ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+                              entry * sizeof(struct yellowfin_desc)),
Quoted 8 lines

Start the continuation lines under 'yp', please.

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1105

Quoted 1 line
drivers/net/ethernet/packetengines/yellowfin.c +1 -0
+                              "\377\377\377\377\377\377")) {

This line should start under le32_to_cpu.

WBR, Sergei

Hi sergei:
you mean this way?

Quoted 7 lines
	!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
				      entry * sizeof(struct yellowfin_desc)),
			  dev->dev_addr) &&

	!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
				      entry * sizeof(struct yellowfin_desc)),
			  "\377\377\377\377\377\377")) {

Does this really matter?
Does anyone have a packetengine NIC anymore?

\377 octal is 0xff, so this is matching a broadcast address. is_broadcast_ether_addr(addr) would be appropriate.

So would using a temporary address.

u8 *addr = (u8 *)(unsigned long)le32_to_cpu(etc)

but the whole thing looks very suspect as an le32
value could not be added to correctly on a
big-endian arch anyway.

My guess is this was tested only on an x86 and
it should be:

	u8 *addr = (u8 *)(unsigned long)(le32_to_cpu(yp->rx_ring_dma) +
					 entry * sizeof(struct yellowfin_desc));

It maybe better just to leave these two alone.

#4 lore raw
Quoted 71 lines · Joe Perches
Quoted 48 lines · Ding Tianhong
Quoted 36 lines · Sergei Shtylyov

Hello.

Quoted 16 lines · Ding Tianhong

Use possibly more efficient ether_addr_equal
to instead of memcmp.

Cc "David S. Miller" <[email protected]>
---
  drivers/net/ethernet/packetengines/yellowfin.c |   12 ++++++------
  1 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/packetengines/yellowfin.c +0 -0
index d28593b..b83ac0e 100644
@@ -1097,12 +1097,12 @@ static int yellowfin_rx(struct net_device *dev)
              if (status2 & 0x80) dev->stats.rx_dropped++;
  #ifdef YF_PROTOTYPE        /* Support for prototype hardware errata. */

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1102

Quoted 10 lines
drivers/net/ethernet/packetengines/yellowfin.c +3 -6
          } else if ((yp->flags & HasMACAddrBug)  &&
-            memcmp(le32_to_cpu(yp->rx_ring_dma +
-                entry*sizeof(struct yellowfin_desc)),
-                dev->dev_addr, 6) != 0 &&
-            memcmp(le32_to_cpu(yp->rx_ring_dma +
-                entry*sizeof(struct yellowfin_desc)),
-                "\377\377\377\377\377\377", 6) != 0) {
+            !ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+                              entry * sizeof(struct yellowfin_desc)),
+                              dev->dev_addr) &&

Previous line was aligned correctly, the above line should start under le32_to_cpu.

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1104

Quoted 2 lines
drivers/net/ethernet/packetengines/yellowfin.c +2 -0
+            !ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+                              entry * sizeof(struct yellowfin_desc)),
Quoted 8 lines

Start the continuation lines under 'yp', please.

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1105

Quoted 1 line
drivers/net/ethernet/packetengines/yellowfin.c +1 -0
+                              "\377\377\377\377\377\377")) {

This line should start under le32_to_cpu.

WBR, Sergei

Hi sergei:
you mean this way?

Quoted 7 lines
	!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
				      entry * sizeof(struct yellowfin_desc)),
			  dev->dev_addr) &&

	!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
				      entry * sizeof(struct yellowfin_desc)),
			  "\377\377\377\377\377\377")) {

Does this really matter?
Does anyone have a packetengine NIC anymore?

\377 octal is 0xff, so this is matching a broadcast address. is_broadcast_ether_addr(addr) would be appropriate.

So would using a temporary address.

u8 *addr = (u8 *)(unsigned long)le32_to_cpu(etc)

but the whole thing looks very suspect as an le32
value could not be added to correctly on a
big-endian arch anyway.

Quoted 8 lines

My guess is this was tested only on an x86 and
it should be:

	u8 *addr = (u8 *)(unsigned long)(le32_to_cpu(yp->rx_ring_dma) +
					 entry * sizeof(struct yellowfin_desc));

It maybe better just to leave these two alone.

Hi Joe:

I don't understand packetengine NIC anymore, But I think the change is clearly, as your said, the broadcast check is enough here, did you mean that?

	!is_broadcast_ether_addr((u8 *)(le32_to_cpu(yp->rx_ring_dma) +
						    entry * sizeof(struct yellowfin_desc)))

Thanks

Regards
Ding

Quoted 3 lines

.

#5 lore raw
Quoted 5 lines · Ding Tianhong

I don't understand packetengine NIC anymore, But I think the change is clearly, as your said, the broadcast check is enough here, did you mean that?

	!is_broadcast_ether_addr((u8 *)(le32_to_cpu(yp->rx_ring_dma) +
						    entry * sizeof(struct yellowfin_desc)))

Not quite. I meant this could be:

		u8 *addr = (u8 *)(unsigned long)le32_to_cpu(yp->rx_ring_dma) +
							    entry * sizeof(struct yellowfin_desc);

		if (!ether_addr_equal(addr, dev->dev_addr) &&
		    !is_broadcast_ether_addr(addr)) {
			etc...

but again, I think thus hardly matters and could just as well be left alone.

#6 lore raw
Quoted 16 lines · Joe Perches
Quoted 5 lines · Ding Tianhong

I don't understand packetengine NIC anymore, But I think the change is clearly, as your said, the broadcast check is enough here, did you mean that?

	!is_broadcast_ether_addr((u8 *)(le32_to_cpu(yp->rx_ring_dma) +
						    entry * sizeof(struct yellowfin_desc)))

Not quite. I meant this could be:

		u8 *addr = (u8 *)(unsigned long)le32_to_cpu(yp->rx_ring_dma) +
							    entry * sizeof(struct yellowfin_desc);

		if (!ether_addr_equal(addr, dev->dev_addr) &&
		    !is_broadcast_ether_addr(addr)) {
			etc...
Quoted 4 lines

but again, I think thus hardly matters and could just as well be left alone.

Ok, I will focus on ether_addr_equal in this patch, anymore will left alone. Thanks

Regards
Ding

Quoted 2 lines
#7 lore raw
In reply to Ding Tianhong

Hello.

Quoted 43 lines · Ding Tianhong
Quoted 32 lines
Quoted 16 lines

Use possibly more efficient ether_addr_equal
to instead of memcmp.

Cc "David S. Miller" <[email protected]>
---
   drivers/net/ethernet/packetengines/yellowfin.c |   12 ++++++------
   1 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/packetengines/yellowfin.c +0 -0
index d28593b..b83ac0e 100644
@@ -1097,12 +1097,12 @@ static int yellowfin_rx(struct net_device *dev)
               if (status2 & 0x80) dev->stats.rx_dropped++;
   #ifdef YF_PROTOTYPE        /* Support for prototype hardware errata. */

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1102

Quoted 10 lines
drivers/net/ethernet/packetengines/yellowfin.c +3 -6
           } else if ((yp->flags & HasMACAddrBug)  &&
-            memcmp(le32_to_cpu(yp->rx_ring_dma +
-                entry*sizeof(struct yellowfin_desc)),
-                dev->dev_addr, 6) != 0 &&
-            memcmp(le32_to_cpu(yp->rx_ring_dma +
-                entry*sizeof(struct yellowfin_desc)),
-                "\377\377\377\377\377\377", 6) != 0) {
+            !ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+                              entry * sizeof(struct yellowfin_desc)),
+                              dev->dev_addr) &&

Previous line was aligned correctly, the above line should start under le32_to_cpu.

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1104

Quoted 2 lines
drivers/net/ethernet/packetengines/yellowfin.c +2 -0
+            !ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
+                              entry * sizeof(struct yellowfin_desc)),
Quoted 7 lines

Start the continuation lines under 'yp', please.

drivers/net/ethernet/packetengines/yellowfin.c static int yellowfin_rx(struct net_device *dev) · line 1105

Quoted 1 line
drivers/net/ethernet/packetengines/yellowfin.c +1 -0
+                              "\377\377\377\377\377\377")) {

This line should start under le32_to_cpu.

WBR, Sergei

Hi sergei:
you mean this way?

Quoted 7 lines
	!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
				      entry * sizeof(struct yellowfin_desc)),
			  dev->dev_addr) &&

	!ether_addr_equal(le32_to_cpu(yp->rx_ring_dma +
				      entry * sizeof(struct yellowfin_desc)),
			  "\377\377\377\377\377\377")) {

Yes, exactly.

Quoted 2 lines

Regards
Ding

WBR, Sergei