Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>
---

 external-module-compat-comm.h |    4 +++
 external-module-compat.c      |   59 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/external-module-compat-comm.h b/external-module-compat-comm.h
index de8ab23..8f56f11 100644
--- a/external-module-compat-comm.h
+++ b/external-module-compat-comm.h
@@ -1000,3 +1000,7 @@ static inline unsigned int cpufreq_get(unsigned int cpu)
        return 0;
 }
 #endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
+int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode);
+#endif
diff --git a/external-module-compat.c b/external-module-compat.c
index 6b69127..327fa6b 100644
--- a/external-module-compat.c
+++ b/external-module-compat.c
@@ -409,3 +409,62 @@ unsigned kvm_get_tsc_khz(void)
 }
 
 #endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
+
+static enum hrtimer_restart kvm_hrtimer_wakeup(struct hrtimer *timer)
+{
+       struct hrtimer_sleeper *t =
+               container_of(timer, struct hrtimer_sleeper, timer);
+       struct task_struct *task = t->task;
+
+       t->task = NULL;
+       if (task)
+               wake_up_process(task);
+
+       return HRTIMER_NORESTART;
+}
+
+int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode)
+{
+       struct hrtimer_sleeper t;
+
+       /*
+        * Optimize when a zero timeout value is given. It does not
+        * matter whether this is an absolute or a relative time.
+        */
+       if (expires && !expires->tv64) {
+               __set_current_state(TASK_RUNNING);
+               return 0;
+       }
+
+       /*
+        * A NULL parameter means "inifinte"
+        */
+       if (!expires) {
+               schedule();
+               __set_current_state(TASK_RUNNING);
+               return -EINTR;
+       }
+
+       hrtimer_init(&t.timer, CLOCK_MONOTONIC, mode);
+       t.timer.expires = *expires;
+
+       t.timer.function = kvm_hrtimer_wakeup;
+       t.task = current;
+
+       hrtimer_start(&t.timer, t.timer.expires, mode);
+       if (!hrtimer_active(&t.timer))
+               t.task = NULL;
+
+       if (likely(t.task))
+               schedule();
+
+       hrtimer_cancel(&t.timer);
+
+       __set_current_state(TASK_RUNNING);
+
+       return !t.task ? 0 : -EINTR;
+}
+
+#endif

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to