From patchwork Thu Dec 3 12:47:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifei Jiang X-Patchwork-Id: 11948683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5EB3C83014 for ; Thu, 3 Dec 2020 12:48:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6944C20709 for ; Thu, 3 Dec 2020 12:48:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388999AbgLCMsd (ORCPT ); Thu, 3 Dec 2020 07:48:33 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:9368 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726961AbgLCMsb (ORCPT ); Thu, 3 Dec 2020 07:48:31 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CmwbD30yNz777t; Thu, 3 Dec 2020 20:47:20 +0800 (CST) Received: from huawei.com (10.174.186.236) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Thu, 3 Dec 2020 20:47:40 +0800 From: Yifei Jiang To: , CC: , , , , , , , , , , , , , Yifei Jiang Subject: [PATCH RFC v4 14/15] target/riscv: Synchronize vcpu's frequency with KVM Date: Thu, 3 Dec 2020 20:47:02 +0800 Message-ID: <20201203124703.168-15-jiangyifei@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20201203124703.168-1-jiangyifei@huawei.com> References: <20201203124703.168-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.186.236] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If vcpu's frequency is specified by cpu option 'frequency', it will be set into KVM by KVM_SET_ONE_REG ioctl. Otherwise, vcpu's frequency will follow KVM by KVM_GET_ONE_REG ioctl. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- target/riscv/kvm.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 1e16d24544..3499efd4eb 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -409,6 +409,8 @@ int kvm_arch_get_registers(CPUState *cs) int kvm_arch_put_registers(CPUState *cs, int level) { int ret = 0; + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; ret = kvm_riscv_put_regs_core(cs); if (ret) { @@ -425,6 +427,10 @@ int kvm_arch_put_registers(CPUState *cs, int level) return ret; } + if (env->frequency) { + ret = kvm_set_one_reg(cs, RISCV_TIMER_REG(frequency), &env->frequency); + } + return ret; } @@ -481,6 +487,17 @@ int kvm_arch_init_vcpu(CPUState *cs) } env->misa = isa; + /* + * Synchronize vcpu's frequency with KVM. If vcpu's frequency is specified + * by cpu option 'frequency', this will be set to KVM. Otherwise, vcpu's + * frequency will follow KVM. + */ + if (env->user_frequency) { + ret = kvm_set_one_reg(cs, RISCV_TIMER_REG(frequency), &env->frequency); + } else { + ret = kvm_get_one_reg(cs, RISCV_TIMER_REG(frequency), &env->frequency); + } + return ret; }