All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Turull <daniel.turull@gmail.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Ben Hutchings <bhutchings@solarflare.com>,
	David Miller <davem@davemloft.net>,
	netdev@vger.kernel.org, Robert Olsson <robert@herjulf.net>,
	Voravit Tanyingyong <voravit@kth.se>,
	Jens Laas <jens.laas@uadm.uu.se>
Subject: Re: [patch] pktgen: bug when calling ndelay in x86 architectures
Date: Thu, 20 Oct 2011 15:22:59 +0200	[thread overview]
Message-ID: <4EA020B3.4030208@gmail.com> (raw)
In-Reply-To: <1319019235.3103.10.camel@edumazet-laptop>

Hi,

I tested the patch and it works well.


On 10/19/2011 12:13 PM, Eric Dumazet wrote:
> Le mercredi 19 octobre 2011 à 11:33 +0200, Daniel Turull a écrit :
>> Hi,
>> then if we want to use the spin more often.
>> maybe we can increase the constant from 100000 (0.1ms) to 1000000 (1ms)?
>> How was the current value chosen?
>>
> 
> Based on user needs ;)

I think if we increase the constant to 1ms, we will reduce the jitter if we have
a rate between 1kpps and 10 kpps, but I guess is not a big deal.

I've plot this new graph with this patch:
http://tslab.ssvl.kth.se/pktgen/img/inter_eric1.eps

> 
>> I did some measurements of the inter-arrival time between packets
>> and with bigger values the maximal is reduced in the rates between
>> 2kpps and 20kpps.
>>
> 
> ndelay()/udelay() have some inaccuracies, for 'long' values, because of
> rounding errors.
> 
> If we spin, just call ktime_now() in a loop until spin_until is
> reached...
> 
> That way you get max possible resolution, given kernel time service
> constraints.
> 
> Untested patch :
> 
> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index 38d6577..5c7e900 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -2145,9 +2145,11 @@ 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) {
> +		do {
> +			end_time = ktime_now();
> +		} while (ktime_lt(end_time, spin_until));
> +	} else {
>  		/* see do_nanosleep */
>  		hrtimer_init_sleeper(&t, current);
>  		do {
> @@ -2162,8 +2164,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);
> 
> 

Daniel

  reply	other threads:[~2011-10-20 13:23 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 [this message]
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
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=4EA020B3.4030208@gmail.com \
    --to=daniel.turull@gmail.com \
    --cc=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.