From patchwork Mon Jul 18 06:56:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kan.liang@intel.com X-Patchwork-Id: 649708 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rtWQ03Z1Tz9s5J for ; Tue, 19 Jul 2016 04:08:40 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 0CA6B30D5E; Mon, 18 Jul 2016 18:08:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4Ox+LcL-bySQ; Mon, 18 Jul 2016 18:08:37 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 034AB30F0B; Mon, 18 Jul 2016 18:08:00 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 6641D1C2A6F for ; Mon, 18 Jul 2016 14:23:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 630778AE99 for ; Mon, 18 Jul 2016 14:23:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l0sbBtK8CQcS for ; Mon, 18 Jul 2016 14:23:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by whitealder.osuosl.org (Postfix) with ESMTP id 694468AD1C for ; Mon, 18 Jul 2016 14:23:29 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 18 Jul 2016 07:23:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,384,1464678000"; d="scan'208"; a="1009027643" Received: from otc-grantly-02.jf.intel.com ([10.54.39.33]) by fmsmga001.fm.intel.com with ESMTP; 18 Jul 2016 07:23:29 -0700 From: kan.liang@intel.com To: davem@davemloft.net, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org Date: Sun, 17 Jul 2016 23:56:16 -0700 Message-Id: <1468824984-65318-23-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1468824984-65318-1-git-send-email-kan.liang@intel.com> References: <1468824984-65318-1-git-send-email-kan.liang@intel.com> X-Mailman-Approved-At: Mon, 18 Jul 2016 18:07:53 +0000 Cc: decot@googlers.com, aduyck@mirantis.com, andi@firstfloor.org, keescook@chromium.org, peterz@infradead.org, Kan Liang , jmorris@namei.org, yoshfuji@linux-ipv6.org, mingo@redhat.com, john.stultz@linaro.org, gorcunov@openvz.org, kuznet@ms2.inr.ac.ru, akpm@linux-foundation.org, ben@decadent.org.uk, kaber@trash.net, viro@zeniv.linux.org.uk Subject: [Intel-wired-lan] [RFC PATCH 22/30] net/netpolicy: set tx queues according to policy X-BeenThere: intel-wired-lan@lists.osuosl.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-wired-lan-bounces@lists.osuosl.org Sender: "Intel-wired-lan" From: Kan Liang When the device tries to transmit a buffer, netdev_pick_tx is called to find the available tx queues. This patch checks the per socket net policy of the binding socket of the buffer. If net policy is set, it picks up the assigned tx queue from net policy module, and redirect the traffic to the assigned queue. Signed-off-by: Kan Liang --- net/core/dev.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 7894e40..6108e3b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3266,6 +3266,7 @@ struct netdev_queue *netdev_pick_tx(struct net_device *dev, void *accel_priv) { int queue_index = 0; + struct sock *sk = skb->sk; #ifdef CONFIG_XPS u32 sender_cpu = skb->sender_cpu - 1; @@ -3279,8 +3280,21 @@ struct netdev_queue *netdev_pick_tx(struct net_device *dev, if (ops->ndo_select_queue) queue_index = ops->ndo_select_queue(dev, skb, accel_priv, __netdev_pick_tx); - else - queue_index = __netdev_pick_tx(dev, skb); + else { +#ifdef CONFIG_NETPOLICY + queue_index = -1; + if (sk && (sk->sk_netpolicy.policy > NET_POLICY_NONE)) { + /* There is no device bind to socket when setting policy + * Assign the dev now. + */ + if (!sk->sk_netpolicy.dev) + sk->sk_netpolicy.dev = dev; + queue_index = netpolicy_pick_queue(&sk->sk_netpolicy, false); + } + if (queue_index < 0) +#endif + queue_index = __netdev_pick_tx(dev, skb); + } if (!accel_priv) queue_index = netdev_cap_txqueue(dev, queue_index);