Skip to contentSkip to conversation

Network Drop Monitor: Make use of consume_skb() in af_can.c

PATCH Applied Oliver Hartkopp 4 participants 13 messages Apr 16, 2009 – Apr 20, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Network Drop Monitor: Make use of consume_skb() in af_can.c

Since commit ead2ceb0ec9f85cff19c43b5cdb2f8a054484431 so called end-of-line points for skb's should use consume_skb() to free the socket buffer.

In opposite to consume_skb() the function kfree_skb() is intended to be used for unexpected skb drops e.g. in error conditions that now can trigger the network drop monitor if enabled.

This patch moves the skb end-of-line point in af_can.c to use consume_skb().

---

net/can/af_can.c +2 -2
index 547bafc..10f0528 100644
@@ -674,8 +674,8 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,
 
 	rcu_read_unlock();
 
-	/* free the skbuff allocated by the netdevice driver */
-	kfree_skb(skb);
+	/* consume the skbuff allocated by the netdevice driver */
+	consume_skb(skb);
 
 	if (matches > 0) {
 		can_stats.matches++;
maintainer Applied
#1 lore raw

From: Oliver Hartkopp <[email protected]>
Date: Thu, 16 Apr 2009 21:58:29 +0200

Quoted 10 lines

Since commit ead2ceb0ec9f85cff19c43b5cdb2f8a054484431 so called end-of-line points for skb's should use consume_skb() to free the socket buffer.

In opposite to consume_skb() the function kfree_skb() is intended to be used for unexpected skb drops e.g. in error conditions that now can trigger the network drop monitor if enabled.

This patch moves the skb end-of-line point in af_can.c to use consume_skb().

Applied, thanks.

#2 lore raw

PATCH 1/1 loopback: packet drops accounting

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:0 dropped:0 overruns:0 frame:0
          TX packets:692562900 errors:3228 dropped:3228 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)

I chose to reflect those errors only in tx_dropped/tx_errors, and not mirror these errors in rx_dropped/rx_errors.

---
 drivers/net/loopback.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
drivers/net/loopback.c +15 -6
index b7d438a..a036296 100644
@@ -62,6 +62,7 @@
 struct pcpu_lstats {
 	unsigned long packets;
 	unsigned long bytes;
+	unsigned long drops;
 };
 
 /*
@@ -71,18 +72,22 @@ struct pcpu_lstats {
 static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct pcpu_lstats *pcpu_lstats, *lb_stats;
+	int len;
 
 	skb_orphan(skb);
 
-	skb->protocol = eth_type_trans(skb,dev);
+	skb->protocol = eth_type_trans(skb, dev);
 
 	/* it's OK to use per_cpu_ptr() because BHs are off */
 	pcpu_lstats = dev->ml_priv;
 	lb_stats = per_cpu_ptr(pcpu_lstats, smp_processor_id());
-	lb_stats->bytes += skb->len;
-	lb_stats->packets++;
 
-	netif_rx(skb);
+	len = skb->len;
+	if (likely(netif_rx(skb) == NET_RX_SUCCESS)) {
+		lb_stats->bytes += len;
+		lb_stats->packets++;
+	} else
+		lb_stats->drops++;
 
 	return 0;
 }
@@ -93,6 +98,7 @@ static struct net_device_stats *loopback_get_stats(struct net_device *dev)
 	struct net_device_stats *stats = &dev->stats;
 	unsigned long bytes = 0;
 	unsigned long packets = 0;
+	unsigned long drops = 0;
 	int i;
 
 	pcpu_lstats = dev->ml_priv;
@@ -102,11 +108,14 @@ static struct net_device_stats *loopback_get_stats(struct net_device *dev)
 		lb_stats = per_cpu_ptr(pcpu_lstats, i);
 		bytes   += lb_stats->bytes;
 		packets += lb_stats->packets;
