From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97E09332912 for ; Tue, 25 Nov 2025 18:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764095672; cv=none; b=S+gHuxdOqzPITaqQv+c4MsOJxTKmcL8vyb524dhRKvpDyvcohF1Vaj+5n8wjhCqWh+6CzjiWEFp22Q4zI/gpDjooQdMB6OIz3O4tu9UPbVwJlV+elxBO9GIWyzmwIrVEs31jjOxhy5V6Vp4karTUmJn4SaVxQlIOcjIWuoU+/Cs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764095672; c=relaxed/simple; bh=POe9YP+q6j+5sVw91zdtbmzGyI2UGPyHQtoOhB45Kmo=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LPcn02brS6CoNdmIrNBdSGKAo1ZCp9U19AhkRPUP5MPpXUvNzVJlJuwZJBqJ420lur7UYqVNCUhrN42SfxdRtS8doZctJ55g/0xdbyozZ7Puk5aO77stJ/aiif4g2/zCdt3QrBgknPnk8QdBVya+vzwQWs1gYa4tLjU5jNbCxe8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aMXE2Oqa; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aMXE2Oqa" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-42b32ff5d10so62404f8f.1 for ; Tue, 25 Nov 2025 10:34:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764095668; x=1764700468; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=5WaOGz/nCEE+Z9PEaWUkBdg/V6cqSUJc0XJR0n5xaj8=; b=aMXE2Oqaw87r9KFCmFKhlekoYezTycEZauZMJ0633eyvdQtCZrzpUZcz7wBljtKpvf P1+J5CfG8PJLoE57xWa1Lp74iinWiTw+u1SsMokrRzL3+sSWGpV+qIkPEZd+u+goP3Vf q/PtX2GBoDfxXp7YkHodHA33cNLJ8XIb983rLvjqJ2AFGZ9Ir+JRetODwlMqZavW1Hj6 0Q1S6g6/nfvOHlw0gKFjHW1dvSHka8LsoEYUE8Q08MQvM1YajB7pcx5bNoAL3EdDrQ3Y +HrRGVcpv2kyPW901nnSg31gvhw2+LQ/M9zivys+VnHK+Nh6KYdujs7zwbYv8WOJM99u 4oDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764095668; x=1764700468; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=5WaOGz/nCEE+Z9PEaWUkBdg/V6cqSUJc0XJR0n5xaj8=; b=NREQNSvHySBbABFTrAZGnRsgLzcVYdQ+2mU9hzgxhvvFq9tdNYuaJ1MfvnhkaL0zcj NaMOyvpxsPzN/lMYHkmQTHPBZptlwjc+26lTisY0dKDFF6igT480xkBHS+JV0rF8742c xF0uvkfF13nV0Yful/7BGpyMX2APRlYHFnv9ewXtRLpk3rfNE+0mU4n9f5P3rSjVk+Z6 x681pj4SkauLaJBqS86bjyT4dUwJEwCJKnqyp0sZ7sgWCZLxVKIUED6XLqq0jfajnXy/ nd9w1XthQDgu33jqppIWlqUeaD959BJPd99rmG/5yViuWoJe65VxTShTIVQHY/ccNb5h uKTA== X-Gm-Message-State: AOJu0Yz7TE9zoNhm+Hf9GPB0R+U2klT45uz8X3VJ2yNfPanof0UCU/cu DvdoOAnfMBeggz//NfGUp9GxzZc63aslltbmr5/wEncTWUycUtgLT2yR X-Gm-Gg: ASbGncvdU+YmyTenIg5ZQHyjBg/OaclVr/dVI/DTBlhM1gr0tn8sJviwWjDllA5Verl GE7h133kBUOfOSd+8Lj7UAsJV8FOBgU/XeWUjtvqfFq1gq58XJkFvz80Vj4KcE6EMTJRJI3e31U avQ9IS3QmDDDb1tbGFx2dK7evEKu18s9edLgAHTzlLTgeC1nu1Cc+s4A0yKSQG02nxOsPujJL4w PTN/1Qs5vRNUEwJKXS0wqAs45ZDn1afT3GOWbqwNak9Qu77Ss/2BmFbqFbQ/H6LJiNkd/xZysH5 5lVCJf3Uipe6zi0iqDJrhuHZ0viN9y5Jwf4yiMeGpXDlc1ZwaCT5cE+hWAqvtYWh1WD1a50HaTM b0mcCuybKhnXSUS7Pb/Na0LgBjcpZAB21TuHwx4v4o8d2zF9jE4WkGsMO2ajLBpIZ39vR18Uz2x ICdua/AfAbA5zXbvlOpoiDLSvuJYbf/X0Pso6ZR8A0T4vpl3s1jIi2 X-Google-Smtp-Source: AGHT+IF2uYQKAwabXmMFqRDkeFgM59AlUdrnwEACSDqsKWkNM9rAcwrMj62vqS/96aT6IeYG8ERcQQ== X-Received: by 2002:a05:6000:268a:b0:429:d59e:d097 with SMTP id ffacd0b85a97d-42cc1302332mr18787162f8f.9.1764095667433; Tue, 25 Nov 2025 10:34:27 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7fa35c2sm34739816f8f.25.2025.11.25.10.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 10:34:27 -0800 (PST) Date: Tue, 25 Nov 2025 18:34:25 +0000 From: David Laight To: Alexandre Chartre Cc: 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 Message-ID: <20251125183425.28880170@pumpkin> In-Reply-To: <71d3a15e-6998-42d6-a56a-5664ce50a5cd@oracle.com> References: <20251124164855.1036513-1-alexandre.chartre@oracle.com> <20251125132902.0cace2c8@pumpkin> <71d3a15e-6998-42d6-a56a-5664ce50a5cd@oracle.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 25 Nov 2025 15:43:10 +0100 Alexandre Chartre wrote: > On 11/25/25 14:29, David Laight wrote: > > On Mon, 24 Nov 2025 17:48:55 +0100 > > Alexandre Chartre 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 > >> Signed-off-by: Peter Zijlstra (Intel) > >> Acked-by: Josh Poimboeuf > >> 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. David > > But this doesn't always work because the value we need can contain spaces > and then it will be split into several fields. > > For example, this works with: > > #define X86_FEATURE_RRSBA_CTRL (11*32+11) /* RET prediction control */ > > But not with: > > #define X86_FEATURE_APIC ( 0*32+ 9) /* "apic" Onboard APIC */ > > > alex. >