From patchwork Fri Oct 27 08:34:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10029351 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 4D765602D6 for ; Fri, 27 Oct 2017 08:35:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A54E28F55 for ; Fri, 27 Oct 2017 08:35:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D68328F5C; Fri, 27 Oct 2017 08:35:28 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 9A0D928F55 for ; Fri, 27 Oct 2017 08:35:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751980AbdJ0IfY (ORCPT ); Fri, 27 Oct 2017 04:35:24 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:56599 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752322AbdJ0IfS (ORCPT ); Fri, 27 Oct 2017 04:35:18 -0400 Received: by mail-lf0-f66.google.com with SMTP id 90so6519969lfs.13 for ; Fri, 27 Oct 2017 01:35:17 -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=54yMnq3f6gaavU5iIqS9YsXqzGR++gW8THLn7Vohq5Q=; b=ETJbZJvjlSs6BYJsOAlW12QMi1jr1TkOvI1t81ElbZF9nhDoB1/exdikkhjk5j75Hp 6S9kkP/OrK9gKGSoH2T6OV+jWGlJHQmA8vLHxfcLe5UYCKiZFlpfNZUhmvYuEVcJaIuC Qjh3wBi0WyjB2faiT+zQ7all85TPFgpD6nFZw= 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=54yMnq3f6gaavU5iIqS9YsXqzGR++gW8THLn7Vohq5Q=; b=nJ3X1MagYpOnilmjRR5AGYa6G6Izb1BLXbBajLNWNVF2QBlBQXF7k5cCKdjnr1xZHQ VPQbOpoLdXpTF7AYv2woYs3Fn9ec90CVCuLpQbwn/UcGxYd7lBEq1BRg51oKRDF9UiG0 2jujRC2SzXKTgvCRBAjR0tMfjSKzxO0Fvl6/5kKxjxPk6CqFGJ98qXwy5fQ1BQaqv0b3 zCQdnpOApijJpGgKIYgZtH5Uv5ZFUhQUDzeHYxwvtorhuAVjQXcJNDPH/aft/Ip+tfra N5AJe7O+bb+jxYCdexTMMYAG6B0qcvlkPCyOrTaQ4j57W72VgFJPjSs9l4GoW3+JbsIm 6Weg== X-Gm-Message-State: AMCzsaUHEN8EsC+a8W3Hhz+cEm1pV4haRFJ4BI9j8EWEOLaW54m8rot2 TRZoO3J5Cx2GdEwFTtux6ylZVA== X-Google-Smtp-Source: ABhQp+SydZLYggHQw31LOUXqkxwmeWhzufjYhYn2Ga8B282zJy/CCUon1hfVGLKN3RgQ2G8O4W+gfQ== X-Received: by 10.46.2.4 with SMTP id 4mr10677756ljc.0.1509093317079; Fri, 27 Oct 2017 01:35:17 -0700 (PDT) Received: from localhost.localdomain (212.27.17.163.bredband.3.dk. [212.27.17.163]) by smtp.gmail.com with ESMTPSA id d204sm1471957lfe.73.2017.10.27.01.35.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Oct 2017 01:35:16 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: Marc Zyngier , Eric Auger , kvm@vger.kernel.org, Catalin Marinas , Will Deacon , Christoffer Dall , Mark Rutland Subject: [PATCH v5 03/20] arm64: Use physical counter for in-kernel reads when booted in EL2 Date: Fri, 27 Oct 2017 10:34:24 +0200 Message-Id: <1509093281-15225-4-git-send-email-cdall@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509093281-15225-1-git-send-email-cdall@linaro.org> References: <1509093281-15225-1-git-send-email-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 virtual counter and get the same view of time as the kernel. This opens up potential improvements for KVM performance, but we have to make a few adjustments to preserve system consistency. Currently get_cycles() is hardwired to arch_counter_get_cntvct() on arm64, but as we move to using the physical timer for the in-kernel time-keeping on systems that boot in EL2, we should use the same counter for get_cycles() as for other in-kernel timekeeping operations. Similarly, implementations of arch_timer_set_next_event_phys() is modified to use the counter specific to the timer being programmed. VHE kernels or kernels continuing to use the virtual timer are unaffected. Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall Acked-by: Catalin Marinas --- arch/arm64/include/asm/timex.h | 2 +- drivers/clocksource/arm_arch_timer.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/timex.h b/arch/arm64/include/asm/timex.h index 81a076e..9ad60ba 100644 --- a/arch/arm64/include/asm/timex.h +++ b/arch/arm64/include/asm/timex.h @@ -22,7 +22,7 @@ * Use the current timer as a cycle counter since this is what we use for * the delay loop. */ -#define get_cycles() arch_counter_get_cntvct() +#define get_cycles() arch_timer_read_counter() #include diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index ff8f8a1..061476e 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -158,6 +158,7 @@ u32 arch_timer_reg_read(int access, enum arch_timer_reg reg, * if we don't have the cp15 accessors we won't have a problem. */ u64 (*arch_timer_read_counter)(void) = arch_counter_get_cntvct; +EXPORT_SYMBOL_GPL(arch_timer_read_counter); static u64 arch_counter_read(struct clocksource *cs) { @@ -329,16 +330,19 @@ static void erratum_set_next_event_tval_generic(const int access, unsigned long struct clock_event_device *clk) { unsigned long ctrl; - u64 cval = evt + arch_counter_get_cntvct(); + u64 cval; ctrl = arch_timer_reg_read(access, ARCH_TIMER_REG_CTRL, clk); ctrl |= ARCH_TIMER_CTRL_ENABLE; ctrl &= ~ARCH_TIMER_CTRL_IT_MASK; - if (access == ARCH_TIMER_PHYS_ACCESS) + if (access == ARCH_TIMER_PHYS_ACCESS) { + cval = evt + arch_counter_get_cntpct(); write_sysreg(cval, cntp_cval_el0); - else + } else { + cval = evt + arch_counter_get_cntvct(); write_sysreg(cval, cntv_cval_el0); + } arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl, clk); } @@ -913,7 +917,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) || + if ((IS_ENABLED(CONFIG_ARM64) && !is_hyp_mode_available()) || arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI) arch_timer_read_counter = arch_counter_get_cntvct; else