From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB35FD1AD3A for ; Wed, 16 Oct 2024 09:58:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=odRMbqFabeFb4k4nF5eV+DtgqQmczJvlfhPEpPABanU=; b=XlMRD9JZCjG4h7+kzUULRMabTD t5ph+jZpV/APeE9dGkFKG4MfM7YqpHm011okPjgMQ9CfxUHNYZHOGcfEiKDlCDk6tbpicLzc30mFB osdQj8DkEtulZ1P+RtKsWuuDUt5tNj20puvxDJDLBcawmHJvjkdlSgSB1KRx8Wcze21shGCd9r++g +ZXGsvaDyJKuUvE2Di1PNFuUrCIUSdpjmOBUR82IzuuNuccXbXRfnXxPeTKWTxs9kweF1bSHRqMim DerQv3JlV+48g33AgECpo9YdCIXKs18U9rNzi+MPSFx6Jsk5tkSrcAtO4GmXMzzdCxcgTTnmDg4JA UH9+KHRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t10nM-0000000BKbY-1hvs; Wed, 16 Oct 2024 09:58:20 +0000 Received: from nyc.source.kernel.org ([147.75.193.91]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t10kB-0000000BJk1-3fR2 for linux-arm-kernel@lists.infradead.org; Wed, 16 Oct 2024 09:55:05 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 1DA4FA43C43; Wed, 16 Oct 2024 09:54:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC7F1C4CEC5; Wed, 16 Oct 2024 09:54:57 +0000 (UTC) Date: Wed, 16 Oct 2024 10:54:55 +0100 From: Catalin Marinas To: "Christoph Lameter (Ampere)" Cc: Ankur Arora , linux-pm@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, pbonzini@redhat.com, wanpengli@tencent.com, vkuznets@redhat.com, rafael@kernel.org, daniel.lezcano@linaro.org, peterz@infradead.org, arnd@arndb.de, lenb@kernel.org, mark.rutland@arm.com, harisokn@amazon.com, mtosatti@redhat.com, sudeep.holla@arm.com, misono.tomohiro@fujitsu.com, maobibo@loongson.cn, joao.m.martins@oracle.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Subject: Re: [PATCH v8 01/11] cpuidle/poll_state: poll via smp_cond_load_relaxed() Message-ID: References: <20240925232425.2763385-1-ankur.a.arora@oracle.com> <20240925232425.2763385-2-ankur.a.arora@oracle.com> <086081ed-e2a8-508d-863c-21f2ff7c5490@gentwo.org> <1e56e83e-83b3-d4fd-67a8-0bc89f3e3d20@gentwo.org> <87jze9rq15.fsf@oracle.com> <95ba9d4a-b90c-c8e8-57f7-31d82722f39e@gentwo.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <95ba9d4a-b90c-c8e8-57f7-31d82722f39e@gentwo.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241016_025503_991517_E017B5EA X-CRM114-Status: GOOD ( 14.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Oct 15, 2024 at 03:40:33PM -0700, Christoph Lameter (Ampere) wrote: > Index: linux/arch/arm64/lib/delay.c > =================================================================== > --- linux.orig/arch/arm64/lib/delay.c > +++ linux/arch/arm64/lib/delay.c > @@ -12,6 +12,8 @@ > #include > #include > #include > +#include > +#include > > #include > > @@ -67,3 +69,27 @@ void __ndelay(unsigned long nsecs) > __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */ > } > EXPORT_SYMBOL(__ndelay); > + > +void cpuidle_wait_for_resched_with_timeout(u64 end) > +{ > + u64 start; > + > + while (!need_resched() && (start = local_clock_noinstr()) < end) { > + > + if (alternative_has_cap_unlikely(ARM64_HAS_WFXT)) { > + > + /* Processor supports waiting for a specified period */ > + wfet(xloops_to_cycles((end - start) * 0x5UL)); > + > + } else > + if (arch_timer_evtstrm_available() && start + ARCH_TIMER_EVT_STREAM_PERIOD_US * 1000 < end) { > + > + /* We can wait until a periodic event occurs */ > + wfe(); > + > + } else > + /* Need to spin until the end */ > + cpu_relax(); > + } > +} The behaviour above is slightly different from the current poll_idle() implementation. The above is more like poll every timeout period rather than continuously poll until either the need_resched() condition is true _or_ the timeout expired. From Ankur's email, an IPI may not happen so we don't have any guarantee that WFET will wake up before the timeout. The only way for WFE/WFET to wake up on need_resched() is to use LDXR to arm the exclusive monitor. That's what smp_cond_load_relaxed() does. If you only need the behaviour proposed above, you might as well go for udelay() directly. Otherwise I think we need to revisit Ankur's smp_cond_load_timeout() proposal from earlier this year. -- Catalin