From patchwork Tue Mar 23 06:24:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changli Gao X-Patchwork-Id: 48323 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 9F046B7CEE for ; Tue, 23 Mar 2010 17:24:55 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754524Ab0CWGYu (ORCPT ); Tue, 23 Mar 2010 02:24:50 -0400 Received: from mail-gw0-f46.google.com ([74.125.83.46]:45078 "EHLO mail-gw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753330Ab0CWGYt (ORCPT ); Tue, 23 Mar 2010 02:24:49 -0400 Received: by gwaa18 with SMTP id a18so1355735gwa.19 for ; Mon, 22 Mar 2010 23:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to :user-agent:mime-version:to:cc:subject:content-type :content-transfer-encoding; bh=Tjh7jszUQqEDGHFDkmPGLksq0f6cVK5w3UXarG+2BFk=; b=FEi7Cr5BKgefLd+g84Nhw0OCvL6VyWwtikIkWivx4EMKkFsy3lMP03QprCvzoAT2BP 9bYHK0dqbc6BzDZM5Qk9dfTzr4KvT3XCw5WU5L065LiaMxFRle3+qHqSsORXW/n1rJzw ThUMZxomGja8ucNNM2oF3gSx3Vxz++zI7CCYw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; b=hRewf2sSQP+mUIk+IJV4g3VCrPkoaZtpsje5UUf3eUkeiI7Kl/L2PMM3MyzDb94wZj YTg31790CtT/1pqDy5OvpftarsfnnlPe/yViipVvnwm8kuAi//ZpV7f3eVSafcxhMu3P 4zMBPqER6E6DR7j6d4koLrULqlrFEj0duU8FI= Received: by 10.101.151.2 with SMTP id d2mr6544379ano.33.1269325489132; Mon, 22 Mar 2010 23:24:49 -0700 (PDT) Received: from [10.13.150.1] ([221.238.105.46]) by mx.google.com with ESMTPS id 9sm2018755ywf.50.2010.03.22.23.24.45 (version=SSLv3 cipher=RC4-MD5); Mon, 22 Mar 2010 23:24:48 -0700 (PDT) Message-ID: <4BA85EA2.1090304@gmail.com> Date: Tue, 23 Mar 2010 14:24:34 +0800 From: Changli Gao Reply-To: xiaosuo@gmail.com User-Agent: Thunderbird 2.0.0.23 (X11/20091022) MIME-Version: 1.0 To: "David S. Miller" CC: Tom Herbert , xiaosuo , netdev@vger.kernel.org Subject: [PATCH] rps: make distributing packets fairly among all the online CPUs default Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org make distributing packets fairly among all the online CPUs default. Make distributing packets fairly among all the online CPUs default, then users don't need any explicit configuration to get the benefit of RPS. Signed-off-by: Changli Gao ---- net/core/dev.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 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 diff --git a/net/core/dev.c b/net/core/dev.c index c0e2608..a4246f1 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5234,6 +5234,24 @@ void netif_stacked_transfer_operstate(const struct net_device *rootdev, } EXPORT_SYMBOL(netif_stacked_transfer_operstate); +static struct rps_map* alloc_rps_map(void) +{ + struct rps_map *map; + int i, cpu; + + map = kzalloc(max_t(unsigned, + RPS_MAP_SIZE(cpumask_weight(cpu_online_mask)), + L1_CACHE_BYTES), GFP_KERNEL); + if (map == NULL) + return NULL; + i = 0; + for_each_online_cpu(cpu) + map->cpus[i++] = cpu; + map->len = i; + + return map; +} + /** * register_netdevice - register a network device * @dev: device to register @@ -5282,7 +5300,13 @@ int register_netdevice(struct net_device *dev) ret = -ENOMEM; goto out; } - + dev->_rx->rps_map = alloc_rps_map(); + if (dev->_rx->rps_map == NULL) { + kfree(dev->_rx); + dev->_rx = NULL; + ret = -ENOMEM; + goto out; + } dev->_rx->first = dev->_rx; atomic_set(&dev->_rx->count, 1); dev->num_rx_queues = 1; @@ -5688,8 +5712,12 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, * Set a pointer to first element in the array which holds the * reference count. */ - for (i = 0; i < queue_count; i++) + for (i = 0; i < queue_count; i++) { rx[i].first = rx; + rx[i].rps_map = alloc_rps_map(); + if (rx[i].rps_map == NULL) + goto free_rx; + } dev = PTR_ALIGN(p, NETDEV_ALIGN); dev->padded = (char *)dev - (char *)p; @@ -5723,6 +5751,8 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, return dev; free_rx: + for (i = 0; i < queue_count; i++) + kfree(rx[i].rps_map); kfree(rx); free_tx: kfree(tx);