Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp56157rdb; Wed, 18 Oct 2023 18:10:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCOGmLzfcx1crHl2gkFV7p6J+KnsxTwCYiqOLqEKsqWO9mlhpaPcAER22/6yYx8YQtg6sk X-Received: by 2002:a05:6808:219b:b0:3a7:4876:6044 with SMTP id be27-20020a056808219b00b003a748766044mr971238oib.52.1697677859136; Wed, 18 Oct 2023 18:10:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697677859; cv=none; d=google.com; s=arc-20160816; b=p1AICsAxa7TCiEa8dByZBV1MXZtGdfE9MB9rZ70OWzBzc6AjT4o5fJY/XWNrCevxVB tmlYnRJBCftPru5ryxcZPIBP7LKaGVWLKd/4vdrWNNDogCE0LSYyJZqM+k/up0shn7Bf AmA5DwpegYs2BD7lahcA/YrnOg9pN3ggwsYkIpFD2wlSlX0A9UCCe5jkRgz5Nom009G5 EZQPe8OBRlD8qhBZBQZqTpwb4NDoZioh55oMolKrsQ58zVpaNcJWY66D3Mg5XbE+sTAL /Lh5d8v/cd6j4w/7c5Eoutp4HYHSLzJK6A68VC128p5+OxaeU4peQMXF1zaG9/jwcEJS VXVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=sP/cRV4QUGjTkFLtwW0tXTJRApQEfvV0GlECJSheTZ0=; fh=UMw/rSJvHug5WZkuRK4Or+fECN0t3JxnW/ph7Io0KUE=; b=p3tcscWNppEMyLth0ntEXQK9BMAZ3ZfDOHBRg2G3gluiq60a+Z0WbsleUQQzswSsv5 wyL5yEj4QA63/Ul8sD8devYEV4tM4ZT1/OAbRqBw/P29KJ2EEi4i0OijVJ2EqODkIskW 69ho9tkXMUQjPmy2tuCnH8XiKsvSSNG2+3HseeXni/ifqwD+8K2gC5awzhl6ILhouBa0 YHISgzE2iKg+YnDY/qgQ32prNKOS49kmlJvC6mksZv6lOD+UvgCmBjETwrkVG9ppVv5S I0vBUBaN+PLNjUUUswsf9r1Vduts9VJrZc0Z88PmQlvIpP6sIhW/1ub37rov8YSIxZcG d+AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=OzA36oun; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id d185-20020a6336c2000000b005780c629ec8si3232853pga.617.2023.10.18.18.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 18:10:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=OzA36oun; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 64591811907B; Wed, 18 Oct 2023 18:10:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbjJSBJz (ORCPT + 99 others); Wed, 18 Oct 2023 21:09:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjJSBJy (ORCPT ); Wed, 18 Oct 2023 21:09:54 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48B7E113 for ; Wed, 18 Oct 2023 18:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1697677783; bh=sP/cRV4QUGjTkFLtwW0tXTJRApQEfvV0GlECJSheTZ0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=OzA36ounnOpYrxRilcLyJmhKG74vt5b0xbblSnpZ38SXwXoRD+pqu81YjaU92OqiS K12o3y54lx6qpe39yAAqNZhbD2Z3NftbZ3odfdwqgqNJ5pR9T+1d1SWyxv5ED4xLsP 8I7wuTWDCuUgDsuuejG9J4zE5bmBSREmXITfJ3eXHU8WKIgnmZAfrtpEVwlb5yQZV9 WNCMgxPvXT0laLMYP1cAF0XEPYLg5zqjCDWUsTrngP8pkzVgbM4HKfbkvRfDCowcFK 4C9L3k65lqlVMLkdmGCI0ViV1t4nAyuFMJNGHHeRywl+mYpfXEyyQkSWfovcLLvz3i nY7Es8JiD1N/w== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4S9qPf4HMkz4wcN; Thu, 19 Oct 2023 12:09:42 +1100 (AEDT) From: Michael Ellerman To: Srikar Dronamraju Cc: linuxppc-dev , Srikar Dronamraju , Aboorva Devarajan , Shrikanth Hegde , Ajay Kaher , Alexey Makhalov , VMware PV-Drivers Reviewers , Nicholas Piggin , Christophe Leroy , virtualization@lists.linux-foundation.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] powerpc/paravirt: Improve vcpu_is_preempted In-Reply-To: <20231018155838.2332822-1-srikar@linux.vnet.ibm.com> References: <20231018155838.2332822-1-srikar@linux.vnet.ibm.com> Date: Thu, 19 Oct 2023 12:09:38 +1100 Message-ID: <877cnj76zx.fsf@mail.lhotse> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 18 Oct 2023 18:10:12 -0700 (PDT) Hi Srikar, Srikar Dronamraju writes: > PowerVM Hypervisor dispatches on a whole core basis. In a shared LPAR, a > CPU from a core that is CEDED or preempted may have a larger latency. In > such a scenario, its preferable to choose a different CPU to run. > > If one of the CPUs in the core is active, i.e neither CEDED nor > preempted, then consider this CPU as not preempted. > > Also if any of the CPUs in the core has yielded but OS has not requested > CEDE or CONFER, then consider this CPU to be preempted. I think the change is OK, but the change log and comments are slightly confusing IMHO. In several places you use "this CPU", but that usually means "the CPU the code is currently executing on". I think it would be clearer if you used eg. "target CPU" or something to make it clear that you're not talking about the currently executing CPU. cheers > Correct detection of preempted CPUs is important for detecting idle > CPUs/cores in task scheduler. > > Changelog: > v1 -> v2: Handle lppaca_of(cpu) in !PPC_SPLPAR case. > v1: https://lore.kernel.org/r/20231009051740.17683-1-srikar%40linux.vnet.ibm.com > 1. Fixed some compilation issues reported by kernelbot > a. https://lore.kernel.org/oe-kbuild-all/202310102341.K0sgoqQL-lkp@intel.com/ > b. https://lore.kernel.org/oe-kbuild-all/202310091636.lElmJkYV-lkp@intel.com/ > 2. Resolved comments from Shrikanth That change log should appear below the break "---". > Tested-by: Aboorva Devarajan > Reviewed-by: Shrikanth Hegde > Signed-off-by: Srikar Dronamraju > --- > arch/powerpc/include/asm/paravirt.h | 42 ++++++++++++++++++++++++++--- > 1 file changed, 39 insertions(+), 3 deletions(-) > > diff --git a/arch/powerpc/include/asm/paravirt.h b/arch/powerpc/include/asm/paravirt.h > index e08513d73119..0372b0093f72 100644 > --- a/arch/powerpc/include/asm/paravirt.h > +++ b/arch/powerpc/include/asm/paravirt.h > @@ -71,6 +71,11 @@ static inline void yield_to_any(void) > { > plpar_hcall_norets_notrace(H_CONFER, -1, 0); > } > + > +static inline bool is_vcpu_idle(int vcpu) > +{ > + return lppaca_of(vcpu).idle; > +} > #else > static inline bool is_shared_processor(void) > { > @@ -100,6 +105,10 @@ static inline void prod_cpu(int cpu) > ___bad_prod_cpu(); /* This would be a bug */ > } > > +static inline bool is_vcpu_idle(int vcpu) > +{ > + return false; > +} > #endif > > #define vcpu_is_preempted vcpu_is_preempted > @@ -121,9 +130,19 @@ static inline bool vcpu_is_preempted(int cpu) > if (!is_shared_processor()) > return false; > > + if (!(yield_count_of(cpu) & 1)) > + return false; Would be nice for that to have a short comment too. > + > + /* > + * If CPU has yielded to Hypervisor but OS has not requested idle > + * then this CPU is definitely preempted. eg. If the target CPU has yielded to the Hypervisor, but the OS has not requested idle then the target CPU has definitely been preempted. > + */ > + if (!is_vcpu_idle(cpu)) > + return true; > + > #ifdef CONFIG_PPC_SPLPAR > if (!is_kvm_guest()) { > - int first_cpu; > + int first_cpu, i; > > /* > * The result of vcpu_is_preempted() is used in a > @@ -149,11 +168,28 @@ static inline bool vcpu_is_preempted(int cpu) > */ > if (cpu_first_thread_sibling(cpu) == first_cpu) > return false; > + > + /* > + * If any of the threads of this core is not preempted or > + * ceded, then consider this CPU to be non-preempted > + */ eg. If any of the threads of the target CPU's core are not preempted or ceded, then consider that the target CPU is also not preempted. > + first_cpu = cpu_first_thread_sibling(cpu); > + for (i = first_cpu; i < first_cpu + threads_per_core; i++) { > + if (i == cpu) > + continue; > + if (!(yield_count_of(i) & 1)) > + return false; > + if (!is_vcpu_idle(i)) > + return true; > + } > } > #endif > > - if (yield_count_of(cpu) & 1) > - return true; > + /* > + * None of the threads in this core are running but none of > + * them were preempted too. Hence assume the thread to be > + * non-preempted. > + */ > return false; > } > > > base-commit: eddc90ea2af5933249ea1a78119f2c8ef8d07156 > -- > 2.31.1