Re: high accuracy timing options?
Re: high accuracy timing options?
- Subject: Re: high accuracy timing options?
- From: "Aaron Turner" <email@hidden>
- Date: Thu, 27 Mar 2008 23:26:13 -0700
On Thu, Mar 27, 2008 at 8:56 PM, Michael Smith <email@hidden> wrote:
>
> On Mar 27, 2008, at 12:04 PM, email@hidden wrote:
>
[snip]
> > Very interesting results:
> >
> > Ran gtod() 68160730 times in 5 seconds.
> > 13.632146 gtod()/usec
> > Failed to increment 63197136 times
>
> > Back in time 0 times
>
> [...etc...]
>
>
> > Interesting how gettimeofday() fails to increment around 90% of the
> > time. I guess technically incrementing 1/10 times while requiring
>
> > ~13 times to measure a usec is good enough, but it's not giving me a
> > warm & fuzzy feeling.
>
> I don't exactly know what you expect here.
>
> % expr 68160730 - 63197136
> 4963594
>
> Of the 5 million unique microsecond values to be experienced in your
> five second test, you saw all but about 36,000 (0.07%) of them.
>
> Or are you dissatisfied that an iteration of your loop takes nearly
> 80ns to run?
Yeah, I realized that after I sent that email.... obviously
gettimeofday() only has usec resolution, so expecting better then that
is a bit silly. Unfortunately the 80ns/loop iteration is very
hardware dependent. I suppose I could try calculating this on a per
system level, but it's a bit of a hack.
> > May just be one of those things where a RTOS is necessary to get
> > any improvement.
>
> In what direction are you looking for "improvement"? It's a common
> mistake to think that RTOS' have better resolution; typically what you
> get from an RTOS is determinism, often achieved at the cost of peak
> performance.
Well going back to my previous email about 125K vs 130K pps, I think
I've figured out my problem. Basically as my packet rate increases,
the necessary resolution is better then 1usec. 125Kpps is 8usec, but
130Kpps is 7.7usec. I've been trying to hit 130K but seeing much
higher rates (around 143K) which is ~7usec delay. Looks like I'm
blocking short.
>
> > Anyone know if OS X/Darwin has the equivalent of Linux's
> > RT scheduler extensions?
>
> Darwin has a fairly modest but effective set of RT-like scheduling
> capabilities. What is it exactly that you are trying to achieve?
> It's very hard to get any sort of "RT" in a system where you have any
> sort of competition, and a desktop Darwin system is very competitive.
I was guessing that part of my problem is that I'm trying to
monopolize the CPU for relatively long periods of time and I'm being
put to sleep while other processes are being serviced. I was
hoping/guessing that trying some RT features might help with being
scheduled accurately when calling nanosleep(). Probably not going to
help since I'm blocking short though.
> > Anyways, I'm going to try to dig around some more and try to find the
> > HPET timer API. Theoretically, that should be more accurate then what
> > I'm seeing with gtod().
>
> What do you mean by "accurate"? Your test above has demonstrated that
> gettimeofday is returning unique microsecond values; it has no greater
> resolution. If you were truly pedantic you could add roughly half
> another significant figure (on your test system) by counting the
> number of iterations since you last saw gettimeofday() wrap, but even
> then the question around that sort of timing resolution is - what do
> you expect it to tell you? Doing any sort of real work takes orders
> of magnitude longer than that...
Well my packet sending code is pretty well optimized... I'm bypassing
the IP stack completely, so it's basically a memcpy() from user space
to the NIC driver to send. But point well taken.
> If you think that the HPET will help you, I'm sorry; it's too slow,
> it's too far away (the connection is highly latent, you can be held
> off talking to it for milliseconds in pathalogical cases), and the
> Darwin kernel owns it entirely.
Really? Suck.
> If I understood what you were actually trying to do, I might have some
> better ideas...
I'm not really sure what more I can say. I have a tight loop which
sends packets at various user defined intervals. Speeds range from
quite slow (a few packets/second) to quite fast (beyond 150K/sec).
I'm hoping to send packets at equal distant intervals for an even
distribution rather then time-slicing it (send a bunch of packets at
once and sleeping for longer periods of time), but I suppose I may be
asking too much.
--
Aaron Turner
http://synfin.net/
http://tcpreplay.synfin.net/ - Pcap editing & replay tools for Unix
They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety. -- Benjamin Franklin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden