示例#1
0
文件: raw_skew.c 项目: 020gzh/linux
void get_monotonic_and_raw(struct timespec *mon, struct timespec *raw)
{
	struct timespec start, mid, end;
	long long diff = 0, tmp;
	int i;

	for (i = 0; i < 3; i++) {
		long long newdiff;

		clock_gettime(CLOCK_MONOTONIC, &start);
		clock_gettime(CLOCK_MONOTONIC_RAW, &mid);
		clock_gettime(CLOCK_MONOTONIC, &end);

		newdiff = diff_timespec(start, end);
		if (diff == 0 || newdiff < diff) {
			diff = newdiff;
			*raw = mid;
			tmp = (ts_to_nsec(start) + ts_to_nsec(end))/2;
			*mon = nsec_to_ts(tmp);
		}
	}
}
示例#2
0
static inline struct timespec add_ts (struct timespec ts, uint64_t add_nsecs) {
	uint64_t nsecs = ts_to_nsec(ts);
	nsecs += add_nsecs;
	return nsec_to_ts (nsecs);
}
示例#3
0
static inline struct timespec add_ts(struct timespec ts, unsigned int usecs)
{
    unsigned long long nsecs = ts_to_nsec(ts);
    nsecs += usecs * 1000LL;
    return nsec_to_ts(nsecs);
}