From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 EB7D51A29A for ; Thu, 28 Nov 2024 13:36:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732800983; cv=none; b=OFBD9ugqdU1IXObr2s6LleFtSWcjEd1l3mWo1YhhFfi5Jv5t31GZCTPNdmobo80lMkibcKBw9tLlhdeza+MVFC7lWdrf9DXlG7SAgG22Gt0gtNIp7uPiCEZGiFDaQRxKWkitxMuj5Q5PUxIazPxsui6g8KuFZSCBETcgbgmUsho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732800983; c=relaxed/simple; bh=nDvvicLumv7EtNvS5GruBIHrJOOqtlAQ1xL9L19APP0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kx9JQhrK08KbRkWQRrxp/1hSpbQtmnp1MrFxx+Pv3DH3QR/pQiLQotAhXoIWieXaAhZeaXINhMlWtQjB5MHBBh/rpDDWpK122CnW8E/1/D2M0ruT3Gqmgm0OY+LGFJvmjWS//p1aHcslwJMY6OZRCC923At/bMuyQy1UbvBCJOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=EFV91fgj; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="EFV91fgj" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-21290973bcbso7708815ad.3 for ; Thu, 28 Nov 2024 05:36:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732800979; x=1733405779; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HcU2ut98rpKpyOZJT3GpoD2fKQDnhCpCbslumGtWhKQ=; b=EFV91fgjVaf6GoiZA4KPwfYm3PQcD1fakdpWnCshh0xL44I7gcxkNSfCo1Y7x8b0rB ua5qyMnUK6jwll5fNw5pka+J7M8jbVoGk1TvkNW07IGPoMyutTYUUZfZ/PSOysrk2IxM 5p5mggz/vAgGSCsQNgPCn1/jZItsGdDtdcYwJQQs98uMwm8s3ZbHtDERRfeqquisbzV/ SLPZBEf55DMeBb5U7RlMZJHeiPcNFVkA+gjfUaTFfcGtUbkeIWy5mQrBfQy40F0SM8d8 Cvay/2Jjdrwsx5i+/VdqdouHme0BPX5AQ5eF5yOE3yGjJglz/g6N55CuBSWG4eDMjyAP I8Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732800979; x=1733405779; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HcU2ut98rpKpyOZJT3GpoD2fKQDnhCpCbslumGtWhKQ=; b=ZNEis4v9QJFhKnOlgpVLn/AkJyKXC5KymT1Cm5Uqv3fJPYi1DKnxtjc/i5NhwTnsYu 7vyNzkpXuPEwKIhJVKZqzWK0LiAF+bcdv2d5T/HGOL1n8wSrz8JmWcpqsm2fxkVwTE6Q cb9qdk0esH2kZ9BZVyr34mAPHgJcRubq1+vEDo/vMKFlWC8LEGDvr0g74q/MD9io9vLd z0QVyo/Hb0s6rqMYcMiYeYcBEtXmBIBnKucPPkLo7D4+Kch3lvzsCKhEnMLTZgLNnhOM fcxS+HpJHJXEJlU/sLRTEJC129xl5FgvjwzlpvquahoSVOm8evnYfGvquul3lUbjk4sY kzkQ== X-Forwarded-Encrypted: i=1; AJvYcCUvOSvMwWgYRHDC07Y0eZwRcWapOONj5+O++Mzm9BTAuUFwVXzGCcSXd1/3iKc6mlcI/6XVUw0OZAMnYdQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1BQ9TL2mIAX+9diTw/U/ab1oxtoEIkZjPXlZFxCAxN7n2MOSB 3RmeA/tn/XD8JvKkZqQpJ2f6kRhiyUnVfx+Ow6AYxt0rZJYPr3xYTeRii9oXiQ0= X-Gm-Gg: ASbGncvm3WZCiX2k9IbhRmi8gQkDUwKKPoVt97E3yXFNTAbxDVqJuh5DmtTCyDpCWT+ 9jypZz36lnq41+tXnrc4hJueJlMLaUMyhIVcQxRDLqPGEExa0wr8ZC4bnWFhMHD59r3GDZMBw9K vJQ9ggGZlbeAaiQClJAqYEMGzxUQ+LjC4VpnteymJAuCWh36QZ3wLt3RVmYCu2Wo09zmds527O0 kfCR16/Zb0dAX/2UkX3vfWlFJtHxw8LjGYUZAQJkNxlnseVG/J7jWA30A== X-Google-Smtp-Source: AGHT+IGXKXpqj6vJl7YkVSjkabWL+8zZNuS1RTCfG2jC3Ds6bcGG/wUkZQPL9fTcY/v0XBWMriNiDQ== X-Received: by 2002:a17:902:e5c7:b0:212:5814:8916 with SMTP id d9443c01a7336-21501b5a330mr69771825ad.45.1732800979052; Thu, 28 Nov 2024 05:36:19 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:36:18 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 01/12] perf record: Add event action support Date: Thu, 28 Nov 2024 21:35:42 +0800 Message-Id: <20241128133553.823722-2-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In perf-record, when an event is triggered, default behavior is to save sample data to perf.data. Sometimes, we may just want to do some lightweight actions, such as printing a log. Based on this requirement, add the --action option to the event to specify the behavior when the event occurs. Signed-off-by: Yang Jihong --- tools/perf/Documentation/perf-record.txt | 8 + tools/perf/builtin-record.c | 31 +++ tools/perf/util/Build | 18 ++ tools/perf/util/parse-action.c | 230 +++++++++++++++++++++++ tools/perf/util/parse-action.h | 75 ++++++++ tools/perf/util/parse-action.l | 40 ++++ tools/perf/util/parse-action.y | 82 ++++++++ tools/perf/util/record_action.c | 15 ++ tools/perf/util/record_action.h | 24 +++ 9 files changed, 523 insertions(+) create mode 100644 tools/perf/util/parse-action.c create mode 100644 tools/perf/util/parse-action.h create mode 100644 tools/perf/util/parse-action.l create mode 100644 tools/perf/util/parse-action.y create mode 100644 tools/perf/util/record_action.c create mode 100644 tools/perf/util/record_action.h diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Document= ation/perf-record.txt index 242223240a08..d0d9e0f69f3d 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt @@ -833,6 +833,14 @@ filtered through the mask provided by -C option. Prepare BPF filter to be used by regular users. The action should be either "pin" or "unpin". The filter can be used after it's pinned. =20 +--action=3D:: + Actions are the programs that run when the sampling event is triggered. + The action is a list of expressions separated by semicolons (;). + The sample data is saved by bpf prog attached by the event. + The call currently supported is print(); some commonly used built-in spec= ial + variables are also supported + For example: + # perf record -e sched:sched_switch --action 'print("[%llu]comm=3D%s, c= pu=3D%d, pid=3D%d, tid=3D%d\n", time, comm, cpu, pid, tid)' true =20 include::intel-hybrid.txt[] =20 diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index f83252472921..108d98706873 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -51,6 +51,10 @@ #include "util/clockid.h" #include "util/off_cpu.h" #include "util/bpf-filter.h" +#ifdef HAVE_BPF_SKEL +#include "util/parse-action.h" +#include "util/record_action.h" +#endif #include "asm/bug.h" #include "perf.h" #include "cputopo.h" @@ -182,6 +186,7 @@ struct record { struct pollfd_index_map *index_map; size_t index_map_sz; size_t index_map_cnt; + bool custom_action; }; =20 static volatile int done; @@ -3316,6 +3321,23 @@ static int parse_record_synth_option(const struct op= tion *opt, return 0; } =20 +#ifdef HAVE_BPF_SKEL +static int parse_record_action_option(const struct option *opt, + const char *str, + int unset __maybe_unused) +{ + int ret; + struct record *rec =3D (struct record *)opt->value; + + ret =3D parse_record_action(rec->evlist, str); + if (ret) + return ret; + + rec->custom_action =3D true; + return 0; +} +#endif + /* * XXX Ideally would be local to cmd_record() and passed to a record__new * because we need to have access to it in record__exit, that is called @@ -3564,6 +3586,9 @@ static struct option __record_options[] =3D { OPT_BOOLEAN(0, "off-cpu", &record.off_cpu, "Enable off-cpu analysis"), OPT_STRING(0, "setup-filter", &record.filter_action, "pin|unpin", "BPF filter action"), +#ifdef HAVE_BPF_SKEL + OPT_CALLBACK(0, "action", &record, "action", "event action", parse_record= _action_option), +#endif OPT_END() }; =20 @@ -4001,6 +4026,12 @@ int cmd_record(int argc, const char **argv) if (quiet) perf_quiet_option(); =20 +#ifdef HAVE_BPF_SKEL + /* Currently, event actions only supported using bpf prog. */ + if (rec->custom_action) + return bpf_perf_record(rec->evlist, argc, argv); +#endif + err =3D symbol__validate_sym_arguments(); if (err) return err; diff --git a/tools/perf/util/Build b/tools/perf/util/Build index c06d2ee9024c..db4c4cabc5f8 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -249,6 +249,12 @@ perf-util-$(CONFIG_LIBBPF) +=3D bpf-utils.o =20 perf-util-$(CONFIG_LIBPFM4) +=3D pfm.o =20 +# perf record event action +perf-util-$(CONFIG_PERF_BPF_SKEL) +=3D parse-action.o +perf-util-$(CONFIG_PERF_BPF_SKEL) +=3D parse-action-flex.o +perf-util-$(CONFIG_PERF_BPF_SKEL) +=3D parse-action-bison.o +perf-util-$(CONFIG_PERF_BPF_SKEL) +=3D record_action.o + CFLAGS_config.o +=3D -DETC_PERFCONFIG=3D"BUILD_STR($(ETC_PERFCONFIG_SQ))" =20 # avoid compiler warnings in 32-bit mode @@ -294,6 +300,16 @@ $(OUTPUT)util/bpf-filter-bison.c $(OUTPUT)util/bpf-fil= ter-bison.h: util/bpf-filt $(Q)$(call echo-cmd,bison)$(BISON) -v $< -d $(PARSER_DEBUG_BISON) $(BISON= _FILE_PREFIX_MAP) \ -o $(OUTPUT)util/bpf-filter-bison.c -p perf_bpf_filter_ =20 +$(OUTPUT)util/parse-action-flex.c $(OUTPUT)util/parse-action-flex.h: util/= parse-action.l $(OUTPUT)util/parse-action-bison.c util/parse-action.h + $(call rule_mkdir) + $(Q)$(call echo-cmd,flex)$(FLEX) -o $(OUTPUT)util/parse-action-flex.c \ + --header-file=3D$(OUTPUT)util/parse-action-flex.h $(PARSER_DEBUG_FLEX) $< + +$(OUTPUT)util/parse-action.c $(OUTPUT)util/parse-action-bison.h: util/pars= e-action.y util/parse-action.h + $(call rule_mkdir) + $(Q)$(call echo-cmd,bison)$(BISON) -v $< -d $(PARSER_DEBUG_BISON) $(BISON= _FILE_PREFIX_MAP) \ + -o $(OUTPUT)util/parse-action-bison.c -p parse_action_ + FLEX_VERSION :=3D $(shell $(FLEX) --version | cut -d' ' -f2) =20 FLEX_GE_260 :=3D $(call version-ge3,$(FLEX_VERSION),2.6.0) @@ -345,11 +361,13 @@ CFLAGS_parse-events-flex.o +=3D $(flex_flags) -Wno-u= nused-label CFLAGS_pmu-flex.o +=3D $(flex_flags) CFLAGS_expr-flex.o +=3D $(flex_flags) CFLAGS_bpf-filter-flex.o +=3D $(flex_flags) +CFLAGS_parse-action-flex.o +=3D $(flex_flags) =20 CFLAGS_parse-events-bison.o +=3D $(bison_flags) CFLAGS_pmu-bison.o +=3D -DYYLTYPE_IS_TRIVIAL=3D0 $(bison_flags) CFLAGS_expr-bison.o +=3D -DYYLTYPE_IS_TRIVIAL=3D0 $(bison_flags) CFLAGS_bpf-filter-bison.o +=3D -DYYLTYPE_IS_TRIVIAL=3D0 $(bison_flags) +CFLAGS_parse-action-bison.o +=3D -DYYLTYPE_IS_TRIVIAL=3D0 $(bison_flags) =20 $(OUTPUT)util/parse-events.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)u= til/parse-events-bison.c $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c new file mode 100644 index 000000000000..01c8c7fdea59 --- /dev/null +++ b/tools/perf/util/parse-action.c @@ -0,0 +1,230 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * Generic actions for sampling events + * Actions are the programs that run when the sampling event is triggered. + * The action is a list of expressions separated by semicolons (;). + * Each action is an expression, added to actions_head node as list_head n= ode. + */ + +#include "util/debug.h" +#include "util/parse-action.h" +#include "util/parse-action-flex.h" +#include "util/parse-action-bison.h" + +static struct list_head actions_head =3D LIST_HEAD_INIT(actions_head); + +int event_actions__for_each_expr(int (*func)(struct evtact_expr *, void *a= rg), + void *arg, bool recursive) +{ + int ret; + struct evtact_expr *expr, *opnd; + + if (list_empty(&actions_head)) + return (*func)(NULL, arg); + + list_for_each_entry(expr, &actions_head, list) { + ret =3D (*func)(expr, arg); + if (ret) + return ret; + + if (recursive && !list_empty(&expr->opnds)) { + list_for_each_entry(opnd, &expr->opnds, list) { + ret =3D (*func)(opnd, arg); + if (ret) + return ret; + } + } + } + + return 0; +} + +int event_actions__for_each_expr_safe(int (*func)(struct evtact_expr *, vo= id *arg), + void *arg, bool recursive) +{ + int ret; + struct evtact_expr *expr, *tmp; + struct evtact_expr *opnd, *opnd_tmp; + + if (list_empty(&actions_head)) + return (*func)(NULL, arg); + + list_for_each_entry_safe(expr, tmp, &actions_head, list) { + ret =3D (*func)(expr, arg); + if (ret) + return ret; + + if (recursive && !list_empty(&expr->opnds)) { + list_for_each_entry_safe(opnd, opnd_tmp, &expr->opnds, list) { + ret =3D (*func)(opnd, arg); + if (ret) + return ret; + } + } + } + + return 0; +} + +static int parse_action_option(const char *str) +{ + int ret; + YY_BUFFER_STATE buffer; + + buffer =3D parse_action__scan_string(str); + ret =3D parse_action_parse(&actions_head); + + parse_action__flush_buffer(buffer); + parse_action__delete_buffer(buffer); + parse_action_lex_destroy(); + + return ret; +} + +int parse_record_action(struct evlist *evlist, const char *str) +{ + int ret; + + if (evlist =3D=3D NULL) { + pr_err("--action option should follow a tracer option\n"); + return -1; + } + + ret =3D parse_action_option(str); + if (ret) { + event_actions__free(); + pr_err("parse action option failed\n"); + return ret; + } + + return 0; +} + +static int do_action_free(struct evtact_expr *action, void *data __maybe_u= nused) +{ + if (action =3D=3D NULL) + return 0; + + list_del(&action->list); + parse_action_expr__free(action); + return 0; +} + +void event_actions__free(void) +{ + (void)event_actions__for_each_expr_safe(do_action_free, NULL, false); +} + +static struct evtact_expr_class *expr_class_list[EVTACT_EXPR_TYPE_MAX] =3D= { +}; + +int parse_action_expr__set_class(enum evtact_expr_type type, + struct evtact_expr_class *class) +{ + if (type >=3D EVTACT_EXPR_TYPE_MAX) { + pr_err("action expr set class ops type invalid\n"); + return -EINVAL; + } + + if (expr_class_list[type] !=3D NULL) { + pr_err("action expr set class ops type already exists\n"); + return -EEXIST; + } + + expr_class_list[type] =3D class; + return 0; +} + +static int expr_set_type(struct evtact_expr *expr) +{ + u64 id; + int ret; + u32 type, opcode; + struct evtact_expr_class *class; + + id =3D expr->id; + evtact_expr_id_decode(id, &type, &opcode); + + if (type >=3D EVTACT_EXPR_TYPE_MAX) { + pr_err("parse_action_expr type invalid: %u\n", type); + return -EINVAL; + } + + class =3D expr_class_list[type]; + if (class =3D=3D NULL) { + pr_err("parse_action_expr class not supported: %u\n", type); + return -ENOTSUP; + } + + if (class->set_ops !=3D NULL) { + ret =3D class->set_ops(expr, opcode); + if (ret) + return ret; + } + + return 0; +} + +struct evtact_expr *parse_action_expr__new(u64 id, struct list_head *opnds, + void *data, int size) +{ + int ret; + struct evtact_expr *expr; + + expr =3D malloc(sizeof(*expr)); + if (expr =3D=3D NULL) { + pr_err("parse_action_expr malloc failed\n"); + goto out_free_opnds; + } + expr->id =3D id; + + if (opnds !=3D NULL) + list_add_tail(&expr->opnds, opnds); + else + INIT_LIST_HEAD(&expr->opnds); + + ret =3D expr_set_type(expr); + if (ret) + goto out_list_del_opnds; + + if (expr->ops->new !=3D NULL) { + ret =3D expr->ops->new(expr, data, size); + if (ret) + goto out_free_expr; + } + + return expr; + +out_free_expr: + free(expr); +out_list_del_opnds: + list_del(&expr->opnds); +out_free_opnds: + parse_action_expr__free_opnds(opnds); + + return NULL; +} + +void parse_action_expr__free_opnds(struct list_head *opnds) +{ + struct evtact_expr *opnd, *tmp; + + if (opnds !=3D NULL && !list_empty(opnds)) { + list_for_each_entry_safe(opnd, tmp, opnds, list) { + list_del(&opnd->list); + parse_action_expr__free(opnd); + } + } +} + +void parse_action_expr__free(struct evtact_expr *expr) +{ + if (expr =3D=3D NULL) + return; + + if (expr->ops->free !=3D NULL) + expr->ops->free(expr); + + parse_action_expr__free_opnds(&expr->opnds); + free(expr); +} diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h new file mode 100644 index 000000000000..71a0a166959e --- /dev/null +++ b/tools/perf/util/parse-action.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_UTIL_PARSE_ACTION_H_ +#define __PERF_UTIL_PARSE_ACTION_H_ + +#include + +#include + +#include "evlist.h" + +enum evtact_expr_type { + EVTACT_EXPR_TYPE_MAX, +}; + +struct evtact_expr; +struct evtact_expr_ops { + int (*new)(struct evtact_expr *expr, void *data, int size); + int (*eval)(struct evtact_expr *expr, + void *in, int in_size, void **out, int *out_size); + void (*free)(struct evtact_expr *expr); +}; + +struct evtact_expr_class { + int (*set_ops)(struct evtact_expr *expr, u32 opcode); +}; + +struct evtact_expr { + struct list_head list; + u64 id; + struct evtact_expr_ops *ops; + struct list_head opnds; + void *priv; +}; + +/* + * The expr id contains two fileds: + * |--------------|----------------| + * | type | opcode | + * |--------------|----------------| + * 32-bit 32-bit + */ +#define EVTACT_EXPR_ID_TYPE_BITS_SHIFT 32 +static inline u64 evtact_expr_id_encode(u32 type, u32 opcode) +{ + return (u64)type << EVTACT_EXPR_ID_TYPE_BITS_SHIFT | opcode; +} + +static inline void evtact_expr_id_decode(u64 id, u32 *type, u32 *opcode) +{ + if (type !=3D NULL) + *type =3D id >> EVTACT_EXPR_ID_TYPE_BITS_SHIFT; + + if (opcode !=3D NULL) + *opcode =3D id & GENMASK(EVTACT_EXPR_ID_TYPE_BITS_SHIFT, 0); +} + +int parse_record_action(struct evlist *evlist, const char *str); +void event_actions__free(void); + +int event_actions__for_each_expr(int (*func)(struct evtact_expr *, void *a= rg), + void *arg, bool recursive); + +int event_actions__for_each_expr_safe(int (*func)(struct evtact_expr *, vo= id *arg), + void *arg, bool recursive); + +struct evtact_expr *parse_action_expr__new(u64 id, struct list_head *opnds, + void *data, int size); + +void parse_action_expr__free_opnds(struct list_head *opnds); +void parse_action_expr__free(struct evtact_expr *expr); + +int parse_action_expr__set_class(enum evtact_expr_type type, + struct evtact_expr_class *ops); + +#endif /* __PERF_UTIL_PARSE_ACTION_H_ */ diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l new file mode 100644 index 000000000000..3cb72de50372 --- /dev/null +++ b/tools/perf/util/parse-action.l @@ -0,0 +1,40 @@ +%option prefix=3D"parse_action_" +%option noyywrap +%option stack + +%{ + +#include +#include +#include + +#include "util/debug.h" + +#include "parse-action.h" +#include "parse-action-bison.h" + +%} + +space [ \t] +ident [_a-zA-Z][_a-zA-Z0-9]* + +%% + +{space} { } + +";" { return SEMI; } + +{ident} { + parse_action_lval.str =3D strdup(parse_action_text); + if (parse_action_lval.str =3D=3D NULL) { + pr_err("parse_action malloc ident string failed\n"); + return ERROR; + } + return IDENT; + } +. { + pr_err("invalid character: '%s'\n", parse_action_text); + return ERROR; + } + +%% diff --git a/tools/perf/util/parse-action.y b/tools/perf/util/parse-action.y new file mode 100644 index 000000000000..fade9d093d4a --- /dev/null +++ b/tools/perf/util/parse-action.y @@ -0,0 +1,82 @@ +%parse-param {struct list_head *actions_head} +%define parse.error verbose + +%{ + +#ifndef NDEBUG +#define YYDEBUG 1 +#endif + +#include +#include +#include + +#include +#include + +#include "util/debug.h" +#include "util/parse-action.h" + +int parse_action_lex(void); + +static void parse_action_error(struct list_head *expr __maybe_unused, + char const *msg) +{ + pr_err("parse_action: %s\n", msg); +} + +%} + +%union +{ + char *str; + struct evtact_expr *expr; + struct list_head *list; +} + +%token IDENT ERROR +%token SEMI +%type action_term expr_term +%destructor { parse_action_expr__free($$); } +%type IDENT + +%% + +actions: +action_term SEMI actions +{ + list_add(&$1->list, actions_head); +} +| +action_term SEMI +{ + list_add(&$1->list, actions_head); +} +| +action_term +{ + list_add(&$1->list, actions_head); +} + +action_term: +expr_term +{ + $$ =3D $1; +} + +expr_term: +IDENT +{ + $$ =3D NULL; + pr_err("unsupported ident: '%s'\n", $1); + free($1); + YYERROR; +} +| +ERROR +{ + $$ =3D NULL; + YYERROR; +} + +%% diff --git a/tools/perf/util/record_action.c b/tools/perf/util/record_actio= n.c new file mode 100644 index 000000000000..44789e0d4678 --- /dev/null +++ b/tools/perf/util/record_action.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * Read event sample data and execute the specified actions. + */ + +#include "util/debug.h" +#include "util/parse-action.h" +#include "util/record_action.h" + +int bpf_perf_record(struct evlist *evlist __maybe_unused, + int argc __maybe_unused, const char **argv __maybe_unused) +{ + event_actions__free(); + return 0; +} diff --git a/tools/perf/util/record_action.h b/tools/perf/util/record_actio= n.h new file mode 100644 index 000000000000..289be4befa97 --- /dev/null +++ b/tools/perf/util/record_action.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_UTIL_RECORD_ACTION_H_ +#define __PERF_UTIL_RECORD_ACTION_H_ + +#include +#include "evlist.h" + +#ifdef HAVE_BPF_SKEL + +int bpf_perf_record(struct evlist *evlist, int argc, const char **argv); + + +#else /* !HAVE_BPF_SKEL */ + +static inline int bpf_perf_record(struct evlist *evlist __maybe_unused, + int argc __maybe_unused, + const char **argv __maybe_unused) +{ + return -EOPNOTSUPP; +} + +#endif /* !HAVE_BPF_SKEL */ + +#endif /* __PERF_UTIL_RECORD_ACTION_H_ */ --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 611ED1AA1E3 for ; Thu, 28 Nov 2024 13:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732800986; cv=none; b=kuQBWgFbWGYbg75WJn5ElLKeVplQe5i8QPU9vub9r9SmLGOC3wlknx8cARpztxo3ZLA99zLf3l56ThMCH0D8StdsKxvfyxcsrFL/fEd1zKKxsHDk3gD697FT5lBUGqP0kt7I2ml1wqzid6EUUvUKU1Nn9SnqvHHTUq83A+pQGtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732800986; c=relaxed/simple; bh=6ThYDcVZyhY//Fe+U3aUG3hZA7Q+8SD/azeS/VR6mWo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CkUkf6zcmLmImBHFEaTJdDgqLOaaUbe4wwmYDI6ShJsccTL9b5CTqllfjFk9FYzF1wId7CosOG/4JocnJtCzROQ0nQJfi+pRkaFHNuOuyIXRNTrs7l+2kBcjVKghUNJRwkskjxByL+r7o8/iwHDIH0NTihdQQx9GJHj6FnFL314= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=GAF4kq84; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="GAF4kq84" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21262a191a5so7315435ad.0 for ; Thu, 28 Nov 2024 05:36:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732800984; x=1733405784; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lYHGwytb9blVTqG0sujztYOJv09yetn3wc+93NLrAqc=; b=GAF4kq84hXqUkeXOFGS4csKZCo6myvBXcbo9zStRgw6zuFcRhk2JXDIfBfnzaJj139 /S/E5as7csUoSzIzWJ0Tm5fx+7Gh7RLlubehKeUTALmqEfVNHnro8IyPh73umCYCxBnx Z6m+pqa0TD7tA7fOP76Vjx/GPg2pBbDThrOO+/0aPHUfnIdHkoPNr9JMIFyEizLZ2o51 cbpNsWeFevsXjOOFSqMk0C+6DccXATwx+b8Zg8MbPEqx/7/4DNRnVZ6Yuzox4s+HwS3d ypgR6P5i7H/ZXvaa8+nKgqMDtyXSMtrP+8CShAU7I6xIqTXc4UqlghtNoAPWKRZPx5Ci An9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732800984; x=1733405784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lYHGwytb9blVTqG0sujztYOJv09yetn3wc+93NLrAqc=; b=rz3M1r+BzpcseoVK7nWK/CX+mYOMW20mDBDxVWaxh7cc6exqvUmYtlpzOckf9mf2Rv DfKLQfJaS9CDbsbcwOJYWMlFJ7seDP3XOByZ4VlskW19q5xbEVVFzMBkDiTbnKb6xlVN yfCdg0uEySGxDFxJBxTgwLtOVdYBy4xVa4RWTRNi3ZjQXyl8MkacIxbkbrXr+0Ri5JNj QFZQDnFvfMGT6XWSMZJxnP43ExCny2UACO3ymtG7/T//Zxzvb8GiEmRx4Lu54oVWXPYd 8V0ZzcXMad1HA18rHqvfCtvvAcshIPAjGsvvxi+O9trQMva2+FMdrwCjKmmg+5HaTrfh W/Ew== X-Forwarded-Encrypted: i=1; AJvYcCULV+lVKnSjFk5dQOgawwuhgM1/deys9Bb3p6TLVRvjwtsLINknXdGEy4Y536rCkqIHFohdxTishomO0DQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7S6lNARF68rXQY9frdaA9+2P6kIUlDjmdk/+S8KTai9LuNPMK KqgdYqLd+aJ5B03MDdk1iWpsArqVCUeck+OfZtzvsWSw1oBpSayjJxfqN8SN64g= X-Gm-Gg: ASbGncuqDfc/deahVZfJCNgSdHWVTI6WXyaThD+rvsPxy5pqxGMMRbfdBs+yAOHiShM gaob3Hs59U3itXyMd98ubH0mPA2j6JJzWBVD+BkpTRygHbqLh5P+pGWGN8wLovAJT/PLcUeZnPj tefVbxgTj3e1/Jyk2Fqt6qqbeebeTqICOPpZU1I1GR8c9g47thEyewGVhwpkg5LYFxNd/k/HjuC 8+1sbGPIlN0+98JW149lceSMuEwRTKlh4lbMWBWo+ci7pwjFpysQgjJLg== X-Google-Smtp-Source: AGHT+IHwW1lu2icW5S94cwvi35KNqg+f7Y0zASnP7MGOuqwai4HXVUNxxnO6Ug/jGgQJijx2DPpjYw== X-Received: by 2002:a17:902:e747:b0:20c:ab33:f8b8 with SMTP id d9443c01a7336-21501381499mr100226835ad.15.1732800984649; Thu, 28 Nov 2024 05:36:24 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:36:24 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 02/12] perf event action: Add parsing const expr support Date: Thu, 28 Nov 2024 21:35:43 +0800 Message-Id: <20241128133553.823722-3-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Event action requires constant expression parsing support, which include constant integer and constant string. Signed-off-by: Yang Jihong --- tools/perf/util/parse-action.c | 27 +++++++++++++++++++++++++++ tools/perf/util/parse-action.h | 5 +++++ 2 files changed, 32 insertions(+) diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index 01c8c7fdea59..391546bf3d73 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -4,6 +4,9 @@ * Actions are the programs that run when the sampling event is triggered. * The action is a list of expressions separated by semicolons (;). * Each action is an expression, added to actions_head node as list_head n= ode. + * + * Supported expressions: + * - constant: */ =20 #include "util/debug.h" @@ -115,7 +118,31 @@ void event_actions__free(void) (void)event_actions__for_each_expr_safe(do_action_free, NULL, false); } =20 +static struct evtact_expr_ops *expr_const_ops_list[EVTACT_EXPR_CONST_TYPE_= MAX] =3D { +}; + +static int expr_const_set_ops(struct evtact_expr *expr, u32 opcode) +{ + if (opcode >=3D EVTACT_EXPR_CONST_TYPE_MAX) { + pr_err("expr_const opcode invalid: %u\n", opcode); + return -EINVAL; + } + + if (expr_const_ops_list[opcode] =3D=3D NULL) { + pr_err("expr_const opcode not supported: %u\n", opcode); + return -ENOTSUP; + } + + expr->ops =3D expr_const_ops_list[opcode]; + return 0; +} + +static struct evtact_expr_class expr_const =3D { + .set_ops =3D expr_const_set_ops, +}; + static struct evtact_expr_class *expr_class_list[EVTACT_EXPR_TYPE_MAX] =3D= { + [EVTACT_EXPR_TYPE_CONST] =3D &expr_const, }; =20 int parse_action_expr__set_class(enum evtact_expr_type type, diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index 71a0a166959e..47bd75264dee 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -9,9 +9,14 @@ #include "evlist.h" =20 enum evtact_expr_type { + EVTACT_EXPR_TYPE_CONST, EVTACT_EXPR_TYPE_MAX, }; =20 +enum evtact_expr_const_type { + EVTACT_EXPR_CONST_TYPE_MAX, +}; + struct evtact_expr; struct evtact_expr_ops { int (*new)(struct evtact_expr *expr, void *data, int size); --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 DB0E11AA1D7 for ; Thu, 28 Nov 2024 13:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732800992; cv=none; b=V6AbYUuIEogm5YyuroQpfV1zaGxR66Wr1++OEMyblRw72kl90nX292NCqH7qZhAhpvZxg+hWItCnAteJ/S53Qf4dgWu19eMMBKunSz6zqG4mgGVxXEDqwesaSEtkEqUUHeQcOBoV2TAScCpml/wFgad1sE28dfaV9M99nrct20A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732800992; c=relaxed/simple; bh=ZXjUJiriPjm3Gh10NHh8Xm8mZQJMBBn+GOzohDYSH70=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LuwSL5VKAfZKUo1XkRIHbHv1zVSFh+jEjMtaQs4d3wbVZeILQ2AraOhb0dS7/tFr1j9rXVBk+jEuQJXHias1skiXy24xmXXAXbM2Y+hIK6ePKSBYQYM8ERZyzGEd/gVhGqoLo6Rd9x9oIdCc7Hg1psnu6HhL69gf7mT7qErqW2E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=TXX+ir1x; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="TXX+ir1x" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-212348d391cso6317825ad.2 for ; Thu, 28 Nov 2024 05:36:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732800990; x=1733405790; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=58uF5FRygjmcuC+XqZTAPSHae1wNP7Gs/dWvt8/LZsA=; b=TXX+ir1xl2vNxBGZ3Vj1q/ZBjBBCgu9rpaC6SQP0OVLmyspwBE+L5pDf4ttvTi8WLI u5MmMBUrB9jj1MhIsI7KiNwS6vZ2eYU77CUH717SiBhc0rMqXL59SEaDvxvlgu5dcHFA 5LpRDN/wb8a8M0kgJjsz6R6eCuzUZjvJMCgq1fYlMlDlFhoOjfK7FT/tVm2JKxbWxxjs LJ+z9HHP+AokumiwqLZ0acyZWmRg61MM+vnhmtwiKCiwWDuHEYd7RHQVR98YswUXlSNC KEPU0gWgzBiiBubLZ4a9I7vwTkPX0Ydxn4MBDRn7p6fbRAsjHiDILKGi1N15YKxe4+Cg NFgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732800990; x=1733405790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=58uF5FRygjmcuC+XqZTAPSHae1wNP7Gs/dWvt8/LZsA=; b=wWCcJb6X5w0CLIUnYcZIigOuOHTueVqQkr8L5pvFtP216S27nmPEh8kFFiqeoV/Jk+ yLqDr9OV9cFqWVeo9M6o+7sHQVLUqRfbBdVCpctdpSRFpRdFjrEWdfg6VTkRX/XYnR5L xELOT1BNrPu0KRQbEqTrP5FGDFXFauIv1DEIOFe6qdkNFplQzq18KWtdEsqMG0N8Jig4 PZPvlRvCtW+tK0r1eH80jZVE1KzuwF7x7ahHBC6U6AxmaX3Jn6ViPf0/Wxjz3UTVuPkZ sL9ZqqtCfRoPnuuMOaIl94joxY7CjFVaAghxRYBORziMLkGGEuZtjTDujrmGo+f/OUe1 W5Fg== X-Forwarded-Encrypted: i=1; AJvYcCXN8gD02cS69OlZ833CUm6Byr06NV0CpLifGAjss8HHAiYrnRnxKvWPGRBwlSm7qeTGAvSAhXjT3l6suGo=@vger.kernel.org X-Gm-Message-State: AOJu0YxRAJGh26pQlJJ++92/WQ8lMMSsCZz/qO1HmNxvpcjQVfOUmPg8 g7AYEkhpKpv8km/iZXbxKH1NvJU9+np7P4vugIlXonjqXnI09dfu6V5ndKV3ldY= X-Gm-Gg: ASbGncsW9JoYTCjEQCayh/jFaLdbB/j3HTSB+HEFlhi5MZZiwR5NSMJUO6FoIyH5olO y9AbvwMof8EsnJraCS4bke5JBuK/ZTT3Lr7Oy2EN5YZBB8PXcimaFe9pUhBtQB8ThABp60Hb0dc oaOydMmEMRWsnibvaITGMIM/mXgClPVlCUZPahhtxTsQ+RAPCa03v04OeSFxxK1fyH7S+W0O5a/ EXGxLEZX9CRyta/PiOFLw5zOSXuC/476u61z8DKN0FINd61ZdS3arf4Zw== X-Google-Smtp-Source: AGHT+IGaa+4siSbSTtBvK2/ptco5CZWZSWnXqlWEx0fjKUf27R0HZxCGvl+sJ2wvI63J9r4eAkvZxQ== X-Received: by 2002:a17:903:2b0b:b0:211:f8c8:3730 with SMTP id d9443c01a7336-2150147a24bmr89630305ad.26.1732800990199; Thu, 28 Nov 2024 05:36:30 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:36:29 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 03/12] perf event action: Add parsing const integer expr support Date: Thu, 28 Nov 2024 21:35:44 +0800 Message-Id: <20241128133553.823722-4-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support parsing of constant integer expression. Signed-off-by: Yang Jihong --- tools/perf/util/parse-action.c | 52 ++++++++++++++++++++++++++++++++++ tools/perf/util/parse-action.h | 1 + tools/perf/util/parse-action.l | 19 +++++++++++++ tools/perf/util/parse-action.y | 13 ++++++++- 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index 391546bf3d73..3b10cf9f99b3 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -7,6 +7,7 @@ * * Supported expressions: * - constant: + * - integer */ =20 #include "util/debug.h" @@ -118,7 +119,58 @@ void event_actions__free(void) (void)event_actions__for_each_expr_safe(do_action_free, NULL, false); } =20 +static int expr_const_int_new(struct evtact_expr *expr, void *data, int si= ze) +{ + if (data =3D=3D NULL || + (size !=3D sizeof(int) + && size !=3D sizeof(long) && size !=3D sizeof(long long))) { + pr_err("expr_const_int size invalid: %d\n", size); + return -EINVAL; + } + + expr->priv =3D malloc(sizeof(long long)); + if (expr->priv =3D=3D NULL) { + pr_err("exp_ const_int malloc failed\n"); + return -ENOMEM; + } + + if (size =3D=3D sizeof(int)) + *(unsigned long long *)(expr->priv) =3D *(unsigned int *)data; + else if (size =3D=3D sizeof(long)) + *(unsigned long long *)(expr->priv) =3D *(unsigned long *)data; + else if (size =3D=3D sizeof(long long)) + *(unsigned long long *)(expr->priv) =3D *(unsigned long long *)data; + + INIT_LIST_HEAD(&expr->opnds); + return 0; +} + +static void expr_const_int_free(struct evtact_expr *expr) +{ + zfree(&expr->priv); +} + +static int expr_const_int_eval(struct evtact_expr *expr, + void *in __maybe_unused, int in_size __maybe_unused, + void **out, int *out_size) +{ + if (out !=3D NULL) + *out =3D expr->priv; + + if (out_size !=3D NULL) + *out_size =3D sizeof(long long); + + return 0; +} + +static struct evtact_expr_ops expr_const_int_ops =3D { + .new =3D expr_const_int_new, + .free =3D expr_const_int_free, + .eval =3D expr_const_int_eval, +}; + static struct evtact_expr_ops *expr_const_ops_list[EVTACT_EXPR_CONST_TYPE_= MAX] =3D { + [EVTACT_EXPR_CONST_TYPE_INT] =3D &expr_const_int_ops, }; =20 static int expr_const_set_ops(struct evtact_expr *expr, u32 opcode) diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index 47bd75264dee..ac81278c590e 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -14,6 +14,7 @@ enum evtact_expr_type { }; =20 enum evtact_expr_const_type { + EVTACT_EXPR_CONST_TYPE_INT, EVTACT_EXPR_CONST_TYPE_MAX, }; =20 diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l index 3cb72de50372..9237399a11ac 100644 --- a/tools/perf/util/parse-action.l +++ b/tools/perf/util/parse-action.l @@ -13,13 +13,32 @@ #include "parse-action.h" #include "parse-action-bison.h" =20 +static int value(int base) +{ + unsigned long long num; + + errno =3D 0; + num =3D strtoul(parse_action_text, NULL, base); + if (errno) { + pr_err("parse_action malloc number failed\n"); + return ERROR; + } + + parse_action_lval.num =3D num; + return NUMBER; +} + %} =20 +num_dec [0-9]+ +num_hex 0[xX][0-9a-fA-F]+ space [ \t] ident [_a-zA-Z][_a-zA-Z0-9]* =20 %% =20 +{num_dec} { return value(10); } +{num_hex} { return value(16); } {space} { } =20 ";" { return SEMI; } diff --git a/tools/perf/util/parse-action.y b/tools/perf/util/parse-action.y index fade9d093d4a..51e77e54f157 100644 --- a/tools/perf/util/parse-action.y +++ b/tools/perf/util/parse-action.y @@ -17,6 +17,8 @@ #include "util/debug.h" #include "util/parse-action.h" =20 +#define expr_id(t, o) evtact_expr_id_encode(EVTACT_EXPR_TYPE_##t, EVTACT_E= XPR_##t##_TYPE_##o) + int parse_action_lex(void); =20 static void parse_action_error(struct list_head *expr __maybe_unused, @@ -32,13 +34,15 @@ static void parse_action_error(struct list_head *expr _= _maybe_unused, char *str; struct evtact_expr *expr; struct list_head *list; + unsigned long long num; } =20 -%token IDENT ERROR +%token IDENT ERROR NUMBER %token SEMI %type action_term expr_term %destructor { parse_action_expr__free($$); } %type IDENT +%type NUMBER =20 %% =20 @@ -65,6 +69,13 @@ expr_term } =20 expr_term: +NUMBER +{ + $$ =3D parse_action_expr__new(expr_id(CONST, INT), NULL, (void *)&$1, siz= eof($1)); + if ($$ =3D=3D NULL) + YYERROR; +} +| IDENT { $$ =3D NULL; --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 BAB481B392C for ; Thu, 28 Nov 2024 13:36:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732800998; cv=none; b=FyINmdCEtRM3rV4iIeixv/L5EX33bsSk+rRgJgZu7aP7e4kXQkw0WkRujx0znyPVipvldT7g9RDwtuj+b9TTK1ViT5vUb9jhO0auU6RhIHFQjJBp21PcVkZX02t/z995VWKn7lXU/Ie5FrKDVixTzgrKIg7vG0K57Y0aF8WT+dM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732800998; c=relaxed/simple; bh=UF8YKzahIh+PwN3AwO6NZv3Y89s7Ox98ADCP/IHgSL4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FeHsaU9VVNn6FrraVhdTGcGZ/9SvfgXzy17ZOZf/D1GkDmPc34Ttt9jRET0rVHKuDzShRMONz1wTPbbV/Y2kC+grdBd5yyNZl5FNz7iukSWMtQTCq+yBlsFZIV2IvyLquzrWlyDU8RXN3xo+QL4B6pMQRjw12uocCPUF0VTIFEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=gKDL0JUj; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="gKDL0JUj" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2124a86f4cbso6682255ad.3 for ; Thu, 28 Nov 2024 05:36:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732800996; x=1733405796; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rQ0MaacFYTQJTLNs968qndbUwHA1XnYLHyx9b8Hlr5k=; b=gKDL0JUjy/aOnvu/4+hmQ1AjfQYQF448GRvFWaiLl+hQEY3i8363TBEbg9xyl46Kl3 GuzsdTtzwKQmhjgpxScG8FEoNTBMpfjmvx9jR8O5nA3vIWxP7GyNpy3f4TmwtFhjHf8r gDmNAtDpYY6s5/x7ZFLP0rhIbBNgptiETQ+qntWZtl/gFCTNTmscAzQ177qNU+lppDOD GXlA2j05Yu+6mLOr/4E/3DVUkjTBOpEjPSt5FULeRkxojpa3p+axI4b7J4rtrq3J88nI FIk/1h4UnUKtYyt2674VVSLFEbBh5JWNBR9AVWMbKveqcXxEHe1KB5xqjMeI44ruorJk Aj2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732800996; x=1733405796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rQ0MaacFYTQJTLNs968qndbUwHA1XnYLHyx9b8Hlr5k=; b=ZyOQ1yWYdS9a5oHFahixSXxYFYSxic3vaMX47lGDRPv7zhxRYIA5ySpJmYlb+WfCQ8 3Zg3VsL9yEOilYRUDwiMaaGwDsEJlXDjic+Rx30HuzQ68RdE17G6B3aQSaTBhQPjFdiq zOrs9OtrQpDBX7qCIjGQF/pGEjIoZQcmUMe9J9KmkRnUnas0pbhh1vFWbqAFgjtU/wM5 BenQ1LJFi4h1bxzZ0iifNSJXpfAqDRob9X1cx3H8suVO8ru1lfOfS5z59IgkMufPzEJy TWQi2sR5vmurALfoMOwdGzPVhQ7TCkhE5pLXkzV8+U8FqrFeiRvqiHXBc4UL/CV/IhWY KFgw== X-Forwarded-Encrypted: i=1; AJvYcCUEX/k+vet8TvzU+uxAFOZ0wbLWSl5pFcZsZYj2++dITcehrZcrneAyD6d4Ina70H4smPDdX08pJEJFZYc=@vger.kernel.org X-Gm-Message-State: AOJu0Yxu4kxEt7jTobaK1W5GWMSs6UQWlZtNvFuiGOJ2vTefvvSXLyOx kU8QwrRDCRusZlxW4xcKVHRUwNvxxNLxwiT/MIkC/SZEn9G+LOUQkEBTytzNXuE= X-Gm-Gg: ASbGncsABCfJB4y6qw/9e6mGSM7ZuYip37pm5bx1liWjQEO6y9HKx0Ewxl8VqMOI6ZS AIhghn7cprwCsxqipRzKae3+M7Uo9LV6RirEvT9/coZeMxQi5URAR0eBJTCYf+qatjnpWS2BASP BqIUOL9itRDlW6094JMlrOLot0+TUhQppyghMzz10Gjc2tL2+bxZjzJ0GjBkOlLtEWR/0+b9I7/ W2i/OyFALMuVQ36g/aqlYexLEjNE6rCfWkzaXb5uK0XM0lyNhfFiBQVTw== X-Google-Smtp-Source: AGHT+IEjDUsjrDGDGc5fQqIO+T+FruzKH27Usz7tqWm1DjvNhvcAFC7JN1TUKGdNBDbfARzHkP8zwQ== X-Received: by 2002:a17:902:c944:b0:20c:bffe:e1e5 with SMTP id d9443c01a7336-2150109a094mr79756385ad.19.1732800996021; Thu, 28 Nov 2024 05:36:36 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:36:35 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 04/12] perf event action: Add parsing const string expr support Date: Thu, 28 Nov 2024 21:35:45 +0800 Message-Id: <20241128133553.823722-5-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support parsing of constant string expression. Signed-off-by: Yang Jihong --- tools/perf/util/parse-action.c | 39 ++++++++++++ tools/perf/util/parse-action.h | 1 + tools/perf/util/parse-action.l | 108 +++++++++++++++++++++++++++++++++ tools/perf/util/parse-action.y | 10 ++- 4 files changed, 157 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index 3b10cf9f99b3..7e5ca889d5b9 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -8,6 +8,7 @@ * Supported expressions: * - constant: * - integer + * - string */ =20 #include "util/debug.h" @@ -169,8 +170,46 @@ static struct evtact_expr_ops expr_const_int_ops =3D { .eval =3D expr_const_int_eval, }; =20 +static int expr_const_str_new(struct evtact_expr *expr, + void *data, int size __maybe_unused) +{ + if (data =3D=3D NULL) { + pr_err("exper const string is NULL\n"); + return -EINVAL; + } + + expr->priv =3D data; + INIT_LIST_HEAD(&expr->opnds); + return 0; +} + +static void expr_const_str_free(struct evtact_expr *expr) +{ + zfree(&expr->priv); +} + +static int expr_const_str_eval(struct evtact_expr *expr, + void *in __maybe_unused, int in_size __maybe_unused, + void **out, int *out_size) +{ + if (out !=3D NULL) + *out =3D expr->priv; + + if (out_size !=3D NULL) + *out_size =3D strlen(expr->priv); + + return 0; +} + +static struct evtact_expr_ops expr_const_str_ops =3D { + .new =3D expr_const_str_new, + .free =3D expr_const_str_free, + .eval =3D expr_const_str_eval, +}; + static struct evtact_expr_ops *expr_const_ops_list[EVTACT_EXPR_CONST_TYPE_= MAX] =3D { [EVTACT_EXPR_CONST_TYPE_INT] =3D &expr_const_int_ops, + [EVTACT_EXPR_CONST_TYPE_STR] =3D &expr_const_str_ops, }; =20 static int expr_const_set_ops(struct evtact_expr *expr, u32 opcode) diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index ac81278c590e..ec422f8a05a7 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -15,6 +15,7 @@ enum evtact_expr_type { =20 enum evtact_expr_const_type { EVTACT_EXPR_CONST_TYPE_INT, + EVTACT_EXPR_CONST_TYPE_STR, EVTACT_EXPR_CONST_TYPE_MAX, }; =20 diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l index 9237399a11ac..f76240276b61 100644 --- a/tools/perf/util/parse-action.l +++ b/tools/perf/util/parse-action.l @@ -28,6 +28,54 @@ static int value(int base) return NUMBER; } =20 +static char *str_buf; +static unsigned int str_buf_size =3D 64; +static int str_begin(void) +{ + if (str_buf =3D=3D NULL) { + str_buf =3D malloc(str_buf_size); + if (str_buf =3D=3D NULL) { + pr_err("parse_action malloc string buffer failed\n"); + return ERROR; + } + } + + str_buf[0] =3D '\0'; + return 0; +} + +static int str_write(const char *s) +{ + char *new_buf; + + if (strlen(str_buf) + strlen(s) >=3D str_buf_size) { + str_buf_size =3D strlen(str_buf) + strlen(s) + 1; + new_buf =3D realloc(str_buf, str_buf_size); + if (new_buf =3D=3D NULL) { + free(str_buf); + str_buf =3D NULL; + pr_err("parse_action realloc string buffer failed\n"); + return ERROR; + } else { + str_buf =3D new_buf; + } + } + + strcat(str_buf, s); + return 0; +} + +static int str_end(void) +{ + parse_action_lval.str =3D strdup(str_buf); + if (parse_action_lval.str =3D=3D NULL) { + pr_err("parse_action strdup string buffer failed\n"); + return ERROR; + } + + return STRING; +} + %} =20 num_dec [0-9]+ @@ -35,6 +83,8 @@ num_hex 0[xX][0-9a-fA-F]+ space [ \t] ident [_a-zA-Z][_a-zA-Z0-9]* =20 +%x STR_BEGIN + %% =20 {num_dec} { return value(10); } @@ -43,6 +93,64 @@ ident [_a-zA-Z][_a-zA-Z0-9]* =20 ";" { return SEMI; } =20 +\" { + int ret; + yy_push_state(STR_BEGIN); + ret =3D str_begin(); + if (ret) { + yy_pop_state(); + return ret; + } + } +{ + \" { + yy_pop_state(); + return str_end(); + } + [^\\\n\"]+ { + int ret; + ret =3D str_write((const char *)yytext); + if (ret) { + yy_pop_state(); + return ret; + } + } + \\n { + int ret; + ret =3D str_write("\n"); + if (ret) { + yy_pop_state(); + return ret; + } + } + \\t { + int ret; + ret =3D str_write("\t"); + if (ret) { + yy_pop_state(); + return ret; + } + } + \\\\ { + int ret; + ret =3D str_write("\\"); + if (ret) { + yy_pop_state(); + return ret; + } + } + \\. { + yy_pop_state(); + pr_err("parse_action invalid escape character: '%s'\n", parse_action_te= xt); + return ERROR; + } + . { + yy_pop_state(); + pr_err("parse_action invalid character: '%s'\n", parse_action_text); + return ERROR; + } +} + {ident} { parse_action_lval.str =3D strdup(parse_action_text); if (parse_action_lval.str =3D=3D NULL) { diff --git a/tools/perf/util/parse-action.y b/tools/perf/util/parse-action.y index 51e77e54f157..4922b2d94aee 100644 --- a/tools/perf/util/parse-action.y +++ b/tools/perf/util/parse-action.y @@ -37,12 +37,13 @@ static void parse_action_error(struct list_head *expr _= _maybe_unused, unsigned long long num; } =20 -%token IDENT ERROR NUMBER +%token IDENT ERROR NUMBER STRING %token SEMI %type action_term expr_term %destructor { parse_action_expr__free($$); } %type IDENT %type NUMBER +%type STRING =20 %% =20 @@ -76,6 +77,13 @@ NUMBER YYERROR; } | +STRING +{ + $$ =3D parse_action_expr__new(expr_id(CONST, STR), NULL, (void *)$1, strl= en($1)); + if ($$ =3D=3D NULL) + YYERROR; +} +| IDENT { $$ =3D NULL; --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 234341AA1F3 for ; Thu, 28 Nov 2024 13:36:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801003; cv=none; b=jn0vGUO8I1jrPasng/FtNpNViYWtyTHQClxPW19OzC/Ux1n3+gtB8Vn/7D0jMhpoAEn0+WrzAwJb9ysInUHEm7MLoUHXBzrmia4ew4hCMlEprX1FFtUPD2G0wC3fZuhQ7GxQxF3Mdz6WtqeFKWNVOJAy1pCaJkRzHy1LxOKI/Tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801003; c=relaxed/simple; bh=iQPmTqPMgE6CGRqj3c3+Z0ssTDESghTFmM14erJ5bzk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L+lf2qoIH3EtRUFmr/XIKPRITQX6FaWG8OUBnnudmtzatg7GVKwe7jQBv8AoEe8W402ESQzKR4rkExYhbcAHxm0mvfFcuPinIo4JQt2Vkw/HoDhMFzRT3InqLvkEIN4fw1Wkgr2DDgBHBZ2Nai2vhVKcoS02NVHiUWiwWjNsA0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=EEyIEgsN; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="EEyIEgsN" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-724f41d520cso559794b3a.1 for ; Thu, 28 Nov 2024 05:36:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732801001; x=1733405801; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ug7s3apMrIYGbjn2T08D5A19MS2gdifOXUiskaMTdCU=; b=EEyIEgsNWoy1AvJemyzu998JPt9rGQ7cNwcsV3Dyl/NwXx9Do3zD+RVD/SQbAKwKr8 0Sq/lnGz9HooMDjhTSwxBJT8Gq0ne2WyLk9uamtKOwSG52DH4u01SxDjPrBOQlpXMVZV sduAshMINnui/FLQrDlRj4UIOuEkFAC/WMmO9anb3uyxmsWl09uud0XNveOu4O0ufT0j m/lZsOn0QpSyewZUQ7hI09QmpMIOL9oZja23KKRgVaqwvxMPgRjmAf+9dSpxfYYxrUKs LkRtY9hfeV8VFZin8cyXLXm3kUBP9K9HyzQgMFD3cYqTCUMkSeCRnDwZswJ/Mx5f5NoK AAKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732801001; x=1733405801; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ug7s3apMrIYGbjn2T08D5A19MS2gdifOXUiskaMTdCU=; b=o0S2g4unf+PvZZCcspQQGk2OuT+hKZscf1i7LyViRjsrDFd9GQYEEwElQpFOxs2pIr bWtPyZ7bY9HTGt7/gC3S5n8NsvA4P4792B2MbKz5gDdvZwKeLtwSMrAVCxeNNKMUw2UI SJipfS+wzH/KENFdpRywxQZWzu9rXBEv0rWtPSlyy41sGQMmx8DQVnqOk682Iwp+gEw6 9To6YHmXkbGP5yBZazX0YUEh460NqQ8UHm31JULon5shpkuKabWBTQsoeAfyxWH21ccA NjSqjfGVxEFxWXQhCkVJ1/UeGTm38LR51s50Dqnho4v33bsGqvsO7vneQo6eI3JBbm0P XYCw== X-Forwarded-Encrypted: i=1; AJvYcCXc4Gg3hpmnxV4RZizD9WqqQCXNnTNANAOo8a59QzqlErbDjeDwjbPi93CZvVLZZvtTB6IF8XvFxbFosek=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2I/Vr9HhgAFWY0uGAWJ2G+7QtRVSzsOZI2I2EgTNS4BvWJMDd AMZRl/QNLfOOQp7AM/HqEdWMGCtEKVk3TlfT0JFfYBwzn3tZOlHwykNJeqYk+V8= X-Gm-Gg: ASbGncutULajMZFKmfLuXnGEucsmRi0igESGTaheD6YuuKcbr06y78U0fEHHvbNZUNh KUCF43oCgC//JgXuD6syf7/uoFfOql1AcST/q7j3legSL40PblcUSrLdU+l1kdHcA6baHVYb7Fl BpWGoppHveif1E8r5s8QX3OhSqu29XZO8nk2hyru5xl4pJ5LRKOf0kS7sT5hkBGUS0yIAyDCZ3s urhXSAqfnwZtk0d9JuJFN9cc9yWS5x0AW5u1kiKnjaBsv80eFMRhPnANA== X-Google-Smtp-Source: AGHT+IEP3FPHTpJbDgEXCPECoTzgQwWMYfxD2So6kaGKpGJn6BnqrIL/OjhQuLz8v4pXQAubpuPN7Q== X-Received: by 2002:a17:902:d48a:b0:20c:9821:6998 with SMTP id d9443c01a7336-21501086e3bmr82419485ad.10.1732801001570; Thu, 28 Nov 2024 05:36:41 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:36:40 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 05/12] perf event action: Add parsing call expr support Date: Thu, 28 Nov 2024 21:35:46 +0800 Message-Id: <20241128133553.823722-6-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for parsing function call expression, the format is similar to C language function call, with parameters specified after function name, inside the parentheses and separated with a comma. Signed-off-by: Yang Jihong --- tools/perf/util/parse-action.c | 25 +++++++++++++++ tools/perf/util/parse-action.h | 5 +++ tools/perf/util/parse-action.l | 3 ++ tools/perf/util/parse-action.y | 56 +++++++++++++++++++++++++++++++--- 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index 7e5ca889d5b9..40e7c8aad7be 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -9,6 +9,7 @@ * - constant: * - integer * - string + * - call: */ =20 #include "util/debug.h" @@ -232,8 +233,32 @@ static struct evtact_expr_class expr_const =3D { .set_ops =3D expr_const_set_ops, }; =20 +static struct evtact_expr_ops *expr_call_ops_list[EVTACT_EXPR_CALL_TYPE_MA= X] =3D { +}; + +static int expr_call_set_ops(struct evtact_expr *expr, u32 opcode) +{ + if (opcode >=3D EVTACT_EXPR_CALL_TYPE_MAX) { + pr_err("expr_call opcode invalid: %u\n", opcode); + return -EINVAL; + } + + if (expr_call_ops_list[opcode] =3D=3D NULL) { + pr_err("expr_call opcode not supported: %u\n", opcode); + return -ENOTSUP; + } + + expr->ops =3D expr_call_ops_list[opcode]; + return 0; +} + +static struct evtact_expr_class expr_call =3D { + .set_ops =3D expr_call_set_ops, +}; + static struct evtact_expr_class *expr_class_list[EVTACT_EXPR_TYPE_MAX] =3D= { [EVTACT_EXPR_TYPE_CONST] =3D &expr_const, + [EVTACT_EXPR_TYPE_CALL] =3D &expr_call, }; =20 int parse_action_expr__set_class(enum evtact_expr_type type, diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index ec422f8a05a7..30c2fd6e81d0 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -10,6 +10,7 @@ =20 enum evtact_expr_type { EVTACT_EXPR_TYPE_CONST, + EVTACT_EXPR_TYPE_CALL, EVTACT_EXPR_TYPE_MAX, }; =20 @@ -19,6 +20,10 @@ enum evtact_expr_const_type { EVTACT_EXPR_CONST_TYPE_MAX, }; =20 +enum evtact_expr_call_type { + EVTACT_EXPR_CALL_TYPE_MAX, +}; + struct evtact_expr; struct evtact_expr_ops { int (*new)(struct evtact_expr *expr, void *data, int size); diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l index f76240276b61..189f73dfc3b1 100644 --- a/tools/perf/util/parse-action.l +++ b/tools/perf/util/parse-action.l @@ -92,6 +92,9 @@ ident [_a-zA-Z][_a-zA-Z0-9]* {space} { } =20 ";" { return SEMI; } +"(" { return LP; } +")" { return RP; } +"," { return COM; } =20 \" { int ret; diff --git a/tools/perf/util/parse-action.y b/tools/perf/util/parse-action.y index 4922b2d94aee..1b162c694218 100644 --- a/tools/perf/util/parse-action.y +++ b/tools/perf/util/parse-action.y @@ -35,15 +35,18 @@ static void parse_action_error(struct list_head *expr _= _maybe_unused, struct evtact_expr *expr; struct list_head *list; unsigned long long num; + u32 opcode; } =20 -%token IDENT ERROR NUMBER STRING -%token SEMI -%type action_term expr_term +%token IDENT ERROR NUMBER STRING CALL +%token SEMI LP RP COM +%type action_term expr_term expr_call_term %destructor { parse_action_expr__free($$); } %type IDENT %type NUMBER %type STRING +%type CALL +%type opnds =20 %% =20 @@ -64,11 +67,56 @@ action_term } =20 action_term: -expr_term +expr_call_term { $$ =3D $1; } =20 +expr_call_term: +CALL LP RP +{ + $$ =3D parse_action_expr__new(evtact_expr_id_encode(EVTACT_EXPR_TYPE_CALL= , $1), NULL, NULL, 0); + if ($$ =3D=3D NULL) + YYERROR; +} +| +CALL LP opnds RP +{ + $$ =3D parse_action_expr__new(evtact_expr_id_encode(EVTACT_EXPR_TYPE_CALL= , $1), $3, NULL, 0); + if ($$ =3D=3D NULL) + YYERROR; +} +| +IDENT LP RP +{ + $$ =3D NULL; + pr_err("unknown function '%s()'\n", $1); + free($1); + YYERROR; +} +| +IDENT LP opnds RP +{ + $$ =3D NULL; + pr_err("unknown function '%s()'\n", $1); + parse_action_expr__free_opnds($3); + free($1); + YYERROR; +} + +opnds: +opnds COM expr_term +{ + list_add_tail(&$3->list, $1); + $$ =3D $1; +} +| +expr_term +{ + INIT_LIST_HEAD(&$1->list); + $$ =3D &$1->list; +} + expr_term: NUMBER { --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 11A701B86E9 for ; Thu, 28 Nov 2024 13:36:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801009; cv=none; b=LwsIVjC5VG6ge3+YSEWc0KNTELKX+SXRp4d26ZythnODz2uHKKl17fKRKONOD41crDe294jtDGt9JCZMNbi1fPsRIdEUK+L1LSy+jXKcFlatx0NAMgk/obV1yoHP5c/LfB67Pgv0YqI27tS+XZKlnR491fV1xSzs4T2L5l8Vd00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801009; c=relaxed/simple; bh=+LNZpBhiaOxnH+Ezhfur1Zzi2CJqROuf+YAka+RZ568=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YthqeClzcveWFpMmsbdBj+2D/+I1Z8klkgBBidCIUSAsBIDKjbBdYBACfxTTGLOj1Bg5wtC1bBPMgkL/80fett6N7UL/tBMJMlYHlMjkGREWdx2WYBQgQ84T2BSqprCAkUGk/rPtQymg/4fZNJohsBRbLLBu0zIf0uSihW2dV3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=VPTI5Pyu; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="VPTI5Pyu" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21210eaa803so7289035ad.2 for ; Thu, 28 Nov 2024 05:36:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732801007; x=1733405807; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zqQaIVC+j9LhZ/TRorXPn9tvoBLETViH2KLqmtwG9as=; b=VPTI5PyuE73XIkTENBetZEkw5CAs938qyDVUgM49iravWX08cGBA6CUYpDm2M8C6L8 5YNLb9+h0RPdR4gy9HDN77bvZIw0mPcqRrBEhkf7CsIULMdvtak55RLj0bRXg57j45Yk N9uEHqR6xR/l8S/AQgsuO0AhYJwy4ZEsFw1sVnvr6OEBORVmbWWqcXzgD8HLAsgYqUO+ QiRrtevP8u7Bq9gW1y593BRwzVaLDVABGLky/WdYvVnZcDrPyGqeKgBSq8ZwZluWXDVx iYUj36vZaRGsVwO1ve8tFpP+xnu7vA4g+BIGjUy8mC4FZX/4MoYQJdhjD4847Xeii5Un cnlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732801007; x=1733405807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zqQaIVC+j9LhZ/TRorXPn9tvoBLETViH2KLqmtwG9as=; b=EG9WvZxAvcMPA2tGrTLYPudDNcyFXx4qaVXCH6oFnUG4TivlhA0IeZrJN5KUMeXm1y dIldUemIq3rHKu7Wu6SrYEn7MSGivOxI4icsAZXJ6aeos+uhR9c80O7ZSeplOD5Qtlj2 mRDQfr02zIX9GL8aLQQvxYZGdPkOdHbt6yuNCtabzpo79whK+4N0h6szTXv6L7czWZpq CRI3mG55rGFmvW7qJfuSJ3Qr7n+5uVxxiG5JVtdmhy2W6KHF1fytBw5mXh78O/r0rPQk grvOZxC4IDmRSbCevSDrwoFaWsRxog8ShDV+LXCBVFvKAHWoF35e7icR10kV+3rBJP4i 1ozw== X-Forwarded-Encrypted: i=1; AJvYcCVlIyIAjfPvsLT56NjAmhWDjU+fMZYFooIa6lULXSAx9HcJSoYncThwaQYZtlqaLiO6v74Qrxsjh1ddNj0=@vger.kernel.org X-Gm-Message-State: AOJu0YwHvE7RT+x0PyOmHb9yrDreR9KCk/kPl6W8trP+u7cGkvZbxXee GGw8QB1Le/+l2jlPm62AtFQVNjMdrwoHNlPQkZ6MWrWoHPxkbIB/HwS6Hn4k6bs= X-Gm-Gg: ASbGncu+T+7K66BI7ODRIeUSKgYcaicTE8xU8vD0h1TWk+VRmqEBxoTXa9SunfCYv+0 DXh60SDn3BV1py7Nn7EEnuUIYYZPf+OOVVev604yR9t+g33GfyrgW223/bnxx/JOWnOGu2TTubG yYmC9uy7zPyDQ8hiZ9qa1JqVx4nC2uUlh6Pf7SqEJgsrkMPVwPRFRLR9hChrcL0LdKvsBMBnyeF luu1l/tBKKvG+6Sgi5NWSyoKxn0I2TjHzZnEjB6V5VWqKEJMWGYcqCsew== X-Google-Smtp-Source: AGHT+IF3rwvUZnobMrf3bzrwFLm6Hr8ohxbpugrVFikYQUJ5h78RZPldvuutj+6JrOe0I8HRAp8V9Q== X-Received: by 2002:a17:903:1ce:b0:211:18bc:e74b with SMTP id d9443c01a7336-21501083ab6mr108542035ad.1.1732801007302; Thu, 28 Nov 2024 05:36:47 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:36:46 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 06/12] perf event action: Add parsing print() call expr support Date: Thu, 28 Nov 2024 21:35:47 +0800 Message-Id: <20241128133553.823722-7-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for parsing print() function calls, the parameter format is similar to C's printf(), the first parameter is a string format, and format specifiers support %c, %d, %d, %o, %u, %x, %X, %s. Currently, it simply checks whether the number of arguments matches the number of format specifiers. Signed-off-by: Yang Jihong --- tools/perf/util/parse-action.c | 329 +++++++++++++++++++++++++++++++++ tools/perf/util/parse-action.h | 1 + tools/perf/util/parse-action.l | 9 + 3 files changed, 339 insertions(+) diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index 40e7c8aad7be..95c06cc071ad 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -10,8 +10,11 @@ * - integer * - string * - call: + * - print */ =20 +#include + #include "util/debug.h" #include "util/parse-action.h" #include "util/parse-action-flex.h" @@ -171,6 +174,12 @@ static struct evtact_expr_ops expr_const_int_ops =3D { .eval =3D expr_const_int_eval, }; =20 +static bool is_const_str_expr(struct evtact_expr *expr) +{ + return expr->id =3D=3D evtact_expr_id_encode(EVTACT_EXPR_TYPE_CONST, + EVTACT_EXPR_CONST_TYPE_STR); +} + static int expr_const_str_new(struct evtact_expr *expr, void *data, int size __maybe_unused) { @@ -233,7 +242,327 @@ static struct evtact_expr_class expr_const =3D { .set_ops =3D expr_const_set_ops, }; =20 +enum print_fmt_spec_len { + PRINT_FMT_SPEC_LEN_INT, + PRINT_FMT_SPEC_LEN_LONG, + PRINT_FMT_SPEC_LEN_LONG_LONG, +}; + +enum print_fmt_spec_type { + PRINT_FMT_SPEC_TYPE_VOID, + PRINT_FMT_SPEC_TYPE_INT, + PRINT_FMT_SPEC_TYPE_STRING, +}; + +struct print_fmt_spec { + struct list_head list; + enum print_fmt_spec_type type; + enum print_fmt_spec_len len; + char *str; +}; + +#define PRINT_OUT_BUF_DEFAULT_LEN 64 +struct print_expr_priv { + struct list_head fmt_specs; + int fmt_spec_num; + int args_num; + char *out; + int out_len; +}; + +static int print_fmt_add_spec(struct print_expr_priv *priv, char *s, + regoff_t len, enum print_fmt_spec_len spec_len, + enum print_fmt_spec_type spec_type) +{ + struct print_fmt_spec *spec; + + spec =3D malloc(sizeof(*spec)); + if (spec =3D=3D NULL) { + pr_err("call print fmt spec malloc failed\n"); + return -ENOMEM; + } + + spec->str =3D strndup(s, len); + if (spec->str =3D=3D NULL) { + pr_err("call print fmt spec strndup failed\n"); + free(spec); + return -ENOMEM; + } + + spec->len =3D spec_len; + spec->type =3D spec_type; + list_add_tail(&spec->list, &priv->fmt_specs); + return 0; +} + +static int print_fmt_spec_get_len(char *s, regoff_t len) +{ + if (len =3D=3D 1 && !strncmp(s, "l", len)) + return PRINT_FMT_SPEC_LEN_LONG; + else if (len =3D=3D 2 && !strncmp(s, "ll", len)) + return PRINT_FMT_SPEC_LEN_LONG_LONG; + + return PRINT_FMT_SPEC_LEN_INT; +} + +static int print_fmt_spec_get_type(char *s) +{ + switch (s[0]) { + case 'c': + case 'd': + case 'o': + case 'u': + case 'x': + case 'X': + return PRINT_FMT_SPEC_TYPE_INT; + case 's': + return PRINT_FMT_SPEC_TYPE_STRING; + default: + break; + } + + return PRINT_FMT_SPEC_TYPE_VOID; +} + +static int print_fmt_get_string(struct evtact_expr *expr, char **fmt) +{ + int ret, fmt_len; + struct evtact_expr *fmt_expr; + + fmt_expr =3D list_first_entry_or_null(&expr->opnds, struct evtact_expr, l= ist); + if (fmt_expr =3D=3D NULL) { + pr_err("print() requires at least one argument\n"); + return -EINVAL; + } else if (!is_const_str_expr(fmt_expr)) { + pr_err("print() first argument expected to be string\n"); + return -EINVAL; + } + + if (fmt_expr->ops->eval !=3D NULL) { + ret =3D fmt_expr->ops->eval(fmt_expr, NULL, 0, (void **)fmt, &fmt_len); + if (ret) + return ret; + } + + return 0; +} + +static void print_fmt_free_specs(struct print_expr_priv *priv) +{ + struct print_fmt_spec *spec, *tmp; + + if (priv =3D=3D NULL) + return; + + list_for_each_entry_safe(spec, tmp, &priv->fmt_specs, list) { + list_del(&spec->list); + free(spec->str); + free(spec); + } +} + +static int print_fmt_split(struct evtact_expr *expr, struct print_expr_pri= v *priv) +{ + int i, ret; + char *s, *fmt; + regex_t regex; + regmatch_t pmatch[6]; + int spec_len, spec_type; + const char *const re =3D "%(-?)([0-9]*)(\\.[0-9]+)?(ll|l)?([cdosuxX])"; + + ret =3D print_fmt_get_string(expr, &fmt); + if (ret) + return ret; + + if (regcomp(®ex, re, REG_EXTENDED)) { + pr_err("expr call print fmt regcomp failed\n"); + return -1; + } + + s =3D fmt; + for (i =3D 0;; i++) { + if (regexec(®ex, s, ARRAY_SIZE(pmatch), pmatch, 0)) + break; + + spec_len =3D print_fmt_spec_get_len(s + pmatch[4].rm_so, + pmatch[4].rm_eo - pmatch[4].rm_so); + spec_type =3D print_fmt_spec_get_type(s + pmatch[5].rm_so); + + ret =3D print_fmt_add_spec(priv, s, pmatch[0].rm_eo, spec_len, spec_type= ); + if (ret) + goto out_free_specs; + + s +=3D pmatch[0].rm_eo; + } + + if ((size_t)(s - fmt) < strlen(fmt)) { + ret =3D print_fmt_add_spec(priv, s, strlen(fmt) - (s - fmt), + PRINT_FMT_SPEC_LEN_INT, PRINT_FMT_SPEC_TYPE_VOID); + if (ret) + goto out_free_specs; + } + + priv->fmt_spec_num =3D i; + return 0; + +out_free_specs: + print_fmt_free_specs(priv); + return ret; +} + +static int print_check_args(struct evtact_expr *expr, struct print_expr_pr= iv *priv) +{ + struct evtact_expr *arg; + + priv->args_num =3D 0; + list_for_each_entry(arg, &expr->opnds, list) + priv->args_num++; + + /* do not count format string argument */ + priv->args_num--; + + if (priv->args_num !=3D priv->fmt_spec_num) { + pr_err("print() arguments number for format string mismatch: %d expected= , %d provided\n", + priv->fmt_spec_num, priv->args_num); + return -EINVAL; + } + + return 0; +} + +static int expr_call_print_new(struct evtact_expr *expr, + void *data __maybe_unused, int size __maybe_unused) +{ + int ret; + struct print_expr_priv *priv; + + priv =3D malloc(sizeof(struct print_expr_priv)); + if (priv =3D=3D NULL) + return -ENOMEM; + + priv->out =3D malloc(PRINT_OUT_BUF_DEFAULT_LEN); + if (priv->out =3D=3D NULL) { + ret =3D -ENOMEM; + goto out_free_priv; + } + priv->out_len =3D PRINT_OUT_BUF_DEFAULT_LEN; + + INIT_LIST_HEAD(&priv->fmt_specs); + ret =3D print_fmt_split(expr, priv); + if (ret) + goto out_free_out_buf; + + ret =3D print_check_args(expr, priv); + if (ret) + goto out_free_specs; + + expr->priv =3D priv; + return 0; + +out_free_specs: + print_fmt_free_specs(priv); +out_free_out_buf: + free(priv->out); + priv->out_len =3D 0; +out_free_priv: + free(priv); + return ret; +} + +static void expr_call_print_free(struct evtact_expr *expr) +{ + struct print_expr_priv *priv; + + priv =3D expr->priv; + if (priv =3D=3D NULL) + return; + + print_fmt_free_specs(expr->priv); + zfree(&priv->out); + priv->out_len =3D 0; + zfree(&expr->priv); +} + +static int expr_call_print_eval(struct evtact_expr *expr, + void *in, int in_size, + void **out __maybe_unused, int *out_size __maybe_unused) +{ + int ret, len; + char *buf_out; + int arg_val_size; + unsigned long long *arg_val; + struct evtact_expr *arg; + struct print_fmt_spec *spec; + struct print_expr_priv *priv =3D expr->priv; + +retry: + len =3D 0; + priv->out[0] =3D '\0'; + arg =3D list_first_entry(&expr->opnds, struct evtact_expr, list); + list_for_each_entry(spec, &priv->fmt_specs, list) { + if (spec->type =3D=3D PRINT_FMT_SPEC_TYPE_VOID) { + len +=3D snprintf(priv->out + len, priv->out_len - len, "%s", spec->str= ); + } else { + arg =3D list_next_entry(arg, list); + if (arg =3D=3D NULL) { + pr_err("expr call print arguments are empty\n"); + return -EINVAL; + } + + ret =3D arg->ops->eval(arg, in, in_size, (void **)&arg_val, &arg_val_si= ze); + if (ret) { + pr_err("expr call print eval argument failed %d\n", ret); + return ret; + } + + if (spec->type =3D=3D PRINT_FMT_SPEC_TYPE_STRING) { + len +=3D snprintf(priv->out + len, priv->out_len - len, + spec->str, arg_val); + } else if (spec->type =3D=3D PRINT_FMT_SPEC_TYPE_INT) { + switch (spec->len) { + case PRINT_FMT_SPEC_LEN_INT: + len +=3D snprintf(priv->out + len, priv->out_len - len, + spec->str, *(unsigned int *)arg_val); + break; + case PRINT_FMT_SPEC_LEN_LONG: + len +=3D snprintf(priv->out + len, priv->out_len - len, + spec->str, *(unsigned long *)arg_val); + break; + case PRINT_FMT_SPEC_LEN_LONG_LONG: + len +=3D snprintf(priv->out + len, priv->out_len - len, + spec->str, *(unsigned long long *)arg_val); + break; + default: + break; + } + } + } + + if (len >=3D priv->out_len) { + buf_out =3D realloc(priv->out, priv->out_len << 1); + if (buf_out !=3D NULL) { + priv->out =3D buf_out; + priv->out_len <<=3D 1; + goto retry; + } + } + + if (len >=3D priv->out_len) + break; + } + + printf("%s", priv->out); + return 0; +} + +static struct evtact_expr_ops expr_call_print_ops =3D { + .new =3D expr_call_print_new, + .free =3D expr_call_print_free, + .eval =3D expr_call_print_eval, +}; + static struct evtact_expr_ops *expr_call_ops_list[EVTACT_EXPR_CALL_TYPE_MA= X] =3D { + [EVTACT_EXPR_CALL_TYPE_PRINT] =3D &expr_call_print_ops, }; =20 static int expr_call_set_ops(struct evtact_expr *expr, u32 opcode) diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index 30c2fd6e81d0..f8aece601a84 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -21,6 +21,7 @@ enum evtact_expr_const_type { }; =20 enum evtact_expr_call_type { + EVTACT_EXPR_CALL_TYPE_PRINT, EVTACT_EXPR_CALL_TYPE_MAX, }; =20 diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l index 189f73dfc3b1..5e75383ba3e7 100644 --- a/tools/perf/util/parse-action.l +++ b/tools/perf/util/parse-action.l @@ -76,6 +76,12 @@ static int str_end(void) return STRING; } =20 +static int call(u32 opcode) +{ + parse_action_lval.opcode =3D opcode; + return CALL; +} + %} =20 num_dec [0-9]+ @@ -91,6 +97,9 @@ ident [_a-zA-Z][_a-zA-Z0-9]* {num_hex} { return value(16); } {space} { } =20 + +print { return call(EVTACT_EXPR_CALL_TYPE_PRINT); } + ";" { return SEMI; } "(" { return LP; } ")" { return RP; } --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 8F20B1BAEDC for ; Thu, 28 Nov 2024 13:36:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801015; cv=none; b=aWQrad/hohZ6+9yTVhhPH3w16vOkN+qOaJUKu0k0z2Xx4m7EdGE44gm3WWtx+rfFvqhivs0VpStFg+FSsmnmLu2EvyJ5H+5AbSCi7aPz9BMBYNCKx6fKucIAmRwNIDnnbaQ0hr7Lwhq551y0cY/VhFSYf8bMgOlXmP+0Dnf/Kc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801015; c=relaxed/simple; bh=LWzk7LsEir8pNmymF4y7WFSgVSAN9W9Dot8AfN2IGYA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cl5a0hrwD2ZKBXQDY9FwljkKTAQEoQaM7mV7Lku8VH+F8AeZ9f1yu+iG6ak0ThDuV/iTSHnksqjkvDSMnSgdLPMCPHot2ze1vxnyOEMJ5GeLqtvoOopEyQ24+xF7y0/sIxaxXYMEsUYfFNF83FzsXvZg4rz3bB5pBskWzoJsyCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=FQ1Ll09+; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="FQ1Ll09+" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7248c1849bdso819301b3a.3 for ; Thu, 28 Nov 2024 05:36:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732801013; x=1733405813; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+pF/gTcrGXSS4/ort4kcDDgWrRYgYOYuykRq88RGJ3I=; b=FQ1Ll09+VXIQKop+iIudWEH40bI3x3pTChkTYXZE6r0KggrborSitune/nCsAiLNkB CSsC7RYqLGy4X4nTvQAfY9W+6BgvOhMBJGwQYvuH+YzY/BqToLurxB9xEun4bbLXSwcN 05NZVq654omiTkWLzEROSQo1UZ26Fh0QhhGln5vz3RB1exq+VRA3PNSzL5JBePgUuquk GoMmRT2uwl7F1BOQZSuNwi22U4gFo7ty9psvOt/cPtWY7enjEvaR6cFNU+MeZuhdKXGX oA7XyVofATzOZT5gI4gvTvIQewVHqe51aQbPPOhU5/KwpqKMOtHHfmhqmD//JlJGLIXs SD/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732801013; x=1733405813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+pF/gTcrGXSS4/ort4kcDDgWrRYgYOYuykRq88RGJ3I=; b=wlF9XEraGKT2qCCqDHcMiEKx8O/jn4fpLD8WhplrejXhRvPip1PbJPbrwUp5uBt39v R6JMVzqlBoseAr5Q4nZ9CrCIGBkYLXq2ekMtQXv3OitfDOATgsoHuN0qVyk2YXawt1Qr p1zwVvQxA3KbCiLZhhDqGgt+D1nXreqrTvRkQfSs9xKc6Lp14eUIMP/f4t8CKgXpOQGj tgeATW8zqOGR2NJ79iGbeFrM19PsnBMQtrNWUu3VSy82Qyo4mkaeS4sBEIqIHHw0oFUM SmtAPkro1NcWGrEdXQbN9+D3t7XTAJCjmhily9kQlxBoNS8PCF6pufIZkaJ2avzVjO3c k5jg== X-Forwarded-Encrypted: i=1; AJvYcCXejw1MFqBYaQOfW1H5YG09B8X9yAaDLZ8KnWAC3cSJpZwwPR1ZvVvMYmbhyFKlBP92XbCi5CX6v3jPBPU=@vger.kernel.org X-Gm-Message-State: AOJu0YyeOiPzy55m21woJironzFX7yG0s7wNIUGOajLxQQEnCVaGtHwB RHWzFp/vRfUNnwrQOvIQTdk8rVfSPAgrhPbsopJnEP7xdSSSsT7bKQKRglw6Zfk= X-Gm-Gg: ASbGncvl0d6532VVePLy26qNFMHtqaMivqaXcE5OYyt99ofRPPBXUGTwNXzQyso5uOc 75yIwO5BN1taf18ckkZwXhulFNDqAsIJPxnw6QpmGb7/o4j8P37zX8GNlRItgKTuODAvSxbxso3 i5O2lDbdZ79gDxQI3kQmlrB7rz2pSLrwf1y8dmoIw55irck9iqgXONBvAfkfBXuw9VchSgwk/Pi v4aDYLQk35LtjoaXbvkigqs/Eweg+WxVY+xeOLT8oCsnY0GKRubVHyjXQ== X-Google-Smtp-Source: AGHT+IHIMHJ67LGq/eKXuEzSHfGZ3n5mOwtZ6W1GG7x7VI5A2fu//2XROxW0PWDTJEFBPPaWxmGEEQ== X-Received: by 2002:a17:902:ecd0:b0:205:3e6d:9949 with SMTP id d9443c01a7336-21501f63bebmr73513465ad.52.1732801012880; Thu, 28 Nov 2024 05:36:52 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:36:52 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 07/12] perf event action: Add parsing builtin expr support Date: Thu, 28 Nov 2024 21:35:48 +0800 Message-Id: <20241128133553.823722-8-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" builtin exprs are some built-in special variables (such as cpu, tid, pid). The bpf program attaches to corresponding event, saves sample data to bpf perf_event ringuffer in handler, perf-tool read data and run actions. Signed-off-by: Yang Jihong --- tools/perf/Makefile.perf | 1 + tools/perf/util/bpf_skel/bpf_record_action.h | 19 + tools/perf/util/bpf_skel/record_action.bpf.c | 74 ++++ tools/perf/util/parse-action.c | 22 ++ tools/perf/util/parse-action.h | 5 + tools/perf/util/parse-action.l | 6 + tools/perf/util/parse-action.y | 11 +- tools/perf/util/record_action.c | 352 ++++++++++++++++++- tools/perf/util/record_action.h | 8 +- 9 files changed, 492 insertions(+), 6 deletions(-) create mode 100644 tools/perf/util/bpf_skel/bpf_record_action.h create mode 100644 tools/perf/util/bpf_skel/record_action.bpf.c diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index d74241a15131..07bc2f8e2565 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -1173,6 +1173,7 @@ SKELETONS +=3D $(SKEL_OUT)/kwork_trace.skel.h $(SKEL_= OUT)/sample_filter.skel.h SKELETONS +=3D $(SKEL_OUT)/kwork_top.skel.h SKELETONS +=3D $(SKEL_OUT)/bench_uprobe.skel.h SKELETONS +=3D $(SKEL_OUT)/augmented_raw_syscalls.skel.h +SKELETONS +=3D $(SKEL_OUT)/record_action.skel.h =20 $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBS= UBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT): $(Q)$(MKDIR) -p $@ diff --git a/tools/perf/util/bpf_skel/bpf_record_action.h b/tools/perf/util= /bpf_skel/bpf_record_action.h new file mode 100644 index 000000000000..ee4d03848e58 --- /dev/null +++ b/tools/perf/util/bpf_skel/bpf_record_action.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_UTIL_BPF_SKEL_BPF_RECORD_ACTION_H_ +#define __PERF_UTIL_BPF_SKEL_BPF_RECORD_ACTION_H_ + +#define __TASK_COMM_MAX_SIZE 16 + +#define __OUTPUT_FORMATS_MAX_NUM 8 + +enum __output_format_type { + __OUTPUT_FORMAT_TYPE_MAX, +}; + +#define __OUTPUT_DATA_MAX_SIZE 256 +struct __output_data_payload { + __u32 __size; + __u8 __data[__OUTPUT_DATA_MAX_SIZE]; +}; + +#endif /* __PERF_UTIL_BPF_SKEL_BPF_RECORD_ACTION_H_ */ diff --git a/tools/perf/util/bpf_skel/record_action.bpf.c b/tools/perf/util= /bpf_skel/record_action.bpf.c new file mode 100644 index 000000000000..424fa8c3e6f1 --- /dev/null +++ b/tools/perf/util/bpf_skel/record_action.bpf.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) + +#include "vmlinux.h" +#include +#include +#include + +#include "bpf_record_action.h" + +int output_formats[__OUTPUT_FORMATS_MAX_NUM] =3D { 0 }; +int output_format_num =3D 0; +int enabled =3D 0; + +#define MAX_CPUS 1024 + +/* bpf-output associated map */ +struct __sample_data__ { + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __type(key, int); + __type(value, __u32); + __uint(max_entries, MAX_CPUS); +} __sample_data__ SEC(".maps"); + +struct sample_data_tmp { + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __type(key, int); + __type(value, struct __output_data_payload); + __uint(max_entries, 1); +} sample_data_tmp SEC(".maps"); + +static inline struct __output_data_payload *sample_data_payload(void) +{ + int key =3D 0; + + return bpf_map_lookup_elem(&sample_data_tmp, &key); +} + +SEC("xxx") +int sample_output(u64 *ctx) +{ + struct __output_data_payload *sample; + int i; + int total =3D 0; + int ret =3D 0; + + if (!enabled) + return 0; + + sample =3D sample_data_payload(); + if (!sample) + return 0; + + for (i =3D 0; i < output_format_num && i < __OUTPUT_FORMATS_MAX_NUM; i++)= { + switch (output_formats[i]) { + default: + ret =3D -1; + break; + } + + if (ret < 0) + return 0; + + total +=3D ret; + if (total > __OUTPUT_DATA_MAX_SIZE) + return 0; + } + + sample->__size =3D total; + bpf_perf_event_output(ctx, &__sample_data__, BPF_F_CURRENT_CPU, + sample, sizeof(__u32) + total); + return 0; +} + +char _license[] SEC("license") =3D "GPL"; diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index 95c06cc071ad..e6299de99bc5 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -11,6 +11,7 @@ * - string * - call: * - print + * - builtin: */ =20 #include @@ -19,6 +20,7 @@ #include "util/parse-action.h" #include "util/parse-action-flex.h" #include "util/parse-action-bison.h" +#include "util/record_action.h" =20 static struct list_head actions_head =3D LIST_HEAD_INIT(actions_head); =20 @@ -90,10 +92,30 @@ static int parse_action_option(const char *str) return ret; } =20 +static bool initialized =3D false; +static int parse_action_init(void) +{ + int ret; + + if (initialized) + return 0; + + ret =3D bpf_perf_record_init(); + if (ret) + return ret; + + initialized =3D true; + return 0; +} + int parse_record_action(struct evlist *evlist, const char *str) { int ret; =20 + ret =3D parse_action_init(); + if (ret) + return ret; + if (evlist =3D=3D NULL) { pr_err("--action option should follow a tracer option\n"); return -1; diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index f8aece601a84..b1a33a77c558 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -11,6 +11,7 @@ enum evtact_expr_type { EVTACT_EXPR_TYPE_CONST, EVTACT_EXPR_TYPE_CALL, + EVTACT_EXPR_TYPE_BUILTIN, EVTACT_EXPR_TYPE_MAX, }; =20 @@ -25,6 +26,10 @@ enum evtact_expr_call_type { EVTACT_EXPR_CALL_TYPE_MAX, }; =20 +enum evtact_expr_builtin_type { + EVTACT_EXPR_BUILTIN_TYPE_MAX, +}; + struct evtact_expr; struct evtact_expr_ops { int (*new)(struct evtact_expr *expr, void *data, int size); diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l index 5e75383ba3e7..1c729b7a0248 100644 --- a/tools/perf/util/parse-action.l +++ b/tools/perf/util/parse-action.l @@ -82,6 +82,12 @@ static int call(u32 opcode) return CALL; } =20 +static int builtin(u32 opcode) +{ + parse_action_lval.opcode =3D opcode; + return BUILTIN; +} + %} =20 num_dec [0-9]+ diff --git a/tools/perf/util/parse-action.y b/tools/perf/util/parse-action.y index 1b162c694218..78a15f146ade 100644 --- a/tools/perf/util/parse-action.y +++ b/tools/perf/util/parse-action.y @@ -38,14 +38,14 @@ static void parse_action_error(struct list_head *expr _= _maybe_unused, u32 opcode; } =20 -%token IDENT ERROR NUMBER STRING CALL +%token IDENT ERROR NUMBER STRING CALL BUILTIN %token SEMI LP RP COM %type action_term expr_term expr_call_term %destructor { parse_action_expr__free($$); } %type IDENT %type NUMBER %type STRING -%type CALL +%type CALL BUILTIN %type opnds =20 %% @@ -132,6 +132,13 @@ STRING YYERROR; } | +BUILTIN +{ + $$ =3D parse_action_expr__new(evtact_expr_id_encode(EVTACT_EXPR_TYPE_BUIL= TIN, $1), NULL, NULL, 0); + if ($$ =3D=3D NULL) + YYERROR; +} +| IDENT { $$ =3D NULL; diff --git a/tools/perf/util/record_action.c b/tools/perf/util/record_actio= n.c index 44789e0d4678..634d6b199bae 100644 --- a/tools/perf/util/record_action.c +++ b/tools/perf/util/record_action.c @@ -1,15 +1,361 @@ // SPDX-License-Identifier: GPL-2.0 /** - * Read event sample data and execute the specified actions. + * Read perf event output sample data and execute the specified actions. */ =20 +#include +#include +#include +#include + #include "util/debug.h" +#include "util/target.h" #include "util/parse-action.h" #include "util/record_action.h" =20 -int bpf_perf_record(struct evlist *evlist __maybe_unused, - int argc __maybe_unused, const char **argv __maybe_unused) +#include "util/bpf_counter.h" +#include "util/bpf_skel/bpf_record_action.h" +#include "util/bpf_skel/record_action.skel.h" + +static struct perf_buffer *pb; +static struct record_action_bpf *skel; + +struct expr_builtin_output_priv { + int offset; + int size; +}; + +static int bpf_expr_builtin_new(struct evtact_expr *expr, + void *data __maybe_unused, int size __maybe_unused) +{ + struct expr_builtin_output_priv *priv; + + priv =3D malloc(sizeof(*priv)); + if (priv =3D=3D NULL) { + pr_err("bpf expr builtin priv malloc failed\n"); + return -ENOMEM; + } + + expr->priv =3D priv; + return 0; +} + +static void bpf_expr_builtin_free(struct evtact_expr *expr) +{ + zfree(&expr->priv); +} + +static int bpf_expr_builtin_eval(struct evtact_expr *expr, + void *in, int in_size, void **out, int *out_size) +{ + struct expr_builtin_output_priv *priv =3D expr->priv; + + if (in_size < priv->size) + return -EINVAL; + + *out =3D (u8 *)in + priv->offset; + *out_size =3D priv->size; + return 0; +} + +static struct evtact_expr_ops bpf_expr_builtin_common =3D { + .new =3D bpf_expr_builtin_new, + .free =3D bpf_expr_builtin_free, + .eval =3D bpf_expr_builtin_eval, +}; + +static int bpf_expr_builtin_set_ops(struct evtact_expr *expr, u32 opcode) +{ + if (opcode >=3D EVTACT_EXPR_BUILTIN_TYPE_MAX) { + pr_err("bpf expr_builtin opcode invalid: %u\n", opcode); + return -EINVAL; + } + + expr->ops =3D &bpf_expr_builtin_common; + return 0; +} + +static struct evtact_expr_class bpf_expr_builtin =3D { + .set_ops =3D bpf_expr_builtin_set_ops, +}; + +int bpf_perf_record_init(void) +{ + return parse_action_expr__set_class(EVTACT_EXPR_TYPE_BUILTIN, + &bpf_expr_builtin); +} + +static int set_expr_builtin_output_format(struct evtact_expr *expr, + u32 opcode, int *offset, + int *format __maybe_unused) +{ + int size =3D 0; + struct expr_builtin_output_priv *priv =3D expr->priv; + + switch (opcode) { + default: + pr_err("set expr builtin output format unknown opcode: %u\n", opcode); + return -1; + } + + priv->offset =3D *offset; + priv->size =3D size; + *offset +=3D size; + return 0; +} + +struct output_args { + int *num; + int *offset; + int *formats; +}; + +static int do_set_output_format(struct evtact_expr *expr, void *data) +{ + int ret; + u32 type, opcode; + struct output_args *args =3D data; + int num =3D *(args->num); + + evtact_expr_id_decode(expr->id, &type, &opcode); + if (type =3D=3D EVTACT_EXPR_TYPE_BUILTIN) { + if (num >=3D __OUTPUT_FORMATS_MAX_NUM) { + pr_err("bpf record action output formats too many\n"); + return -1; + } + + ret =3D set_expr_builtin_output_format(expr, opcode, args->offset, + args->formats + num); + if (ret) + return ret; + num++; + } + + *(args->num) =3D num; + return 0; +} + +static int bpf_set_output_format(int *formats) +{ + int ret; + int offset =3D 0; + int num =3D 0; + struct output_args args =3D { + .num =3D &num, + .offset =3D &offset, + .formats =3D formats, + }; + + ret =3D event_actions__for_each_expr(do_set_output_format, &args, true); + if (ret) + return ret; + + if (offset > __OUTPUT_DATA_MAX_SIZE) { + pr_err("bpf record action output too large\n"); + return -1; + } + + skel->bss->output_format_num =3D num; + return 0; +} + + +struct eval_args { + void *data; + __u32 size; +}; + +static int do_sample_handler(struct evtact_expr *expr, void *data) +{ + int ret; + struct eval_args *args =3D data; + + if (expr !=3D NULL && expr->ops->eval !=3D NULL) { + ret =3D expr->ops->eval(expr, args->data, args->size, NULL, NULL); + if (ret) + return ret; + } + + return 0; +} + +static void sample_callback(void *ctx __maybe_unused, int cpu __maybe_unus= ed, + void *data, __u32 size __maybe_unused) +{ + struct __output_data_payload *sample_data =3D data; + struct eval_args args =3D { + .data =3D sample_data->__data, + .size =3D sample_data->__size, + }; + (void)event_actions__for_each_expr(do_sample_handler, &args, false); +} + +static void lost_callback(void *ctx __maybe_unused, int cpu, __u64 cnt) +{ + fprintf(stderr, "Lost %llu events on CPU #%d\n", cnt, cpu); +} + +static int bpf_record_prepare(const char *subsystem, const char *event_nam= e) +{ + int ret, map_fd; + + skel =3D record_action_bpf__open(); + if (!skel) { + pr_err("open record-action BPF skeleton failed\n"); + return -1; + } + + set_max_rlimit(); + + ret =3D bpf_program__set_type(skel->progs.sample_output, BPF_PROG_TYPE_TR= ACEPOINT); + if (ret) { + pr_err("set type record-action BPF skeleton failed\n"); + goto out; + } + + ret =3D record_action_bpf__load(skel); + if (ret) { + pr_err("load record-action BPF skeleton failed\n"); + goto out; + } + + ret =3D bpf_set_output_format(skel->bss->output_formats); + if (ret) + goto out; + + map_fd =3D bpf_map__fd(skel->maps.__sample_data__); + if (map_fd < 0) { + pr_err("map fd record-action BPF skeleton failed\n"); + goto out; + } + + skel->links.sample_output =3D bpf_program__attach_tracepoint( + skel->progs.sample_output, subsystem, event_name); + if (IS_ERR(skel->links.sample_output)) { + pr_err("attach record-action BPF skeleton failed\n"); + goto out; + } + + pb =3D perf_buffer__new(map_fd, 8, sample_callback, + lost_callback, NULL, NULL); + ret =3D libbpf_get_error(pb); + if (ret) { + pr_err("setup record-action perf_buffer failed: %d\n", ret); + goto out; + } + + return 0; + +out: + record_action_bpf__destroy(skel); + return -1; +} + +static inline void bpf_record_start(void) +{ + skel->bss->enabled =3D 1; +} + +static inline void bpf_record_stop(void) { + skel->bss->enabled =3D 0; +} + +static volatile int done; +static volatile sig_atomic_t child_finished; +static void sig_handler(int sig) +{ + if (sig =3D=3D SIGCHLD) + child_finished =3D 1; + + done =3D 1; +} + +static bool is_bpf_record_supported(struct evlist *evlist, + char **subsystem, char **event_name) +{ + struct evsel *evsel; + + if (evlist =3D=3D NULL) { + pr_err("--action option should follow a tracer option\n"); + return false; + } + + /* only one fixed bpf prog and can only be attached to one event. */ + if (evlist->core.nr_entries > 1) { + pr_err("too many events for specified action\n"); + return false; + } + + evsel =3D evlist__last(evlist); + if (evsel =3D=3D NULL) { + pr_err("evlist for bpf record action is empty\n"); + return false; + } + + if (evsel->core.attr.type !=3D PERF_TYPE_TRACEPOINT) { + pr_err("bpf record action only supports specifying for tracepoint tracer= \n"); + return false; + } + + *subsystem =3D strtok_r(evsel->name, ":", event_name); + if (*subsystem =3D=3D NULL || event_name =3D=3D NULL) { + pr_err("bpf record action tracepoint name format incorrect\n"); + return false; + } + + return true; +} + +int bpf_perf_record(struct evlist *evlist, int argc, const char **argv) +{ + int ret; + char *subsystem, *event_name; + struct target target =3D { + .system_wide =3D true, + }; + + if (!is_bpf_record_supported(evlist, &subsystem, &event_name)) + goto out_free_event_actions; + + ret =3D bpf_record_prepare(subsystem, event_name); + if (ret) + goto out_free_event_actions; + + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); + signal(SIGCHLD, sig_handler); + + if (argc > 0) { + ret =3D evlist__prepare_workload(evlist, &target, argv, false, NULL); + if (ret < 0) { + pr_err("evlist workload create failed\n"); + goto out_destroy_record_action_bpf; + } + } + + bpf_record_start(); + evlist__start_workload(evlist); + + while ((ret =3D perf_buffer__poll(pb, 1000)) >=3D 0) { + if (done =3D=3D 1) + break; + } + + bpf_record_stop(); + + if (argc > 0) { + int exit_status; + + if (!child_finished) + kill(evlist->workload.pid, SIGTERM); + + wait(&exit_status); + } + +out_destroy_record_action_bpf: + record_action_bpf__destroy(skel); +out_free_event_actions: event_actions__free(); return 0; } diff --git a/tools/perf/util/record_action.h b/tools/perf/util/record_actio= n.h index 289be4befa97..6cd578af2ccb 100644 --- a/tools/perf/util/record_action.h +++ b/tools/perf/util/record_action.h @@ -7,8 +7,9 @@ =20 #ifdef HAVE_BPF_SKEL =20 -int bpf_perf_record(struct evlist *evlist, int argc, const char **argv); +int bpf_perf_record_init(void); =20 +int bpf_perf_record(struct evlist *evlist, int argc, const char **argv); =20 #else /* !HAVE_BPF_SKEL */ =20 @@ -19,6 +20,11 @@ static inline int bpf_perf_record(struct evlist *evlist = __maybe_unused, return -EOPNOTSUPP; } =20 +static inline int bpf_perf_record_init(void) +{ + return 0; +} + #endif /* !HAVE_BPF_SKEL */ =20 #endif /* __PERF_UTIL_RECORD_ACTION_H_ */ --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 EE6621ADFED for ; Thu, 28 Nov 2024 13:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801020; cv=none; b=DyPLPAYGLpzH9ZEavhWMyKHzaYMWp9DO/zf4VakrrRlP585U4vUcikx3P3Iyt6TKPOGjJhKgK/e38lQn0JGSfiWojxMi3JasSLowbfjt+o3WoV0BiC63jbrMy7WszH1pXOrAEJ1K/JIOliSFwCfkUU1IIv6BJ6//VDUyHzSWOiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801020; c=relaxed/simple; bh=BBDOWJUMQQVfP0zujIc5xIWnrs6gRTLQkCf6I2SIpPQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GwGVBMClDhljlB6HoSng5H47NCJqz0cCWRVRuSOX9xkIwwOAljlervSKBMrKiC8gel8RT7BYx1lKbXChEjz6NMYAAxCAnhOpeandLTIc37byN2bUECYadHxeS/jUyuxaJvzIuPmd7iI102P8pwuOFF1ybHqYECNNCRl0gn3vpCQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=HQiXQNiz; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="HQiXQNiz" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-21285c1b196so7811555ad.3 for ; Thu, 28 Nov 2024 05:36:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732801018; x=1733405818; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RUD8vqFZbss9TRcSki6gkGZU4MXDWWiXU3SDa6QRj9s=; b=HQiXQNiz9WDas3UsP+I/1jTzhW3KK0Q172En91k/gMbcmD+ky1xdDafRqgJVshRMU5 UQSWDh5DwoKYHp6My2WPaPzS6fqgVcDUTo4haFX9/oGLy8R5ZrPgpjY6IE5ylfWVhFIQ eWBDdpiFB2uK8iyX6BHQVgBuV0ZbxXQzpRSFzu3D7OsCwgD2PvxZrliEY+CLF0FM3oNX iHQ1hc2z8O5itxY4/ctYWdnbDxaIYokZWxmJvO8q9kzchatFk1IwNAqxgc/0zi/niqwY wrD0w7bEhXu817ra+R9KzbBxoC80O/tZuf0mxX1q0Xy+kq3aICOPjklATcoI6Gn6fKqR Kq/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732801018; x=1733405818; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RUD8vqFZbss9TRcSki6gkGZU4MXDWWiXU3SDa6QRj9s=; b=UBaFkSh8ROs8N/kgjYZ0UIVdSDIw0EamQfk6TnZPJyZiSsnbCX5m6mAdDvTrn0H5Nk WztySrIurfBP0fxR7z5CxeyENzKvJ92SMNR0ug8lJjiGwwjABmmInVem3m7VDMQG7IrJ 88wfU4PMe9CAAeEfuGqCcLsn9lSxO50+zAvLUczYvLooPvLPDvn/xq+aiTeBAJKtAC+W TPs0RMyobrzZ5MbikOyV22mIlWtcYtDkPoV+jwFD1wr7VbJb+XLndK+XdOsOcXQX+VDo ajfS+004hxLmo3MuF8jmuFQc2WR/+h4PnXjMB8FJX0x0up011YRnKzO7JN8olz0Py2aR yZHA== X-Forwarded-Encrypted: i=1; AJvYcCUG16jMlWV53GKj9PRE5OGROeRZfz2SDld/bILjRVyolcgxIjK02MNAaE2au0mjr7uBlVSxn2Q9eDmNtFs=@vger.kernel.org X-Gm-Message-State: AOJu0YxlrYN3o2bOH8qAnG2WAp9C1Oj6hjBlfk8YOS04bhgio/inZoFD p+iJmdO6sIjwgqNxNx+6s+P3zosNxi869EUcu5QaPfn9L01vQvEqhixTG+K8v2Q= X-Gm-Gg: ASbGnctkryHVl7u1Ga5dM5Uns5WTIa0VI65jZuA9DpGBoX7bUDmhZTuGWdZS2R0aM3u P5oGz9X8xKOviCZ9sC8/dZVFi2HwH00r/liORq2fnhhMeXHZBTb4NOSUCXOK2mcHHTRVnuw+uFU NPXZGemaY7rHI4ks5UCdzaVp7YXvC2tuIsAI4OTTAUkvyH/8vITsRqXhHCpe32sakrFxUkymsZ0 36LE6XjgK6Rcfpg9WK4xhy3qIZk8zs7CYTGW8c/jwZihM+/Bcvkc8gDhg== X-Google-Smtp-Source: AGHT+IGf15rlbVH2/JLbhmcoCT0wHnv6QABKy0ywOplhv0zyME4662tjPK99hOetjLPgzweDrC1BCw== X-Received: by 2002:a17:902:d54e:b0:212:5b57:80ed with SMTP id d9443c01a7336-21501087642mr98852365ad.11.1732801018544; Thu, 28 Nov 2024 05:36:58 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.36.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:36:57 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 08/12] perf event action: Add parsing builtin cpu expr support Date: Thu, 28 Nov 2024 21:35:49 +0800 Message-Id: <20241128133553.823722-9-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support parsing of builtin cpu expression. Testcase: # perf record -e sched:sched_switch --action 'print("cpu =3D %d\n", cpu)' cpu =3D 7 cpu =3D 7 cpu =3D 7 cpu =3D 7 cpu =3D 7 cpu =3D 7 cpu =3D 7 cpu =3D 7 cpu =3D 7 ... Signed-off-by: Yang Jihong --- tools/perf/util/bpf_skel/bpf_record_action.h | 1 + tools/perf/util/bpf_skel/record_action.bpf.c | 16 ++++++++++++++++ tools/perf/util/parse-action.c | 1 + tools/perf/util/parse-action.h | 1 + tools/perf/util/parse-action.l | 1 + tools/perf/util/record_action.c | 7 +++++-- 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/bpf_skel/bpf_record_action.h b/tools/perf/util= /bpf_skel/bpf_record_action.h index ee4d03848e58..91a307b89f85 100644 --- a/tools/perf/util/bpf_skel/bpf_record_action.h +++ b/tools/perf/util/bpf_skel/bpf_record_action.h @@ -7,6 +7,7 @@ #define __OUTPUT_FORMATS_MAX_NUM 8 =20 enum __output_format_type { + __OUTPUT_FORMAT_TYPE_CPU, __OUTPUT_FORMAT_TYPE_MAX, }; =20 diff --git a/tools/perf/util/bpf_skel/record_action.bpf.c b/tools/perf/util= /bpf_skel/record_action.bpf.c index 424fa8c3e6f1..4b7698554ead 100644 --- a/tools/perf/util/bpf_skel/record_action.bpf.c +++ b/tools/perf/util/bpf_skel/record_action.bpf.c @@ -35,10 +35,22 @@ static inline struct __output_data_payload *sample_data= _payload(void) return bpf_map_lookup_elem(&sample_data_tmp, &key); } =20 +static inline int output_cpu(__u8 *data, int size) +{ + __u32 *cpu =3D (__u32 *)data; + + if (size < sizeof(__u32)) + return -1; + + *cpu =3D bpf_get_smp_processor_id(); + return sizeof(__u32); +} + SEC("xxx") int sample_output(u64 *ctx) { struct __output_data_payload *sample; + __u8 *data; int i; int total =3D 0; int ret =3D 0; @@ -50,8 +62,12 @@ int sample_output(u64 *ctx) if (!sample) return 0; =20 + data =3D sample->__data; for (i =3D 0; i < output_format_num && i < __OUTPUT_FORMATS_MAX_NUM; i++)= { switch (output_formats[i]) { + case __OUTPUT_FORMAT_TYPE_CPU: + ret =3D output_cpu(data + total, __OUTPUT_DATA_MAX_SIZE - total); + break; default: ret =3D -1; break; diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index e6299de99bc5..2bb32cc16ae7 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -12,6 +12,7 @@ * - call: * - print * - builtin: + * - cpu */ =20 #include diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index b1a33a77c558..ee949ed07111 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -27,6 +27,7 @@ enum evtact_expr_call_type { }; =20 enum evtact_expr_builtin_type { + EVTACT_EXPR_BUILTIN_TYPE_CPU, EVTACT_EXPR_BUILTIN_TYPE_MAX, }; =20 diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l index 1c729b7a0248..dab8066a1038 100644 --- a/tools/perf/util/parse-action.l +++ b/tools/perf/util/parse-action.l @@ -103,6 +103,7 @@ ident [_a-zA-Z][_a-zA-Z0-9]* {num_hex} { return value(16); } {space} { } =20 +cpu { return builtin(EVTACT_EXPR_BUILTIN_TYPE_CPU); } =20 print { return call(EVTACT_EXPR_CALL_TYPE_PRINT); } =20 diff --git a/tools/perf/util/record_action.c b/tools/perf/util/record_actio= n.c index 634d6b199bae..15e8b1740e32 100644 --- a/tools/perf/util/record_action.c +++ b/tools/perf/util/record_action.c @@ -86,13 +86,16 @@ int bpf_perf_record_init(void) } =20 static int set_expr_builtin_output_format(struct evtact_expr *expr, - u32 opcode, int *offset, - int *format __maybe_unused) + u32 opcode, int *offset, int *format) { int size =3D 0; struct expr_builtin_output_priv *priv =3D expr->priv; =20 switch (opcode) { + case EVTACT_EXPR_BUILTIN_TYPE_CPU: + *format =3D __OUTPUT_FORMAT_TYPE_CPU; + size =3D sizeof(u32); + break; default: pr_err("set expr builtin output format unknown opcode: %u\n", opcode); return -1; --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 CF6EC158527 for ; Thu, 28 Nov 2024 13:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801026; cv=none; b=gwSQR7hZ7Inty5UdQI88XLztjHblDtNmH6SjuTVGIaVXVKOAKmVVxDEGlbncGQ49+A9MQxPU6jV3NEJ2Xlqb0ckiUa/TN9LQVfggah7GqYLupfTqfjMeDB7kCeL6J2fZBT8RQan9jFgXhRfSjxWQzGTO9B5MlBOPtEPoJm/Ouq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801026; c=relaxed/simple; bh=50d69piWWU2jaYxxxoAX9izh5i1+CaCy4aEpH5ck7fM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WwgQgAii2an0EiL2KTe6cGr2rH7B7d/JzLD8SOcDuf74qtQYqk82L1K/An4+ckvhMUkNajzMFSRC7CRHjJd8Uw4CBPMvTHuZOdQGDkjkU7f/ZeLShEyPSz6wr0NMw0hptonKn55vGiS0bbAwZ1MlKRJPPmd3JFmOqIN9VhCmzkI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=ZJ+DZRDv; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="ZJ+DZRDv" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-21285c1b196so7812195ad.3 for ; Thu, 28 Nov 2024 05:37:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732801024; x=1733405824; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dgdLWqoEhgyt5G/z7Uvb0KNRe9T81wk05S67wMjuGxY=; b=ZJ+DZRDv5M2Degdik/SSLlV86pFgsPsF/Z7jjPMog66MvU6ZwYp0k1ZKj7a4drq907 1+0HNyYjY2OrYfc5rFvrocqNl4FfsilgwTFxCu/5llB66AOqWgHLBmEOaExRV8kwV8ZA v/lnf78b5htj8C/gd4+D7UDOBQsb7t/2VBOVS/il5RMS83Y5OBIelQEylJWZMbHO4480 DHOXu+i7u/o4tzEdAXe69MfKhFEkpcUYa/eRIcu1QPr3A3wxCSMwBRoWsXxRoRwzKkEt h7G2nNCT8OkocU5ybPtr61r69T5euixpv+qdAZAx6rB/2CecwKkfIBO/Jdq8zoOZzseJ gPbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732801024; x=1733405824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dgdLWqoEhgyt5G/z7Uvb0KNRe9T81wk05S67wMjuGxY=; b=go1t+IwTi3SiRQlid0lkNsT5SHIPGbv6dZ9eg5DgHZknTTsxTn576NoednzbtM3Pth 63Gwkn/6LOWF5Erp2luwtyBzUR+nSSP8XP8PEFG+SHM00Bq/7egndZ6/Wy+sv454NfCL JhGi0kgxqpR6xDRdqQV6AbrAsgQf5kaGi+umUkkw4LrkTAi96dlUUekFZ+frfiEkmTbO OPQBRbS6T23Ug7LqfB0e4hA+OJBd+0yJn8Hgz/H+cUGl32uMCJTuoafMWZE3xO5kQEVP ++kAaXuQYGShZ11AiVrmd44D9/bWlIfIk1MrTr8s8ioCc1ubYm/6IXljCmGmM6gYlMCU P8dQ== X-Forwarded-Encrypted: i=1; AJvYcCUFFZefKv0cm7UUtUDgnVVdl4GdtWqWYj1eGo9mMpQ/Ks3TIHSaocpYUQwV5Z7XFo26br6fNjOa2fT4Wmo=@vger.kernel.org X-Gm-Message-State: AOJu0YxpMw/CROuisAP4Pqiifc60uz8pGCtzUoIQMdE/5AzqIo5TzxBe 6e3auhTJAOZgIeXgLDSsxlbmCoc2lTOC+yXuQo2WEOr0pBwrP/7eQeKq9TXA8RdB3zftnzzU24y b X-Gm-Gg: ASbGncvPNDgDfP2tE5PvC0Eim0O1gBNlrZy+H3i/WZswu4Y8vbxrKa/Nw6WCEp6iWIn 9fGDmad8CleimiG/sUyqk4aM/gf09BbUXul84M18Ke63mO8EhVXOVSC/7itCiroCWXiOK6vPcf2 mmn2gX1U+GWkqNP4HDIn/wosRHUbUkXe3cxlsqPWC3qYdpU1jDy/+2eg9iBAo4i6Q3ubEaUNyb0 HJUPqksUKnHDYnjTGYXQIhFaFzBbj7EhLW547fHVG0e4CNEWVlhOV90aw== X-Google-Smtp-Source: AGHT+IG1kcWnGOJI3fbIBd0J1173C2aDQsba2PEgZo0mOOfdj4DoYdahDuneldwbxDr6nCD+qCY1WA== X-Received: by 2002:a17:902:ecc2:b0:212:b2b:6f10 with SMTP id d9443c01a7336-21501088172mr82517785ad.8.1732801024126; Thu, 28 Nov 2024 05:37:04 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.36.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:37:03 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 09/12] perf event action: Add parsing builtin pid expr support Date: Thu, 28 Nov 2024 21:35:50 +0800 Message-Id: <20241128133553.823722-10-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support parsing of builtin pid expression. Testcase: # perf record -e sched:sched_switch --action 'print("pid =3D %d\n", pid)' pid =3D 132784 pid =3D 0 pid =3D 132784 pid =3D 132778 pid =3D 0 pid =3D 0 pid =3D 132784 pid =3D 0 pid =3D 132784 pid =3D 0 pid =3D 132784 pid =3D 0 pid =3D 132784 ... Signed-off-by: Yang Jihong --- tools/perf/util/bpf_skel/bpf_record_action.h | 1 + tools/perf/util/bpf_skel/record_action.bpf.c | 14 ++++++++++++++ tools/perf/util/parse-action.c | 1 + tools/perf/util/parse-action.h | 1 + tools/perf/util/parse-action.l | 1 + tools/perf/util/record_action.c | 4 ++++ 6 files changed, 22 insertions(+) diff --git a/tools/perf/util/bpf_skel/bpf_record_action.h b/tools/perf/util= /bpf_skel/bpf_record_action.h index 91a307b89f85..a4817d62bce8 100644 --- a/tools/perf/util/bpf_skel/bpf_record_action.h +++ b/tools/perf/util/bpf_skel/bpf_record_action.h @@ -8,6 +8,7 @@ =20 enum __output_format_type { __OUTPUT_FORMAT_TYPE_CPU, + __OUTPUT_FORMAT_TYPE_PID, __OUTPUT_FORMAT_TYPE_MAX, }; =20 diff --git a/tools/perf/util/bpf_skel/record_action.bpf.c b/tools/perf/util= /bpf_skel/record_action.bpf.c index 4b7698554ead..fd44bb3da663 100644 --- a/tools/perf/util/bpf_skel/record_action.bpf.c +++ b/tools/perf/util/bpf_skel/record_action.bpf.c @@ -46,6 +46,17 @@ static inline int output_cpu(__u8 *data, int size) return sizeof(__u32); } =20 +static inline int output_pid(__u8 *data, int size) +{ + __u32 *pid =3D (__u32 *)data; + + if (size < sizeof(__u32)) + return -1; + + *pid =3D bpf_get_current_pid_tgid() >> 32; + return sizeof(__u32); +} + SEC("xxx") int sample_output(u64 *ctx) { @@ -68,6 +79,9 @@ int sample_output(u64 *ctx) case __OUTPUT_FORMAT_TYPE_CPU: ret =3D output_cpu(data + total, __OUTPUT_DATA_MAX_SIZE - total); break; + case __OUTPUT_FORMAT_TYPE_PID: + ret =3D output_pid(data + total, __OUTPUT_DATA_MAX_SIZE - total); + break; default: ret =3D -1; break; diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index 2bb32cc16ae7..0ae998a5d286 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -13,6 +13,7 @@ * - print * - builtin: * - cpu + * - pid */ =20 #include diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index ee949ed07111..e74d3b4e5de8 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -28,6 +28,7 @@ enum evtact_expr_call_type { =20 enum evtact_expr_builtin_type { EVTACT_EXPR_BUILTIN_TYPE_CPU, + EVTACT_EXPR_BUILTIN_TYPE_PID, EVTACT_EXPR_BUILTIN_TYPE_MAX, }; =20 diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l index dab8066a1038..5a5bbe3e1f94 100644 --- a/tools/perf/util/parse-action.l +++ b/tools/perf/util/parse-action.l @@ -104,6 +104,7 @@ ident [_a-zA-Z][_a-zA-Z0-9]* {space} { } =20 cpu { return builtin(EVTACT_EXPR_BUILTIN_TYPE_CPU); } +pid { return builtin(EVTACT_EXPR_BUILTIN_TYPE_PID); } =20 print { return call(EVTACT_EXPR_CALL_TYPE_PRINT); } =20 diff --git a/tools/perf/util/record_action.c b/tools/perf/util/record_actio= n.c index 15e8b1740e32..1d7b603713d1 100644 --- a/tools/perf/util/record_action.c +++ b/tools/perf/util/record_action.c @@ -96,6 +96,10 @@ static int set_expr_builtin_output_format(struct evtact_= expr *expr, *format =3D __OUTPUT_FORMAT_TYPE_CPU; size =3D sizeof(u32); break; + case EVTACT_EXPR_BUILTIN_TYPE_PID: + *format =3D __OUTPUT_FORMAT_TYPE_PID; + size =3D sizeof(u32); + break; default: pr_err("set expr builtin output format unknown opcode: %u\n", opcode); return -1; --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 7E655158527 for ; Thu, 28 Nov 2024 13:37:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801032; cv=none; b=R4YRMBcyV2G4rtggZJALCh1jKYPe/CXE0LDQp91E1xuH7g6XVE6JwInCDu7E57TgEtLXOXalQy2wOaP+74URssGj19gowYEu40xJfBWwutgwzTpy0S/sdXGr1XLlOsIADYALXQgkEp+iI7+w3Bcrykxp1GlQybI2FojeO/iVfk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801032; c=relaxed/simple; bh=DiJVAYAQcrZJd8gKJAcZ/lxvrshliSd5sO0F5CaEIj0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QPGZcL/9UIjYWJ/uF5xA9l6ddupPnprcYsl8dN2tp3zBXhfJeNApPFMJB1LX40FdzwZHFUxOmsuiUFhBnulcb/W/3lPbq/vyY68LV0DIn76c2U7NkM2IjtqILYVvvzvdVW1BixCQ1AbU0rLbSr92VTmujRQEbREFuq4XmmqzAh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=KovYsLmz; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="KovYsLmz" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-212348d391cso6323605ad.2 for ; Thu, 28 Nov 2024 05:37:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732801030; x=1733405830; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IH0bZMOBu3riqiEWEU9vnXR7lOK6GZQof6s3qx/MtSI=; b=KovYsLmzDKLKMvmdSk+pRmZhIUWiDnOqf8mRPW/NkGaVncYwHbPIvNlDuqGE6mDjUT 8mLYcY4r5iP/QFtWtaI6qXl7AZT+1KcwZK/PGccukd/YxNqWKiFVzkZOMNUpJjZLUlOs 9UkyI1LFTVIh+jCxB0v8BzCj+jrzgNOjkAAVSs5tRmzfQogWGOFyGLiksSlq5qjXeedZ rpg4HGHqBp4SPD+NgSUsfJKF6SuoCyISAX5M/+eJUH4+/JlGQF7o6GWOzE/gV05fU3cv Ll5RU4mOnLpHZsx9QE3Fi37jCMOMdvmRhYPE3Yk1bzJxMfwlmcz0ONqK6lMxWh4H4Nxe FFcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732801030; x=1733405830; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IH0bZMOBu3riqiEWEU9vnXR7lOK6GZQof6s3qx/MtSI=; b=GOP2k69QdDPy5gnI2kocCO8mGe1Ppr4cYsUS3pUrhrxZX5Hv0/bHEq37oLlwBoMo5L 0A/UuN9HcusdvEwQDCma6L6EUf9UEKUn2wC6fG2cGldNKP7hxOYuRoaLkJgVycoWZk5j kt/qOdNWFLZk9jaodUNE9Vc4YjtB5udrkkPAGFjGqbHQ3OATh8cfgEdA7id9jx3YRwFs tHjMGBtCnMIZf7gw8AuXNX7Kl0uIlYZBDqmP014JEy6rpVyejPMiKqOGKqtDK3NMndS6 jOKHU+FXk43MSAbq4PexGsspGi8IcKbchu97mGxkCCe+T6w86xcw+vh0SAEByO5llILq 6vkw== X-Forwarded-Encrypted: i=1; AJvYcCUox+6uS3Oc7idn1/jN0HYp0SDrxPvaHr3JO4BB8Fcp1ZFxt0BPiRTzliqr4EIfeOIbHWvfHXW+n5fEWw0=@vger.kernel.org X-Gm-Message-State: AOJu0YytKI3qfyRbm5h2wkLZ67zutKQfBpNz8j/YprUrA8u8EwxvTzUs u6ywzbZ6dN6J0m9c6bac4R90ltnY9/Gxgl03hDNLopL3ubv3+7FFJuQa5lD4qzU= X-Gm-Gg: ASbGncsEJ78ixbU8hGlAUTghCX5SW5dQ0Sr1BzmHLYU5SC7L5xezt1+NfOWmf7x2knK kNZfrcTChbgutMFp7hjrXxqv8FLCizZEVeLYWEAvCkKl+5iGytIAB/tf5x39To52nV4IH+XKiPy MrADw+nglLgEdLMJylVREwqTCZT2W6WS4mm1f+FNYv6LGnt6GvI5WDXXtkKSsZlzJgCbhv//OPr pnvOPKj63OlrIuq3o/tivvAWc9h3tdl7OutG+7pnMXH0WcVTBJksx7T+g== X-Google-Smtp-Source: AGHT+IHRR/nnxlLBQ0K72YvBnIQpQxBM2gsi0t+qZpJP/RxQa0B53I/b7kFI4jpJBRiClaBbUkYt4Q== X-Received: by 2002:a17:902:da92:b0:207:1675:6709 with SMTP id d9443c01a7336-21500fee592mr91980655ad.0.1732801029815; Thu, 28 Nov 2024 05:37:09 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:37:09 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 10/12] perf event action: Add parsing builtin tid expr support Date: Thu, 28 Nov 2024 21:35:51 +0800 Message-Id: <20241128133553.823722-11-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support parsing of builtin tid expression. Testcase: # perf record -e sched:sched_switch --action 'print("tid =3D %d\n", tid)'= true tid =3D 134891 tid =3D 0 tid =3D 134891 tid =3D 0 tid =3D 0 tid =3D 134891 tid =3D 132778 tid =3D 134891 tid =3D 132778 tid =3D 134891 tid =3D 132778 tid =3D 134891 tid =3D 132778 tid =3D 134891 tid =3D 132778 ... Signed-off-by: Yang Jihong --- tools/perf/util/bpf_skel/bpf_record_action.h | 1 + tools/perf/util/bpf_skel/record_action.bpf.c | 14 ++++++++++++++ tools/perf/util/parse-action.c | 1 + tools/perf/util/parse-action.h | 1 + tools/perf/util/parse-action.l | 1 + tools/perf/util/record_action.c | 4 ++++ 6 files changed, 22 insertions(+) diff --git a/tools/perf/util/bpf_skel/bpf_record_action.h b/tools/perf/util= /bpf_skel/bpf_record_action.h index a4817d62bce8..1d2ffa3c260f 100644 --- a/tools/perf/util/bpf_skel/bpf_record_action.h +++ b/tools/perf/util/bpf_skel/bpf_record_action.h @@ -9,6 +9,7 @@ enum __output_format_type { __OUTPUT_FORMAT_TYPE_CPU, __OUTPUT_FORMAT_TYPE_PID, + __OUTPUT_FORMAT_TYPE_TID, __OUTPUT_FORMAT_TYPE_MAX, }; =20 diff --git a/tools/perf/util/bpf_skel/record_action.bpf.c b/tools/perf/util= /bpf_skel/record_action.bpf.c index fd44bb3da663..b6049b9af055 100644 --- a/tools/perf/util/bpf_skel/record_action.bpf.c +++ b/tools/perf/util/bpf_skel/record_action.bpf.c @@ -57,6 +57,17 @@ static inline int output_pid(__u8 *data, int size) return sizeof(__u32); } =20 +static inline int output_tid(__u8 *data, int size) +{ + __u32 *pid =3D (__u32 *)data; + + if (size < sizeof(__u32)) + return -1; + + *pid =3D bpf_get_current_pid_tgid() & 0xffffffff; + return sizeof(__u32); +} + SEC("xxx") int sample_output(u64 *ctx) { @@ -82,6 +93,9 @@ int sample_output(u64 *ctx) case __OUTPUT_FORMAT_TYPE_PID: ret =3D output_pid(data + total, __OUTPUT_DATA_MAX_SIZE - total); break; + case __OUTPUT_FORMAT_TYPE_TID: + ret =3D output_tid(data + total, __OUTPUT_DATA_MAX_SIZE - total); + break; default: ret =3D -1; break; diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index 0ae998a5d286..6928990c9106 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -14,6 +14,7 @@ * - builtin: * - cpu * - pid + * - tid */ =20 #include diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index e74d3b4e5de8..817e2c4213e0 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -29,6 +29,7 @@ enum evtact_expr_call_type { enum evtact_expr_builtin_type { EVTACT_EXPR_BUILTIN_TYPE_CPU, EVTACT_EXPR_BUILTIN_TYPE_PID, + EVTACT_EXPR_BUILTIN_TYPE_TID, EVTACT_EXPR_BUILTIN_TYPE_MAX, }; =20 diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l index 5a5bbe3e1f94..2ada6b4bf091 100644 --- a/tools/perf/util/parse-action.l +++ b/tools/perf/util/parse-action.l @@ -105,6 +105,7 @@ ident [_a-zA-Z][_a-zA-Z0-9]* =20 cpu { return builtin(EVTACT_EXPR_BUILTIN_TYPE_CPU); } pid { return builtin(EVTACT_EXPR_BUILTIN_TYPE_PID); } +tid { return builtin(EVTACT_EXPR_BUILTIN_TYPE_TID); } =20 print { return call(EVTACT_EXPR_CALL_TYPE_PRINT); } =20 diff --git a/tools/perf/util/record_action.c b/tools/perf/util/record_actio= n.c index 1d7b603713d1..f4db98b7df4d 100644 --- a/tools/perf/util/record_action.c +++ b/tools/perf/util/record_action.c @@ -100,6 +100,10 @@ static int set_expr_builtin_output_format(struct evtac= t_expr *expr, *format =3D __OUTPUT_FORMAT_TYPE_PID; size =3D sizeof(u32); break; + case EVTACT_EXPR_BUILTIN_TYPE_TID: + *format =3D __OUTPUT_FORMAT_TYPE_TID; + size =3D sizeof(u32); + break; default: pr_err("set expr builtin output format unknown opcode: %u\n", opcode); return -1; --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 068441AE01D for ; Thu, 28 Nov 2024 13:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801039; cv=none; b=dWlOA2rm5fRm4cFP4EdnsGmfFKFTtveeInj8LlkRrHazVPlOJH3ocO7HhZqS8FIdEDfDfUrxMm5e9Qxe/+agcg/7VcN9Fu+HM1TA3MvBqnsMxl9ySiG1tJBsgPSVOEjsJjk6p3qFn87t3bAGV/uwpR2NnSsTThjmUT6sn//m9Ms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801039; c=relaxed/simple; bh=aCJwLOVVtyE/8Zq+i3p+hR8TjcyJ97yAVt7uvU+jGmY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JunHIJcXRYHYH3RnPalaaoAWM99s94aSmWz41Rxz1BmSY4niJys3qgg7gifZEqeEkv1+SijIHqpyZ5ioG0WYB9PSNIQVG6qMEQP/gI4tIZFs56sYk/a3sTjKHenW/+gxqtjGe29lbof7kUisxlomq8OidpnfWZ1ApfsmypZy62k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=CohC4Icn; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="CohC4Icn" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-21263dbbbc4so8188325ad.1 for ; Thu, 28 Nov 2024 05:37:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732801037; x=1733405837; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NwyLyxXascgIdIFuCrV9bXavAvFUrbiIh9Has6iaSvs=; b=CohC4IcnixUqUkvaXmr/sm4/HHjvCSfGL/bl6QusaaXUReAq0t1+N1DLX5p5fboexf Lox3EI51amleRMfWKticatlr+uvu2zq87QSrge4S2GrNi46g8oEMDed0/Qn4E0JM9Eis weCmF1pDVKOBQ54zalfAXAaLXakaWt61pIeUKk3qY4nDOS2F9fsx0npbqONBWTwJRaGk 6jgGl7gkYbCr7MBlcdWYOYmaC/jWM8YZU4yxQfvMSH67iVxohYpZukYJ68EbE12dMl7b qAt9e+Mspy49ctKroMXyAW7CRfdBYJc/zzQ6DQZxLVmjbJ+Jg1p48vMkO9N7MCaEQKXP TXxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732801037; x=1733405837; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NwyLyxXascgIdIFuCrV9bXavAvFUrbiIh9Has6iaSvs=; b=tH76W8AWWNM0PK50k8EUrx+1eWhwNZm8mX9drBxR6PJd1LsSZV6MVrMP9FPOcFgceU 7mJ2H2UR99x6vmY8odEle9nMRSvJurKDgcLANv6owHBIRSNvxrh+noLb6z+zB9kbKkmO 2lu+VOMvzMCuHmHOHGuEQDmRrT0W3RrKR5FQ3J9S4Tpkq5XhOhBwYqqEUHHKR0VqZiB8 KJrJcbJ1W+KgPxeOAQ2mN0TTKVRt1ASCr4enzbQNRf9z8yqeZTBqMXVSKaDIpyjcsLeb nUXHlRykrT67WghrlgWz6dhYIKee+9lcq1NPBrHtAoRmKy6A5R6jYJ/pP8Qfkk8kZmU1 yOBQ== X-Forwarded-Encrypted: i=1; AJvYcCVvSXZkfKUTdE6PTO5373LPhyanvc7Dj0S+BZw1t14IvdRTCc+14xVJEZWelTWnar+yfLqwLMr9CS/y1GI=@vger.kernel.org X-Gm-Message-State: AOJu0YxHuPUj7uI5138D2fCbZnHZ48f+nu7peqvKqTqSmMTMeHJM0koA RomyLraCklZMT92mR4g457uvUbH9SznlKKlLTUEjVHhMi4AtKS9d3j2VEaWx5Hw= X-Gm-Gg: ASbGncvpApjVgrxowqKKqfgUvm+CJD50jsCzlPGMSBCBOe6+o5L5JGitHxIrIOoSt+R Kzt5v+GLlm0n3yB47qIqKSBEtnk+4Uw0c7KwR4ExdCIQ7gymEcMTbzRZDNq7syz56w8neMm0AQv ewvJxdayHxAnHSyTdV71GqsStZscYm7tHlkqK1cdVmblHwVh1THV9sVQk8UoihjiuoKAB+ymxrJ gFFdXludxRzifcVliFR3Ooy9yvwo+ffKmWQj6GgoUbmW0WjSfbeTNPjmw== X-Google-Smtp-Source: AGHT+IE4a3HwlWMVvu8/IkbUqmVlhEIwHVCXNf6Xu3znJAzuSXsDK+/mKFwZPq9Fisvr4knYX9PbVQ== X-Received: by 2002:a17:902:ce88:b0:20c:c9db:7c45 with SMTP id d9443c01a7336-215010921d9mr72930415ad.20.1732801037414; Thu, 28 Nov 2024 05:37:17 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:37:14 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 11/12] perf event action: Add parsing builtin comm expr support Date: Thu, 28 Nov 2024 21:35:52 +0800 Message-Id: <20241128133553.823722-12-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support parsing of builtin comm expression. Testcase: # perf record -e sched:sched_switch --action 'print("comm =3D %s\n", comm= )' true comm =3D perf comm =3D swapper/7 comm =3D perf comm =3D swapper/7 comm =3D swapper/1 comm =3D perf comm =3D kworker/u40:0 comm =3D perf comm =3D kworker/u40:0 ... Signed-off-by: Yang Jihong --- tools/perf/util/bpf_skel/bpf_record_action.h | 1 + tools/perf/util/bpf_skel/record_action.bpf.c | 19 +++++++++++++++++++ tools/perf/util/parse-action.c | 1 + tools/perf/util/parse-action.h | 1 + tools/perf/util/parse-action.l | 1 + tools/perf/util/record_action.c | 4 ++++ 6 files changed, 27 insertions(+) diff --git a/tools/perf/util/bpf_skel/bpf_record_action.h b/tools/perf/util= /bpf_skel/bpf_record_action.h index 1d2ffa3c260f..325964b7aac9 100644 --- a/tools/perf/util/bpf_skel/bpf_record_action.h +++ b/tools/perf/util/bpf_skel/bpf_record_action.h @@ -10,6 +10,7 @@ enum __output_format_type { __OUTPUT_FORMAT_TYPE_CPU, __OUTPUT_FORMAT_TYPE_PID, __OUTPUT_FORMAT_TYPE_TID, + __OUTPUT_FORMAT_TYPE_COMM, __OUTPUT_FORMAT_TYPE_MAX, }; =20 diff --git a/tools/perf/util/bpf_skel/record_action.bpf.c b/tools/perf/util= /bpf_skel/record_action.bpf.c index b6049b9af055..f809305b16be 100644 --- a/tools/perf/util/bpf_skel/record_action.bpf.c +++ b/tools/perf/util/bpf_skel/record_action.bpf.c @@ -68,6 +68,22 @@ static inline int output_tid(__u8 *data, int size) return sizeof(__u32); } =20 +static inline int output_comm(__u8 *data, int size) +{ + struct task_struct *task =3D (struct task_struct *)bpf_get_current_task(); + + if (!task) { + data[0] =3D '\0'; + return 0; + } + + if (size < __TASK_COMM_MAX_SIZE) + return -1; + + bpf_core_read_str(data, __TASK_COMM_MAX_SIZE, &task->comm); + return __TASK_COMM_MAX_SIZE; +} + SEC("xxx") int sample_output(u64 *ctx) { @@ -96,6 +112,9 @@ int sample_output(u64 *ctx) case __OUTPUT_FORMAT_TYPE_TID: ret =3D output_tid(data + total, __OUTPUT_DATA_MAX_SIZE - total); break; + case __OUTPUT_FORMAT_TYPE_COMM: + ret =3D output_comm(data + total, __OUTPUT_DATA_MAX_SIZE - total); + break; default: ret =3D -1; break; diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index 6928990c9106..8bc1646abe27 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -15,6 +15,7 @@ * - cpu * - pid * - tid + * - comm */ =20 #include diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index 817e2c4213e0..39fb521f3193 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -30,6 +30,7 @@ enum evtact_expr_builtin_type { EVTACT_EXPR_BUILTIN_TYPE_CPU, EVTACT_EXPR_BUILTIN_TYPE_PID, EVTACT_EXPR_BUILTIN_TYPE_TID, + EVTACT_EXPR_BUILTIN_TYPE_COMM, EVTACT_EXPR_BUILTIN_TYPE_MAX, }; =20 diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l index 2ada6b4bf091..ddac305c1ca4 100644 --- a/tools/perf/util/parse-action.l +++ b/tools/perf/util/parse-action.l @@ -106,6 +106,7 @@ ident [_a-zA-Z][_a-zA-Z0-9]* cpu { return builtin(EVTACT_EXPR_BUILTIN_TYPE_CPU); } pid { return builtin(EVTACT_EXPR_BUILTIN_TYPE_PID); } tid { return builtin(EVTACT_EXPR_BUILTIN_TYPE_TID); } +comm { return builtin(EVTACT_EXPR_BUILTIN_TYPE_COMM); } =20 print { return call(EVTACT_EXPR_CALL_TYPE_PRINT); } =20 diff --git a/tools/perf/util/record_action.c b/tools/perf/util/record_actio= n.c index f4db98b7df4d..ead7eeffb7cc 100644 --- a/tools/perf/util/record_action.c +++ b/tools/perf/util/record_action.c @@ -104,6 +104,10 @@ static int set_expr_builtin_output_format(struct evtac= t_expr *expr, *format =3D __OUTPUT_FORMAT_TYPE_TID; size =3D sizeof(u32); break; + case EVTACT_EXPR_BUILTIN_TYPE_COMM: + *format =3D __OUTPUT_FORMAT_TYPE_COMM; + size =3D __TASK_COMM_MAX_SIZE; + break; default: pr_err("set expr builtin output format unknown opcode: %u\n", opcode); return -1; --=20 2.25.1 From nobody Sat Feb 7 07:25:43 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 C7E421BFE0D for ; Thu, 28 Nov 2024 13:37:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801045; cv=none; b=PX8JuMCVhtNDZMzcJ3m6AimXhALtZA4JjA6PcIXIGmsg1/3/aGwKMVnB2iR1wlki6oL0f1dFCluEqrg0QYeOzmJQhVYlPROPYmSrPdb5FdNwIQTGreLYre0XdweKTfvMiu27jm87dcEmW4e4TWNygMaAc8gBny/2n9U2uC0/d70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732801045; c=relaxed/simple; bh=Ku4hN7xfqlPUv5w30C4DCKNBadD3qKAbjpkGgl0RasU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FQsPx8pIs79zlyJppoxrAPKNWQFC6/lbThYQ6Edv8uXpgunmCa5xlqDjko68errwavng5o3yosYigP1wnCvPyZCvOEgEnca77/CgX5WSvKRvjwha2obD8CsVa6iQrBoTXkmQDfoESWUvzMxrPgK6UvzVIgmdSfIylEPJxW9mQZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=j1gmhwxI; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="j1gmhwxI" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-21200c749bfso7383925ad.1 for ; Thu, 28 Nov 2024 05:37:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732801043; x=1733405843; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OEQuel0RUI05tTYvOewxgm0mSB+lb7Esf6H6O4xZV1s=; b=j1gmhwxIMg4u/5OJ7PCjiCw94uQTNdIXIoJhvQNmv4QczEWkbWOZsOQX235Bo8jcqb Uf4k9najhsdEAUa1TdnLOrx35360hGkIxc6bgZMj9h+kSj9NRoGGz3IS0u8PJdVCTC3C QnrnKHGYZ+g36Gl7EvtO+YIjHnGJuD9RC24muouOW2EKplO0mVDCZhC2fbi6w7Nscqwq EM8JDAP733LEotG0kwzZ8931vVRMZafcv/AnDhVZurrQzdX9vFD89qScB3s1AQ+ilHCC IQjP9z/c4THJuQmXlpTxCw6kFWxoIW6piIJJhl75IwCFdecnIwaP5z06QIYC9BJQ9hN9 A3xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732801043; x=1733405843; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OEQuel0RUI05tTYvOewxgm0mSB+lb7Esf6H6O4xZV1s=; b=CmZ0ZxWFmMiNxQ6KxEzUXT5eJGuefZE5kXtRHJZvHC1c+dXhXZ8L0W7mPMNUa6HGzk aK0Poz/WfBmx41VMVD8a8KIL6Vm+z1afDEHBR/PcKdfaHkv1SDIo7Ha+ZINwxyEEMjIo 8carh5vaxW6r3JWEiTY4fJcA6ACqxd0RMPSDoDWJD7a/7sTSuyiJmo3Kv1M0kmD4nsLw TP0h424Yhx+IRwW0UoHMSZNAI61PcpY7nCXFTM91sZRylXMGNbo2R3XQ+Avg7FU0muaF uIpEZ3HUqTP1qK45dK8Araxf9hN4Ar0jFgLUUIrskYfVqTe49Rp5uT/1ECKYaz5Nrd8x LM7w== X-Forwarded-Encrypted: i=1; AJvYcCW4eHhvbS8CKFKzghgWqKxtKqlsqxyypHuao0v7vwEJwU56E7PAXakq/kyiNJ42XdC2TTnJX8KypUnnimE=@vger.kernel.org X-Gm-Message-State: AOJu0YwflmC5mjcmpLKTf3oXKl54HRtTMCR0ESQluVqIecJkLbsUA84M noVDxSw5Cbk1nzJWYeOPyNKymvDzBWNuTf7yOE/WiwbQCXX7OTjWNz2RjSGiGig= X-Gm-Gg: ASbGncs5iJuO0dvFwnWkBRoJ4ia3ILKEER4dTzpOgrS1JaABw/Cr2IN6trYIxxx8721 FHCnf6kKckXR3139zfBy7mmuzboT+eogackt98jlaIdNYmeMwYUUvcYwStJ3SiiUzDd0xcHDeSK gI6Jmh5Y98ChW+VZVmuQ8bNcbSoQLUczVKdJ3R4poasWTEvFONQoFCTjNXmlj7BcynJSWmSpKUY L5Q6jeeoa95bLW07GeMAZycCm7WGoqG+vDfkwn6W62fZXH4+GxL2Hg3IQ== X-Google-Smtp-Source: AGHT+IGJDPD9pE+AeJXDwNp8BJXO/DIHoUo2WDZp9IvM7Np2ou1DN2+QaRrIFaalT7td21LjD7k1Vw== X-Received: by 2002:a17:902:fc47:b0:20c:6bff:fcae with SMTP id d9443c01a7336-21501095f5fmr92201495ad.5.1732801043131; Thu, 28 Nov 2024 05:37:23 -0800 (PST) Received: from ubuntu20.04 ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21521985632sm12952975ad.206.2024.11.28.05.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 05:37:22 -0800 (PST) From: Yang Jihong To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, james.clark@arm.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yangjihong@bytedance.com Subject: [RFC 12/12] perf event action: Add parsing builtin time expr support Date: Thu, 28 Nov 2024 21:35:53 +0800 Message-Id: <20241128133553.823722-13-yangjihong@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com> References: <20241128133553.823722-1-yangjihong@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support parsing of builtin time expression. Testcase: # perf record -e sched:sched_switch --action 'print("time =3D %llu\n", ti= me)' true time =3D 787661350481404 time =3D 787661350483823 time =3D 787661350493754 time =3D 787661350623109 time =3D 787661350482984 time =3D 787661350642538 time =3D 787661350647575 time =3D 787661350649706 time =3D 787661350650968 time =3D 787661350653686 time =3D 787661350654928 ... Signed-off-by: Yang Jihong --- tools/perf/util/bpf_skel/bpf_record_action.h | 1 + tools/perf/util/bpf_skel/record_action.bpf.c | 14 ++++++++++++++ tools/perf/util/parse-action.c | 1 + tools/perf/util/parse-action.h | 1 + tools/perf/util/parse-action.l | 1 + tools/perf/util/record_action.c | 4 ++++ 6 files changed, 22 insertions(+) diff --git a/tools/perf/util/bpf_skel/bpf_record_action.h b/tools/perf/util= /bpf_skel/bpf_record_action.h index 325964b7aac9..e514ac14705e 100644 --- a/tools/perf/util/bpf_skel/bpf_record_action.h +++ b/tools/perf/util/bpf_skel/bpf_record_action.h @@ -11,6 +11,7 @@ enum __output_format_type { __OUTPUT_FORMAT_TYPE_PID, __OUTPUT_FORMAT_TYPE_TID, __OUTPUT_FORMAT_TYPE_COMM, + __OUTPUT_FORMAT_TYPE_TIME, __OUTPUT_FORMAT_TYPE_MAX, }; =20 diff --git a/tools/perf/util/bpf_skel/record_action.bpf.c b/tools/perf/util= /bpf_skel/record_action.bpf.c index f809305b16be..ed36f121e90b 100644 --- a/tools/perf/util/bpf_skel/record_action.bpf.c +++ b/tools/perf/util/bpf_skel/record_action.bpf.c @@ -84,6 +84,17 @@ static inline int output_comm(__u8 *data, int size) return __TASK_COMM_MAX_SIZE; } =20 +static inline int output_time(__u8 *data, int size) +{ + __u64 *ts =3D (__u64 *)data; + + if (size < sizeof(__u64)) + return -1; + + *ts =3D bpf_ktime_get_ns(); + return sizeof(__u64); +} + SEC("xxx") int sample_output(u64 *ctx) { @@ -115,6 +126,9 @@ int sample_output(u64 *ctx) case __OUTPUT_FORMAT_TYPE_COMM: ret =3D output_comm(data + total, __OUTPUT_DATA_MAX_SIZE - total); break; + case __OUTPUT_FORMAT_TYPE_TIME: + ret =3D output_time(data + total, __OUTPUT_DATA_MAX_SIZE - total); + break; default: ret =3D -1; break; diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c index 8bc1646abe27..4f40e4a24357 100644 --- a/tools/perf/util/parse-action.c +++ b/tools/perf/util/parse-action.c @@ -16,6 +16,7 @@ * - pid * - tid * - comm + * - time */ =20 #include diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h index 39fb521f3193..57df6f8294f5 100644 --- a/tools/perf/util/parse-action.h +++ b/tools/perf/util/parse-action.h @@ -31,6 +31,7 @@ enum evtact_expr_builtin_type { EVTACT_EXPR_BUILTIN_TYPE_PID, EVTACT_EXPR_BUILTIN_TYPE_TID, EVTACT_EXPR_BUILTIN_TYPE_COMM, + EVTACT_EXPR_BUILTIN_TYPE_TIME, EVTACT_EXPR_BUILTIN_TYPE_MAX, }; =20 diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l index ddac305c1ca4..9029ac19c128 100644 --- a/tools/perf/util/parse-action.l +++ b/tools/perf/util/parse-action.l @@ -107,6 +107,7 @@ cpu { return builtin(EVTACT_EXPR_BUILTIN_TYPE_CPU); } pid { return builtin(EVTACT_EXPR_BUILTIN_TYPE_PID); } tid { return builtin(EVTACT_EXPR_BUILTIN_TYPE_TID); } comm { return builtin(EVTACT_EXPR_BUILTIN_TYPE_COMM); } +time { return builtin(EVTACT_EXPR_BUILTIN_TYPE_TIME); } =20 print { return call(EVTACT_EXPR_CALL_TYPE_PRINT); } =20 diff --git a/tools/perf/util/record_action.c b/tools/perf/util/record_actio= n.c index ead7eeffb7cc..4de6afcbfb26 100644 --- a/tools/perf/util/record_action.c +++ b/tools/perf/util/record_action.c @@ -108,6 +108,10 @@ static int set_expr_builtin_output_format(struct evtac= t_expr *expr, *format =3D __OUTPUT_FORMAT_TYPE_COMM; size =3D __TASK_COMM_MAX_SIZE; break; + case EVTACT_EXPR_BUILTIN_TYPE_TIME: + *format =3D __OUTPUT_FORMAT_TYPE_TIME; + size =3D sizeof(u64); + break; default: pr_err("set expr builtin output format unknown opcode: %u\n", opcode); return -1; --=20 2.25.1