From patchwork Thu Feb 2 17:53:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 9552847 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DDD9860236 for ; Thu, 2 Feb 2017 18:05:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0E22284A3 for ; Thu, 2 Feb 2017 18:05:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6022284A7; Thu, 2 Feb 2017 18:05:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 76EC1284A3 for ; Thu, 2 Feb 2017 18:05:45 +0000 (UTC) Received: from localhost ([::1]:58283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZLlQ-0000OV-HW for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Feb 2017 13:05:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZLkk-0000Gn-C9 for qemu-devel@nongnu.org; Thu, 02 Feb 2017 13:05:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZLkh-0007QI-Ba for qemu-devel@nongnu.org; Thu, 02 Feb 2017 13:05:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56010) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZLkh-0007Pv-2o for qemu-devel@nongnu.org; Thu, 02 Feb 2017 13:04:59 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 923738046A; Thu, 2 Feb 2017 18:04:58 +0000 (UTC) Received: from amt.cnet (vpn1-4-135.gru2.redhat.com [10.97.4.135]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v12I4v8C008966; Thu, 2 Feb 2017 13:04:58 -0500 Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 8CE84100918; Thu, 2 Feb 2017 16:04:37 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id v12I4Xo5015573; Thu, 2 Feb 2017 16:04:33 -0200 Message-Id: <20170202180400.069973224@redhat.com> User-Agent: quilt/0.60-1 Date: Thu, 02 Feb 2017 15:53:34 -0200 From: Marcelo Tosatti To: kvm@vger.kernel.org, qemu-devel@nongnu.org References: <20170202175332.346975248@redhat.com> Content-Disposition: inline; filename=qemu-support-allow-freq-hc X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 02 Feb 2017 18:04:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [patch 2/2] kvm: introduce cpu flag to enable cpu frequency changes via hypercall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Radim Krcmar Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Guests with DPDK, whose vcpus run isolated on physical CPUs, want to control the frequency of such physical CPUs. Introduce a allow-freq-hc CPU flag to enable such hypercalls. Signed-off-by: Marcelo Tosatti --- target/i386/cpu.c | 1 + target/i386/cpu.h | 6 ++++++ target/i386/kvm.c | 29 +++++++++++++++++++++++++++++ target/i386/kvm_i386.h | 1 + 4 files changed, 37 insertions(+) Index: qemu/target/i386/cpu.c =================================================================== --- qemu.orig/target/i386/cpu.c 2017-01-31 09:18:52.944948296 -0200 +++ qemu/target/i386/cpu.c 2017-01-31 09:47:58.050671578 -0200 @@ -3659,6 +3659,7 @@ DEFINE_PROP_BOOL("lmce", X86CPU, enable_lmce, false), DEFINE_PROP_BOOL("l3-cache", X86CPU, enable_l3_cache, true), DEFINE_PROP_BOOL("vmware-cpuid-freq", X86CPU, vmware_cpuid_freq, true), + DEFINE_PROP_BOOL("allow-freq-hc", X86CPU, allow_freq_hc, false), DEFINE_PROP_END_OF_LIST() }; Index: qemu/target/i386/cpu.h =================================================================== --- qemu.orig/target/i386/cpu.h 2017-01-31 09:18:52.944948296 -0200 +++ qemu/target/i386/cpu.h 2017-01-31 09:47:58.051671580 -0200 @@ -1243,6 +1243,12 @@ */ bool enable_l3_cache; + /* Direct frequency hypercalls from guest userspace can be + * enabled/disabled via cpu option 'allow_freq_hc=on/off'. + * It is disabled by default. + */ + bool allow_freq_hc; + /* Compatibility bits for old machine types: */ bool enable_cpuid_0xb; Index: qemu/target/i386/kvm.c =================================================================== --- qemu.orig/target/i386/kvm.c 2017-01-31 09:18:52.944948296 -0200 +++ qemu/target/i386/kvm.c 2017-01-31 10:05:01.546855265 -0200 @@ -163,6 +163,11 @@ has_x2apic_api); } +bool kvm_has_allow_freq_hc(void) +{ + return kvm_check_extension(kvm_state, KVM_CAP_ALLOW_FREQ_HC); +} + static int kvm_get_tsc(CPUState *cs) { X86CPU *cpu = X86_CPU(cs); @@ -692,6 +697,15 @@ return 0; } +static int kvm_set_vcpu_allow_freq(X86CPU *cpu) +{ + struct kvm_vcpu_allow_freq fr; + + fr.enable = 1; + + return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_VCPU_ALLOW_FREQ_HC, &fr); +} + static Error *invtsc_mig_blocker; #define KVM_MAX_CPUID_ENTRIES 100 @@ -1040,6 +1054,21 @@ has_msr_tsc_aux = false; } + if (cpu->allow_freq_hc) { + int ret; + + if (!kvm_has_allow_freq_hc()) { + error_report("kvm: allow freq hypercall not supported"); + return -ENOTSUP; + } + + ret = kvm_set_vcpu_allow_freq(cpu); + if (ret) { + error_report("kvm: kvm_set_allow_freq failure, ret=%d", ret); + return ret; + } + } + return 0; fail: Index: qemu/target/i386/kvm_i386.h =================================================================== --- qemu.orig/target/i386/kvm_i386.h 2017-01-31 09:18:52.944948296 -0200 +++ qemu/target/i386/kvm_i386.h 2017-01-31 09:47:58.052671582 -0200 @@ -21,6 +21,7 @@ void kvm_synchronize_all_tsc(void); void kvm_arch_reset_vcpu(X86CPU *cs); void kvm_arch_do_init_vcpu(X86CPU *cs); +bool kvm_has_allow_freq_hc(void); int kvm_device_pci_assign(KVMState *s, PCIHostDeviceAddress *dev_addr, uint32_t flags, uint32_t *dev_id);