Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp443532pxu; Thu, 3 Dec 2020 04:24:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMXJPaqyHCncNKBty00heyRWruoZFw7acfC6YD0upC+UYJlbAVBDIHzksbfUJP2j5ixiEg X-Received: by 2002:a50:99c3:: with SMTP id n3mr2573253edb.213.1606998270886; Thu, 03 Dec 2020 04:24:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606998270; cv=none; d=google.com; s=arc-20160816; b=v3sz9uoZdRbBBX0AcCJU/3NuGlEurQdXDGJoCZXwrQSeJfB6k2VuP01FEY9e+DfNmD NycN0s/+gY7hfnCCdOvI+VEFBdAIvKnaVbfxr34HGwSM3TjTa6dQl4bpBMxVn6mawk2X v+dSqDiSo9C2pkvg3ojvBIaP2luMprof9S/4mNUFPBhhVOKcXpqIu4fs222duNKK1zbv AdH+i1sLaZdLsyIyLEiOz62mElIUxy5pGfPkU+XDzyc9Ylo5K9Q5Iq8zXP1Qb3zT9ba0 l+H6a7bOvs9vfdZLy/u3oFEIkHIE9Az3yCieIJqu5CGTXJxYWwqKcFRdOOddzztkXuBy Zsug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BepbnxanVcC2toac/XCv5+a7QYNLMxxsWcjHRgz6l1c=; b=Up2/5Rc7zK4mwmWzy3XdL6UnY2lmbGlzY31qhfQZO/Nc7+aRkV/q4+AH86amAzUJxe ZD11okFAe/z2uka6s/djzEQ1F2Rqq8tbVHNo0cHvLLYgPtmi5eDhi17+rkYpsW/GMr86 xJCVsdVSoboIQ/WcahtKf3EevZdY+fpcBTzTngYVEbjKljcuOcsjMEHVqj0EzvZTWZq9 x0JLsjtNHyrpJrhD73GNE0Xytbv0dRMG8M1BrRO611JetF4TtdwAwjtmrdGe9XNLEqjy olC2SFYC1TYECSdgvug1HTvoTzKkGRrRXkwTR/oLQpSYnnX5rpHxWQ+Q9F17fhgeac3x P4Lg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e1si978865ejf.335.2020.12.03.04.24.07; Thu, 03 Dec 2020 04:24:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388755AbgLCMV4 (ORCPT + 99 others); Thu, 3 Dec 2020 07:21:56 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9098 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730455AbgLCMVz (ORCPT ); Thu, 3 Dec 2020 07:21:55 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Cmw0N6GcxzLywj; Thu, 3 Dec 2020 20:20:36 +0800 (CST) Received: from huawei.com (10.174.186.236) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Thu, 3 Dec 2020 20:21:05 +0800 From: Yifei Jiang To: , , , , , CC: , , , , , , , , , Yifei Jiang Subject: [PATCH RFC 1/3] RISC-V: KVM: Change the method of calculating cycles to nanoseconds Date: Thu, 3 Dec 2020 20:18:37 +0800 Message-ID: <20201203121839.308-2-jiangyifei@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20201203121839.308-1-jiangyifei@huawei.com> References: <20201203121839.308-1-jiangyifei@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Originating-IP: [10.174.186.236] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Because we will introduce the dynamic guest frequency later, we can't use the fixed mult and shift to calculate nanoseconds. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- arch/riscv/include/asm/kvm_vcpu_timer.h | 3 --- arch/riscv/kvm/vcpu_timer.c | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_timer.h b/arch/riscv/include/asm/kvm_vcpu_timer.h index 375281eb49e0..87e00d878999 100644 --- a/arch/riscv/include/asm/kvm_vcpu_timer.h +++ b/arch/riscv/include/asm/kvm_vcpu_timer.h @@ -12,9 +12,6 @@ #include struct kvm_guest_timer { - /* Mult & Shift values to get nanoseconds from cycles */ - u32 nsec_mult; - u32 nsec_shift; /* Time delta value */ u64 time_delta; }; diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c index ddd0ce727b83..f6b35180199a 100644 --- a/arch/riscv/kvm/vcpu_timer.c +++ b/arch/riscv/kvm/vcpu_timer.c @@ -33,7 +33,7 @@ static u64 kvm_riscv_delta_cycles2ns(u64 cycles, cycles_delta = cycles - cycles_now; else cycles_delta = 0; - delta_ns = (cycles_delta * gt->nsec_mult) >> gt->nsec_shift; + delta_ns = mul_u64_u64_div_u64(cycles_delta, NSEC_PER_SEC, riscv_timebase); local_irq_restore(flags); return delta_ns; @@ -218,7 +218,6 @@ int kvm_riscv_guest_timer_init(struct kvm *kvm) { struct kvm_guest_timer *gt = &kvm->arch.timer; - riscv_cs_get_mult_shift(>->nsec_mult, >->nsec_shift); gt->time_delta = -get_cycles64(); return 0; -- 2.19.1