From: Avi Kivity <[EMAIL PROTECTED]> Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
diff --git a/kernel/external-module-compat.c b/kernel/external-module-compat.c index 2a22119..436d0f1 100644 --- a/kernel/external-module-compat.c +++ b/kernel/external-module-compat.c @@ -198,3 +198,38 @@ void (*hrtimer_init_p)(struct hrtimer *timer, clockid_t which_clock, int (*hrtimer_start_p)(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode); int (*hrtimer_cancel_p)(struct hrtimer *timer); + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) + +static void kvm_set_normalized_timespec(struct timespec *ts, time_t sec, + long nsec) +{ + while (nsec >= NSEC_PER_SEC) { + nsec -= NSEC_PER_SEC; + ++sec; + } + while (nsec < 0) { + nsec += NSEC_PER_SEC; + --sec; + } + ts->tv_sec = sec; + ts->tv_nsec = nsec; +} + +struct timespec kvm_ns_to_timespec(const s64 nsec) +{ + struct timespec ts; + + if (!nsec) + return (struct timespec) {0, 0}; + + ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC, &ts.tv_nsec); + if (unlikely(nsec < 0)) + set_normalized_timespec(&ts, ts.tv_sec, ts.tv_nsec); + + return ts; +} +EXPORT_SYMBOL_GPL(kvm_ns_to_timespec); + +#endif + diff --git a/kernel/external-module-compat.h b/kernel/external-module-compat.h index 2a51eeb..96d13ef 100644 --- a/kernel/external-module-compat.h +++ b/kernel/external-module-compat.h @@ -717,3 +717,11 @@ static inline void hrtimer_data_pointer(struct hrtimer *timer) {} #ifndef MSR_IA32_CR_PAT #define MSR_IA32_CR_PAT 0x00000277 #endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) + +#define ns_to_timespec kvm_ns_to_timespec + +struct timespec kvm_ns_to_timespec(const s64 nsec); + +#endif -- To unsubscribe from this list: send the line "unsubscribe kvm-commits" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html