From: Eric Dumazet <eric.dumazet@gmail.com>
To: Stephen Hemminger <shemminger@vyatta.com>
Cc: David Miller <davem@davemloft.net>, jamal <hadi@cyberus.ca>,
netdev@vger.kernel.org
Subject: Re: [PATCH net-next 5/5] ifb: convert to 64 bit stats
Date: Mon, 20 Jun 2011 23:42:52 +0200 [thread overview]
Message-ID: <1308606172.2658.31.camel@edumazet-laptop> (raw)
In-Reply-To: <20110620143813.233f1642@nehalam.ftrdhcpuser.net>
From: Stephen Hemminger <shemminger@vyatta.com>
Le lundi 20 juin 2011 à 14:38 -0700, Stephen Hemminger a écrit :
> On Mon, 20 Jun 2011 23:27:01 +0200
> Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
> > Le lundi 20 juin 2011 à 23:23 +0200, Eric Dumazet a écrit :
> > > Le lundi 20 juin 2011 à 14:12 -0700, Stephen Hemminger a écrit :
> > > > Convert input functional block device to use 64 bit stats.
> > > >
> > > > Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> > > >
> > > > ---
> > > > v2 - add stats_sync
> > > >
> > >
> > > Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
> > >
> >
> > Ah well, I am wondering if ri_tasklet() & ifb_xmit() could run
> > concurrently
> >
> > If so, we need two separate syncp, one for each function.
>
> For the normal case that isn't possible but
> someone could be perverse and put an address on the ifb device and
> try and use like loopback?
Hmm, this can occur on normal case I think, on SMP.
Here is an updated patch
[PATCH net-next v3] ifb: convert to 64 bit stats
Convert input functional block device to use 64 bit stats.
[Eric Dumazet]: Use two different synchronization points for rx and tx.
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
v2 - add stats_sync
v3 - must use two different sync
drivers/net/ifb.c | 58 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 49 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index ce53f4a..2443e90 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -41,8 +41,16 @@
struct ifb_private {
struct tasklet_struct ifb_tasklet;
int tasklet_pending;
+
struct sk_buff_head rq;
+ u64 rx_packets;
+ u64 rx_bytes;
+ struct u64_stats_sync stats_rx_sync;
+
struct sk_buff_head tq;
+ u64 tx_packets;
+ u64 tx_bytes;
+ struct u64_stats_sync stats_tx_sync;
};
static int numifbs = 2;
@@ -54,10 +62,8 @@ static int ifb_close(struct net_device *dev);
static void ri_tasklet(unsigned long dev)
{
-
struct net_device *_dev = (struct net_device *)dev;
struct ifb_private *dp = netdev_priv(_dev);
- struct net_device_stats *stats = &_dev->stats;
struct netdev_queue *txq;
struct sk_buff *skb;
@@ -77,15 +83,18 @@ static void ri_tasklet(unsigned long dev)
skb->tc_verd = 0;
skb->tc_verd = SET_TC_NCLS(skb->tc_verd);
- stats->tx_packets++;
- stats->tx_bytes +=skb->len;
+
+ u64_stats_update_begin(&dp->stats_tx_sync);
+ dp->tx_packets++;
+ dp->tx_bytes += skb->len;
+ u64_stats_update_end(&dp->stats_tx_sync);
rcu_read_lock();
skb->dev = dev_get_by_index_rcu(&init_net, skb->skb_iif);
if (!skb->dev) {
rcu_read_unlock();
dev_kfree_skb(skb);
- stats->tx_dropped++;
+ _dev->stats.tx_dropped++;
if (skb_queue_len(&dp->tq) != 0)
goto resched;
break;
@@ -120,9 +129,39 @@ resched:
}
+static struct rtnl_link_stats64 *ifb_stats64(struct net_device *dev,
+ struct rtnl_link_stats64 *stats)
+{
+ const struct ifb_private *dp = netdev_priv(dev);
+ unsigned int start;
+
+ do {
+ start = u64_stats_fetch_begin_bh(&dp->stats_rx_sync);
+
+ stats->rx_packets = dp->rx_packets;
+ stats->rx_bytes = dp->rx_bytes;
+
+ } while (u64_stats_fetch_retry_bh(&dp->stats_rx_sync, start));
+
+ do {
+ start = u64_stats_fetch_begin_bh(&dp->stats_tx_sync);
+
+ stats->tx_packets = dp->tx_packets;
+ stats->tx_bytes = dp->tx_bytes;
+
+ } while (u64_stats_fetch_retry_bh(&dp->stats_tx_sync, start));
+
+ stats->rx_dropped = dev->stats.rx_dropped;
+ stats->tx_dropped = dev->stats.tx_dropped;
+
+ return stats;
+}
+
+
static const struct net_device_ops ifb_netdev_ops = {
.ndo_open = ifb_open,
.ndo_stop = ifb_close,
+ .ndo_get_stats64 = ifb_stats64,
.ndo_start_xmit = ifb_xmit,
.ndo_validate_addr = eth_validate_addr,
};
@@ -153,15 +192,16 @@ static void ifb_setup(struct net_device *dev)
static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct ifb_private *dp = netdev_priv(dev);
- struct net_device_stats *stats = &dev->stats;
u32 from = G_TC_FROM(skb->tc_verd);
- stats->rx_packets++;
- stats->rx_bytes+=skb->len;
+ u64_stats_update_begin(&dp->stats_rx_sync);
+ dp->rx_packets++;
+ dp->rx_bytes += skb->len;
+ u64_stats_update_end(&dp->stats_rx_sync);
if (!(from & (AT_INGRESS|AT_EGRESS)) || !skb->skb_iif) {
dev_kfree_skb(skb);
- stats->rx_dropped++;
+ dev->stats.rx_dropped++;
return NETDEV_TX_OK;
}
next prev parent reply other threads:[~2011-06-20 21:42 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-20 20:35 [PATCH net-next 0/5] more statistics updates Stephen Hemminger
2011-06-20 20:35 ` [PATCH net-next 1/5] vxge: fix 64 bit access on 32 bit platforms Stephen Hemminger
2011-06-21 22:56 ` David Miller
2011-06-20 20:35 ` [PATCH net-next 2/5] niu: fix 64 bit statistics on 32 bit platform Stephen Hemminger
2011-06-20 21:45 ` Ben Hutchings
2011-06-20 21:52 ` Stephen Hemminger
2011-06-20 22:02 ` Eric Dumazet
2011-06-20 20:35 ` [PATCH net-next 3/5] netxen: make 64 bit stats safe " Stephen Hemminger
2011-06-20 21:50 ` Eric Dumazet
2011-06-20 21:52 ` Ben Hutchings
2011-06-20 22:18 ` Stephen Hemminger
2011-06-20 22:27 ` Ben Hutchings
2011-06-20 20:35 ` [PATCH net-next 4/5] xen: convert to 64 bit stats interface Stephen Hemminger
2011-06-21 14:05 ` [Xen-devel] " Ian Campbell
2011-06-21 15:29 ` Stephen Hemminger
2011-06-21 15:35 ` Stephen Hemminger
2011-06-21 15:38 ` Ian Campbell
2011-06-21 22:57 ` David Miller
2011-06-20 20:56 ` [PATCH net-next 0/5] more statistics updates David Miller
2011-06-20 21:12 ` [PATCH net-next 5/5] ifb: convert to 64 bit stats Stephen Hemminger
2011-06-20 21:23 ` Eric Dumazet
2011-06-20 21:27 ` Eric Dumazet
2011-06-20 21:38 ` Stephen Hemminger
2011-06-20 21:42 ` Eric Dumazet [this message]
2011-06-20 21:42 ` [PATCH net-next 5/5] ifb: convert to 64 bit stats (v3) Stephen Hemminger
2011-06-20 21:44 ` Eric Dumazet
2011-06-21 0:04 ` jamal
2011-06-21 22:55 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1308606172.2658.31.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=hadi@cyberus.ca \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox