From patchwork Mon Dec 5 08:29:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Chen X-Patchwork-Id: 29598 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2131650wrr; Mon, 5 Dec 2022 00:37:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf6UT9YO6cNnA+2vY9Mgz9F9gtAvLh6R3tjqlJ4c01gsdQrd7wwEs7Sb5pYBupN00LOWcTMT X-Received: by 2002:a17:906:180e:b0:7a2:6d38:1085 with SMTP id v14-20020a170906180e00b007a26d381085mr52499280eje.114.1670229421615; Mon, 05 Dec 2022 00:37:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670229421; cv=none; d=google.com; s=arc-20160816; b=mF70RlznbtkhARCgDy6hV56L+LLqg4ZHs7lhCAI8/3r4A67ozoRfFd0S/Ef24aRIqN Cul98ijbqV08UMrkS2sk5Ei417x7EI/dfG3aXbiUEq0MFVTOPJ7YaJ7JtdwaqeOFZImw w15SjImqhyUsctdeUJyUhsY6O6sxJKYdAfs/xKX1zoCu8UkAJsFmw6h1LXO9ygChFO85 c389Lsg7knOJuFm7LnENITkbjukfAdKh7kWWQ+rWX9hkAe8kxh0V1eHOYQOJ4BN/+fUi a4gHJQ+ig9EH5VxTaEqT5ZOeEl/dL1tIMQ4d2XZRTahhRKEWrlJvONxzkSivVE7+tbCo yYPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=T0iubkX/aGcE5J0sCAGGmZH3x+m4tjyk3l6b6YP0zOQ=; b=RYZEjBTwHEBwgnHxcBuqfyB3XZIZUUO/GN7rGu6FWuyeYKEBF80qpRwUCbZaJUjMFi t1plD5xRmzP5VA8kex306JQAWEaGmYvWrx7DGQFSv4jiuoLJRvbFcuRJDwWmkipx6p8Y Jp3b2A1+TMzh8+gqZ/Img0Rt5FdwmXUfcs38gm5Ohpvc1LoZw9O99NOFrPVaJTh9VM22 pRU55L1Z4tfe7ppwf8bS2e6V7X4b+jHRsH7SAbdh2ynRDhJpJjWt+okTwMGWmpgzLOtF 3ePh5hfDHBYWQmxAkOvqkf+DMdL20LVjYtvL9TkYflpLbUf2OQBjO8dUk/6egIq5V9ng jGgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb40-20020a170907962800b007ae4717bf08si12671470ejc.359.2022.12.05.00.36.38; Mon, 05 Dec 2022 00:37:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231825AbiLEI0d (ORCPT + 99 others); Mon, 5 Dec 2022 03:26:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231530AbiLEI0b (ORCPT ); Mon, 5 Dec 2022 03:26:31 -0500 X-Greylist: delayed 224 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 05 Dec 2022 00:26:29 PST Received: from 189.cn (ptr.189.cn [183.61.185.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7710DA1A9; Mon, 5 Dec 2022 00:26:29 -0800 (PST) HMM_SOURCE_IP: 10.64.8.31:42842.508648307 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-123.150.8.42 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id 3A51D1002F0; Mon, 5 Dec 2022 16:22:57 +0800 (CST) Received: from ([123.150.8.42]) by gateway-153622-dep-6cffbd87dd-pzsb9 with ESMTP id 284d2c4e1823427eb96ba1d9d9009b4e for rostedt@goodmis.org; Mon, 05 Dec 2022 16:22:58 CST X-Transaction-ID: 284d2c4e1823427eb96ba1d9d9009b4e X-Real-From: chensong_2000@189.cn X-Receive-IP: 123.150.8.42 X-MEDUSA-Status: 0 Sender: chensong_2000@189.cn From: Song Chen To: rostedt@goodmis.org, mhiramat@kernel.org, arnd@arndb.de Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Song Chen Subject: [PATCH v3 1/4] kernel/trace: Introduce trace_probe_print_args and use it in *probes Date: Mon, 5 Dec 2022 16:29:47 +0800 Message-Id: <1670228987-3977-1-git-send-email-chensong_2000@189.cn> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751362486005738730?= X-GMAIL-MSGID: =?utf-8?q?1751362486005738730?= print_probe_args is currently inplemented in trace_probe_tmpl.h and included by *probes, as a result, each probe has an identical copy. This patch will move it to trace_probe.c as an new API, each probe calls it to print their args in trace file. Signed-off-by: Song Chen --- kernel/trace/trace_eprobe.c | 2 +- kernel/trace/trace_kprobe.c | 4 ++-- kernel/trace/trace_probe.c | 27 +++++++++++++++++++++++++++ kernel/trace/trace_probe.h | 2 ++ kernel/trace/trace_probe_tmpl.h | 28 ---------------------------- kernel/trace/trace_uprobe.c | 2 +- 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index 5dd0617e5df6..bdb26eee7a0c 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -310,7 +310,7 @@ print_eprobe_event(struct trace_iterator *iter, int flags, trace_seq_putc(s, ')'); - if (print_probe_args(s, tp->args, tp->nr_args, + if (trace_probe_print_args(s, tp->args, tp->nr_args, (u8 *)&field[1], field) < 0) goto out; diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 5a75b039e586..a4ffa864dbb7 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -1426,7 +1426,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags, trace_seq_putc(s, ')'); - if (print_probe_args(s, tp->args, tp->nr_args, + if (trace_probe_print_args(s, tp->args, tp->nr_args, (u8 *)&field[1], field) < 0) goto out; @@ -1461,7 +1461,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags, trace_seq_putc(s, ')'); - if (print_probe_args(s, tp->args, tp->nr_args, + if (trace_probe_print_args(s, tp->args, tp->nr_args, (u8 *)&field[1], field) < 0) goto out; diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 36dff277de46..ae13b6b2d5da 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1218,3 +1218,30 @@ int trace_probe_create(const char *raw_command, int (*createfn)(int, const char return ret; } + +int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args, + u8 *data, void *field) +{ + void *p; + int i, j; + + for (i = 0; i < nr_args; i++) { + struct probe_arg *a = args + i; + + trace_seq_printf(s, " %s=", a->name); + if (likely(!a->count)) { + if (!a->type->print(s, data + a->offset, field)) + return -ENOMEM; + continue; + } + trace_seq_putc(s, '{'); + p = data + a->offset; + for (j = 0; j < a->count; j++) { + if (!a->type->print(s, p, field)) + return -ENOMEM; + trace_seq_putc(s, j == a->count - 1 ? '}' : ','); + p += a->type->size; + } + } + return 0; +} diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index de38f1c03776..cfef198013af 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -343,6 +343,8 @@ int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b); bool trace_probe_match_command_args(struct trace_probe *tp, int argc, const char **argv); int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **)); +int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args, + u8 *data, void *field); #define trace_probe_for_each_link(pos, tp) \ list_for_each_entry(pos, &(tp)->event->files, list) diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index b3bdb8ddb862..1b57420857e1 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -212,31 +212,3 @@ store_trace_args(void *data, struct trace_probe *tp, void *rec, } } } - -static inline int -print_probe_args(struct trace_seq *s, struct probe_arg *args, int nr_args, - u8 *data, void *field) -{ - void *p; - int i, j; - - for (i = 0; i < nr_args; i++) { - struct probe_arg *a = args + i; - - trace_seq_printf(s, " %s=", a->name); - if (likely(!a->count)) { - if (!a->type->print(s, data + a->offset, field)) - return -ENOMEM; - continue; - } - trace_seq_putc(s, '{'); - p = data + a->offset; - for (j = 0; j < a->count; j++) { - if (!a->type->print(s, p, field)) - return -ENOMEM; - trace_seq_putc(s, j == a->count - 1 ? '}' : ','); - p += a->type->size; - } - } - return 0; -} diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index fb58e86dd117..1ff8f87211a6 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -1041,7 +1041,7 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e data = DATAOF_TRACE_ENTRY(entry, false); } - if (print_probe_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0) + if (trace_probe_print_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0) goto out; trace_seq_putc(s, '\n');