From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vadim Rozenfeld Subject: [RFC PATCH 5/7] [hyper-v] hyper-v helper functions Date: Sun, 9 Oct 2011 20:52:53 +0200 Message-ID: <1318186375-27672-6-git-send-email-vrozenfe@redhat.com> References: <1318186375-27672-1-git-send-email-vrozenfe@redhat.com> Cc: Avi Kivity , Vadim Rozenfeld To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:34886 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751988Ab1JISxP (ORCPT ); Sun, 9 Oct 2011 14:53:15 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p99IrF9I003895 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 9 Oct 2011 14:53:15 -0400 In-Reply-To: <1318186375-27672-1-git-send-email-vrozenfe@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: --- hyperv.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hyperv.h | 7 +++++++ 2 files changed, 51 insertions(+), 0 deletions(-) diff --git a/hyperv.c b/hyperv.c index a17f879..57915b9 100644 --- a/hyperv.c +++ b/hyperv.c @@ -3,6 +3,10 @@ #include "qemu-option.h" #include "qemu-config.h" +static int hyperv_apic; +static int hyperv_wd; +static int hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY; + void hyperv_init(void) { QemuOpts *opts = QTAILQ_FIRST(&qemu_hyperv_opts.head); @@ -10,6 +14,46 @@ void hyperv_init(void) if (!opts) { return; } + + hyperv_spinlock_attempts = qemu_opt_get_number(opts, "spinlock", + HYPERV_SPINLOCK_NEVER_RETRY + ); + hyperv_wd = qemu_opt_get_bool(opts, "wd", 0); + hyperv_apic = qemu_opt_get_bool(opts, "vapic", 0); + +} + +int hyperv_enabled(void) +{ + return hyperv_hypercall_available() | hyperv_relaxed_timing(); +} + +int hyperv_hypercall_available(void) +{ + if (hyperv_apic || + (hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY)) { + return 1; + } + return 0; +} + +int hyperv_relaxed_timing(void) +{ + return !hyperv_wd; +} + +int hyperv_apic_recommended(void) +{ +#ifdef KVM_CAP_IRQCHIP + return hyperv_apic; +#else + return 0; +#endif +} + +int hyperv_spinlock_retries(void) +{ + return hyperv_spinlock_attempts; } static void hyperv_initialize(void) diff --git a/hyperv.h b/hyperv.h index eaf974a..27d2e6e 100644 --- a/hyperv.h +++ b/hyperv.h @@ -6,7 +6,14 @@ #include +#define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF + void hyperv_init(void); +int hyperv_enabled(void); +int hyperv_hypercall_available(void); +int hyperv_relaxed_timing(void); +int hyperv_apic_recommended(void); +int hyperv_spinlock_retries(void); #endif /* QEMU_HW_HYPERV_H */ -- 1.7.4.4