+		drops   += lb_stats->drops;
 	}
 	stats->rx_packets = packets;
 	stats->tx_packets = packets;
-	stats->rx_bytes = bytes;
-	stats->tx_bytes = bytes;
+	stats->tx_dropped = drops;
+	stats->tx_errors  = drops;
+	stats->rx_bytes   = bytes;
+	stats->tx_bytes   = bytes;
 	return stats;
 }
 
maintainer
#3 lore raw

Re: [PATCH] loopback: packet drops accounting

From: Eric Dumazet <[email protected]>
Date: Fri, 17 Apr 2009 10:56:57 +0200

Quoted 16 lines

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:0 dropped:0 overruns:0 frame:0
          TX packets:692562900 errors:3228 dropped:3228 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)
Quoted 4 lines

I chose to reflect those errors only in tx_dropped/tx_errors, and not mirror these errors in rx_dropped/rx_errors.

Well, logically the receive is what failed, not the transmit.

I think it's therefore misleading to count it as a TX drop.

Do you feel strongly about this?

#4 lore raw

Re: [PATCH] loopback: packet drops accounting

Quoted 22 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Fri, 17 Apr 2009 10:56:57 +0200

Quoted 19 lines

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:0 dropped:0 overruns:0 frame:0
          TX packets:692562900 errors:3228 dropped:3228 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)

I chose to reflect those errors only in tx_dropped/tx_errors, and not mirror these errors in rx_dropped/rx_errors.

Quoted 7 lines
Quoted 1 line

Well, logically the receive is what failed, not the transmit.

I think it's therefore misleading to count it as a TX drop.

Do you feel strongly about this?

Not at all, but my plan was to go a litle bit further, ie being able to return from loopback_xmit() with a non null value.

netif_rx() usage in loopback device is biased, since its really a transmit :)

Oh well...

#5 lore raw

PATCH 1/1 loopback: better handling of packet drops

Quoted 24 lines · Eric Dumazet
Quoted 23 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Fri, 17 Apr 2009 10:56:57 +0200

Quoted 20 lines

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:0 dropped:0 overruns:0 frame:0
          TX packets:692562900 errors:3228 dropped:3228 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)

I chose to reflect those errors only in tx_dropped/tx_errors, and not mirror these errors in rx_dropped/rx_errors.

Quoted 9 lines
Quoted 5 lines

Well, logically the receive is what failed, not the transmit.

I think it's therefore misleading to count it as a TX drop.

Do you feel strongly about this?

Not at all, but my plan was to go a litle bit further, ie being able to return from loopback_xmit() with a non null value.

Something like this :

[PATCH] loopback: better handling of packet drops

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts. Also upper layers are not warned of these transmit failures.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:0 dropped:0 overruns:0 frame:0
          TX packets:692562900 errors:3228 dropped:3228 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)

More over, loopback_xmit() can now return to its caller the indication that packet was not transmitted for better queue management and error handling.

I chose to reflect those errors only in tx_dropped/tx_errors, and not mirror them in rx_dropped/rx_errors.

Splitting netif_rx() with a helper function boosts tbench performance by 1%, because we can avoid two tests (about netpoll and timestamping)

Tested with /proc/sys/net/core/netdev_max_backlog set to 0, tbench can run at full speed even with some 'losses' on loopback. No more tcp stalls...

---
 drivers/net/loopback.c    |   24 +++++++++---
 include/linux/netdevice.h |    1
 net/core/dev.c            |   68 +++++++++++++++++++++++-------------
 3 files changed, 62 insertions(+), 31 deletions(-)
