netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iproute2: use IFLA_TXQLEN when it is available
@ 2011-05-12  2:47 Changli Gao
  2011-05-12  3:28 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Changli Gao @ 2011-05-12  2:47 UTC (permalink / raw)
  To: shemminger; +Cc: netdev, kuznet, Changli Gao

Use IFLA_TXQLEN when it is available, to avoid additional system calls.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
---
 ip/ipaddress.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index a1f78b9..59afafd 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -285,8 +285,16 @@ int print_linkinfo(const struct sockaddr_nl *who,
 	if (tb[IFLA_OPERSTATE])
 		print_operstate(fp, *(__u8 *)RTA_DATA(tb[IFLA_OPERSTATE]));
 		
-	if (filter.showqueue)
-		print_queuelen(fp, (char*)RTA_DATA(tb[IFLA_IFNAME]));
+	if (filter.showqueue) {
+		if (tb[IFLA_TXQLEN]) {
+			__u32 txqlen = *(__u32 *)RTA_DATA(tb[IFLA_TXQLEN]);
+
+			if (txqlen)
+				fprintf(fp, "qlen %u", txqlen);
+		} else {
+			print_queuelen(fp, (char*)RTA_DATA(tb[IFLA_IFNAME]));
+		}
+	}
 
 	if (!filter.family || filter.family == AF_PACKET) {
 		SPRINT_BUF(b1);

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

* Re: [PATCH] iproute2: use IFLA_TXQLEN when it is available
  2011-05-12  2:47 [PATCH] iproute2: use IFLA_TXQLEN when it is available Changli Gao
@ 2011-05-12  3:28 ` Eric Dumazet
  2011-05-12  4:40   ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2011-05-12  3:28 UTC (permalink / raw)
  To: Changli Gao; +Cc: shemminger, netdev, kuznet

Le jeudi 12 mai 2011 à 10:47 +0800, Changli Gao a écrit :
> Use IFLA_TXQLEN when it is available, to avoid additional system calls.
> 
> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
> ---
>  ip/ipaddress.c |   12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> diff --git a/ip/ipaddress.c b/ip/ipaddress.c
> index a1f78b9..59afafd 100644
> --- a/ip/ipaddress.c
> +++ b/ip/ipaddress.c
> @@ -285,8 +285,16 @@ int print_linkinfo(const struct sockaddr_nl *who,
>  	if (tb[IFLA_OPERSTATE])
>  		print_operstate(fp, *(__u8 *)RTA_DATA(tb[IFLA_OPERSTATE]));
>  		
> -	if (filter.showqueue)
> -		print_queuelen(fp, (char*)RTA_DATA(tb[IFLA_IFNAME]));
> +	if (filter.showqueue) {
> +		if (tb[IFLA_TXQLEN]) {
> +			__u32 txqlen = *(__u32 *)RTA_DATA(tb[IFLA_TXQLEN]);
> +
> +			if (txqlen)
> +				fprintf(fp, "qlen %u", txqlen);
> +		} else {
> +			print_queuelen(fp, (char*)RTA_DATA(tb[IFLA_IFNAME]));
> +		}
> +	}
>  
>  	if (!filter.family || filter.family == AF_PACKET) {
>  		SPRINT_BUF(b1);

Hmm, what iproute2 version do you use ???

commit 62a5e0668e2920b7f09896abd884753255712a46
Author: Eric Dumazet <dada1@cosmosbay.com>
Date:   Fri Oct 23 06:25:53 2009 +0200

    ip: Support IFLA_TXQLEN in ip link show command
    
    We currently use an expensive ioctl() to get device txqueuelen, while
    rtnetlink gave it to us for free. This patch speeds up ip link operation
    when many devices are registered.




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

* Re: [PATCH] iproute2: use IFLA_TXQLEN when it is available
  2011-05-12  3:28 ` Eric Dumazet
@ 2011-05-12  4:40   ` Eric Dumazet
  2011-05-12 15:57     ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2011-05-12  4:40 UTC (permalink / raw)
  To: Changli Gao; +Cc: shemminger, netdev, kuznet

Le jeudi 12 mai 2011 à 05:28 +0200, Eric Dumazet a écrit :
> Le jeudi 12 mai 2011 à 10:47 +0800, Changli Gao a écrit :
> > Use IFLA_TXQLEN when it is available, to avoid additional system calls.
> > 
> > Signed-off-by: Changli Gao <xiaosuo@gmail.com>
> > ---
> >  ip/ipaddress.c |   12 ++++++++++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> > diff --git a/ip/ipaddress.c b/ip/ipaddress.c
> > index a1f78b9..59afafd 100644
> > --- a/ip/ipaddress.c
> > +++ b/ip/ipaddress.c
> > @@ -285,8 +285,16 @@ int print_linkinfo(const struct sockaddr_nl *who,
> >  	if (tb[IFLA_OPERSTATE])
> >  		print_operstate(fp, *(__u8 *)RTA_DATA(tb[IFLA_OPERSTATE]));
> >  		
> > -	if (filter.showqueue)
> > -		print_queuelen(fp, (char*)RTA_DATA(tb[IFLA_IFNAME]));
> > +	if (filter.showqueue) {
> > +		if (tb[IFLA_TXQLEN]) {
> > +			__u32 txqlen = *(__u32 *)RTA_DATA(tb[IFLA_TXQLEN]);
> > +
> > +			if (txqlen)
> > +				fprintf(fp, "qlen %u", txqlen);
> > +		} else {
> > +			print_queuelen(fp, (char*)RTA_DATA(tb[IFLA_IFNAME]));
> > +		}
> > +	}
> >  
> >  	if (!filter.family || filter.family == AF_PACKET) {
> >  		SPRINT_BUF(b1);
> 
> Hmm, what iproute2 version do you use ???
> 
> commit 62a5e0668e2920b7f09896abd884753255712a46
> Author: Eric Dumazet <dada1@cosmosbay.com>
> Date:   Fri Oct 23 06:25:53 2009 +0200
> 
>     ip: Support IFLA_TXQLEN in ip link show command
>     
>     We currently use an expensive ioctl() to get device txqueuelen, while
>     rtnetlink gave it to us for free. This patch speeds up ip link operation
>     when many devices are registered.
> 
> 


Apparently my patch was somehow lost

http://patchwork.ozlabs.org/patch/36762/

Strange thing is it's in my git tree.

Stephen, any idea of what happened ?

Thanks

commit 62a5e0668e2920b7f09896abd884753255712a46
Author: Eric Dumazet <dada1@cosmosbay.com>
Date:   Fri Oct 23 06:25:53 2009 +0200

[PATCH iproute2] ip: Support IFLA_TXQLEN in ip link show command
    
We currently use an expensive ioctl() to get device txqueuelen, while
rtnetlink gave it to us for free. This patch speeds up ip link operation
when many devices are registered.

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 267ecb3..cadc1a3 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -131,26 +131,31 @@ static void print_operstate(FILE *f, __u8 state)
 		fprintf(f, "state %s ", oper_states[state]);
 }
 
-static void print_queuelen(FILE *f, const char *name)
+static void print_queuelen(FILE *f, struct rtattr *tb[IFLA_MAX + 1])
 {
-	struct ifreq ifr;
-	int s;
-
-	s = socket(AF_INET, SOCK_STREAM, 0);
-	if (s < 0)
-		return;
-
-	memset(&ifr, 0, sizeof(ifr));
-	strcpy(ifr.ifr_name, name);
-	if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
-		fprintf(f, "ioctl(SIOCGIFXQLEN) failed: %s\n", strerror(errno));
+	int qlen;
+
+	if (tb[IFLA_TXQLEN])
+		qlen = *(int *)RTA_DATA(tb[IFLA_TXQLEN]);
+	else {
+		struct ifreq ifr;
+		int s = socket(AF_INET, SOCK_STREAM, 0);
+
+		if (s < 0)
+			return;
+
+		memset(&ifr, 0, sizeof(ifr));
+		strcpy(ifr.ifr_name, (char *)RTA_DATA(tb[IFLA_IFNAME]));
+		if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
+			fprintf(f, "ioctl(SIOCGIFXQLEN) failed: %s\n", strerror(errno));
+			close(s);
+			return;
+		}
 		close(s);
-		return;
+		qlen = ifr.ifr_qlen;
 	}
-	close(s);
-
-	if (ifr.ifr_qlen)
-		fprintf(f, "qlen %d", ifr.ifr_qlen);
+	if (qlen)
+		fprintf(f, "qlen %d", qlen);
 }
 
 static void print_linktype(FILE *fp, struct rtattr *tb)
@@ -253,7 +258,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
 		print_operstate(fp, *(__u8 *)RTA_DATA(tb[IFLA_OPERSTATE]));
 		
 	if (filter.showqueue)
-		print_queuelen(fp, (char*)RTA_DATA(tb[IFLA_IFNAME]));
+		print_queuelen(fp, tb);
 
 	if (!filter.family || filter.family == AF_PACKET) {
 		SPRINT_BUF(b1);



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

* Re: [PATCH] iproute2: use IFLA_TXQLEN when it is available
  2011-05-12  4:40   ` Eric Dumazet
@ 2011-05-12 15:57     ` Stephen Hemminger
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2011-05-12 15:57 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Changli Gao, netdev, kuznet

I just applied Eric's patch

-- 

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

end of thread, other threads:[~2011-05-12 15:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-12  2:47 [PATCH] iproute2: use IFLA_TXQLEN when it is available Changli Gao
2011-05-12  3:28 ` Eric Dumazet
2011-05-12  4:40   ` Eric Dumazet
2011-05-12 15:57     ` Stephen Hemminger

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).