[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <78436d01-2e91-44ad-ac99-145ddbd5e857@zytor.com>
Date: Sat, 22 Jun 2024 10:34:49 -0700
From: Xin Li <xin@...or.com>
To: "H. Peter Anvin" <hpa@...or.com>, linux-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org
Cc: tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
dave.hansen@...ux.intel.com, x86@...nel.org, will@...nel.org,
peterz@...radead.org, akpm@...ux-foundation.org, acme@...nel.org,
namhyung@...nel.org
Subject: Re: [RESEND v1 2/3] x86/cpufeatures: Generate a feature mask header
based on build config
On 6/17/2024 6:46 AM, H. Peter Anvin wrote:
> On June 16, 2024 12:26:48 AM PDT, Xin Li <xin@...or.com> wrote:
>> On 5/9/2024 1:53 PM, Xin Li (Intel) wrote:
>>> From: "H. Peter Anvin (Intel)" <hpa@...or.com>
>>>
>>> Introduce an AWK script to auto-generate a header with required and
>>> disabled feature masks based on <asm/cpufeatures.h> and current build
>>> config. Thus for any CPU feature with a build config, e.g., X86_FRED,
>>> simply add
>>
>> ...
>>
>>> +
>>> + printf "\n#define %s_MASKS ", s;
>>> + pfx = "{";
>>> + for (i = 0; i < ncapints; i++) {
>>> + printf "%s \\\n\t%s_MASK_%d", pfx, s, i;
>>> + pfx = ",";
>>> + }
>>> + printf " \\\n}\n\n";
>>> +
>>> + printf "#define %s_FEATURE(x) \\\n", s;
>>> + printf "\t((( ";
>>> + for (i = 0; i < ncapints; i++) {
>>> + if (masks[i]) {
>>> + printf "\\\n\t\t((x) >> 5) == %2d ? %s_MASK%-3d : ", i, s, i;
>>> + }
>>> + }
>>> + printf "0 \\\n";
>>> + printf "\t) >> ((x) & 31)) & 1)\n\n";
>>
>> This code generates macros {REQUIRED,DISABLED}_FEATURE(x) to tell if a
>> CPU feature, e.g., X86_FEATURE_FRED, is a required or disabled feature
>> for this particular compile-time configuration.
>>
>> But they are NOT currently used, so I prefer to remove them for now.
>>
>> Thanks!
>> Xin
>
> The goal with these is that it can eliminate the handwritten code that tests a long list of masks. Again, automation.
>
This piece of code is added back in the last patch of v3:
https://lore.kernel.org/lkml/20240622171435.3725548-5-xin@zytor.com/
The generated macros {REQUIRED|DISABLED}_MASK_BIT_SET are way shorter
than that in the original form:
#define REQUIRED_FEATURE(x) \
(( \
((x) >> 5) == 0 ? REQUIRED_MASK0 : \
((x) >> 5) == 1 ? REQUIRED_MASK1 : \
((x) >> 5) == 3 ? REQUIRED_MASK3 : 0 \
) & (1 << ((x) & 31)))
#define REQUIRED_MASK_BIT_SET(x) \
(REQUIRED_FEATURE(x) || BUILD_BUG_ON_ZERO(NCAPINTS != 22))
Thanks!
Xin
Powered by blists - more mailing lists