From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D245419413B for ; Mon, 30 Sep 2024 16:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714562; cv=none; b=jr3N8eCU8HHokatQGCHuiWZ7FODBJ9MTtyo0e8S9e3wIQ94bfmtZhVTdDtTZH9zDcN3+X1xuEGoZZj/fJY3nQwdhVXPd7iKkLtU0jDa3hBOe3jetQDzcGiR/tZIIPXRginvlOQh+Af9gT0tQQuhgtfn9J7DNcksnk5vPAKHnXdo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714562; c=relaxed/simple; bh=LeyyP1O6TvZS1JU0KHaoMN6aRjl0wxM5oKrThBUtxuc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iS+dUCTN7gGIZ86fE7qXsfcOY2X8yaHrD9eHCUx1/HHPM0mwD8sb9yOFrgGM0OfK4EDcZxXA+TiN12MZj70Vt58Fb3v8JJFSLwhw6Xh2jIX3NMrusKi1Wyq6qrLBYZ5yloPPiEr5yxfYVKpNJ05Tg1/kbi0qf7rguQX+XuDG3qs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 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 8CACF367; Mon, 30 Sep 2024 09:43:08 -0700 (PDT) Received: from [10.1.196.28] (eglon.cambridge.arm.com [10.1.196.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5E5A53F58B; Mon, 30 Sep 2024 09:42:33 -0700 (PDT) Message-ID: <5492c93e-b6c6-4443-afd3-b30c6267c2ab@arm.com> Date: Mon, 30 Sep 2024 17:42:31 +0100 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 v4 17/39] x86/resctrl: Rewrite and move the for_each_*_rdt_resource() walkers Content-Language: en-GB To: "Shaopeng Tan (Fujitsu)" , "x86@kernel.org" , "linux-kernel@vger.kernel.org" Cc: Fenghua Yu , Reinette Chatre , 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" , "baolin.wang@linux.alibaba.com" , Jamie Iles , Xin Hao , "peternewman@google.com" , "dfustini@baylibre.com" , "amitsinght@marvell.com" , David Hildenbrand , Rex Nie , Dave Martin References: <20240802172853.22529-1-james.morse@arm.com> <20240802172853.22529-18-james.morse@arm.com> From: James Morse In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Shaopeng Tan, On 15/08/2024 07:43, Shaopeng Tan (Fujitsu) wrote: >> Subject: [PATCH v4 17/39] x86/resctrl: Rewrite and move the >> for_each_*_rdt_resource() walkers >> >> The for_each_*_rdt_resource() helpers walk the architecture's array of >> structures, using the resctrl visible part as an iterator. These became >> over-complex when the structures were split into a filesystem and >> architecture-specific struct. This approach avoided the need to touch every call >> site, and was done before there was a helper to retrieve a resource by rid. >> >> Once the filesystem parts of resctrl are moved to /fs/, both the architecture's >> resource array, and the definition of those structures is no longer accessible. To >> support resctrl, each architecture would have to provide equally complex >> macros. >> >> Rewrite the macro to make use of resctrl_arch_get_resource(), and move these >> to the core header so existing x86 arch code continues to use them. >> diff --git a/arch/x86/kernel/cpu/resctrl/internal.h >> b/arch/x86/kernel/cpu/resctrl/internal.h >> index 8e52e81a044b..84e0d019423d 100644 >> --- a/arch/x86/kernel/cpu/resctrl/internal.h >> +++ b/arch/x86/kernel/cpu/resctrl/internal.h >> @@ -472,14 +472,6 @@ extern struct rdt_hw_resource rdt_resources_all[]; >> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index >> c8cd6dde91ed..04a410a5e739 100644 >> --- a/include/linux/resctrl.h >> +++ b/include/linux/resctrl.h >> @@ -26,6 +26,24 @@ int proc_resctrl_show(struct seq_file *m, >> /* max value for struct rdt_domain's mbps_val */ >> #define MBA_MAX_MBPS U32_MAX >> >> +/* Walk all possible resources, with variants for only controls or monitors. */ >> +#define for_each_rdt_resource(_r) >> \ >> + for ((_r) = resctrl_arch_get_resource(0); \ >> + (_r)->rid < RDT_NUM_RESOURCES - 1; >> \ >> + (_r) = resctrl_arch_get_resource((_r)->rid + 1)) >> + >> +#define for_each_capable_rdt_resource(r) >> \ >> + for_each_rdt_resource((r)) >> \ >> + if ((r)->alloc_capable || (r)->mon_capable) >> + >> +#define for_each_alloc_capable_rdt_resource(r) >> \ >> + for_each_rdt_resource((r)) >> \ >> + if ((r)->alloc_capable) >> + >> +#define for_each_mon_capable_rdt_resource(r) >> \ >> + for_each_rdt_resource((r)) >> \ >> + if ((r)->mon_capable) >> + > ERROR: Macros with complex values should be enclosed in parentheses This is from checkpatch - I've ignored it because the 'r' values are in parenthesis... I _think_ what it wants is this: \|/ | #define for_each_mon_capable_rdt_resource(r) ( \ | for_each_rdt_resource((r)) \ | if ((r)->mon_capable)) \ but then this macro wouldn't work in the way it is intended to be used because it breaks the deliberately dangling if statement Checkpatch also complains about the existing code. I think this is just a pattern of code that is frowned on (including by me!). Previous versions of this series rolled these out as a loop and condition at each call site, but Reinette didn't think this was worth the churn as the existing helpers are well understood. Thanks, James