From patchwork Fri Oct 19 10:07:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Mackerras X-Patchwork-Id: 10648945 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB3793B73 for ; Fri, 19 Oct 2018 10:07:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB03C288A9 for ; Fri, 19 Oct 2018 10:07:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2CA3288B2; Fri, 19 Oct 2018 10:07:35 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62C99288B2 for ; Fri, 19 Oct 2018 10:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbeJSSMw (ORCPT ); Fri, 19 Oct 2018 14:12:52 -0400 Received: from ozlabs.org ([203.11.71.1]:38091 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726664AbeJSSMw (ORCPT ); Fri, 19 Oct 2018 14:12:52 -0400 Received: by ozlabs.org (Postfix, from userid 1003) id 42c1ms540cz9sDX; Fri, 19 Oct 2018 21:07:25 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1539943645; bh=0eHO2Wmc7CupXpP9PN2V8DAMr7huM0vPQf7eRVHAWKw=; h=Date:From:To:Cc:Subject:From; b=oMI7Y8t8Zzg5aUhbekkxFmamCeFdH1i0GyMecODysj1NT03BFjq36PTLTaJFLXflc CxuENTBz0CpoyUOyzaUpMtFw6vBDW91TKPuMRSbdrIJos6uTdOFf4QQXUS7e/ce5qM gzSXqwQPuhstcZ7B1SNEz32yXNsHMyedQSLXP7c7NlBMPRGS158JqwIUDLvf59V8kC DaYxXv2gGsTr1edpbrSv2YjU8Trt8DMRRK85/OHp99KbOQmmjsuLA+O//D01f+DTeJ PITgNkK4nU4a/yuXxWe9yvsj/t7F8GQYKXp5R83RJffL65vcc3SrMpHdREjp6+wkZo HSpqAWPbbgXYA== Date: Fri, 19 Oct 2018 21:07:22 +1100 From: Paul Mackerras To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: linuxppc-dev@ozlabs.org, Michael Ellerman Subject: [PATCH] KVM: PPC: Use exported tb_to_ns() function in decrementer emulation Message-ID: <20181019100722.GB6230@blackberry> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This changes the KVM code that emulates the decrementer function to do the conversion of decrementer values to time intervals in nanoseconds by calling the tb_to_ns() function exported by the powerpc timer code, in preference to open-coded arithmetic using values from the decrementer_clockevent struct. Similarly, the HV-KVM code that did the same conversion using arithmetic on tb_ticks_per_sec also now uses tb_to_ns(). Signed-off-by: Paul Mackerras --- arch/powerpc/kvm/book3s_hv.c | 3 +-- arch/powerpc/kvm/emulate.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index bf8def2..d65b961 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -2337,8 +2337,7 @@ static void kvmppc_set_timer(struct kvm_vcpu *vcpu) kvmppc_core_prepare_to_enter(vcpu); return; } - dec_nsec = (vcpu->arch.dec_expires - now) * NSEC_PER_SEC - / tb_ticks_per_sec; + dec_nsec = tb_to_ns(vcpu->arch.dec_expires - now); hrtimer_start(&vcpu->arch.dec_timer, dec_nsec, HRTIMER_MODE_REL); vcpu->arch.timer_running = 1; } diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c index fa888bf..7a7c348 100644 --- a/arch/powerpc/kvm/emulate.c +++ b/arch/powerpc/kvm/emulate.c @@ -62,11 +62,9 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) dec_time = vcpu->arch.dec; /* * Guest timebase ticks at the same frequency as host decrementer. - * So use the host decrementer calculations for decrementer emulation. + * So use the host timebase calculations for decrementer emulation. */ - dec_time = dec_time << decrementer_clockevent.shift; - do_div(dec_time, decrementer_clockevent.mult); - dec_nsec = do_div(dec_time, NSEC_PER_SEC); + dec_nsec = tb_to_ns(dec_time); hrtimer_start(&vcpu->arch.dec_timer, ktime_set(dec_time, dec_nsec), HRTIMER_MODE_REL); vcpu->arch.dec_jiffies = get_tb();