From patchwork Fri Oct 23 04:13:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 36762 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 06CBAB7BB0 for ; Fri, 23 Oct 2009 15:17:42 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750864AbZJWENV (ORCPT ); Fri, 23 Oct 2009 00:13:21 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1750824AbZJWENV (ORCPT ); Fri, 23 Oct 2009 00:13:21 -0400 Received: from gw1.cosmosbay.com ([212.99.114.194]:39789 "EHLO gw1.cosmosbay.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750799AbZJWENU (ORCPT ); Fri, 23 Oct 2009 00:13:20 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by gw1.cosmosbay.com (8.13.7/8.13.7) with ESMTP id n9N4DNU5008869; Fri, 23 Oct 2009 06:13:23 +0200 Message-ID: <4AE12D61.2040607@gmail.com> Date: Fri, 23 Oct 2009 06:13:21 +0200 From: Eric Dumazet User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Stephen Hemminger CC: Linux Netdev List Subject: Re: [PATCH iproute2] ip: Support IFLA_TXQLEN in ip link command References: <4AE068EB.70005@gmail.com> In-Reply-To: <4AE068EB.70005@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6 (gw1.cosmosbay.com [0.0.0.0]); Fri, 23 Oct 2009 06:13:23 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Eric Dumazet a écrit : > 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. > Here is a 2nd version od this patch, not displaying "qlen 0" useless info [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. Signed-off-by: Eric Dumazet --- -- 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 --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);