Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6844789rdb; Fri, 15 Dec 2023 09:41:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjgwYRW4c7SoWhIZcyr4olITGQJtFphj92iYQWZ92GFR8w1MN7jrLCn7e8YZ4bplYMqJ7v X-Received: by 2002:a05:622a:1905:b0:425:9957:5fd5 with SMTP id w5-20020a05622a190500b0042599575fd5mr16301892qtc.133.1702662117037; Fri, 15 Dec 2023 09:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702662117; cv=none; d=google.com; s=arc-20160816; b=zWAqp9q9f8zXgczRbn9j5LEYlRcO8/F6XDSADbwN1mPBQTwYGfUh1Dx6KDfeP9cBNP EIVDtMITbE6RbsryxJnNqSVo/Qax+JNbp0xt5h37iwV4SqCMRi1GDLjY59nt0eplFHU/ pSz4FmDzhwFECb2E/QhhFjb7mFj/LR/GU9LMZIHP766SUnQ/fUMWEHs2VckMYQhQ4I88 2bee7gQNbcI7VP9YdjBJ+vDA8vZb6LLbU9g3/n17nwhs+DbmKGYWt67OfQUk1ItRi1ch cqL7Y02Mj7sNyAIcLXV5yDGgWhtLGzhoYTtp2cMpK+uhVWLlBcn+GkQIMOiyHCjxPzQA qyKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=iByNZ9iuxrucc80M1Cf1SbfHYaR8Xzx+2xfjkA5vSZo=; fh=V3EXrfhtPXQ8VZs+995Yo8T+zOpBnshrD4ANVkhZrjM=; b=nKG8/JOhP4gCBtP0QYHGfszu2upRcPfqjBflLZ6u7Zyo1PLP7Psn1seQfMpzn4xQrc HNkU2enoFm30l8Kr/0xdZh+gHhEkToVvu4caruk1eArQFj5sVFOTm1m4PpGNPhhKgLJg xNSnZaCvDLHcf16N+Sv4ZY6JQ77sr+6tKTaUxcKBQz1MSLkCzDGd424ZfBAFggMI/KfE pEU/B3K/ZAVzNN6zakOncmFAl1/rJMbzkGsJCQta6BcHkCNzR5fWgYAL23hjb+YFiAG+ WKyK0Ro6Q0jxz3xujJv9OIgxUweuciT1Tb/XaDqL0tD65BReVWX2SOxciRrWwnku2/Cc TxZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1436-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1436-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i6-20020ac85e46000000b00425f24df298si6414085qtx.548.2023.12.15.09.41.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:41:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1436-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1436-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1436-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BB0551C24379 for ; Fri, 15 Dec 2023 17:41:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 060103010F; Fri, 15 Dec 2023 17:41:51 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81BB830104 for ; Fri, 15 Dec 2023 17:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ECDB9C15; Fri, 15 Dec 2023 09:42:32 -0800 (PST) Received: from [10.57.4.221] (unknown [10.57.4.221]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A5B7E3F5A1; Fri, 15 Dec 2023 09:41:43 -0800 (PST) Message-ID: Date: Fri, 15 Dec 2023 17:41:42 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 21/24] x86/resctrl: Allow overflow/limbo handlers to be scheduled on any-but cpu Content-Language: en-US To: Reinette Chatre , x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com References: <20231025180345.28061-1-james.morse@arm.com> <20231025180345.28061-22-james.morse@arm.com> <9084cb79-22bd-4cb3-b48d-f0d8d71aa47c@intel.com> <9a66b7f8-097b-45af-97b2-4c403c295301@intel.com> From: James Morse Autocr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jepPbXLweMPLzUy/jd86TBnM3HHqCu BbV1x8kZCYaPlq+8IlHvrcANj92pxLbjl7tCJVbx70+nXAUshMos82pKbMTvMV0b9NxzIbdd O66DqxISgwARAQABwsF8BBgBCgAmAhsMFiEEbHTOsUbkyIPacxU46zf2z+uDUs4FAmRf+m8F CQwffHQACgkQ6zf2z+uDUs6lrg/+J3YQ5i3D5wrTvRjhXm9bH6WUQODPEqkYZ5YWNRs2OdC8 NVsJFGUAvSkD+Qu0KBOf1e4BBSjl+R6lbIHXoTtCu84+RI4rTtb7UP5OvnoR4fLgCIWFv/4/ v09mlGsXrsv+lr5M/alidkLLfMrgUWZAqWXNUE/7eAZfp4XIIv2oTscgvWg/m0BL50xZkyNc jEF6RzZjNjcjtlDD7Kxgf21t+gDyEaSvC+X6j0bZ3onf2IXwFbg9LifeoDjA+NzGN9JkGtLp eWmhN3utNP5XwG1+75PM6bOfCwasorFX3eyFj98R/yo0ByACWRI1vKQPZol+zDZ0ZOKIZUGa Rrr5+0tVoopeYkBuFrtY3N8Glv3mWIcN0wVneY6k0nAvDaShre1evNnqSh9xAWR6/ZnbwX31 cJD4oBSl3HnmfEHytKugEsndaLMZbAbH9TSAZoTPR2Mnu+/3r0FXaUF8rjY89Xwk16ZFH4yH SrUVzFOO6bhEKmdJX9tUfCR1u6k7/Cv/J+sL5S5I+/bd7jlwdgMYgHs6uB+5FlPyw2JdXe3N Z6Z4YTWcwRdfKKY6RZX1mzTkLuJDuKMbA4xJ+2OgG9N4YLMPyxXm1V5/gu3tnM9QIgmDHeCr RCZNANToJ3eaUvYMW+f3CD0g7gDykJRvlNeIDl14zasM4C95vuRh3bTzXk/ScPs= In-Reply-To: <9a66b7f8-097b-45af-97b2-4c403c295301@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Reinette, On 12/14/23 18:53, Reinette Chatre wrote: > On 12/14/2023 3:38 AM, James Morse wrote: >> On 09/11/2023 17:48, Reinette Chatre wrote: >>> On 10/25/2023 11:03 AM, James Morse wrote: >>>> diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h >>>> index c4c1e1909058..f5fff2f0d866 100644 >>>> --- a/arch/x86/kernel/cpu/resctrl/internal.h >>>> +++ b/arch/x86/kernel/cpu/resctrl/internal.h >>>> @@ -61,19 +61,36 @@ >>>> * cpumask_any_housekeeping() - Choose any CPU in @mask, preferring those that >>>> * aren't marked nohz_full >>>> * @mask: The mask to pick a CPU from. >>>> + * @exclude_cpu:The CPU to avoid picking. >>>> * >>>> - * Returns a CPU in @mask. If there are housekeeping CPUs that don't use >>>> - * nohz_full, these are preferred. >>>> + * Returns a CPU from @mask, but not @exclude_cpu. If there are housekeeping >>>> + * CPUs that don't use nohz_full, these are preferred. Pass >>>> + * RESCTRL_PICK_ANY_CPU to avoid excluding any CPUs. >>>> + * >>>> + * When a CPU is excluded, returns >= nr_cpu_ids if no CPUs are available. >>>> */ >>>> -static inline unsigned int cpumask_any_housekeeping(const struct cpumask *mask) >>>> +static inline unsigned int >>>> +cpumask_any_housekeeping(const struct cpumask *mask, int exclude_cpu) >>>> { >>>> unsigned int cpu, hk_cpu; >>>> >>>> - cpu = cpumask_any(mask); >>>> - if (!tick_nohz_full_cpu(cpu)) >>>> + if (exclude_cpu == RESCTRL_PICK_ANY_CPU) >>>> + cpu = cpumask_any(mask); >>>> + else >>>> + cpu = cpumask_any_but(mask, exclude_cpu); >>>> + >>>> + if (!IS_ENABLED(CONFIG_NO_HZ_FULL)) >>>> + return cpu; >>> >>> It is not clear to me how cpumask_any_but() failure is handled. >>> >>> cpumask_any_but() returns ">= nr_cpu_ids if no cpus set" ... >> >> It wasn't a satisfiable request, there are no CPUs for this domain other than the one that >> was excluded. cpumask_any_but() also describes its errors as "returns >= nr_cpu_ids if no >> CPUs are available". >> >> The places this can happen in resctrl are: >> cqm_setup_limbo_handler(), where it causes the schedule_delayed_work_on() call to be skipped. >> mbm_setup_overflow_handler(), which does similar. >> >> These two cases are triggered from resctrl_offline_cpu() when the last CPU in a domain is >> going offline, and the domain is about to be free()d. This is how the limbo/overflow >> 'threads' stop. > Right ... yet this is a generic function, if there are any requirements on when/how it should > be called then it needs to be specified in the function comments. I do not expect this to > be the case for this function. There are no special requirements, like all the other cpumask_foo() helpers, you can feed it an empty bitmap and it will return '>= nr_cpu_ids' as an error. [...] >>> But that would have >>> code continue ... so maybe it needs explicit error check of >>> cpumask_any_but() failure with an earlier exit? >> >> I'm not sure what the problem you refer to here is. >> If 'cpu' is valid, and not marked nohz_full, nothing more needs doing. >> If 'cpu' is invalid or a CPU marked nohz_full, then a second attempt is made to find a >> housekeeping CPU into 'hk_cpu'. If the second attempt is valid, it's used in preference. > > Considering that the second attempt can only be on the same or smaller set of CPUs, > how could the second attempt ever succeed if the first attempt failed? I do not see > why it is worth continuing. Its harmless, its not on a performance sensitive path and it would take extra logic in the more common cases to detect this and return early. Thanks, James