Esempio n. 1
0
/**
 * Get current system time in ticks
 *
 * linux doesn't provide an easy access to jiffies so implement it by measuring
 * the time since the first call to this function.
 *
 * Since this function is used to seed the (non-cryptographic) random
 * number generator, we round the start time down to the nearest whole
 * second.  This minimises the chances of generating identical RNG
 * sequences (and hence identical TCP port numbers, etc) on
 * consecutive invocations of iPXE.
 *
 * @ret ticks		Current time, in ticks
 */
static unsigned long linux_currticks(void)
{
	static struct timeval start;
	static int initialized = 0;

	if (! initialized) {
		linux_gettimeofday(&start, NULL);
		initialized = 1;
	}

	struct timeval now;
	linux_gettimeofday(&now, NULL);

	unsigned long ticks = (now.tv_sec - start.tv_sec) * linux_ticks_per_sec();
	ticks += now.tv_usec / (long)(1000000 / linux_ticks_per_sec());

	return ticks;
}
Esempio n. 2
0
/**
 * Get current time in seconds
 *
 * @ret time		Time, in seconds
 */
static time_t linux_now ( void ) {
	struct timeval now;

	linux_gettimeofday ( &now, NULL );
	return now.tv_sec;
}