From nobody Mon Feb 9 19:06:50 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 AB2CF399037 for ; Wed, 14 Jan 2026 15:57:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768406261; cv=none; b=ZV41U4rxH0HTbImaell2KMm0f7bjRKnskbo2COKgfcq/UKLMcd6/xS7h13gRCQ25aNfaVv4fuxpNBMsPCgkp0Qua6WtAg9LZHqB/Ocp8NM/rfQrWv6+AblK0AWIwkxQRcGsjpR0jqB7JxxU9AIRofoog39Xa7lnmF/pmroZFGKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768406261; c=relaxed/simple; bh=PAkf0NbnSlWBogq8yeUp6HixGYaT60O+RjPgTXYfoto=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=h3gG5KCYwW7EW4e2QMdp0obNTj3uEIDCXsycAdI6wghFWJlHVi5dbLALROg9pbXC7tZSFJwR1SbOjNGv396s1zXjns0b8UldELk+o24J7C12joXVTxewIX0c9KjqqhRUT2asWqGGaZ81H/Z+WNRGzdYBSzEt7rIGhRiGd28mgcQ= 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=Ju/1RPEN; arc=none smtp.client-ip=209.85.128.53 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="Ju/1RPEN" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-47ee3da7447so5645e9.0 for ; Wed, 14 Jan 2026 07:57:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1768406258; x=1769011058; 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=dLNSFy2x/hIrhk0Ax93bLHz2woErNJIZ/GG5lWWV+fA=; b=Ju/1RPENCdRgOBDcSMdbwSObg44vCqGD9MmUs5H1rSSk3AZcePcYjyeAWCF2nl+ka9 B4fpEYlGMa1DgElKbEG3K75JmoiZ7c/Ezic3uhdaAR9ynRCoLIZZkKePrUNrHk9oH/ul B1FkLMxzTA+ynlGAfBEcMJebnqnK8DbkZ6+CPnnP0sqXmTlsv1WPqAF4NNuYrWkhFqVm V+Ad3mImSX25r39Lck7XfmZSkNyYT3PpW+UHxu+0GthJK8asTlm+SD6phCQvi81cr04M 2RVoVvo8fqQXc5wQWKwWFmixp1pOh/6pRFo0cldHxvvedzB7LDjXPXduulizqg2YAsOe O6Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768406258; x=1769011058; 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=dLNSFy2x/hIrhk0Ax93bLHz2woErNJIZ/GG5lWWV+fA=; b=UzPF281BneQW0b1zASTvAySYRLkwePGOfhF5uLWZgMBNGGIXfj8FI8557lVa7icKra 7IFa5aqO26pNRzO3TfyQT+PeR+tt0hzbxhfJCDKRdp/osJZFm80/5Va1hFsuDkim5pjo yCY2Ec7VW69R0KGUNaa1FUDO3VkAK0PZmYKiuZntWhDekTuXzYg6rUIGTO7biBKoBZsK k4kHoITmTUAmxvk+QaKpbWaxcBYwqVMlNP8km7VaX4F2Sfu9j2EALWuLhn+NphJqoSyL /QCdDYgAArrQK8VsQfUWVPfFuooPqBEVpjjCSZAirB6Lj1foP46Rk7MWD2rVWbYXWqIz 640w== X-Forwarded-Encrypted: i=1; AJvYcCVucoE/C1tTYB5IRiMh1OI5jxMMeeEOCl+b182b+dxwVUK+8Rp72dQvu742VqG23iUygegjx5NUIo2EYDU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw66Vbfq8oKE6zTckSQM+fV0N76Oxmsy7SKL3LO1kz88doT5o1h 0MTXNasn+MZZIk0a8ejnfGTKF+qZHno+eP1l7/l5A4gJKGPXEI6gTcbtdnDGeLP/LOY= X-Gm-Gg: AY/fxX7DzqRe8zF9BGJ13NftjcbLi9nA6SRpSpd3yWubVLZGd+1LgLCGX5XKx14ftTE T/zfN1dpEP6jWpnrMT0OabXzU0zQkXWFpH1luJ24eDWmSeWuGW7TjjottVsx56En07WmFURprs1 MufYNK7bTL090CE7CFuvBmsN4iZ4WQBuaMIkkwrBkuYXHsGuYiIf70M0b6jDFaGAgxMUtwUwNRt UGzrYUxJF5MMtyleok+QrpsU0K93+ImxI7Rtu5WYtmUKHb8EizwnAI6TJpQw4r23jVtw0E6HGyA J/uj+G6xybsZJGgW7KT17ZdPwDwAYcYeEaAa1GIU7+XeZoO+HOS2I/H9Z+FMD1MOSSeL2Dq/Nmd cTer94qoDR2gNgmEffP6H6DRycbCfTgazexnWPiNBteATTqqrOBJHGKrB42wxJysno28/sLPs+U oDiAl9cMcp9LfblMwFOlSdk+Yliy22Bfo= X-Received: by 2002:a05:600c:8b58:b0:47e:d943:ec08 with SMTP id 5b1f17b1804b1-47ee483adc2mr28644605e9.28.1768406257990; Wed, 14 Jan 2026 07:57:37 -0800 (PST) Received: from ho-tower-lan.lan ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47ee85e8807sm7426475e9.16.2026.01.14.07.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 07:57:37 -0800 (PST) From: James Clark Date: Wed, 14 Jan 2026 15:57:13 +0000 Subject: [PATCH v5 01/14] 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: <20260114-james-perf-config-bits-v5-1-0ef97aaf1ac0@linaro.org> References: <20260114-james-perf-config-bits-v5-0-0ef97aaf1ac0@linaro.org> In-Reply-To: <20260114-james-perf-config-bits-v5-0-0ef97aaf1ac0@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.0 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. Reviewed-by: Ian Rogers 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 bcd3a978f0c4..685fd8d5c4a8 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 17c1c36a7bf9..46422286380f 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