Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: bhutchings@solarflare.com, daniel.turull@gmail.com,
	netdev@vger.kernel.org, robert@herjulf.net, voravit@kth.se,
	jens.laas@uadm.uu.se
Subject: Re: [patch] pktgen: bug when calling ndelay in x86 architectures
Date: Thu, 20 Oct 2011 22:55:38 +0200	[thread overview]
Message-ID: <1319144138.2854.33.camel@edumazet-laptop> (raw)
In-Reply-To: <20111020.162444.559487256559727633.davem@davemloft.net>

Le jeudi 20 octobre 2011 à 16:24 -0400, David Miller a écrit :
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Tue, 18 Oct 2011 16:47:44 +0200
> 
> > Le mardi 18 octobre 2011 à 15:00 +0100, Ben Hutchings a écrit :
> > 
> >> AIUI, the reason for limits on delays is not that it's bad practice to
> >> spin for so long, but that the delay calculations may overflow or
> >> otherwise become inaccurate.
> > 
> > OK, I can understand that, then a more appropriate patch would be :
> 
> I think doing the udelay/ndelay thing is the way to go for 'net' and
> -stable.  We can do something sophisticated with ktime et al. in
> 'net-next'.
> 

Well, I am not sure a patch is needed for net, since there is no bug,
but maybe small inaccuracies ? Correct me if I misunderstood Daniel !

> Eric, could you please formally submit this patch with proper
> changelog etc.?

Sure !

[PATCH net-next] pktgen: remove ndelay() call

Daniel Turull reported inaccuracies in pktgen when using low packet
rates, because we call ndelay(val) with values bigger than 20000.

Instead of calling ndelay() for delays < 100us, we can instead loop
calling ktime_now() only.

Reported-by: Daniel Turull <daniel.turull@gmail.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 net/core/pktgen.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 6bbf008..0001c24 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -2145,9 +2145,12 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
 	}
 
 	start_time = ktime_now();
-	if (remaining < 100000)
-		ndelay(remaining);	/* really small just spin */
-	else {
+	if (remaining < 100000) {
+		/* for small delays (<100us), just loop until limit is reached */
+		do {
+			end_time = ktime_now();
+		} while (ktime_lt(end_time, spin_until));
+	} else {
 		/* see do_nanosleep */
 		hrtimer_init_sleeper(&t, current);
 		do {
@@ -2162,8 +2165,8 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
 			hrtimer_cancel(&t.timer);
 		} while (t.task && pkt_dev->running && !signal_pending(current));
 		__set_current_state(TASK_RUNNING);
+		end_time = ktime_now();
 	}
-	end_time = ktime_now();
 
 	pkt_dev->idle_acc += ktime_to_ns(ktime_sub(end_time, start_time));
 	pkt_dev->next_tx = ktime_add_ns(spin_until, pkt_dev->delay);

  reply	other threads:[~2011-10-20 20:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-18 11:08 [patch] pktgen: bug when calling ndelay in x86 architectures Daniel Turull
2011-10-18 11:56 ` Eric Dumazet
2011-10-18 14:00   ` Ben Hutchings
2011-10-18 14:47     ` Eric Dumazet
     [not found]       ` <4E9E9963.7090209@gmail.com>
2011-10-19 10:13         ` Eric Dumazet
2011-10-20 13:22           ` Daniel Turull
2011-10-20 13:44             ` Eric Dumazet
2011-10-20 14:26               ` Daniel Turull
2011-10-20 20:24       ` David Miller
2011-10-20 20:55         ` Eric Dumazet [this message]
2011-10-20 21:02           ` 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=1319144138.2854.33.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=bhutchings@solarflare.com \
    --cc=daniel.turull@gmail.com \
    --cc=davem@davemloft.net \
    --cc=jens.laas@uadm.uu.se \
    --cc=netdev@vger.kernel.org \
    --cc=robert@herjulf.net \
    --cc=voravit@kth.se \
    /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