From: Xin Li <xin@zytor.com>
To: "H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, will@kernel.org,
peterz@infradead.org, akpm@linux-foundation.org, acme@kernel.org,
namhyung@kernel.org
Subject: Re: [RESEND v1 2/3] x86/cpufeatures: Generate a feature mask header based on build config
Date: Sat, 22 Jun 2024 10:34:49 -0700 [thread overview]
Message-ID: <78436d01-2e91-44ad-ac99-145ddbd5e857@zytor.com> (raw)
In-Reply-To: <8F9E89A4-B05B-493C-8BED-52AC6777D915@zytor.com>
On 6/17/2024 6:46 AM, H. Peter Anvin wrote:
> On June 16, 2024 12:26:48 AM PDT, Xin Li <xin@zytor.com> wrote:
>> On 5/9/2024 1:53 PM, Xin Li (Intel) wrote:
>>> From: "H. Peter Anvin (Intel)" <hpa@zytor.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
next prev parent reply other threads:[~2024-06-22 17:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-09 20:53 [RESEND v1 0/3] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li (Intel)
2024-05-09 20:53 ` [RESEND v1 1/3] x86/cpufeatures: Add {required,disabled} feature configs Xin Li (Intel)
2024-06-12 13:33 ` Borislav Petkov
2024-06-13 2:56 ` Xin Li
2024-05-09 20:53 ` [RESEND v1 2/3] x86/cpufeatures: Generate a feature mask header based on build config Xin Li (Intel)
2024-06-16 7:26 ` Xin Li
2024-06-17 13:46 ` H. Peter Anvin
2024-06-22 17:34 ` Xin Li [this message]
2024-05-09 20:53 ` [RESEND v1 3/3] x86/cpufeatures: Remove {disabled,required}-features.h Xin Li (Intel)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78436d01-2e91-44ad-ac99-145ddbd5e857@zytor.com \
--to=xin@zytor.com \
--cc=acme@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®