From patchwork Thu Apr 15 05:30:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changli Gao X-Patchwork-Id: 50217 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 E22BBB6ED0 for ; Thu, 15 Apr 2010 15:31:01 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754747Ab0DOFah (ORCPT ); Thu, 15 Apr 2010 01:30:37 -0400 Received: from mail-pz0-f204.google.com ([209.85.222.204]:49476 "EHLO mail-pz0-f204.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754698Ab0DOFaa (ORCPT ); Thu, 15 Apr 2010 01:30:30 -0400 Received: by pzk42 with SMTP id 42so813019pzk.4 for ; Wed, 14 Apr 2010 22:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=uUnxYH8swO2HssWKa67uq0IjwyQXTTyOzhAcdVRFmYY=; b=fr3YPJdRAURzejaINBMcLnjqUtWKKfYVAbx2RHH7sDok6YJ1wj3s/xyluUbz++0Sou WM31YnXn/ttNjXoay/2b6g0Klx1DiYePe1cPh0alMVELC1Ge0eAhAs7DmWtaeXHRqmWI eaGIsIxcEX+GLTZ5kSKL+6qnF4NwvuWbRrT90= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=AgSOIvaq/AiW7ekqdbYC9c8ghtiCpueEUsRpz7keP7gGu2n/V/ltKPSz0TKa0kcmkg KQ4lPK1YprxmSUaK5UH9q7OtB1cv/OuTGB4V8eeXvNEZjnNytr8+7rPVPOAfvNYUZdXk COZTqx59+er44bvn8YCR3vN4mwh8q/jTmdLZ4= Received: by 10.141.53.10 with SMTP id f10mr2982076rvk.134.1271309429331; Wed, 14 Apr 2010 22:30:29 -0700 (PDT) Received: from localhost.localdomain ([60.29.39.134]) by mx.google.com with ESMTPS id 22sm683988iwn.12.2010.04.14.22.30.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 14 Apr 2010 22:30:28 -0700 (PDT) From: Changli Gao To: "David S. Miller" Cc: Tom Herbert , Eric Dumazet , netdev@vger.kernel.org, Changli Gao Subject: [PATCH v2] net: fix softnet_stat Date: Thu, 15 Apr 2010 13:30:53 +0800 Message-Id: <1271309453-14987-1-git-send-email-xiaosuo@gmail.com> X-Mailer: git-send-email 1.6.4.4 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org fix softnet_stat Per cpu variable softnet_data.total was shared between IRQ and SoftIRQ context without any protection. And enqueue_to_backlog should update the netdev_rx_stat of the target CPU. This patch splits softnet_data.total into softnet_data.received and softnet_data.dropped internally, in order to avoid it sharing between IRQ and SoftIRQ. The old ABI softnet_data.total is kept by summing softnet_data.received and softnet_data.dropped when exporting it to userland. And softnet_data.dropped is protected in the corresponding input_pkt_queue.lock, if RPS is enabled. This patch also fixed a bug: packets received by enqueue_to_backlog() were counted twice: one in enqueue_to_backlog(), and the other in __netif_receive_skb(), although they maybe not on the same CPUs, if RPS is involved. Signed-off-by: Changli Gao ---- include/linux/netdevice.h | 2 +- net/core/dev.c | 7 +++---- 2 files changed, 4 insertions(+), 5 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/include/linux/netdevice.h b/include/linux/netdevice.h index d1a21b5..394e850 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -219,7 +219,7 @@ struct neigh_parms; struct sk_buff; struct netif_rx_stats { - unsigned total; + unsigned received; unsigned dropped; unsigned time_squeeze; unsigned cpu_collision; diff --git a/net/core/dev.c b/net/core/dev.c index a10a216..5817f0e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2336,7 +2336,6 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu) queue = &per_cpu(softnet_data, cpu); local_irq_save(flags); - __get_cpu_var(netdev_rx_stat).total++; rps_lock(queue); if (queue->input_pkt_queue.qlen <= netdev_max_backlog) { @@ -2366,9 +2365,9 @@ enqueue: goto enqueue; } + per_cpu(netdev_rx_stat, cpu).dropped++; rps_unlock(queue); - __get_cpu_var(netdev_rx_stat).dropped++; local_irq_restore(flags); kfree_skb(skb); @@ -2679,7 +2678,7 @@ static int __netif_receive_skb(struct sk_buff *skb) skb->dev = master; } - __get_cpu_var(netdev_rx_stat).total++; + __get_cpu_var(netdev_rx_stat).received++; skb_reset_network_header(skb); skb_reset_transport_header(skb); @@ -3565,7 +3564,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v) struct netif_rx_stats *s = v; seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", - s->total, s->dropped, s->time_squeeze, 0, + s->received + s->dropped, s->dropped, s->time_squeeze, 0, 0, 0, 0, 0, /* was fastroute */ s->cpu_collision, s->received_rps); return 0;