cpu clock: add independent test for monotonic/sane TSC

Fire up all threads on the system, checking the clock 100,000
times on each. Then collect and compare results, to ensure we
never have a clock that goes backwards.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
gettime: locking fix and debug check for identical sequence

Signed-off-by: Jens Axboe <axboe@kernel.dk>
gettime: include per-cpu clock calibration in cpu clock test

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Add --cpuclock-test and clocksource= option help

Signed-off-by: Jens Axboe <axboe@kernel.dk>
gettime: fix race/bug with threads and time keeping

Sam writes:

First, the 1 second latency events come in batches and those batches
occur suspiciously close to a usec wrap (0.999999 us -> 1.000000 us).
Second, if you subtract exactly 1 second from these outlier latencies,
the remaining amount is very close to what our instrumented low level
driver records for the IO latency and consistent with the expected
latencies of our SSD.  Similarly, the tv_usec portion of the timeval
structs shows increasing values.  See snippet below.

Format is like    start: <start_time.tv_sec>.<start_time.tv_usec>

latency: 1004657 us, lba: 1111289192, start: 1355776806.995294 issue: 1355776806.995312 complete: 1355776807.999969
latency: 1000494 us, lba: 203093568, start: 1355776806.999456 issue: 1355776806.999475 complete: 1355776807.999969
latency: 1000404 us, lba: 551350992, start: 1355776806.999546 issue: 1355776806.999565 complete: 1355776807.999969
latency: 1000477 us, lba: 449672928, start: 1355776806.999484 issue: 1355776806.999492 complete: 1355776807.999969

All this pointed to the time collection code being buggy.  Reviewing the
code, I spotted this in fio_gettime():

	/*
	 * If Linux is using the tsc clock on non-synced processors,
	 * sometimes time can appear to drift backwards. Fix that up.
	 */
	if (last_tv_valid) {
		if (tp->tv_sec < last_tv.tv_sec)
			tp->tv_sec = last_tv.tv_sec;
		else if (last_tv.tv_sec == tp->tv_sec &&
			 tp->tv_usec < last_tv.tv_usec)
			tp->tv_usec = last_tv.tv_usec;
	}
	last_tv_valid = 1;
	memcpy(&last_tv, tp, sizeof(*tp));

This does not appear to be multi-thread safe.  Pre-emption can occur
between either comparison and the subsequent update.  Commenting it out
makes the problem go away (at the expense of being subject to drift).
How about making last_tv & last_tv_valid thread-local?

Reported-by: Sam Bradshaw <sbradshaw@micron.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
gettime: use pthread_{set,get}specific() for TLS

__thread doesn't work on OSX at least (thanks...), so resort to
using the pthread functions to maintaining a per-thread clock
check.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
gettime: make last_cycles thread local too

Avoids a lot of cache line bouncing for threads.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
windowsaio: fix typo

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Fio 2.0.12

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Fixup CPUID for 32-bit x86

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Fio 2.0.12.1

Fix issue with 32-bit x86 build.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Fix $(CC) override: use system compiler except on HP-UX and Solaris.

$(CC) was being overridden, preventing the system compiler from
being used. This caused a problem on FreeBSD systems where gcc has
been removed.  Since fio requires gcc on HP-UX and Solaris, always
set $(CC) on those platforms.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Create a new Windows installer product GUID for 2.0.12.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Consistently indent using tabs in Windows files and remove trailing spaces.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Use clock_gettime() for CPU clock calibration

gettimeofday() has very poor resolution on some platforms. So
use clock_gettime() instead.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Add return statements to arch_init functions for ia64 and ppc.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Fio 2.0.12.2

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Include <stdint.h> before checking __WORDSIZE

Signed-off-by: Jens Axboe <axboe@kernel.dk>
t/axmap: update tester for lfsr_init() taking a seed argument

Signed-off-by: Jens Axboe <axboe@kernel.dk>
clock: turn expensive division into multiply + cheap division

On x86-64, dividing by a variable turns into a hugely expensive
divq. It's much cheaper to invert the division. Instead of
dividing clocks by clocks-per-usec, multiply by a 16M/clocks-per-usec
constant instead.

Signed-off-by: Jens Axboe <axboe@kernel.dk>