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: 10029379 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 94DE9602D6 for ; Fri, 27 Oct 2017 08:36:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80B1728F55 for ; Fri, 27 Oct 2017 08:36:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 756E028F5C; Fri, 27 Oct 2017 08:36:42 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 81E2C28F55 for ; Fri, 27 Oct 2017 08:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3LHzhwzSLXOj54rFhtATAWOtreI6dxRVbOTrPfV7N1c=; b=gR5rj5GODaXXuQJqUWRaOcT/NL crDtGxlvkuZ8Nl1DVj8WHnksTJ0TUa5QNHR9puUqDSdYf5u8hUJLeOoN17J2vqlYkxOmZoHs3fQ4b kjJxi0WQbfVztTVgBOS9VTc6nGHY9WErFNEmjmJIyilyrmteXX1UVxA3RTqJ9U2a5nCDr9KMxoSTc l0poVysudXvbwVfrn2aEAS7B7+pEZ1yABNg3w2pIJ1lWE/qcfLpFEmXsiKbWVh4fWY4SAXYQAOz5i WML2aIWIKQE0qEKS3ObDTk05GwBj9hEwTh7UXAeQx27yKbCvnlXZLyzD/SmvPjlMEGuDsfUpMHQQ8 uBO/oruw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e8080-0000ti-E7; Fri, 27 Oct 2017 08:36:32 +0000 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e8077-0008PM-HD for linux-arm-kernel@lists.infradead.org; Fri, 27 Oct 2017 08:35:45 +0000 Received: by mail-lf0-x244.google.com with SMTP id b190so6534188lfg.9 for ; Fri, 27 Oct 2017 01:35:18 -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=FNoQGS/ZgJFlTQYG7+QGErNmxMGSp7xW7c5FNjVarxDiuRIsgs9PrCML+BWMoA2v/w RpLLU5nZhEBM0dJblsJxDrIMvCkFAFCjyANg3XCMFsaxmZiemHic6WaG/u+BFemKDdzm IbVTS+DvSDOYNRb0i2lmwP9EoV1Gl/NgBqmQCCkcB0YB/wdc4VVomcXqfUy/Ke+4iEmh ZHRGqSpxichxtdoT3wSs5Lb1GRg2ooWaAQ7rls0dZRcNaHjGgRLSpsxZ/N67qUjS6sOY WQrtb2zCMnNRitt03TIXDQx7fimM3OoHXd91OSE7KN/RMjvbEAd26/W04PZi0hk2Fdfq ncbA== X-Gm-Message-State: AMCzsaVowQXhGkUyJJQTRmHFtXh1sqVIvrCpo5KZWwvj1XNcauE0GnY4 QdOhsTX7/D3JLhu+A8JYV0c0nXKlxCg= 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171027_013538_540568_9C6C411D X-CRM114-Status: GOOD ( 16.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Christoffer Dall , kvm@vger.kernel.org, Marc Zyngier , Catalin Marinas , Will Deacon , Eric Auger MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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