From nobody Sun Dec 14 11:53:50 2025 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 29B0631770E for ; Fri, 12 Dec 2025 15:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765553567; cv=none; b=U6OPqjyxesskNHmzAw2sToW/Ev3+8uXVtzNwSMJcAmBfPTSEVf9raxPoXc26I9p9cbVmRFgjDp2x02ZLnME+njB0ZkmNaov3J5/JdFZ9mi6ErIOzIWLAlhABDrupIp5LUk/eoor3HEdj/uw92r3H/7eY4l8IDWKe82xc724P5dQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765553567; c=relaxed/simple; bh=ZX17Rkes7dkEtPsDUoS6OmWNz00dlWz49jtuaAUKFWU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gDCzVYgwgGyZxvgZDCQzxxDKf3oEHedv4IolYdgfMy0o/pDioz7aRIva5TcEh19PzdLXJJlIeuS8tkw9nwwe9dmqFsDkYByvNWGQChPtz8S+NIvOZ6GvwXJ5aLFmhKIGSxx5CASTc/9iwTyr8bwD3Gjlj0+YvgzhSuLSfCxT+/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=L9n0WA6O; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="L9n0WA6O" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-6492e78ce07so1794468a12.3 for ; Fri, 12 Dec 2025 07:32:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765553563; x=1766158363; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=n5ZLabgmBWGVHBvnREIfc+SWl2RRHRg5YFpCcVKIHms=; b=L9n0WA6Od6v4oV/okveXVOioavfEXZ/VJPb8IXMkz4Q6AoNfuY667EfeQQVCvU66Il uxyqrg8Ukh47sPkGSfUZlLawgTexg/lolie8lVv6Ol+0XLUOQHbVDUU9uWmtuWoj7ejJ tbmZNIrPfuJ7bSsab8308pc/jAVo+yYf7KxAODVW7ap2IPCVlLFaUVKzr8ltGYsGpafP fBSXPyUJ80L8lQLqqjvbEq0fQNY9HDYp8T1qwiFw5gB9bHDRJKthGo/guf75tcG6elMq kCxP6K5x7oT7iX76IqCGaYPCirHUbrxk+NAy4khmy2tZSskfjV+I8BjXDO9HOVDKES01 iBcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765553563; x=1766158363; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=n5ZLabgmBWGVHBvnREIfc+SWl2RRHRg5YFpCcVKIHms=; b=Tx74+tifmFRR1NSfwvfmt4KFIyd0wq12EQUfpbUNYh7rIb6tc4FwR8cqR8fU1NHQbr U8wx5GKuqxuqkQbD0GyogEuiO/sG/ovwFC7UhT5j0drJ6CWiKUfCcRe/hDtKthtdNjsP fVpMOHFEJY8FpNgW/PQm+AkknNRuIeYOeF0F4T2pjpYCBMiJHmBFFZMzToRry6TwP7iX ogFy1stVTStYrXUBLXvVzJCqs7SZ8DFJCHQRZMVr4JMxtkPoi0HISJyBNsGMizSsRC6K dQ+inSM+ZbVdcs9ACyRx2NTVflU9dppw7yT8i/HanUxiC+/6OW33tk6PW0TAkg6lFPk1 mUOg== X-Forwarded-Encrypted: i=1; AJvYcCXp26J9TiPbtU452p5QszKe6O6yF9+FZ9HLt4M/nZJMy6PuWJNGWXmOFhlFc2Z3ElIpdqteeqaXofglsao=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1ygvCpGCkojHzvFr9dX9bca3hdsLdLQz7+bEtNLHck4HtW5Tu igQEtPikUJ4bDim672CW5Oc7ol4+izDqd4hGjmhzlBGvJ88uqF5jswic8CNx83YIos4= X-Gm-Gg: AY/fxX5yB8PMxcI9Aw1ifowBEyMQ5I2UJ8Fq6cujVV5cQYFPJcBn5MsJKAz7jvBKEs8 06/zashC7ug+Dx1Mg5yoDnX96LiiTeDktGpzCJBN7b7/2AwatH6Uv6PKZcF9vyHF813XcNgwM4A a7PiSMyNBYV8mKT09hM6F59WMyM0q9hvDoQ6acPULOa0GuBhwvZcw32Tv7fTTHeJTSQ7M0YC6mw QAv1fsm8c/iaGvda5vUEiixEwRh3pTGYR6uoWnZ5Rqig/UfLtYzdedUwZH6qJeeAwEfdZUQ0r5y vv/xnXLw/Y1Hv6P5jjsGCiUGo7KjBEDpXeD/l6VhV4SbB905arECkSA6lW07T9OIm7X64cYFvEy HnC/jaV7qaB21qV/RyUKayysFtMblEkoYzJdoJI+EsziQQAQmmUCVpkjLy2LNByMhoFECQWoHdE cIL5LO5Gl/8874DQ3eUqSLCmn1+IrZAlo= X-Google-Smtp-Source: AGHT+IEqNbfSYkOtyXU7vPkI7qHD3gJ9+5d7AnSBhvsFB2ufQkU7DAINBVA90jbUKOQb02dY9d6XxQ== X-Received: by 2002:a05:6402:2083:10b0:649:aa77:5ec3 with SMTP id 4fb4d7f45d1cf-649aa775f32mr808892a12.18.1765553563242; Fri, 12 Dec 2025 07:32:43 -0800 (PST) Received: from e133063.arm.com ([130.185.218.160]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6498210ed32sm5433234a12.29.2025.12.12.07.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Dec 2025 07:32:42 -0800 (PST) From: James Clark Date: Fri, 12 Dec 2025 17:32:18 +0200 Subject: [PATCH v3 01/12] perf parse-events: Refactor get_config_terms() to remove macros 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251212-james-perf-config-bits-v3-1-aa36a4846776@linaro.org> References: <20251212-james-perf-config-bits-v3-0-aa36a4846776@linaro.org> In-Reply-To: <20251212-james-perf-config-bits-v3-0-aa36a4846776@linaro.org> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, James Clark X-Mailer: b4 0.14.2 The ADD_CONFIG_TERM() macros build the __type argument out of a partial EVSEL__CONFIG_TERM_x enum name. This means that they can't be called from a function where __type is a variable and it's also impossible to grep the codebase to find usages of these enums as they're never typed in full. Fix this by removing the macros and replacing them with an add_config_term() function. It seems the main reason these existed in the first place was to avoid type punning and to write to a specific field in the union, but the same thing can be achieved with a single write to a u64 'val' field. Running the Perf tests with "-fsanitize=3Dundefined -fno-sanitize-recover" results in no new issues as a result of this change. Signed-off-by: James Clark --- tools/perf/util/evsel_config.h | 1 + tools/perf/util/parse-events.c | 146 ++++++++++++++++++++++++-------------= ---- 2 files changed, 86 insertions(+), 61 deletions(-) diff --git a/tools/perf/util/evsel_config.h b/tools/perf/util/evsel_config.h index bcd3a978f0c415a8829d3fa37e9dd6bf664b39f2..685fd8d5c4a88fb8ae601ded60c= 1fc36dde73403 100644 --- a/tools/perf/util/evsel_config.h +++ b/tools/perf/util/evsel_config.h @@ -50,6 +50,7 @@ struct evsel_config_term { u64 cfg_chg; char *str; int cpu; + u64 val; } val; bool weak; }; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 17c1c36a7bf9a3ec08812c4de700e3a3b3e547cc..46422286380f33a48087e7079a4= 5bb21beb2d573 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1116,105 +1116,107 @@ static int config_attr(struct perf_event_attr *at= tr, return 0; } =20 -static int get_config_terms(const struct parse_events_terms *head_config, - struct list_head *head_terms) +static struct evsel_config_term *add_config_term(enum evsel_term_type type, + struct list_head *head_terms, + bool weak) { -#define ADD_CONFIG_TERM(__type, __weak) \ - struct evsel_config_term *__t; \ - \ - __t =3D zalloc(sizeof(*__t)); \ - if (!__t) \ - return -ENOMEM; \ - \ - INIT_LIST_HEAD(&__t->list); \ - __t->type =3D EVSEL__CONFIG_TERM_ ## __type; \ - __t->weak =3D __weak; \ - list_add_tail(&__t->list, head_terms) - -#define ADD_CONFIG_TERM_VAL(__type, __name, __val, __weak) \ -do { \ - ADD_CONFIG_TERM(__type, __weak); \ - __t->val.__name =3D __val; \ -} while (0) + struct evsel_config_term *t; =20 -#define ADD_CONFIG_TERM_STR(__type, __val, __weak) \ -do { \ - ADD_CONFIG_TERM(__type, __weak); \ - __t->val.str =3D strdup(__val); \ - if (!__t->val.str) { \ - zfree(&__t); \ - return -ENOMEM; \ - } \ - __t->free_str =3D true; \ -} while (0) + t =3D zalloc(sizeof(*t)); + if (!t) + return NULL; + + INIT_LIST_HEAD(&t->list); + t->type =3D type; + t->weak =3D weak; + list_add_tail(&t->list, head_terms); =20 + return t; +} + +static int get_config_terms(const struct parse_events_terms *head_config, + struct list_head *head_terms) +{ struct parse_events_term *term; =20 list_for_each_entry(term, &head_config->terms, list) { + struct evsel_config_term *new_term; + enum evsel_term_type new_type; + bool str_type =3D false; + u64 val; + switch (term->type_term) { case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD: - ADD_CONFIG_TERM_VAL(PERIOD, period, term->val.num, term->weak); + new_type =3D EVSEL__CONFIG_TERM_PERIOD; + val =3D term->val.num; break; case PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ: - ADD_CONFIG_TERM_VAL(FREQ, freq, term->val.num, term->weak); + new_type =3D EVSEL__CONFIG_TERM_FREQ; + val =3D term->val.num; break; case PARSE_EVENTS__TERM_TYPE_TIME: - ADD_CONFIG_TERM_VAL(TIME, time, term->val.num, term->weak); + new_type =3D EVSEL__CONFIG_TERM_TIME; + val =3D term->val.num; break; case PARSE_EVENTS__TERM_TYPE_CALLGRAPH: - ADD_CONFIG_TERM_STR(CALLGRAPH, term->val.str, term->weak); + new_type =3D EVSEL__CONFIG_TERM_CALLGRAPH; + str_type =3D true; break; case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE: - ADD_CONFIG_TERM_STR(BRANCH, term->val.str, term->weak); + new_type =3D EVSEL__CONFIG_TERM_BRANCH; + str_type =3D true; break; case PARSE_EVENTS__TERM_TYPE_STACKSIZE: - ADD_CONFIG_TERM_VAL(STACK_USER, stack_user, - term->val.num, term->weak); + new_type =3D EVSEL__CONFIG_TERM_STACK_USER; + val =3D term->val.num; break; case PARSE_EVENTS__TERM_TYPE_INHERIT: - ADD_CONFIG_TERM_VAL(INHERIT, inherit, - term->val.num ? 1 : 0, term->weak); + new_type =3D EVSEL__CONFIG_TERM_INHERIT; + val =3D term->val.num ? 1 : 0; break; case PARSE_EVENTS__TERM_TYPE_NOINHERIT: - ADD_CONFIG_TERM_VAL(INHERIT, inherit, - term->val.num ? 0 : 1, term->weak); + new_type =3D EVSEL__CONFIG_TERM_INHERIT; + val =3D term->val.num ? 0 : 1; break; case PARSE_EVENTS__TERM_TYPE_MAX_STACK: - ADD_CONFIG_TERM_VAL(MAX_STACK, max_stack, - term->val.num, term->weak); + new_type =3D EVSEL__CONFIG_TERM_MAX_STACK; + val =3D term->val.num; break; case PARSE_EVENTS__TERM_TYPE_MAX_EVENTS: - ADD_CONFIG_TERM_VAL(MAX_EVENTS, max_events, - term->val.num, term->weak); + new_type =3D EVSEL__CONFIG_TERM_MAX_EVENTS; + val =3D term->val.num; break; case PARSE_EVENTS__TERM_TYPE_OVERWRITE: - ADD_CONFIG_TERM_VAL(OVERWRITE, overwrite, - term->val.num ? 1 : 0, term->weak); + new_type =3D EVSEL__CONFIG_TERM_OVERWRITE; + val =3D term->val.num ? 1 : 0; break; case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE: - ADD_CONFIG_TERM_VAL(OVERWRITE, overwrite, - term->val.num ? 0 : 1, term->weak); + new_type =3D EVSEL__CONFIG_TERM_OVERWRITE; + val =3D term->val.num ? 0 : 1; break; case PARSE_EVENTS__TERM_TYPE_DRV_CFG: - ADD_CONFIG_TERM_STR(DRV_CFG, term->val.str, term->weak); + new_type =3D EVSEL__CONFIG_TERM_DRV_CFG; + str_type =3D true; break; case PARSE_EVENTS__TERM_TYPE_PERCORE: - ADD_CONFIG_TERM_VAL(PERCORE, percore, - term->val.num ? true : false, term->weak); + new_type =3D EVSEL__CONFIG_TERM_PERCORE; + val =3D term->val.num ? true : false; break; case PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT: - ADD_CONFIG_TERM_VAL(AUX_OUTPUT, aux_output, - term->val.num ? 1 : 0, term->weak); + new_type =3D EVSEL__CONFIG_TERM_AUX_OUTPUT; + val =3D term->val.num ? 1 : 0; break; case PARSE_EVENTS__TERM_TYPE_AUX_ACTION: - ADD_CONFIG_TERM_STR(AUX_ACTION, term->val.str, term->weak); + new_type =3D EVSEL__CONFIG_TERM_AUX_ACTION; + str_type =3D true; break; case PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE: - ADD_CONFIG_TERM_VAL(AUX_SAMPLE_SIZE, aux_sample_size, - term->val.num, term->weak); + new_type =3D EVSEL__CONFIG_TERM_AUX_SAMPLE_SIZE; + val =3D term->val.num; break; case PARSE_EVENTS__TERM_TYPE_RATIO_TO_PREV: - ADD_CONFIG_TERM_STR(RATIO_TO_PREV, term->val.str, term->weak); + new_type =3D EVSEL__CONFIG_TERM_RATIO_TO_PREV; + str_type =3D true; break; case PARSE_EVENTS__TERM_TYPE_USER: case PARSE_EVENTS__TERM_TYPE_CONFIG: @@ -1229,7 +1231,23 @@ do { \ case PARSE_EVENTS__TERM_TYPE_RAW: case PARSE_EVENTS__TERM_TYPE_CPU: default: - break; + /* Don't add a new term for these ones */ + continue; + } + + new_term =3D add_config_term(new_type, head_terms, term->weak); + if (!new_term) + return -ENOMEM; + + if (str_type) { + new_term->val.str =3D strdup(term->val.str); + if (!new_term->val.str) { + zfree(&new_term); + return -ENOMEM; + } + new_term->free_str =3D true; + } else { + new_term->val.val =3D val; } } return 0; @@ -1290,10 +1308,16 @@ static int get_config_chgs(struct perf_pmu *pmu, st= ruct parse_events_terms *head } } =20 - if (bits) - ADD_CONFIG_TERM_VAL(CFG_CHG, cfg_chg, bits, false); + if (bits) { + struct evsel_config_term *new_term; + + new_term =3D add_config_term(EVSEL__CONFIG_TERM_CFG_CHG, + head_terms, false); + if (!new_term) + return -ENOMEM; + new_term->val.cfg_chg =3D bits; + } =20 -#undef ADD_CONFIG_TERM return 0; } =20 --=20 2.34.1