From patchwork Mon Oct 19 10:59:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 54737 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9JB4peK026141 for ; Mon, 19 Oct 2009 11:04:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756031AbZJSLEm (ORCPT ); Mon, 19 Oct 2009 07:04:42 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755930AbZJSLEm (ORCPT ); Mon, 19 Oct 2009 07:04:42 -0400 Received: from thoth.sbs.de ([192.35.17.2]:16719 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755985AbZJSLEh (ORCPT ); Mon, 19 Oct 2009 07:04:37 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.12.11.20060308/8.12.11) with ESMTP id n9JB4SjR032519; Mon, 19 Oct 2009 13:04:28 +0200 Received: from [139.25.109.167] (mchn012c.mchp.siemens.de [139.25.109.167] (may be forged)) by mail1.siemens.de (8.12.11.20060308/8.12.11) with ESMTP id n9JB4SF3020777; Mon, 19 Oct 2009 13:04:28 +0200 From: Jan Kiszka Subject: [PATCH 01/12] Provide schedule_hrtimeout for pre-2.6.28 kernels To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org Date: Mon, 19 Oct 2009 12:59:24 +0200 Message-ID: <20091019105924.3988.55195.stgit@mchn012c.ww002.siemens.net> In-Reply-To: <20091019105923.3988.42243.stgit@mchn012c.ww002.siemens.net> References: <20091019105923.3988.42243.stgit@mchn012c.ww002.siemens.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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