Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp167100pxu; Thu, 3 Dec 2020 23:35:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyoWYo/OTe153OsaNkCV7kPDxthzWSaW2cYliwplpJBC83yrcjwAUg9kx0K6BDb8TbsPhM X-Received: by 2002:a17:906:9588:: with SMTP id r8mr5773998ejx.148.1607067353265; Thu, 03 Dec 2020 23:35:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607067353; cv=none; d=google.com; s=arc-20160816; b=w0ndsBV6QaxjndcYqH33ePpvPt+lMgzYxRhSo7XreTGCMBvVvyR+ix4Fw2In/WgujZ BKSYym1pe0YbygucpHbqa7zW9WPrIx1uka40/tEWP4pOyq7yE8H8ggNfGlMzZ7JVybUa dtEnwOF5R6XoNC59jEVUbuZSgf6HwcWSju9htDiRZYpfcOb0CFj7dhgoGyfsXfGC09cq UvHsoUTOu+JaXbI2Le9k8/6kigcMiFkTnZ6S6P4NdXs/yyX2lsVmsldwfBiIziBKY/PN nLXRN2kgOCweuG11sInRykJj7zjRse4CsSFjoL/qWa8D+38dQ7vHf26DjWKAVgDL8n5A LTJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=w+QhGKBei7jnnCEKNNql5easP+EUqdTgNRc5uowjdKw=; b=oMcprSVJnQGCl8/gLYC+y1q3XAdXjx4pnQ+5IhiGRARfjTMk02Dt4Vjxx/cbfEQAxP 8qdgo1xUamOuaAC9cZCC0XEs/y1VYVq/6XmDOKM5bUYF9zRlNeb5Z2Fce/ORk+jeEre8 N6j5UibjrmGfyxNXN0KzhTr0GAG9MTGs/GtjbXkA1oU6NJUksfKfQvWyHiddvwww62IT 4pwGISesMOnso0+3A28kcN2iRS2qUizXMDDiVlVL9b6+CsHc/r+eVkYJ0FIPEiJQrw25 AD4sGYKgjwzJjADCPmE9bfCnK0ORo0HNNcK5iM44kTSEi8XncT0dUNrFybaoOzZL3vX/ d/Ag== 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 ml22si898169ejb.172.2020.12.03.23.35.30; Thu, 03 Dec 2020 23:35:53 -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 S1728733AbgLDHdJ (ORCPT + 99 others); Fri, 4 Dec 2020 02:33:09 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9103 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726826AbgLDHdG (ORCPT ); Fri, 4 Dec 2020 02:33:06 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CnPXh56xczM0M1; Fri, 4 Dec 2020 15:31:48 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.187.37) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Fri, 4 Dec 2020 15:32:14 +0800 From: Keqian Zhu To: , , , CC: Marc Zyngier , Daniel Lezcano , Thomas Gleixner , Catalin Marinas , Will Deacon , James Morse , Suzuki K Poulose , "Sean Christopherson" , Julien Thierry , Mark Brown , "Andrew Morton" , Alexios Zavras , , Keqian Zhu Subject: [PATCH v3 2/2] clocksource: arm_arch_timer: Correct fault programming of CNTKCTL_EL1.EVNTI Date: Fri, 4 Dec 2020 15:31:26 +0800 Message-ID: <20201204073126.6920-3-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20201204073126.6920-1-zhukeqian1@huawei.com> References: <20201204073126.6920-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.37] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ARM virtual counter supports event stream, it can only trigger an event when the trigger bit (the value of CNTKCTL_EL1.EVNTI) of CNTVCT_EL0 changes, so the actual period of event stream is 2^(cntkctl_evnti + 1). For example, when the trigger bit is 0, then virtual counter trigger an event for every two cycles. Fixes: 037f637767a8 ("drivers: clocksource: add support for ARM architected timer event stream") Suggested-by: Marc Zyngier Signed-off-by: Keqian Zhu --- drivers/clocksource/arm_arch_timer.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index 777d38cb39b0..d0177824c518 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -822,15 +822,24 @@ static void arch_timer_evtstrm_enable(int divider) static void arch_timer_configure_evtstream(void) { - int evt_stream_div, pos; + int evt_stream_div, lsb; + + /* + * As the event stream can at most be generated at half the frequency + * of the counter, use half the frequency when computing the divider. + */ + evt_stream_div = arch_timer_rate / ARCH_TIMER_EVT_STREAM_FREQ / 2; + + /* + * Find the closest power of two to the divisor. If the adjacent bit + * of lsb (last set bit, starts from 0) is set, then we use (lsb + 1). + */ + lsb = fls(evt_stream_div) - 1; + if (lsb > 0 && (evt_stream_div & BIT(lsb - 1))) + lsb++; - /* Find the closest power of two to the divisor */ - evt_stream_div = arch_timer_rate / ARCH_TIMER_EVT_STREAM_FREQ; - pos = fls(evt_stream_div); - if (pos > 1 && !(evt_stream_div & (1 << (pos - 2)))) - pos--; /* enable event stream */ - arch_timer_evtstrm_enable(min(pos, 15)); + arch_timer_evtstrm_enable(max(0, min(lsb, 15))); } static void arch_counter_set_user_access(void) -- 2.23.0