[BUG] 2.6.37-rc3 massive interactivity regression on ARM

Russell King - ARM Linux linux at arm.linux.org.uk
Wed Dec 8 10:05:17 EST 2010


On Wed, Dec 08, 2010 at 03:44:19PM +0100, Peter Zijlstra wrote:
> One of the problems is I think the cycles2ns multiplication of the raw
> clock, that makes dealing with wrap-around lots harder, so I guess we
> should deal with the wrap on the raw clock values and then apply
> cycles2ns on the delta or somesuch. But I expect the clocksource
> infrastructure already has something like that, John?

I've thought about that, but it becomes slightly problematical, as
was shown in one of the examples I provided.  If you do scale by
doing a 64-bit multiply and shift, you're always going to end up
with less than a 64-bit result.

I think your idea makes sense though, but I think for it to be able
to cover the full 64-bit range, we need to do the wraparound handling
after scaling.  So maybe something like the following:

static unsigned long long last_ns, cur_ns;
static unsigned long long max = (max_read_clock() * mult) >> shift;

unsigned long long sched_clock(void)
{
	unsigned long long cyc = read_clock();
	unsigned long long ns = (cyc * mult) >> shift;
	unsigned long long delta;

	spin_lock(&sched_clock_lock);
	delta = last_ns - ns;
	if (ns < last_ns)
		delta += max;

	last_ns = ns;
	ns = cur_ns += delta;
	spin_unlock(&sched_clock_lock);

	return ns;
}



More information about the linux-arm-kernel mailing list