From patchwork Sat Dec 10 20:47:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9469467 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 06962607F0 for ; Sat, 10 Dec 2016 20:47:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEFC427F4B for ; Sat, 10 Dec 2016 20:47:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3C62284E9; Sat, 10 Dec 2016 20:47:13 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 DB699284E6 for ; Sat, 10 Dec 2016 20:47:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752787AbcLJUrL (ORCPT ); Sat, 10 Dec 2016 15:47:11 -0500 Received: from mail-lf0-f50.google.com ([209.85.215.50]:36051 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752521AbcLJUrI (ORCPT ); Sat, 10 Dec 2016 15:47:08 -0500 Received: by mail-lf0-f50.google.com with SMTP id t196so21825004lff.3 for ; Sat, 10 Dec 2016 12:47:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5OqKqg2r3AZdjr3oadZIEnKl9hUkNcmyyEs5WnO21Q0=; b=cGGIl3X0m4tZBeMHaChYWnrBv8T7GJWAEmbX2Le0T7r4ThRCXnZ0PHcTB4KmK1zRcu lqjyz1ZwSVJdgy/m/cBrUilpUCdbaeLNbiCuvAkfYiCHlPJALOF8nPk0JxuokYsAX3E1 2qMa2kBnhysZuQsO2NbFkmbfw5XW03/ryEaTI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5OqKqg2r3AZdjr3oadZIEnKl9hUkNcmyyEs5WnO21Q0=; b=YeJQdWsT+xdWv5ekSuZrueaMVYLRrkYnwqqlLWlMI5pWNY3ErVNr0MwSVEbuwd6zxi 9MB/lfav2Qm4S5jqcGe+ansBbAlj2H+Sma91eCO4ahdh8KEnNh3W9Ja3a8Lw7lFgMdXG QmW1M1YXDZHbThcCcdVwewf45lrSn6BSdSECTjg57FFv97Fojmz7FR+6ir5w42bAUW2O PY4S6xGH+ksR0Yn1Tj7AirOVRr6EqN5EQ6EnGN81MAKgOA2a8DekIsfu5Dn5EwBD+tSU 0QnI/BUYFHT/r/UEGwTIfpCYdbkaK33krm4rxcr4gvsh0aL7JQTYVEqNaY2atXbY1VRu hFYQ== X-Gm-Message-State: AKaTC033ufE6CrbEg9DyqXBlrlmnH5sAcakN+BHsRAsI+ezTOHSMVoPVZrOMsmt8jmR5WYS5 X-Received: by 10.46.78.26 with SMTP id c26mr37613518ljb.46.1481402826623; Sat, 10 Dec 2016 12:47:06 -0800 (PST) Received: from localhost.localdomain (x1-6-50-6a-03-de-ec-c2.cpe.webspeed.dk. [2.108.209.202]) by smtp.gmail.com with ESMTPSA id 29sm7578325lft.43.2016.12.10.12.47.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Dec 2016 12:47:06 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: Marc Zyngier , Christoffer Dall Subject: [RFC PATCH 1/7] arm64: Use physical counter for in-kernel reads Date: Sat, 10 Dec 2016 21:47:06 +0100 Message-Id: <20161210204712.21830-2-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20161210204712.21830-1-christoffer.dall@linaro.org> References: <20161210204712.21830-1-christoffer.dall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using the physical counter allows KVM to retain the offset between the virtual and physical counter as long as it is actively running a VCPU. As soon as a VCPU is released, another thread is scheduled or we start running userspace applications, we reset the offset to 0, so that VDSO operations can still read the virtual counter and get the same view of time as the kernel. This opens up potential improvements for KVM performance. VHE kernels or kernels using the virtual timer are unaffected by this. Signed-off-by: Christoffer Dall --- arch/arm64/include/asm/arch_timer.h | 6 ++++-- drivers/clocksource/arm_arch_timer.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/arch_timer.h b/arch/arm64/include/asm/arch_timer.h index eaa5bbe..cec2549 100644 --- a/arch/arm64/include/asm/arch_timer.h +++ b/arch/arm64/include/asm/arch_timer.h @@ -139,11 +139,13 @@ static inline void arch_timer_set_cntkctl(u32 cntkctl) static inline u64 arch_counter_get_cntpct(void) { + u64 cval; /* * AArch64 kernel and user space mandate the use of CNTVCT. */ - BUG(); - return 0; + isb(); + asm volatile("mrs %0, cntpct_el0" : "=r" (cval)); + return cval; } static inline u64 arch_counter_get_cntvct(void) diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index 73c487d..a5b0789 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -597,7 +597,7 @@ static void __init arch_counter_register(unsigned type) /* Register the CP15 based counter if we have one */ if (type & ARCH_CP15_TIMER) { - if (IS_ENABLED(CONFIG_ARM64) || arch_timer_uses_ppi == VIRT_PPI) + if (arch_timer_uses_ppi == VIRT_PPI || is_kernel_in_hyp_mode()) arch_timer_read_counter = arch_counter_get_cntvct; else arch_timer_read_counter = arch_counter_get_cntpct;