drivers/net/loopback.c +17 -7
index b7d438a..a1308fd 100644
@@ -62,6 +62,7 @@
 struct pcpu_lstats {
 	unsigned long packets;
 	unsigned long bytes;
+	unsigned long drops;
 };
 
 /*
@@ -71,20 +72,25 @@ struct pcpu_lstats {
 static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct pcpu_lstats *pcpu_lstats, *lb_stats;
+	int len;
 
 	skb_orphan(skb);
 
-	skb->protocol = eth_type_trans(skb,dev);
+	skb->protocol = eth_type_trans(skb, dev);
 
 	/* it's OK to use per_cpu_ptr() because BHs are off */
 	pcpu_lstats = dev->ml_priv;
 	lb_stats = per_cpu_ptr(pcpu_lstats, smp_processor_id());
-	lb_stats->bytes += skb->len;
-	lb_stats->packets++;
 
-	netif_rx(skb);
+	len = skb->len;
+	if (likely(__netif_rx(skb) == NET_RX_SUCCESS)) {
+		lb_stats->bytes += len;
+		lb_stats->packets++;
+		return 0;
+	}
+	lb_stats->drops++;
 
-	return 0;
+	return 1;
 }
 
 static struct net_device_stats *loopback_get_stats(struct net_device *dev)
@@ -93,6 +99,7 @@ static struct net_device_stats *loopback_get_stats(struct net_device *dev)
 	struct net_device_stats *stats = &dev->stats;
 	unsigned long bytes = 0;
 	unsigned long packets = 0;
+	unsigned long drops = 0;
 	int i;
 
 	pcpu_lstats = dev->ml_priv;
@@ -102,11 +109,14 @@ static struct net_device_stats *loopback_get_stats(struct net_device *dev)
 		lb_stats = per_cpu_ptr(pcpu_lstats, i);
 		bytes   += lb_stats->bytes;
 		packets += lb_stats->packets;
+		drops   += lb_stats->drops;
 	}
 	stats->rx_packets = packets;
 	stats->tx_packets = packets;
-	stats->rx_bytes = bytes;
-	stats->tx_bytes = bytes;
+	stats->tx_dropped = drops;
+	stats->tx_errors  = drops;
+	stats->rx_bytes   = bytes;
+	stats->tx_bytes   = bytes;
 	return stats;
 }
 
include/linux/netdevice.h +1 -0
index 2e7783f..c60e250 100644
@@ -1430,6 +1430,7 @@ extern void dev_kfree_skb_irq(struct sk_buff *skb);
 extern void dev_kfree_skb_any(struct sk_buff *skb);
 
 #define HAVE_NETIF_RX 1
+extern int		__netif_rx(struct sk_buff *skb);
 extern int		netif_rx(struct sk_buff *skb);
 extern int		netif_rx_ni(struct sk_buff *skb);
 #define HAVE_NETIF_RECEIVE_SKB 1
net/core/dev.c +44 -24

95 lines not on this page · raw message

#6 lore raw

Re: [PATCH] loopback: better handling of packet drops

Quoted 27 lines · Eric Dumazet
Quoted 26 lines · Eric Dumazet
Quoted 25 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Fri, 17 Apr 2009 10:56:57 +0200

Quoted 16 lines

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:0 dropped:0 overruns:0 frame:0
          TX packets:692562900 errors:3228 dropped:3228 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)
Quoted 4 lines

I chose to reflect those errors only in tx_dropped/tx_errors, and not mirror these errors in rx_dropped/rx_errors.

Well, logically the receive is what failed, not the transmit.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I think it's therefore misleading to count it as a TX drop.

Do you feel strongly about this?

Not at all, but my plan was to go a litle bit further, ie being able to return from loopback_xmit() with a non null value.

Something like this :

I just noticed NETDEV_TX_BUSY & NETDEV_TX_OK, so here is an updated version using these macros instead of 0 & 1

[PATCH] loopback: better handling of packet drops

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts. Also upper layers are not warned of these transmit failures.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:0 dropped:0 overruns:0 frame:0
          TX packets:692562900 errors:3228 dropped:3228 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)

More over, loopback_xmit() can now return to its caller the indication that packet was not transmitted for better queue management and error handling.

I chose to reflect those errors only in tx_dropped/tx_errors, and not mirror them in rx_dropped/rx_errors.

