From nobody Tue Feb 10 05:26:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606999765; cv=none; d=zohomail.com; s=zohoarc; b=bamaWJE++N+kueFqKfpU2JytYWlXe9sykU4ft60VbfiprEWt3TMgICCAD4+f3AwdIsyVTxxcWsk7hpjX6KjV4VK2/2lH3b0zgLkLwo9UC+jjw7+VRqzUif1UR7LMZ066hQakcmxBRrY12e76raEDJSZF0l3hbgUM5gwLCt1oo0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999765; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SzhZ1Is9ag9UY1NdlziQmm8ukk5rcBpPyYTYTHAW1ns=; b=J+C9DNW3KRRv+sFdmhFKhTuXycG9MKSbR0kb1nHLXPXHFfVF5Px6FXyoNcaQ1CMX5B9SvLtflM20Gg1JgRvy3HE7pFz0LY/pX+Emz2NGd+suIrmxMPThj6M23olHaRpZa9ul4QzeiwirWgZ6h1Ad6GnmIO85M3PTPfFiyKvibyY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606999765083958.22118699782; Thu, 3 Dec 2020 04:49:25 -0800 (PST) Received: from localhost ([::1]:49304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kko30-0006Oh-78 for importer@patchew.org; Thu, 03 Dec 2020 07:49:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kko1Z-0004aX-Vu; Thu, 03 Dec 2020 07:47:54 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2162) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kko1X-0006x8-Ey; Thu, 03 Dec 2020 07:47:53 -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: , 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 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.186.236] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.35; envelope-from=jiangyifei@huawei.com; helo=szxga07-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: victor.zhangxiaofeng@huawei.com, sagark@eecs.berkeley.edu, kvm@vger.kernel.org, libvir-list@redhat.com, kbastian@mail.uni-paderborn.de, anup.patel@wdc.com, yinyipeng1@huawei.com, Alistair.Francis@wdc.com, Yifei Jiang , kvm-riscv@lists.infradead.org, palmer@dabbelt.com, dengkai1@huawei.com, wu.wubin@huawei.com, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 =3D 0; + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; =20 ret =3D kvm_riscv_put_regs_core(cs); if (ret) { @@ -425,6 +427,10 @@ int kvm_arch_put_registers(CPUState *cs, int level) return ret; } =20 + if (env->frequency) { + ret =3D kvm_set_one_reg(cs, RISCV_TIMER_REG(frequency), &env->freq= uency); + } + return ret; } =20 @@ -481,6 +487,17 @@ int kvm_arch_init_vcpu(CPUState *cs) } env->misa =3D isa; =20 + /* + * Synchronize vcpu's frequency with KVM. If vcpu's frequency is speci= fied + * by cpu option 'frequency', this will be set to KVM. Otherwise, vcpu= 's + * frequency will follow KVM. + */ + if (env->user_frequency) { + ret =3D kvm_set_one_reg(cs, RISCV_TIMER_REG(frequency), &env->freq= uency); + } else { + ret =3D kvm_get_one_reg(cs, RISCV_TIMER_REG(frequency), &env->freq= uency); + } + return ret; } =20 --=20 2.19.1