From patchwork Thu May 12 04:40:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 95247 X-Patchwork-Delegate: shemminger@vyatta.com 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.180.67]) by ozlabs.org (Postfix) with ESMTP id 1756B1007D5 for ; Thu, 12 May 2011 14:47:19 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752767Ab1ELElD (ORCPT ); Thu, 12 May 2011 00:41:03 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:33800 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752659Ab1ELElB (ORCPT ); Thu, 12 May 2011 00:41:01 -0400 Received: by wwa36 with SMTP id 36so1324244wwa.1 for ; Wed, 11 May 2011 21:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:subject:from:to:cc:in-reply-to:references :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=MCctZWjzvoT8EZ/+oG1P6SQSklow0NoXNhVOsTfEICA=; b=CraPfdPl6Sy6UugBXjrpBfGcGMq22FFJMUeKRvayJGXEx3aPbDX0HtJN+S8SxfCMUl gRCqr0MzYkEyI7SX2IGkQD3XEpAWqB8pQk2cDZSvFn2fhkrba+3OuqKBxHfZTsFJyyWZ Ssk0j+miH9Nu6WjOiTg8qe0HaphfA1sVZyvQk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; b=ELK/PC8PA67luOHqc/YbtwV67h8SjUaL6xzFoLTk86Tf3x+NrudPLr/dUuNa4pJl5B 18GxfmvXAxwBJ+zBCVN28jT93gdq7nVp8wkV5KDCBR1hXJ8lM41uvfam/NzxJdiVvJML O6puM+IaDELC3YadLYeZp67xEvky4ciaZrGlk= Received: by 10.227.53.206 with SMTP id n14mr879038wbg.14.1305175258889; Wed, 11 May 2011 21:40:58 -0700 (PDT) Received: from [10.150.51.212] (gw0.net.jmsp.net [212.23.165.14]) by mx.google.com with ESMTPS id ca12sm495440wbb.2.2011.05.11.21.40.57 (version=SSLv3 cipher=OTHER); Wed, 11 May 2011 21:40:57 -0700 (PDT) Subject: Re: [PATCH] iproute2: use IFLA_TXQLEN when it is available From: Eric Dumazet To: Changli Gao Cc: shemminger@vyatta.com, netdev@vger.kernel.org, kuznet@ms2.inr.ac.ru In-Reply-To: <1305170886.3232.13.camel@edumazet-laptop> References: <1305168451-14491-1-git-send-email-xiaosuo@gmail.com> <1305170886.3232.13.camel@edumazet-laptop> Date: Thu, 12 May 2011 06:40:55 +0200 Message-ID: <1305175255.20318.4.camel@edumazet-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.32.2 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 > > --- > > 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 > 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 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. --- 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);