Splitting netif_rx() with a helper function boosts tbench performance by 1%, because we can avoid two tests (about netpoll and timestamping)

Tested with /proc/sys/net/core/netdev_max_backlog set to 0, tbench can run at full speed even with some 'losses' on loopback. No more tcp stalls...

---
 drivers/net/loopback.c    |   24 +++++++++---
 include/linux/netdevice.h |    1
 net/core/dev.c            |   68 +++++++++++++++++++++++-------------
 3 files changed, 62 insertions(+), 31 deletions(-)
drivers/net/loopback.c +17 -7
index b7d438a..101a3bc 100644
@@ -62,6 +62,7 @@
 struct pcpu_lstats {
 	unsigned long packets;
 	unsigned long bytes;
+	unsigned long drops;
 };
 
 /*
@@ -71,20 +72,25 @@ struct pcpu_lstats {
 static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct pcpu_lstats *pcpu_lstats, *lb_stats;
+	int len;
 
 	skb_orphan(skb);
 
-	skb->protocol = eth_type_trans(skb,dev);
+	skb->protocol = eth_type_trans(skb, dev);
 
 	/* it's OK to use per_cpu_ptr() because BHs are off */
 	pcpu_lstats = dev->ml_priv;
 	lb_stats = per_cpu_ptr(pcpu_lstats, smp_processor_id());
-	lb_stats->bytes += skb->len;
-	lb_stats->packets++;
 
-	netif_rx(skb);
+	len = skb->len;
+	if (likely(__netif_rx(skb) == NET_RX_SUCCESS)) {
+		lb_stats->bytes += len;
+		lb_stats->packets++;
+		return NETDEV_TX_OK;
+	}
+	lb_stats->drops++;
 
-	return 0;
+	return NETDEV_TX_BUSY;
 }
 
 static struct net_device_stats *loopback_get_stats(struct net_device *dev)
@@ -93,6 +99,7 @@ static struct net_device_stats *loopback_get_stats(struct net_device *dev)
 	struct net_device_stats *stats = &dev->stats;
 	unsigned long bytes = 0;
 	unsigned long packets = 0;
+	unsigned long drops = 0;
 	int i;
 
 	pcpu_lstats = dev->ml_priv;
@@ -102,11 +109,14 @@ static struct net_device_stats *loopback_get_stats(struct net_device *dev)
 		lb_stats = per_cpu_ptr(pcpu_lstats, i);
 		bytes   += lb_stats->bytes;
 		packets += lb_stats->packets;
+		drops   += lb_stats->drops;
 	}
 	stats->rx_packets = packets;
 	stats->tx_packets = packets;
-	stats->rx_bytes = bytes;
-	stats->tx_bytes = bytes;
+	stats->tx_dropped = drops;
+	stats->tx_errors  = drops;
+	stats->rx_bytes   = bytes;
+	stats->tx_bytes   = bytes;
 	return stats;
 }
 
include/linux/netdevice.h +1 -0
index 2e7783f..c60e250 100644
@@ -1430,6 +1430,7 @@ extern void dev_kfree_skb_irq(struct sk_buff *skb);
 extern void dev_kfree_skb_any(struct sk_buff *skb);
 
 #define HAVE_NETIF_RX 1
+extern int		__netif_rx(struct sk_buff *skb);
 extern int		netif_rx(struct sk_buff *skb);
 extern int		netif_rx_ni(struct sk_buff *skb);
 #define HAVE_NETIF_RECEIVE_SKB 1
net/core/dev.c +44 -24

95 lines not on this page · raw message

maintainer
#7 lore raw

Re: [PATCH] loopback: better handling of packet drops

From: Eric Dumazet <[email protected]>
Date: Fri, 17 Apr 2009 12:33:33 +0200

Quoted 3 lines

Splitting netif_rx() with a helper function boosts tbench performance by 1%, because we can avoid two tests (about netpoll and timestamping)

