diff mbox

[01/12] Provide schedule_hrtimeout for pre-2.6.28 kernels

Message ID 20091019105924.3988.55195.stgit@mchn012c.ww002.siemens.net (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Kiszka Oct. 19, 2009, 10:59 a.m. UTC
None
diff mbox

Patch

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