public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Need better is_better_time_interpolator() algorithm
@ 2005-08-25 16:44 Alex Williamson
  2005-08-25 17:36 ` john stultz
  0 siblings, 1 reply; 15+ messages in thread
From: Alex Williamson @ 2005-08-25 16:44 UTC (permalink / raw)
  To: linux-kernel

Hi,

   In playing with an HPET device, I noticed that
kernel/timer.c:is_better_time_interpolator() is completely non-symmetric
in the timer it returns.  The test is simply:

return new->frequency > 2*time_interpolator->frequency ||
 (unsigned long)new->drift < (unsigned long)time_interpolator->drift;

Given two timers:

(a) 1.5GHz, 750ppm
(b) 250Mhz, 500ppm

the resulting "better" timer is completely dependent on the order
they're passed in.  For example, (a),(b) = (b); (b),(a) = (a).

   What are we really looking for in a "better" timer?  There are at
least 4 factors that I can think of that seem important to determining a
better clock:

      * resolution (frequency)
      * accuracy (drift)
      * access latency (may be non-uniform across the system?)
      * jitter (monotonically increasing)

How can we munge these all together to come up with a single goodness
factor for comparison?  There's probably a thesis covering algorithms to
handle this.  Anyone know of one or have some good ideas?  Thanks,

	Alex

-- 
Alex Williamson                             HP Linux & Open Source Lab


^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: Need better is_better_time_interpolator() algorithm
@ 2005-08-25 21:40 linux
  2005-08-25 23:07 ` Alex Williamson
  0 siblings, 1 reply; 15+ messages in thread
From: linux @ 2005-08-25 21:40 UTC (permalink / raw)
  To: alex.williamson; +Cc: linux-kernel

> (frequency) * (1/drift) * (1/latency) * (1/(jitter_factor * cpus))

(Note that 1/cpus, being a constant for all evaluations of this
expression, has no effect on the final ranking.)
The usual way it's done is with some fiddle factors:

quality_a^a * quality_b^b * quality_c^c

Or, equivalently:

a * log(quality_a) + b * log(quality_b) + c * log(quality_c)

Then you use the a, b and c factors to weight the relative importance
of them.  Your suggestion is equivalent to setting all the exponents to 1.

But you can also say that "a is twice as important as b" in a
consistent manner.

Note that computing a few bits of log_2 is not hard to do in integer
math if you're not too anxious about efficiency:

unsigned log2(unsigned x)
{
	unsigned result = 31;
	unsigned i;

	assert(x);
	while (!x & (1u<<31)) {
		x <<= 1;
		result--;
	}
	/* Think of x as a 1.31-bit fixed-point number, 1 <= x < 2 */
	for (i = 0; i < NUM_FRACTION_BITS; i++) {
		unsigned long long y = x;
		/* Square x and compare to 2. */
		y *= x;
		result <<= 1;
		if (y & (1ull<<63)) {
			result++;
			x = (unsigned)(y >> 32);
		} else {
			x = (unsigned)(y >> 31);
		}
	}
	return result;
}

Setting NUM_FRACTION_BITS to 16 or so would give enough room for
reasonable-sized weights and not have the total overflow 32 bits.

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

end of thread, other threads:[~2005-08-29 17:01 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-25 16:44 Need better is_better_time_interpolator() algorithm Alex Williamson
2005-08-25 17:36 ` john stultz
2005-08-25 18:43   ` Alex Williamson
2005-08-25 19:02     ` john stultz
2005-08-26 15:39     ` Christoph Lameter
2005-08-26 16:18       ` Alex Williamson
2005-08-26 19:16         ` George Anzinger
2005-08-26 19:26           ` Alex Williamson
2005-08-26 19:33             ` Christoph Lameter
2005-08-26 19:51               ` George Anzinger
2005-08-27 11:55               ` Pavel Machek
2005-08-29 17:00                 ` Christoph Lameter
  -- strict thread matches above, loose matches on Subject: below --
2005-08-25 21:40 linux
2005-08-25 23:07 ` Alex Williamson
2005-08-26 16:48   ` Christoph Lameter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox