diff mbox

[net-next?] pktgen: Use simpler test for non-zero ipv6 address

Message ID 1349894559.2035.12.camel@joe-AO722
State Superseded, archived
Delegated to: David Miller
Headers show

Commit Message

Joe Perches Oct. 10, 2012, 6:42 p.m. UTC
Reduces object size and should be slightly faster.

allyesconfig:

$ size net/core/pktgen.o*
   text	   data	    bss	    dec	    hex	filename
  52251	   4293	  11824	  68368	  10b10	net/core/pktgen.o.new
  52310	   4293	  11848	  68451	  10b63	net/core/pktgen.o.old

Signed-off-by: Joe Perches <joe@perches.com>
---
Found by looking for if (foo) ; tests with a perl regex

Yes Eric, it could be 2 compares instead of 4 on 64-bit
systems with HAS_EFFICIENT_UNALIGNED_ACCESS.  Maybe later
or if there are other tests that could become something
like ipv6_is_zeronet.

cheers, Joe

 net/core/pktgen.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Brian Haley Oct. 10, 2012, 6:59 p.m. UTC | #1
On 10/10/2012 02:42 PM, Joe Perches wrote:
> Found by looking for if (foo) ; tests with a perl regex
> 
> Yes Eric, it could be 2 compares instead of 4 on 64-bit
> systems with HAS_EFFICIENT_UNALIGNED_ACCESS.  Maybe later
> or if there are other tests that could become something
> like ipv6_is_zeronet.
> 
> cheers, Joe
> 
>  net/core/pktgen.c |    9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index 148e73d..3aa8417 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -2422,11 +2422,10 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev)
>  		}
>  	} else {		/* IPV6 * */
>  
> -		if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
> -		    pkt_dev->min_in6_daddr.s6_addr32[1] == 0 &&
> -		    pkt_dev->min_in6_daddr.s6_addr32[2] == 0 &&
> -		    pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ;
> -		else {
> +		if (pkt_dev->min_in6_daddr.s6_addr32[0] |
> +		    pkt_dev->min_in6_daddr.s6_addr32[1] |
> +		    pkt_dev->min_in6_daddr.s6_addr32[2] |
> +		    pkt_dev->min_in6_daddr.s6_addr32[3]) {
>  			int i;

Why not just use ipv6_addr_any() ?  It has an HAS_EFFICIENT_UNALIGNED_ACCESS
check too.

-Brian
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eric Dumazet Oct. 10, 2012, 7:01 p.m. UTC | #2
On Wed, 2012-10-10 at 11:42 -0700, Joe Perches wrote:
> Reduces object size and should be slightly faster.
> 
> allyesconfig:
> 
> $ size net/core/pktgen.o*
>    text	   data	    bss	    dec	    hex	filename
>   52251	   4293	  11824	  68368	  10b10	net/core/pktgen.o.new
>   52310	   4293	  11848	  68451	  10b63	net/core/pktgen.o.old
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
> Found by looking for if (foo) ; tests with a perl regex
> 
> Yes Eric, it could be 2 compares instead of 4 on 64-bit
> systems with HAS_EFFICIENT_UNALIGNED_ACCESS.  Maybe later
> or if there are other tests that could become something
> like ipv6_is_zeronet.
> 
> cheers, Joe
> 
>  net/core/pktgen.c |    9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index 148e73d..3aa8417 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -2422,11 +2422,10 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev)
>  		}
>  	} else {		/* IPV6 * */
>  
> -		if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
> -		    pkt_dev->min_in6_daddr.s6_addr32[1] == 0 &&
> -		    pkt_dev->min_in6_daddr.s6_addr32[2] == 0 &&
> -		    pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ;
> -		else {
> +		if (pkt_dev->min_in6_daddr.s6_addr32[0] |
> +		    pkt_dev->min_in6_daddr.s6_addr32[1] |
> +		    pkt_dev->min_in6_daddr.s6_addr32[2] |
> +		    pkt_dev->min_in6_daddr.s6_addr32[3]) {
>  			int i;
>  
>  			/* Only random destinations yet */
> 



What about ipv6_addr_any() ?

anyway net-next is not opened yet


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Laight Oct. 11, 2012, 8:08 a.m. UTC | #3
> -		if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
> -		    pkt_dev->min_in6_daddr.s6_addr32[1] == 0 &&
> -		    pkt_dev->min_in6_daddr.s6_addr32[2] == 0 &&
> -		    pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ;
> -		else {
> +		if (pkt_dev->min_in6_daddr.s6_addr32[0] |
> +		    pkt_dev->min_in6_daddr.s6_addr32[1] |
> +		    pkt_dev->min_in6_daddr.s6_addr32[2] |
> +		    pkt_dev->min_in6_daddr.s6_addr32[3]) {

Given the likely values, it might be worth using:
		if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
		    pkt_dev->min_in6_daddr.s6_addr32[1] |
		    pkt_dev->min_in6_daddr.s6_addr32[2] |
		    pkt_dev->min_in6_daddr.s6_addr32[3]) {

	David



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 148e73d..3aa8417 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -2422,11 +2422,10 @@  static void mod_cur_headers(struct pktgen_dev *pkt_dev)
 		}
 	} else {		/* IPV6 * */
 
-		if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
-		    pkt_dev->min_in6_daddr.s6_addr32[1] == 0 &&
-		    pkt_dev->min_in6_daddr.s6_addr32[2] == 0 &&
-		    pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ;
-		else {
+		if (pkt_dev->min_in6_daddr.s6_addr32[0] |
+		    pkt_dev->min_in6_daddr.s6_addr32[1] |
+		    pkt_dev->min_in6_daddr.s6_addr32[2] |
+		    pkt_dev->min_in6_daddr.s6_addr32[3]) {
 			int i;
 
 			/* Only random destinations yet */