From patchwork Sat Sep 23 00:41:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9967293 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 AB38C602CB for ; Sat, 23 Sep 2017 00:42:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E51329590 for ; Sat, 23 Sep 2017 00:42:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 933D8299C6; Sat, 23 Sep 2017 00:42:15 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 2C21929590 for ; Sat, 23 Sep 2017 00:42:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752402AbdIWAmK (ORCPT ); Fri, 22 Sep 2017 20:42:10 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:45633 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752004AbdIWAmH (ORCPT ); Fri, 22 Sep 2017 20:42:07 -0400 Received: by mail-wm0-f42.google.com with SMTP id q124so7622796wmb.0 for ; Fri, 22 Sep 2017 17:42:07 -0700 (PDT) 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=UHzHLZOYR5TVTmXGJM/1OeserICXEN/Lr8qfjGDu8oU=; b=FpY2In7SJudOKbrxNJeBK3xddHSGbC3+cMJCyOe8j4ibn9fc2HORRUrte0QLRdH7bA 8B4Eza1zcYN0wiG30HUj20CG970SZURXYWZHHbZtPH7DEoOg56W4Wgz6o5mugjIbMug+ Fan3pEMwxc2lnVZ84nCsko67dQFNPVUrUbBJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UHzHLZOYR5TVTmXGJM/1OeserICXEN/Lr8qfjGDu8oU=; b=TrNC7eSOo/pH4eOYvfKrytyLWMRzzIbKPicNK9TnOroaUIGIgsuj4BraaBmBCtKT1a cT2drIXfZQucGqouxfVKi8PQYy0aoXWvOV4aOYmE0w5SvEfv2u5eZ1ExzqhMfof2qTqx SLgx9t+zvhszv3HzdqpIja03+baaqOX3EZzfHA9KypY1zVCXal+EGtW5uYDThVUY9FI2 OmIUvF4dLY+HoIzOYYYJ9MB1jiEcPGXvGStH/xlZsg+CHZDVv36KswSmCc3PS2S7LaXM 2Kw6KtDT9cUJQJdT9R+Pd+3EN5nCaAdzJDLRPBUbxv55OtGH6Le/KEtY+Q9PDYdj9qkH U76w== X-Gm-Message-State: AHPjjUjHPGHfGoQihLebm0GSipTHjjmjeT+NZ5qDE7c2BPEUBellBEKL LRbqHH/gaaXC2rmUBAQQSDtDdw== X-Google-Smtp-Source: AOwi7QCDBfVthVxhV68iPICBAsgA4tMm2dE9XpiV6GpUzONHZj3LiAJA/xhJizYqm/w1ueaVh0JmFA== X-Received: by 10.80.228.5 with SMTP id d5mr6538074edm.16.1506127326327; Fri, 22 Sep 2017 17:42:06 -0700 (PDT) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id c25sm646085edb.57.2017.09.22.17.42.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Sep 2017 17:42:05 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Will Deacon , Catalin Marinas , Christoffer Dall Subject: [PATCH v3 02/20] arm64: Use physical counter for in-kernel reads Date: Sat, 23 Sep 2017 02:41:49 +0200 Message-Id: <20170923004207.22356-3-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170923004207.22356-1-cdall@linaro.org> References: <20170923004207.22356-1-cdall@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 userspace accessing the virtual timer can still read the cirtual counter and get the same view of time as the kernel. This opens up potential improvements for KVM performance. VHE kernels or kernels continuing to use the virtual timer are unaffected. Signed-off-by: Christoffer Dall --- arch/arm64/include/asm/arch_timer.h | 9 ++++----- drivers/clocksource/arm_arch_timer.c | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/arch_timer.h b/arch/arm64/include/asm/arch_timer.h index a652ce0..1859a1c 100644 --- a/arch/arm64/include/asm/arch_timer.h +++ b/arch/arm64/include/asm/arch_timer.h @@ -148,11 +148,10 @@ static inline void arch_timer_set_cntkctl(u32 cntkctl) static inline u64 arch_counter_get_cntpct(void) { - /* - * AArch64 kernel and user space mandate the use of CNTVCT. - */ - BUG(); - return 0; + u64 cval; + 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 fd4b7f6..9b3322a 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -890,8 +890,7 @@ static void __init arch_counter_register(unsigned type) /* Register the CP15 based counter if we have one */ if (type & ARCH_TIMER_TYPE_CP15) { - if (IS_ENABLED(CONFIG_ARM64) || - arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI) + if (arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI) arch_timer_read_counter = arch_counter_get_cntvct; else arch_timer_read_counter = arch_counter_get_cntpct;