From patchwork Mon Aug 25 15:27:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 382762 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.180.67]) by ozlabs.org (Postfix) with ESMTP id A2D0614010B for ; Tue, 26 Aug 2014 01:28:06 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756055AbaHYP2A (ORCPT ); Mon, 25 Aug 2014 11:28:00 -0400 Received: from mail-ig0-f202.google.com ([209.85.213.202]:40459 "EHLO mail-ig0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756046AbaHYP15 (ORCPT ); Mon, 25 Aug 2014 11:27:57 -0400 Received: by mail-ig0-f202.google.com with SMTP id r2so433360igi.1 for ; Mon, 25 Aug 2014 08:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:subject:message-id:user-agent:mime-version :content-type; bh=2lwXks3vmIeli2c/jyQ2NivihIE5Ze3O4phK1wlnA00=; b=DU7tY9lPgVNkN/busvKpmWCmAq7KHm30hf9O/4Twp+9u6beY19hJt1EHe69DsEUH7C SjEOjGItSJwl2dy9rvTN+07VyHDRAxKBqpKZyV33iPuWOL9WqRGUhxJwZ0apY3QQcbdR 9DBJ4mRWIC8J/MBCtQyIjTD3L3akUYeyLdIuvt2g0o+lJrWv0Sa9EEW3ARGAek45PMWW 0PH1EaO+oBshSrrKEYDrJYFbGplMwYTMDoOZihZR7/VbTzZYvj50TfMAP6F+fCII18Jz IEIB5w8CIPCKvzdA5vQBWj4XJ5+kuWXOgXGM5L7GGmM/bAbh8+JW62Pw/ULSXW4qq7HI tcMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:user-agent :mime-version:content-type; bh=2lwXks3vmIeli2c/jyQ2NivihIE5Ze3O4phK1wlnA00=; b=Xr6dpO0M6ojroZtAw/QAt/xdlpyUyexAu+WPTW3xMR1H0E7vnfssIsLuT2+TTDWYN/ S39y+yy+ZQEKUWEZoICdpbcvzKFceUECFCCq58ESACo+tgJYoAyTLX4rX2MrFueVFC2v 2TrFZTj3eUw1b903tmIADsryy0zjNX7tmLjj+ZBwffwCYcmqU81pWgJKPWMe6Dwz1OIh kNL1ACkehWpxq8OSd76X1Aj69FeY6C+hZpIHrTR4m+QSg/uHwehHnIPwRmevkHi+5yjj JhlY/PyGqVp2TEqejACfQc35sU7FBCZ24itdeVGyjjEcgVf+BY/HOLSBq8QsOtqS04CE Y3yw== X-Gm-Message-State: ALoCoQkbA2rHz4K1RmOdbk2smqdMSxfON+BTDcLrm2CTEpwrIeOdLJDrkBWdRxFOgrWPigTdMIHr X-Received: by 10.182.110.130 with SMTP id ia2mr15177423obb.42.1408980476960; Mon, 25 Aug 2014 08:27:56 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id e55si11931yhb.3.2014.08.25.08.27.56 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Aug 2014 08:27:56 -0700 (PDT) Received: from tomh.mtv.corp.google.com (tomh.mtv.corp.google.com [172.18.117.126]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id C13E05A41D6; Mon, 25 Aug 2014 08:27:56 -0700 (PDT) Received: by tomh.mtv.corp.google.com (Postfix, from userid 60832) id 5576D2003E8; Mon, 25 Aug 2014 08:27:56 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by tomh.mtv.corp.google.com (Postfix) with ESMTP id 33DE62003C4; Mon, 25 Aug 2014 08:27:56 -0700 (PDT) Date: Mon, 25 Aug 2014 08:27:56 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net, netdev@vger.kernel.org Subject: [PATCH v2 net-next] net: Functions to report space available in device TX queues Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds netdev_tx_avail_queue and netdev_avail_queue which are used to report number of bytes available in transmit queues per BQL. The functions call dql_avail which returns BQL limit minus number of inflight bytes. These functions can be called without txlock, for instance to ascertain how much data should be dequeued from a qdisc in a batch. When called without the tx_lock, the result is technically a hint, subsequently when the tx_lock is done for a transmit it is possible the availability has changed (for example a transmit completion may have freed up more space in the queue or changed the limit). Signed-off-by: Tom Herbert --- include/linux/netdevice.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 0fac884..bdf6c85 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2544,6 +2544,30 @@ static inline void netdev_completed_queue(struct net_device *dev, netdev_tx_completed_queue(netdev_get_tx_queue(dev, 0), pkts, bytes); } +static inline int netdev_tx_avail_queue(struct netdev_queue *dev_queue) +{ +#ifdef CONFIG_BQL + return dql_avail(&dev_queue->dql); +#else + return DQL_MAX_LIMIT; +#endif +} + +/** + * netdev_avail_queue - report how much space is availble for xmit + * @dev: network device + * + * Report the amount of space available in the TX queue in terms of + * number of bytes. This returns the number of bytes avaiable per + * DQL. This function may be called without taking the txlock on + * the device, however in that case the result should be taken as + * a (strong) hint. + */ +static inline int netdev_avail_queue(struct net_device *dev) +{ + return netdev_tx_avail_queue(netdev_get_tx_queue(dev, 0)); +} + static inline void netdev_tx_reset_queue(struct netdev_queue *q) { #ifdef CONFIG_BQL @@ -2559,9 +2583,9 @@ static inline void netdev_tx_reset_queue(struct netdev_queue *q) * Reset the bytes and packet count of a network device and clear the * software flow control OFF bit for this network device */ -static inline void netdev_reset_queue(struct net_device *dev_queue) +static inline void netdev_reset_queue(struct net_device *dev) { - netdev_tx_reset_queue(netdev_get_tx_queue(dev_queue, 0)); + netdev_tx_reset_queue(netdev_get_tx_queue(dev, 0)); } /**