Re: sched_clock() uses are broken

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Russell King wrote:

There are several solutions to this - the most obvious being that we
need a function which returns the nanosecond difference between two
sched_clock() return values, and this function needs to know how to
handle the case where sched_clock() has wrapped.

IOW:

	t0 = sched_clock();
	/* do something */
	t1 = sched_clock();

	time_passed = sched_clock_diff(t1, t0);

Comments?


There is another problem John pointed out to me: sched_clock (at least
on i386) can do tsc frequency scaling on the raw tsc value. I'm not
sure if this is still a problem (I'm not aware that it has been fixed),
however it would mean that between two sched_clock()s, the values
returned can be basically completely arbitrary.

What is needed is something like:
    t0 = get_cycles_unsynchronized();
    t1 = get_cycles_unsynchronized();
    ns = cycles_to_ns(t1, t0);

Where unsynchronized means not synchronized between CPUs.

This would still cause the `ns' value to be skewed if a frequency change
occured between t0 and t1, however at least it should be within some
realistic range (something like ns +/- ns * max freq / min freq).

--
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com -
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux