mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandre Chartre <alexandre.chartre@oracle.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: alexandre.chartre@oracle.com, linux-kernel@vger.kernel.org,
	mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org
Subject: Re: [PATCH v6 26/30 (mawk fix)] objtool: Add function to get the name of a CPU feature
Date: Tue, 25 Nov 2025 20:36:41 +0100	[thread overview]
Message-ID: <a750bde1-bc70-496e-9a84-00951e67a32b@oracle.com> (raw)
In-Reply-To: <20251125183425.28880170@pumpkin>


On 11/25/25 19:34, David Laight wrote:
> On Tue, 25 Nov 2025 15:43:10 +0100
> Alexandre Chartre <alexandre.chartre@oracle.com> wrote:
> 
>> On 11/25/25 14:29, David Laight wrote:
>>> On Mon, 24 Nov 2025 17:48:55 +0100
>>> Alexandre Chartre <alexandre.chartre@oracle.com> wrote:
>>>    
>>>> Add a function to get the name of a CPU feature. The function is
>>>> architecture dependent and currently only implemented for x86. The
>>>> feature names are automatically generated from the cpufeatures.h
>>>> include file.
>>>>
>>>> Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
>>>> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
>>>> Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
>>>> Link: https://patch.msgid.link/20251121095340.464045-27-alexandre.chartre@oracle.com
>>>> ---
>>>>    .../x86/tools/gen-cpu-feature-names-x86.awk   | 34 +++++++++++++++++++
>>>>    tools/objtool/.gitignore                      |  1 +
>>>>    tools/objtool/Makefile                        |  1 +
>>>>    tools/objtool/arch/loongarch/special.c        |  5 +++
>>>>    tools/objtool/arch/powerpc/special.c          |  5 +++
>>>>    tools/objtool/arch/x86/Build                  | 10 ++++++
>>>>    tools/objtool/arch/x86/special.c              | 10 ++++++
>>>>    tools/objtool/include/objtool/special.h       |  2 ++
>>>>    8 files changed, 68 insertions(+)
>>>>    create mode 100644 tools/arch/x86/tools/gen-cpu-feature-names-x86.awk
>>>>
>>>> diff --git a/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk b/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk
>>>> new file mode 100644
>>>> index 0000000000000..cc4c7a3e6c2e2
>>>> --- /dev/null
>>>> +++ b/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk
>>>> @@ -0,0 +1,34 @@
>>>> +#!/bin/awk -f
>>>> +# SPDX-License-Identifier: GPL-2.0
>>>> +#
>>>> +# Copyright (c) 2025, Oracle and/or its affiliates.
>>>> +#
>>>> +# Usage: awk -f gen-cpu-feature-names-x86.awk cpufeatures.h > cpu-feature-names.c
>>>> +#
>>>> +
>>>> +BEGIN {
>>>> +	print "/* cpu feature name array generated from cpufeatures.h */"
>>>> +	print "/* Do not change this code. */"
>>>> +	print
>>>> +	print "static const char *cpu_feature_names[(NCAPINTS+NBUGINTS)*32] = {"
>>>
>>> Since this code is #include'd into a .c file the line above (and the final })
>>> can be in that source file.
>>> You only need to generate the initialisers here.
>>
>> Sure, I can do that.
>>
>>>    
>>>> +
>>>> +	value_expr = "\\([0-9*+ ]+\\)"
>>>> +}
>>>> +
>>>> +/^#define X86_FEATURE_/ {
>>>> +	if (match($0, value_expr)) {
>>>> +		value = substr($0, RSTART + 1, RLENGTH - 2)
>>>> +		print "\t[" value "] = \"" $2 "\","
>>>> +	}
>>>
>>> Can't you just do:
>>> 	print "\t[" $2 "] = \"" $2 "\","
>>
>>
>> I presume you mean:  print "\t[" $3 "] = \"" $2 "\","
> 
> No $2 and $2, so it generates:
> 	[X86_FEATURE_RRSBA_CTRL] = "X86_FEATURE_RRSBA_CTRL",
> 
> All the #defines are defined - so you might as well use them.
> I suggested this sed command that has the same effect:
> 	sed -n -E '/^#define (X86_(FEATURE|BUG)_([^	 ]*)).*/s//	[\1] = "\1",/p'
> which can be put directly into the makefile.
> 
> It isn't as though the pattern match for lines has to be very selective.
> It just needs to be 'good enough' for the current file.
> 

Yes, right! I initially wanted to not have to include cpufeatures.h so I used
the X86_FEATURE_* values directly. Then I added X86_BUG_* which required NCAPINTS
and so cpufeatures.h.

So. of course, sed is good enough. I will simplify this.

Thanks,

alex.


      reply	other threads:[~2025-11-25 19:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-24 16:48 Alexandre Chartre
2025-11-24 19:35 ` Peter Zijlstra
2025-11-24 19:45   ` Peter Zijlstra
2025-11-25  7:55   ` Alexandre Chartre
2025-11-25 13:29 ` David Laight
2025-11-25 14:43   ` Alexandre Chartre
2025-11-25 18:34     ` David Laight
2025-11-25 19:36       ` Alexandre Chartre [this message]

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=a750bde1-bc70-496e-9a84-00951e67a32b@oracle.com \
    --to=alexandre.chartre@oracle.com \
    --cc=david.laight.linux@gmail.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.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®