netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Small pktgen bug.
@ 2009-11-05  2:22 Ben Greear
  2009-11-05  5:20 ` [PATCH net-next-2.6] pktgen: tx_bytes might be slightly wrong Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Ben Greear @ 2009-11-05  2:22 UTC (permalink / raw)
  To: NetDev

There is a subtle bug in pktgen tx_bytes accounting.

If one is using clone_skb, then the cur_pkt_size may be modified
without a new skb actually being created (quite yet) by setting
min_pkt_size through the proc fs.

I think if you just saved pkt_dev->skb->len before transmitting and used
that to increment pkt_dev->tx_bytes that would fix the counter
problem.

	if (unlikely(netif_tx_queue_stopped(txq) || netif_tx_queue_frozen(txq)))
		ret = NETDEV_TX_BUSY;
	else
		ret = (*xmit)(pkt_dev->skb, odev);

	switch (ret) {
	case NETDEV_TX_OK:
		txq_trans_update(txq);
		pkt_dev->last_ok = 1;
		pkt_dev->sofar++;
		pkt_dev->seq_num++;
		pkt_dev->tx_bytes += pkt_dev->cur_pkt_size;
		break;


Thanks,
Ben

-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net-next-2.6] pktgen: tx_bytes might be slightly wrong
  2009-11-05  2:22 Small pktgen bug Ben Greear
@ 2009-11-05  5:20 ` Eric Dumazet
  2009-11-06  5:08   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2009-11-05  5:20 UTC (permalink / raw)
  To: Ben Greear; +Cc: NetDev

From: Ben Greear <greearb@candelatech.com>

Ben Greear a écrit :
> There is a subtle bug in pktgen tx_bytes accounting.
> 
> If one is using clone_skb, then the cur_pkt_size may be modified
> without a new skb actually being created (quite yet) by setting
> min_pkt_size through the proc fs.
> 
> I think if you just saved pkt_dev->skb->len before transmitting and used
> that to increment pkt_dev->tx_bytes that would fix the counter
> problem.
> 
>     if (unlikely(netif_tx_queue_stopped(txq) ||
> netif_tx_queue_frozen(txq)))
>         ret = NETDEV_TX_BUSY;
>     else
>         ret = (*xmit)(pkt_dev->skb, odev);
> 
>     switch (ret) {
>     case NETDEV_TX_OK:
>         txq_trans_update(txq);
>         pkt_dev->last_ok = 1;
>         pkt_dev->sofar++;
>         pkt_dev->seq_num++;
>         pkt_dev->tx_bytes += pkt_dev->cur_pkt_size;
>         break;
> 
> 

Hi Ben

Nice catch :)

Note that clone_skb>0 makes the race window bigger, but its also racy for clone_skb=0

Instead of storing pkt_dev->skb->len in a temporary variable,
we could store it in pkt_dev->last_pkt_size, it'll be a bit faster.

[PATCH net-next-2.6] pktgen: tx_bytes might be slightly wrong

cur_pkt_size can be changed in proc fs while pktgen is running,
we better use a private field to get precise tx-bytes counter.

Signed-off-by: Ben Greear <greearb@candelatech.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 5ce017b..d38470a 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -340,6 +340,7 @@ struct pktgen_dev {
 	__u16 cur_udp_src;
 	__u16 cur_queue_map;
 	__u32 cur_pkt_size;
+	__u32 last_pkt_size;
 
 	__u8 hh[14];
 	/* = {
@@ -3434,7 +3435,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
 			pkt_dev->clone_count--;	/* back out increment, OOM */
 			return;
 		}
-
+		pkt_dev->last_pkt_size = pkt_dev->skb->len;
 		pkt_dev->allocated_skbs++;
 		pkt_dev->clone_count = 0;	/* reset counter */
 	}
@@ -3461,7 +3462,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
 		pkt_dev->last_ok = 1;
 		pkt_dev->sofar++;
 		pkt_dev->seq_num++;
-		pkt_dev->tx_bytes += pkt_dev->cur_pkt_size;
+		pkt_dev->tx_bytes += pkt_dev->last_pkt_size;
 		break;
 	default: /* Drivers are not supposed to return other values! */
 		if (net_ratelimit())

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next-2.6] pktgen: tx_bytes might be slightly wrong
  2009-11-05  5:20 ` [PATCH net-next-2.6] pktgen: tx_bytes might be slightly wrong Eric Dumazet
@ 2009-11-06  5:08   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2009-11-06  5:08 UTC (permalink / raw)
  To: eric.dumazet; +Cc: greearb, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 05 Nov 2009 06:20:59 +0100

> [PATCH net-next-2.6] pktgen: tx_bytes might be slightly wrong
> 
> cur_pkt_size can be changed in proc fs while pktgen is running,
> we better use a private field to get precise tx-bytes counter.
> 
> Signed-off-by: Ben Greear <greearb@candelatech.com>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied to net-next-2.6

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-06  5:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-05  2:22 Small pktgen bug Ben Greear
2009-11-05  5:20 ` [PATCH net-next-2.6] pktgen: tx_bytes might be slightly wrong Eric Dumazet
2009-11-06  5:08   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).