Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp994489pxb; Fri, 13 Nov 2020 01:05:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5fgUTVzuZE5WI0p25Tn+g2wprAzwSha4qfe4As0hcjh89PlzIovfDm8O+KhIKZZxBzyuf X-Received: by 2002:a17:906:3c17:: with SMTP id h23mr1013670ejg.374.1605258306761; Fri, 13 Nov 2020 01:05:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605258306; cv=none; d=google.com; s=arc-20160816; b=aYJLVXWfS8fFWvRMOJIkLk2C4fZ7e9T2qRCfIvbSQovM5D4ERqEODydn0VXpa1RhX9 29maNPQs6yNlCYt2+yDJGG9PIq1zX7a4t6T2JQh0kQNeh9lpsU98QvmPgVotLJPJE672 WwcA6TNm/wwriPNetxsoYib4Y4gSr1eM/ucvpobjl569nubJDw4GjD+qlSzCjjxOcwvU BIEBorpql5QIiYeJEF07AO47zspSENtD1386uGbw/l4v9YdAEZVVm8b++4wMZGOVfOs7 z6cpmWZdjFUPDCsEgIk9gegYKA7/W5Y3pNeLLPYnRN5jxT+t2g1mqWm7s4iYvsFmRMCT k2Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jOx9/hL9gcypJbYKVQmbDZbvLP/OxmK+3X0k+2YLwtI=; b=nZu0qUHT334OHFHH8m3LSy1mPbpd52h4QB9UMEphBX5CFFB/ndxj++U0t8k3/QvGXU I5uqVZgO+BNXQ1S7UzCbQqif9JCDPNGLOLXhVDb1c5F4rpEut3Ch36CA00wslhYNwFue M1YQUG8T29TCIxLT+8dmt/KySx9I3ejwQtLXDe4RU1Q9G88XoVb3AQbO4hzFshvnFmGE Q3Qg25tdUlk9hKktZzYL2hdkrRl377nTMBd724prF263zrG9vA/8R4IqfI6egXH6GwLJ mcYL6tnstNcIviKBwRSz94Q6+neD1c/vxQV2Fnmcnl8lZj18PAgWpVhdwsZuZdnXn023 UrGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QB2KkR+Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f23si5559056ejb.6.2020.11.13.01.04.43; Fri, 13 Nov 2020 01:05:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QB2KkR+Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726325AbgKMJDU (ORCPT + 99 others); Fri, 13 Nov 2020 04:03:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726237AbgKMJDT (ORCPT ); Fri, 13 Nov 2020 04:03:19 -0500 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EC53C0613D1; Fri, 13 Nov 2020 01:03:19 -0800 (PST) Received: by mail-lj1-x243.google.com with SMTP id 11so9795972ljf.2; Fri, 13 Nov 2020 01:03:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jOx9/hL9gcypJbYKVQmbDZbvLP/OxmK+3X0k+2YLwtI=; b=QB2KkR+ZBDshhCgbXCg99iRunoBLOQQuuJHx03u+I9M4KWg3oSRSC93pCOAeYozgON FJG5lxKfLfkf3vOkJv+BbszR0Tec0IET8GqxXdcdWKA+ctGe1J1Oq12fkrS2L4R5TU3m evSW2v9MT2PsoFqEQDomHux7UzKKstuI3at1e8KwUM+kjhXSfqc+Hn1gYWeYboM4rUM6 mOAwf9MhHy0zJ5qqhn2FYlFjURh8lAV0h0ncHyAqphl7A3c2xA0kfZHoqCAE8aOYzXez kvAvknzfYwPYpuphZZ8gVggrIJtS6u3uHfKqcvOZPp5eOjO9QhxWrNmI7mYcBv/f4YYj +Fyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jOx9/hL9gcypJbYKVQmbDZbvLP/OxmK+3X0k+2YLwtI=; b=AgFbaIkxPEJF55As37lVonKIKXy3DM2JwVnRTWxQZ6h4X3KxbEYgv6xaeiyCFPv2fI FKxktBm66sA3ImuHv/1KCIMfBylX9jRCm7pryaeeFZUyU93EdON7JFEAv0Q1RBceXJQN GHe9/ZH6A/lWdmPovxwV7vsPcotS7wFhbW43zddW872ETNub6KrAuVn/MODcMfcJPAmQ csLDv3PYlGtSSndsJoMsiWpIXW+/U+OFRKqhVg+OpM6WgPMHUuwI+q2vXOTJA/9Dsxgt 6fTeu2VLzLeRfAJkURLBy0eht5gBvV1IC6bF1pK3Ln2U5ZbIN7FmRFChP4/wqqRRUb0j VlPQ== X-Gm-Message-State: AOAM531VxKDzBokXoMNNwIbkYB8jiwJiE+vnqwAKgUqg6y6bYJ2hruP8 6rIdMQ0G0lVOE6u0ZM2Gy/Q= X-Received: by 2002:a2e:91cd:: with SMTP id u13mr584825ljg.239.1605258197991; Fri, 13 Nov 2020 01:03:17 -0800 (PST) Received: from localhost.localdomain (dmjt96jhvbz3j2f08hy-4.rev.dnainternet.fi. [2001:14bb:51:e1dd:1cd1:d2e:7b13:dc30]) by smtp.gmail.com with ESMTPSA id c6sm1477876lfm.226.2020.11.13.01.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 01:03:17 -0800 (PST) From: Lev Stipakov X-Google-Original-From: Lev Stipakov To: Pravin B Shelar , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, dev@openvswitch.org, linux-kernel@vger.kernel.org, Heiner Kallweit Cc: Lev Stipakov Subject: [PATCH v2 2/3] net: openvswitch: use core API to update/provide stats Date: Fri, 13 Nov 2020 11:02:40 +0200 Message-Id: <20201113090240.116518-1-lev@openvpn.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <598c779c-fb0b-a9a6-43be-3a7cd5b38946@gmail.com> References: <598c779c-fb0b-a9a6-43be-3a7cd5b38946@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit d3fd65484c781 ("net: core: add dev_sw_netstats_tx_add") has added function "dev_sw_netstats_tx_add()" to update net device per-cpu TX stats. Use this function instead of own code. While on it, remove internal_get_stats() and replace it with dev_get_tstats64(). Signed-off-by: Lev Stipakov --- v2: - do not delete len variable and add comment why - replace internal_get_stats() vs dev_get_tstats64() net/openvswitch/vport-internal_dev.c | 29 +++++++--------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c index 1e30d8df3ba5..5b2ee9c1c00b 100644 --- a/net/openvswitch/vport-internal_dev.c +++ b/net/openvswitch/vport-internal_dev.c @@ -35,21 +35,18 @@ internal_dev_xmit(struct sk_buff *skb, struct net_device *netdev) { int len, err; + /* store len value because skb can be freed inside ovs_vport_receive() */ len = skb->len; + rcu_read_lock(); err = ovs_vport_receive(internal_dev_priv(netdev)->vport, skb, NULL); rcu_read_unlock(); - if (likely(!err)) { - struct pcpu_sw_netstats *tstats = this_cpu_ptr(netdev->tstats); - - u64_stats_update_begin(&tstats->syncp); - tstats->tx_bytes += len; - tstats->tx_packets++; - u64_stats_update_end(&tstats->syncp); - } else { + if (likely(!err)) + dev_sw_netstats_tx_add(netdev, 1, len); + else netdev->stats.tx_errors++; - } + return NETDEV_TX_OK; } @@ -83,24 +80,12 @@ static void internal_dev_destructor(struct net_device *dev) ovs_vport_free(vport); } -static void -internal_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) -{ - memset(stats, 0, sizeof(*stats)); - stats->rx_errors = dev->stats.rx_errors; - stats->tx_errors = dev->stats.tx_errors; - stats->tx_dropped = dev->stats.tx_dropped; - stats->rx_dropped = dev->stats.rx_dropped; - - dev_fetch_sw_netstats(stats, dev->tstats); -} - static const struct net_device_ops internal_dev_netdev_ops = { .ndo_open = internal_dev_open, .ndo_stop = internal_dev_stop, .ndo_start_xmit = internal_dev_xmit, .ndo_set_mac_address = eth_mac_addr, - .ndo_get_stats64 = internal_get_stats, + .ndo_get_stats64 = dev_get_tstats64, }; static struct rtnl_link_ops internal_dev_link_ops __read_mostly = { -- 2.25.1