Ejemplo n.º 1
0
/*
 * High res timers changes: First we want to use full nsec for all
 * the math to avoid the double round off (on the offset and xtime).
 * Second, we want to allow a boot with HRT turned off at boot time.
 * This will cause hrtimer_use to be false, and we then fall back to 
 * the old code.  We also shorten the xtime lock region and eliminate
 * the lost tick code as this kernel will never have lost ticks under
 * the lock (i.e. wall_jiffies will never differ from jiffies except
 * when the write xtime lock is held).
 */
void do_gettimeofday(struct timeval *tv)
{
	unsigned long seq;
	unsigned long sec, nsec, clk_nsec;
	unsigned long max_ntp_tick;

	do {
		seq = read_seqbegin(&xtime_lock);
#ifdef CONFIG_HIGH_RES_TIMERS
		if (hrtimer_use) 
			nsec = arch_cycle_to_nsec(get_arch_cycles(wall_jiffies));
		else 
#endif
			nsec = cur_timer->get_offset() * NSEC_PER_USEC;
		

		sec = xtime.tv_sec;
		clk_nsec = xtime.tv_nsec;
		max_ntp_tick = current_tick_length() >> (SHIFT_SCALE - 10);
	} while (read_seqretry(&xtime_lock, seq));

	/* ensure we don't advance beyond the current tick length */
	nsec = min(nsec, max_ntp_tick);

	nsec += clk_nsec;
				
	while (nsec >= NSEC_PER_SEC) {
		nsec -=  NSEC_PER_SEC;
		sec++;
	}

	tv->tv_sec = sec;
	tv->tv_usec = nsec / NSEC_PER_USEC;
}
Ejemplo n.º 2
0
/*!
 * mxc_hrt_trace_elapsed() - return micro-seconds between two tick values
 *
 */
u64 mxc_hrt_trace_elapsed(u64 *t1, u64 *t2)
{
        u64 ticks = (*t1 > *t2) ? (*t1 - *t2) : (*t2 - *t1);
        return (arch_cycle_to_nsec (ticks)/1000);
}