diff mbox

iproute2: use IFLA_TXQLEN when it is available

Message ID 1305168451-14491-1-git-send-email-xiaosuo@gmail.com
State Not Applicable, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Changli Gao May 12, 2011, 2:47 a.m. UTC
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(-)
--
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

Eric Dumazet May 12, 2011, 3:28 a.m. UTC | #1
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.



--
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/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);