Loopback is not a special device no matter how much you wish it might be :-)

This is why I haven't really pursued any further those patches I showed you that treat local TCP connections specially, it just had the realy possibility to break clever things people might be doing over loopback using the packet scheduler classifier and packet scheduler actions.

I also think it is valid to use netpoll over loopback, especially for testing.

So please undo this part of the patch. You always try to combine multiple distinct changes, and I would have taken just your TX drop change if you hadn't added this __netif_rx() stuff to it :-(

#8 lore raw

Re: [PATCH] loopback: better handling of packet drops

Quoted 7 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Fri, 17 Apr 2009 12:33:33 +0200

Quoted 3 lines

Splitting netif_rx() with a helper function boosts tbench performance by 1%, because we can avoid two tests (about netpoll and timestamping)

Quoted 8 lines

Loopback is not a special device no matter how much you wish it might be :-)

This is why I haven't really pursued any further those patches I showed you that treat local TCP connections specially, it just had the realy possibility to break clever things people might be doing over loopback using the packet scheduler classifier and packet scheduler actions.

Point taken.

Quoted 3 lines

I also think it is valid to use netpoll over loopback, especially for testing.

Oh I didnt knew it was possible/useful, sorry about that.

Quoted 4 lines

So please undo this part of the patch. You always try to combine multiple distinct changes, and I would have taken just your TX drop change if you hadn't added this __netif_rx() stuff to it :-(

I followed on this patch to show what I had in mind, and why I thought it was a transmit error more than a receive one.

1) Do you reject idea of splitting netif_rx() to be able to not freeing skb in case of congestion ?
2) If not, do you want me to send two separate patches ?
3) Should I update rx_errors or tx_errors or both ?

Thank you

#9 lore raw

Re: [PATCH] loopback: better handling of packet drops

In reply to Eric Dumazet
Quoted 110 lines · On Fri, 17 Apr 2009 12:33:33 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 27 lines · Eric Dumazet
Quoted 26 lines · Eric Dumazet
Quoted 25 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Fri, 17 Apr 2009 10:56:57 +0200

Quoted 16 lines

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:0 dropped:0 overruns:0 frame:0
          TX packets:692562900 errors:3228 dropped:3228 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)
Quoted 4 lines

I chose to reflect those errors only in tx_dropped/tx_errors, and not mirror these errors in rx_dropped/rx_errors.

Well, logically the receive is what failed, not the transmit.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I think it's therefore misleading to count it as a TX drop.

Do you feel strongly about this?

Not at all, but my plan was to go a litle bit further, ie being able to return from loopback_xmit() with a non null value.

Something like this :

I just noticed NETDEV_TX_BUSY & NETDEV_TX_OK, so here is an updated version using these macros instead of 0 & 1

[PATCH] loopback: better handling of packet drops

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts. Also upper layers are not warned of these transmit failures.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:0 dropped:0 overruns:0 frame:0
          TX packets:692562900 errors:3228 dropped:3228 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)

More over, loopback_xmit() can now return to its caller the indication that packet was not transmitted for better queue management and error handling.

I chose to reflect those errors only in tx_dropped/tx_errors, and not mirror them in rx_dropped/rx_errors.

Splitting netif_rx() with a helper function boosts tbench performance by 1%, because we can avoid two tests (about netpoll and timestamping)

Tested with /proc/sys/net/core/netdev_max_backlog set to 0, tbench can run at full speed even with some 'losses' on loopback. No more tcp stalls...

---
 drivers/net/loopback.c    |   24 +++++++++---
 include/linux/netdevice.h |    1
 net/core/dev.c            |   68 +++++++++++++++++++++++-------------
 3 files changed, 62 insertions(+), 31 deletions(-)
drivers/net/loopback.c +4 -4
index b7d438a..101a3bc 100644
@@ -62,6 +62,7 @@
 struct pcpu_lstats {
 	unsigned long packets;
 	unsigned long bytes;
+	unsigned long drops;
 };
 
 /*
@@ -71,20 +72,25 @@ struct pcpu_lstats {
 static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct pcpu_lstats *pcpu_lstats, *lb_stats;
+	int len;
 
 	skb_orphan(skb);
 
-	skb->protocol = eth_type_trans(skb,dev);
+	skb->protocol = eth_type_trans(skb, dev);
 
 	/* it's OK to use per_cpu_ptr() because BHs are off */
 	pcpu_lstats = dev->ml_priv;
 	lb_stats = per_cpu_ptr(pcpu_lstats, smp_processor_id());
-	lb_stats->bytes += skb->len;
-	lb_stats->packets++;
 
-	netif_rx(skb);
+	len = skb->len;

drivers/net/loopback.c struct pcpu_lstats { · line 94

Quoted 10 lines
drivers/net/loopback.c +7 -1
+	if (likely(__netif_rx(skb) == NET_RX_SUCCESS)) {
+		lb_stats->bytes += len;
+		lb_stats->packets++;
+		return NETDEV_TX_OK;
+	}
+	lb_stats->drops++;
 
-	return 0;
+	return NETDEV_TX_BUSY;
 }

If you return NETDEV_TX_BUSY, then the xmit logic will retry so it is not really a drop but a stall. I think it is confusing to call this a packet loss.

#10 lore raw

Re: [PATCH] loopback: better handling of packet drops

Quoted 27 lines · Stephen Hemminger
Quoted 25 lines · On Fri, 17 Apr 2009 12:33:33 +0200 Eric Dumazet <[email protected]> wrote:

static int loopback_xmit(struct sk_buff *skb, struct net_device *dev) {

drivers/net/loopback.c +9 -4
 	struct pcpu_lstats *pcpu_lstats, *lb_stats;
+	int len;
 
 	skb_orphan(skb);
 
-	skb->protocol = eth_type_trans(skb,dev);
+	skb->protocol = eth_type_trans(skb, dev);
 
 	/* it's OK to use per_cpu_ptr() because BHs are off */
 	pcpu_lstats = dev->ml_priv;
 	lb_stats = per_cpu_ptr(pcpu_lstats, smp_processor_id());
-	lb_stats->bytes += skb->len;
-	lb_stats->packets++;
 
-	netif_rx(skb);
+	len = skb->len;
+	if (likely(__netif_rx(skb) == NET_RX_SUCCESS)) {
+		lb_stats->bytes += len;
+		lb_stats->packets++;
+		return NETDEV_TX_OK;
+	}
+	lb_stats->drops++;
Quoted 7 lines

drivers/net/loopback.c struct pcpu_lstats { · line 94

Quoted 3 lines
drivers/net/loopback.c +1 -1
-	return 0;
+	return NETDEV_TX_BUSY;
 }

If you return NETDEV_TX_BUSY, then the xmit logic will retry so it is not really a drop but a stall. I think it is confusing to call this a packet loss.

Good point, thanks.
So we should not account this stall in dev stats ? Maybe in 'collisions' ?

I also discovered we had to do
skb_push(skb, ETH_HLEN); /* undo the skb_pull() done in eth_type_trans() */ before returning NETDEV_TX_BUSY;

#11 lore raw

Re: [PATCH] loopback: packet drops accounting

In reply to Eric Dumazet
Quoted 23 lines · Eric Dumazet
Quoted 22 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Fri, 17 Apr 2009 10:56:57 +0200

Quoted 19 lines

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:0 dropped:0 overruns:0 frame:0
          TX packets:692562900 errors:3228 dropped:3228 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)

I chose to reflect those errors only in tx_dropped/tx_errors, and not mirror these errors in rx_dropped/rx_errors.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Well, logically the receive is what failed, not the transmit.

I think it's therefore misleading to count it as a TX drop.

Do you feel strongly about this?

Hi David

You were right :)

Considering that loopbak_xmit() calls eth_type_trans(skb, dev) and this function already starts the RX handling of the packet (skb_pull(...))

So, trying to make loopback_xmit() returns NETDEV_TX_BUSY is wrong too, or too complex, because we would have to undo all changes that might happened during failed xmit. This would be hard to maintain and over-engineering at least, given that these drops are very unlikely.

So I resubmit my initial patch, changing the errors to be reported on the rx stats.

Thanks

[PATCH] loopback: packet drops accounting

We can in some situations drop packets in netif_rx()

loopback driver does not report these (unlikely) drops to its stats, and incorrectly change packets/bytes counts.

After this patch applied, "ifconfig lo" can reports these drops as in :

# ifconfig lo
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:692562900 errors:3228 dropped:3228 overruns:0 frame:0
          TX packets:692562900 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2865674174 (2.6 GiB)  TX bytes:2865674174 (2.6 GiB)

I initialy chose to reflect those errors only in tx_dropped/tx_errors, but David convinced me that it was really RX errors, as loopback_xmit() really starts a RX process. (calling eth_type_trans() for example, that itself pulls the ethernet header)

These errors are accounted in rx_dropped/rx_errors.

---
 drivers/net/loopback.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
drivers/net/loopback.c +15 -6
index b7d438a..a036296 100644
@@ -62,6 +62,7 @@
 struct pcpu_lstats {
 	unsigned long packets;
 	unsigned long bytes;
+	unsigned long drops;
 };
 
 /*
@@ -71,18 +72,22 @@ struct pcpu_lstats {
 static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct pcpu_lstats *pcpu_lstats, *lb_stats;
+	int len;
 
 	skb_orphan(skb);
 
-	skb->protocol = eth_type_trans(skb,dev);
+	skb->protocol = eth_type_trans(skb, dev);
 
 	/* it's OK to use per_cpu_ptr() because BHs are off */
 	pcpu_lstats = dev->ml_priv;
 	lb_stats = per_cpu_ptr(pcpu_lstats, smp_processor_id());
-	lb_stats->bytes += skb->len;
-	lb_stats->packets++;
 
-	netif_rx(skb);
+	len = skb->len;
+	if (likely(netif_rx(skb) == NET_RX_SUCCESS)) {
+		lb_stats->bytes += len;
+		lb_stats->packets++;
+	} else
+		lb_stats->drops++;
 
 	return 0;
 }
@@ -93,6 +98,7 @@ static struct net_device_stats *loopback_get_stats(struct net_device *dev)
 	struct net_device_stats *stats = &dev->stats;
 	unsigned long bytes = 0;
 	unsigned long packets = 0;
+	unsigned long drops = 0;
 	int i;
 
 	pcpu_lstats = dev->ml_priv;
@@ -102,11 +108,14 @@ static struct net_device_stats *loopback_get_stats(struct net_device *dev)
 		lb_stats = per_cpu_ptr(pcpu_lstats, i);
 		bytes   += lb_stats->bytes;
 		packets += lb_stats->packets;
+		drops   += lb_stats->drops;
 	}
 	stats->rx_packets = packets;
 	stats->tx_packets = packets;
-	stats->rx_bytes = bytes;
-	stats->tx_bytes = bytes;
+	stats->rx_dropped = drops;
+	stats->rx_errors  = drops;
+	stats->rx_bytes   = bytes;
+	stats->tx_bytes   = bytes;
 	return stats;
 }
 
maintainer Applied
#12 lore raw

Re: [PATCH] loopback: packet drops accounting

From: Eric Dumazet <[email protected]>
Date: Sat, 18 Apr 2009 10:03:10 +0200

Quoted 1 line

You were right :)

There is a first time for everything :)

Quoted 1 line

[PATCH] loopback: packet drops accounting

Applied, thanks Eric!