From patchwork Thu Nov 24 14:50:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25601 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3441517wrr; Thu, 24 Nov 2022 06:52:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf456C2z8WQxCRGfq5U4ydWyirUkPu/JKGiSKhaYLS6mUETK1A9EQ6x42C/flt0M9SshQhFB X-Received: by 2002:a17:906:edd2:b0:7bb:1424:b112 with SMTP id sb18-20020a170906edd200b007bb1424b112mr3359083ejb.168.1669301537539; Thu, 24 Nov 2022 06:52:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301537; cv=none; d=google.com; s=arc-20160816; b=OGtxIzD7EA5kfhutjTTxzTLv3ohPhlGXo862PUDMEIrQbpiB6ILgL4CgXH5nsiu40E fJobOpw6+CdNzrE3d68Imsl0rwukf1b92eS6IwBusLeQlJdqZ3BBVOrRH5QmN0skCqID Q8VQXgbpAK1JjEGWOjuPVGGRhajJGbfjraBoH5FnDHndOJazsLpZMtXA7sMO1WZQX2Gy nSX1CKLsy8HyvNahbwJBk3axGgp5n/AVEqVKx7eIoPqGjVh1Jpc6tKfHe/CA1cZ9zSJD nPxM+Hbf6DQ0f0ACuXdUI7yIntPgdIi1TsjyOIVlFNjLYUxW+WzDJgcVVauVupG4BN17 F9aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=RG/rbw2lt2Sa/LHCZzO53iOZ8G4uwOh36t9/K8+HICE=; b=u0AF1ZlWFTBVeJcHwWKT0UDtR2PgvJsX5LGcoP0X6jWdj3Pe+UrplxfYW5ygMNc5y3 Hv6jc20Zvo2dwM6ZGpgDRZxiJkCfd0ltlwqN2/DwZ5SGFRxi5OjMgbtPok241FexqBZK s1xamKbLFCskTCZfZmlXVSSQi7+QAtjWMMqu60I4KiNK2Ox+36R0bvStlPYVNK2QTO1x Qy/XwQ++plahOuVtZ2qPUCsjYmRfPVRwjzL8WxFuB7SSYuH4/S2FIJqz5eMcXXNUM5jx gYZlqKy5d8juxYdSIomMnyDht29URQK83vwkuLeXqZhDbwPY4oh4xxYIhV7XuwM8Z5uw 4Wtw== 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 ht14-20020a170907608e00b00711da52c6e4si815735ejc.309.2022.11.24.06.51.52; Thu, 24 Nov 2022 06:52:17 -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 S229833AbiKXOvY (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbiKXOu7 (ORCPT ); Thu, 24 Nov 2022 09:50:59 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5535512E206 for ; Thu, 24 Nov 2022 06:50:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 02863B8283B for ; Thu, 24 Nov 2022 14:50:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B84BEC433D7; Thu, 24 Nov 2022 14:50:46 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYr-001X2a-2L; Thu, 24 Nov 2022 09:50:45 -0500 Message-ID: <20221124145045.604009892@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:20 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Zheng Yejian Subject: [for-next][PATCH 01/11] ftrace: Clean comments related to FTRACE_OPS_FL_PER_CPU References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1750389528786965276?= X-GMAIL-MSGID: =?utf-8?q?1750389528786965276?= From: Zheng Yejian Commit b3a88803ac5b ("ftrace: Kill FTRACE_OPS_FL_PER_CPU") didn't completely remove the comments related to FTRACE_OPS_FL_PER_CPU. Link: https://lkml.kernel.org/r/20221025153923.1995973-1-zhengyejian1@huawei.com Fixes: b3a88803ac5b ("ftrace: Kill FTRACE_OPS_FL_PER_CPU") Signed-off-by: Zheng Yejian Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 33236241f236..65a5d36463e0 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -163,7 +163,7 @@ static void ftrace_sync_ipi(void *data) static ftrace_func_t ftrace_ops_get_list_func(struct ftrace_ops *ops) { /* - * If this is a dynamic, RCU, or per CPU ops, or we force list func, + * If this is a dynamic or RCU ops, or we force list func, * then it needs to call the list anyway. */ if (ops->flags & (FTRACE_OPS_FL_DYNAMIC | FTRACE_OPS_FL_RCU) || @@ -3071,8 +3071,6 @@ int ftrace_shutdown(struct ftrace_ops *ops, int command) /* * Dynamic ops may be freed, we must make sure that all * callers are done before leaving this function. - * The same goes for freeing the per_cpu data of the per_cpu - * ops. */ if (ops->flags & FTRACE_OPS_FL_DYNAMIC) { /* @@ -7519,8 +7517,6 @@ __ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip, /* * Check the following for each ops before calling their func: * if RCU flag is set, then rcu_is_watching() must be true - * if PER_CPU is set, then ftrace_function_local_disable() - * must be false * Otherwise test if the ip matches the ops filter * * If any of the above fails then the op->func() is not executed. @@ -7570,8 +7566,8 @@ NOKPROBE_SYMBOL(arch_ftrace_ops_list_func); /* * If there's only one function registered but it does not support - * recursion, needs RCU protection and/or requires per cpu handling, then - * this function will be called by the mcount trampoline. + * recursion, needs RCU protection, then this function will be called + * by the mcount trampoline. */ static void ftrace_ops_assist_func(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs) From patchwork Thu Nov 24 14:50:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25604 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3442077wrr; Thu, 24 Nov 2022 06:53:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4lM+4Fsfd3pM4ZN8jpXsJLVVK3ovf00enOBNQAiEJoWutecEVsORzSa0y0bBtAIs2hVATu X-Received: by 2002:aa7:cd99:0:b0:462:719:3372 with SMTP id x25-20020aa7cd99000000b0046207193372mr30777466edv.361.1669301622777; Thu, 24 Nov 2022 06:53:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301622; cv=none; d=google.com; s=arc-20160816; b=v5CW10AiRTVQIKJ3SHUqwtuglinewJnXBRXGB6aRqdqnN3tXG0QY4muBgsxn5pHK0K uDqoJNGatGkWW9zo9ZoO2MGIVquimhavPF+3Pdew2CpRictO7vlfb8y3Rcxj7ft6n0S7 Si52u4hFrh32ma++I9UGsKRLbkmE3LGEDf9h7wJ71oszYa1FMKzWqV36gdPA/7jPQfsh qgntbos5PYgmlQox8zG+lFB84CnC83ns7KkH2pyOTr4h86zX4oKbqiajv99ugg3+ZqeX iALiSGXj3lp5JnfhisMOeD4EK42NGcyHwSGAvD0SkPSzlDTPy6Nj0NC/2+7bQqx2xe6i oUrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=MWTqObLTyhV4MjgwawNgVNP4Zej8Dsg0xcG5C1raG2I=; b=dfYNQcylJME3B3xpMGBhaCnY12wyVqH/KhVBcinRKc/ZslHDUhdK7G38JNDrt+aJIJ F/hgtsZ6x2jZijwRbQ4kRTheu3erVyVvalHID1tll3ImyqRaHTVTNvQRQw91GSq9hJ9H R56Fls5Q+kBpHyXYINWZiKAD/YSIvcpnB8dp2xxlVBmJ45zEBpAn3Pph3fXmoaqVrbZP x28dImGkwa19OVlRAOkdliWzq9+GsDUi1mC9KW+BYfuxD+rwux+orKY/S/suPbkNNrCG jonzufmkVSUWi3A4JugaO3VzSgjy7KjUCOm+99IuVw9anw+Gcu7WUeQjaSwnjhELFNfL rZtA== 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 ji11-20020a170907980b00b007adcaf49e94si260725ejc.157.2022.11.24.06.53.17; Thu, 24 Nov 2022 06:53:42 -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 S229943AbiKXOvb (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbiKXOvC (ORCPT ); Thu, 24 Nov 2022 09:51:02 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E20C112E217 for ; Thu, 24 Nov 2022 06:50:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 589D3B82845 for ; Thu, 24 Nov 2022 14:50:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D14E1C43470; Thu, 24 Nov 2022 14:50:46 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYr-001X34-2m; Thu, 24 Nov 2022 09:50:45 -0500 Message-ID: <20221124145045.743308431@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:21 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Valentin Schneider Subject: [for-next][PATCH 02/11] tracing: Add __cpumask to denote a trace event field that is a cpumask_t References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1750389618260044928?= X-GMAIL-MSGID: =?utf-8?q?1750389618260044928?= From: "Steven Rostedt (Google)" The trace events have a __bitmask field that can be used for anything that requires bitmasks. Although currently it is only used for CPU masks, it could be used in the future for any type of bitmasks. There is some user space tooling that wants to know if a field is a CPU mask and not just some random unsigned long bitmask. Introduce "__cpumask()" helper functions that work the same as the current __bitmask() helpers but displays in the format file: field:__data_loc cpumask_t *[] mask; offset:36; size:4; signed:0; Instead of: field:__data_loc unsigned long[] mask; offset:32; size:4; signed:0; The main difference is the type. Instead of "unsigned long" it is "cpumask_t *". Note, this type field needs to be a real type in the __dynamic_array() logic that both __cpumask and__bitmask use, but the comparison field requires it to be a scalar type whereas cpumask_t is a structure (non-scalar). But everything works when making it a pointer. Valentin added changes to remove the need of passing in "nr_bits" and the __cpumask will always use nr_cpumask_bits as its size. Link: https://lkml.kernel.org/r/20221014080456.1d32b989@rorschach.local.home Requested-by: Valentin Schneider Reviewed-by: Valentin Schneider Signed-off-by: Valentin Schneider Signed-off-by: Steven Rostedt (Google) --- include/trace/bpf_probe.h | 6 ++++ include/trace/perf.h | 6 ++++ include/trace/stages/stage1_struct_define.h | 6 ++++ include/trace/stages/stage2_data_offsets.h | 6 ++++ include/trace/stages/stage3_trace_output.h | 6 ++++ include/trace/stages/stage4_event_fields.h | 6 ++++ include/trace/stages/stage5_get_offsets.h | 6 ++++ include/trace/stages/stage6_event_callback.h | 20 ++++++++++++ include/trace/stages/stage7_class_define.h | 2 ++ samples/trace_events/trace-events-sample.c | 2 +- samples/trace_events/trace-events-sample.h | 34 +++++++++++++++----- 11 files changed, 91 insertions(+), 9 deletions(-) diff --git a/include/trace/bpf_probe.h b/include/trace/bpf_probe.h index 6a13220d2d27..155c495b89ea 100644 --- a/include/trace/bpf_probe.h +++ b/include/trace/bpf_probe.h @@ -21,6 +21,9 @@ #undef __get_bitmask #define __get_bitmask(field) (char *)__get_dynamic_array(field) +#undef __get_cpumask +#define __get_cpumask(field) (char *)__get_dynamic_array(field) + #undef __get_sockaddr #define __get_sockaddr(field) ((struct sockaddr *)__get_dynamic_array(field)) @@ -40,6 +43,9 @@ #undef __get_rel_bitmask #define __get_rel_bitmask(field) (char *)__get_rel_dynamic_array(field) +#undef __get_rel_cpumask +#define __get_rel_cpumask(field) (char *)__get_rel_dynamic_array(field) + #undef __get_rel_sockaddr #define __get_rel_sockaddr(field) ((struct sockaddr *)__get_rel_dynamic_array(field)) diff --git a/include/trace/perf.h b/include/trace/perf.h index 5800d13146c3..8f3bf1e17707 100644 --- a/include/trace/perf.h +++ b/include/trace/perf.h @@ -21,6 +21,9 @@ #undef __get_bitmask #define __get_bitmask(field) (char *)__get_dynamic_array(field) +#undef __get_cpumask +#define __get_cpumask(field) (char *)__get_dynamic_array(field) + #undef __get_sockaddr #define __get_sockaddr(field) ((struct sockaddr *)__get_dynamic_array(field)) @@ -41,6 +44,9 @@ #undef __get_rel_bitmask #define __get_rel_bitmask(field) (char *)__get_rel_dynamic_array(field) +#undef __get_rel_cpumask +#define __get_rel_cpumask(field) (char *)__get_rel_dynamic_array(field) + #undef __get_rel_sockaddr #define __get_rel_sockaddr(field) ((struct sockaddr *)__get_rel_dynamic_array(field)) diff --git a/include/trace/stages/stage1_struct_define.h b/include/trace/stages/stage1_struct_define.h index 1b7bab60434c..69e0dae453bf 100644 --- a/include/trace/stages/stage1_struct_define.h +++ b/include/trace/stages/stage1_struct_define.h @@ -32,6 +32,9 @@ #undef __bitmask #define __bitmask(item, nr_bits) __dynamic_array(char, item, -1) +#undef __cpumask +#define __cpumask(item) __dynamic_array(char, item, -1) + #undef __sockaddr #define __sockaddr(field, len) __dynamic_array(u8, field, len) @@ -47,6 +50,9 @@ #undef __rel_bitmask #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(char, item, -1) +#undef __rel_cpumask +#define __rel_cpumask(item) __rel_dynamic_array(char, item, -1) + #undef __rel_sockaddr #define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len) diff --git a/include/trace/stages/stage2_data_offsets.h b/include/trace/stages/stage2_data_offsets.h index 1b7a8f764fdd..469b6a64293d 100644 --- a/include/trace/stages/stage2_data_offsets.h +++ b/include/trace/stages/stage2_data_offsets.h @@ -38,6 +38,9 @@ #undef __bitmask #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1) +#undef __cpumask +#define __cpumask(item) __dynamic_array(unsigned long, item, -1) + #undef __sockaddr #define __sockaddr(field, len) __dynamic_array(u8, field, len) @@ -53,5 +56,8 @@ #undef __rel_bitmask #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1) +#undef __rel_cpumask +#define __rel_cpumask(item) __rel_dynamic_array(unsigned long, item, -1) + #undef __rel_sockaddr #define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len) diff --git a/include/trace/stages/stage3_trace_output.h b/include/trace/stages/stage3_trace_output.h index e3b183e9d18e..66374df61ed3 100644 --- a/include/trace/stages/stage3_trace_output.h +++ b/include/trace/stages/stage3_trace_output.h @@ -42,6 +42,9 @@ trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \ }) +#undef __get_cpumask +#define __get_cpumask(field) __get_bitmask(field) + #undef __get_rel_bitmask #define __get_rel_bitmask(field) \ ({ \ @@ -51,6 +54,9 @@ trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \ }) +#undef __get_rel_cpumask +#define __get_rel_cpumask(field) __get_rel_bitmask(field) + #undef __get_sockaddr #define __get_sockaddr(field) ((struct sockaddr *)__get_dynamic_array(field)) diff --git a/include/trace/stages/stage4_event_fields.h b/include/trace/stages/stage4_event_fields.h index a8fb25f39a99..f2990d22313c 100644 --- a/include/trace/stages/stage4_event_fields.h +++ b/include/trace/stages/stage4_event_fields.h @@ -46,6 +46,9 @@ #undef __bitmask #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1) +#undef __cpumask +#define __cpumask(item) __dynamic_array(cpumask_t *, item, -1) + #undef __sockaddr #define __sockaddr(field, len) __dynamic_array(u8, field, len) @@ -64,5 +67,8 @@ #undef __rel_bitmask #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1) +#undef __rel_cpumask +#define __rel_cpumask(item) __rel_dynamic_array(cpumask_t *, item, -1) + #undef __rel_sockaddr #define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len) diff --git a/include/trace/stages/stage5_get_offsets.h b/include/trace/stages/stage5_get_offsets.h index fba4c24ed9e6..ac5c24d3beeb 100644 --- a/include/trace/stages/stage5_get_offsets.h +++ b/include/trace/stages/stage5_get_offsets.h @@ -82,10 +82,16 @@ #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \ __bitmask_size_in_longs(nr_bits)) +#undef __cpumask +#define __cpumask(item) __bitmask(item, nr_cpumask_bits) + #undef __rel_bitmask #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, \ __bitmask_size_in_longs(nr_bits)) +#undef __rel_cpumask +#define __rel_cpumask(item) __rel_bitmask(item, nr_cpumask_bits) + #undef __sockaddr #define __sockaddr(field, len) __dynamic_array(u8, field, len) diff --git a/include/trace/stages/stage6_event_callback.h b/include/trace/stages/stage6_event_callback.h index 3c554a585320..49c32394b53f 100644 --- a/include/trace/stages/stage6_event_callback.h +++ b/include/trace/stages/stage6_event_callback.h @@ -57,6 +57,16 @@ #define __assign_bitmask(dst, src, nr_bits) \ memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits)) +#undef __cpumask +#define __cpumask(item) __dynamic_array(unsigned long, item, -1) + +#undef __get_cpumask +#define __get_cpumask(field) (char *)__get_dynamic_array(field) + +#undef __assign_cpumask +#define __assign_cpumask(dst, src) \ + memcpy(__get_cpumask(dst), (src), __bitmask_size_in_bytes(nr_cpumask_bits)) + #undef __sockaddr #define __sockaddr(field, len) __dynamic_array(u8, field, len) @@ -98,6 +108,16 @@ #define __assign_rel_bitmask(dst, src, nr_bits) \ memcpy(__get_rel_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits)) +#undef __rel_cpumask +#define __rel_cpumask(item) __rel_dynamic_array(unsigned long, item, -1) + +#undef __get_rel_cpumask +#define __get_rel_cpumask(field) (char *)__get_rel_dynamic_array(field) + +#undef __assign_rel_cpumask +#define __assign_rel_cpumask(dst, src) \ + memcpy(__get_rel_cpumask(dst), (src), __bitmask_size_in_bytes(nr_cpumask_bits)) + #undef __rel_sockaddr #define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len) diff --git a/include/trace/stages/stage7_class_define.h b/include/trace/stages/stage7_class_define.h index 8a7ec24c246d..8795429f388b 100644 --- a/include/trace/stages/stage7_class_define.h +++ b/include/trace/stages/stage7_class_define.h @@ -13,11 +13,13 @@ #undef __get_dynamic_array_len #undef __get_str #undef __get_bitmask +#undef __get_cpumask #undef __get_sockaddr #undef __get_rel_dynamic_array #undef __get_rel_dynamic_array_len #undef __get_rel_str #undef __get_rel_bitmask +#undef __get_rel_cpumask #undef __get_rel_sockaddr #undef __print_array #undef __print_hex_dump diff --git a/samples/trace_events/trace-events-sample.c b/samples/trace_events/trace-events-sample.c index 608c4ae3b08a..ecc7db237f2e 100644 --- a/samples/trace_events/trace-events-sample.c +++ b/samples/trace_events/trace-events-sample.c @@ -50,7 +50,7 @@ static void do_simple_thread_func(int cnt, const char *fmt, ...) trace_foo_with_template_print("I have to be different", cnt); - trace_foo_rel_loc("Hello __rel_loc", cnt, bitmask); + trace_foo_rel_loc("Hello __rel_loc", cnt, bitmask, current->cpus_ptr); } static void simple_thread_func(int cnt) diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h index 1a92226202fc..fb4548a44153 100644 --- a/samples/trace_events/trace-events-sample.h +++ b/samples/trace_events/trace-events-sample.h @@ -200,6 +200,16 @@ * * __assign_bitmask(target_cpus, cpumask_bits(bar), nr_cpumask_bits); * + * __cpumask: This is pretty much the same as __bitmask but is specific for + * CPU masks. The type displayed to the user via the format files will + * be "cpumaks_t" such that user space may deal with them differently + * if they choose to do so, and the bits is always set to nr_cpumask_bits. + * + * __cpumask(target_cpu) + * + * To assign a cpumask, use the __assign_cpumask() helper macro. + * + * __assign_cpumask(target_cpus, cpumask_bits(bar)); * * fast_assign: This is a C like function that is used to store the items * into the ring buffer. A special variable called "__entry" will be the @@ -212,8 +222,8 @@ * This is also used to print out the data from the trace files. * Again, the __entry macro is used to access the data from the ring buffer. * - * Note, __dynamic_array, __string, and __bitmask require special helpers - * to access the data. + * Note, __dynamic_array, __string, __bitmask and __cpumask require special + * helpers to access the data. * * For __dynamic_array(int, foo, bar) use __get_dynamic_array(foo) * Use __get_dynamic_array_len(foo) to get the length of the array @@ -226,6 +236,8 @@ * * For __bitmask(target_cpus, nr_cpumask_bits) use __get_bitmask(target_cpus) * + * For __cpumask(target_cpus) use __get_cpumask(target_cpus) + * * * Note, that for both the assign and the printk, __entry is the handler * to the data structure in the ring buffer, and is defined by the @@ -288,6 +300,7 @@ TRACE_EVENT(foo_bar, __dynamic_array(int, list, __length_of(lst)) __string( str, string ) __bitmask( cpus, num_possible_cpus() ) + __cpumask( cpum ) __vstring( vstr, fmt, va ) ), @@ -299,9 +312,10 @@ TRACE_EVENT(foo_bar, __assign_str(str, string); __assign_vstr(vstr, fmt, va); __assign_bitmask(cpus, cpumask_bits(mask), num_possible_cpus()); + __assign_cpumask(cpum, cpumask_bits(mask)); ), - TP_printk("foo %s %d %s %s %s %s (%s) %s", __entry->foo, __entry->bar, + TP_printk("foo %s %d %s %s %s %s (%s) (%s) %s", __entry->foo, __entry->bar, /* * Notice here the use of some helper functions. This includes: @@ -345,7 +359,8 @@ TRACE_EVENT(foo_bar, __print_array(__get_dynamic_array(list), __get_dynamic_array_len(list) / sizeof(int), sizeof(int)), - __get_str(str), __get_bitmask(cpus), __get_str(vstr)) + __get_str(str), __get_bitmask(cpus), __get_cpumask(cpus), + __get_str(vstr)) ); /* @@ -542,15 +557,16 @@ DEFINE_EVENT_PRINT(foo_template, foo_with_template_print, TRACE_EVENT(foo_rel_loc, - TP_PROTO(const char *foo, int bar, unsigned long *mask), + TP_PROTO(const char *foo, int bar, unsigned long *mask, const cpumask_t *cpus), - TP_ARGS(foo, bar, mask), + TP_ARGS(foo, bar, mask, cpus), TP_STRUCT__entry( __rel_string( foo, foo ) __field( int, bar ) __rel_bitmask( bitmask, BITS_PER_BYTE * sizeof(unsigned long) ) + __rel_cpumask( cpumask ) ), TP_fast_assign( @@ -558,10 +574,12 @@ TRACE_EVENT(foo_rel_loc, __entry->bar = bar; __assign_rel_bitmask(bitmask, mask, BITS_PER_BYTE * sizeof(unsigned long)); + __assign_rel_cpumask(cpumask, cpus); ), - TP_printk("foo_rel_loc %s, %d, %s", __get_rel_str(foo), __entry->bar, - __get_rel_bitmask(bitmask)) + TP_printk("foo_rel_loc %s, %d, %s, %s", __get_rel_str(foo), __entry->bar, + __get_rel_bitmask(bitmask), + __get_rel_cpumask(cpumask)) ); #endif From patchwork Thu Nov 24 14:50:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3441415wrr; Thu, 24 Nov 2022 06:52:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf42vM2DKVsmRMzxpoR/WfGyCIiyGVJUbTIUK73mFG+YtWVopQd9rizOf6kX6fWyVcuy0G6Q X-Received: by 2002:a05:6402:24a0:b0:458:ad54:20d5 with SMTP id q32-20020a05640224a000b00458ad5420d5mr29871499eda.86.1669301524395; Thu, 24 Nov 2022 06:52:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301524; cv=none; d=google.com; s=arc-20160816; b=fH7E7FBr9H533eSM4MEd70+hNoZERj6/5u4zCTAWf1iYJRcOhYuNUEBee/32e/Ck/u kK2jvTVyxXCMSG+D+3VwhVxdBFTLKB/33gDSlaiv0cXAE/gdQb4owm3hi+sk/SiZas5F lrsJt0fBdxkhGsRDjhXSUVlVmrMlZgjdjYhzQ4+92Xp0RPtfFSIklhtoRm0fdKp97Br5 W4HQGq1ErfG1yqXpTYQ9vIF7OhgVMQslD+VUgen02lu5IaQP/UpZ9N2yX2uDS5FqyX+V e59h5VNJzGJ3gEhjjs42MP4orxbMz64mtSr+ZhFJIvxNXubjRyHJgy3FGnFlGza5dFL+ nd1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=/W+RjamvJf1FGshjowReMio63x+jYVRMteGeaCPD82A=; b=AXW/gLBvydVirK54FYX0qEpuAgQ1rEEGqeAXxLan946n41LLy7SOQQtt/oUZlIbGjg wjAtR56ss0cGoOAj7F6mUC6D6wFD6SMOxC1qKezJvQ18P/xWFFbC5z5NYj+atDipGU7i /qhYqT+MzFphC/APpJNw+Bl5nB/NRptcNvhetfOPzWeL189DOM1je7qbqZHAqadx+EOC J8FS9lBxtgptar3pnVl4rWpHNi99LZq9nTSVI6Dq10AF3gJPJFliOP1/UZEgAp0eJ/QB oIhsoDWk2Vo6ShfVvfV9dOiCVGIDvuxtyI2Lxzq3mApa3e/SeVHoIrWTXZDEz7DAkVLK Q/gA== 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 y33-20020a50bb24000000b0045a0e39062esi1064647ede.76.2022.11.24.06.51.40; Thu, 24 Nov 2022 06:52:04 -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 S229794AbiKXOvL (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbiKXOuz (ORCPT ); Thu, 24 Nov 2022 09:50:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB664D9B82 for ; Thu, 24 Nov 2022 06:50:47 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7921862187 for ; Thu, 24 Nov 2022 14:50:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9D20C43146; Thu, 24 Nov 2022 14:50:46 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYs-001X3Y-00; Thu, 24 Nov 2022 09:50:46 -0500 Message-ID: <20221124145045.881004349@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:22 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton Subject: [for-next][PATCH 03/11] tracing: Add trace_trigger kernel command line option References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1750389515102500654?= X-GMAIL-MSGID: =?utf-8?q?1750389515102500654?= From: "Steven Rostedt (Google)" Allow triggers to be enabled at kernel boot up. For example: trace_trigger="sched_switch.stacktrace if prev_state == 2" The above will enable the stacktrace trigger on top of the sched_switch event and only trigger if its prev_state is 2 (TASK_UNINTERRUPTIBLE). Then at boot up, a stacktrace will trigger and be recorded in the tracing ring buffer every time the sched_switch happens where the previous state is TASK_INTERRUPTIBLE. Another useful trigger would be "traceoff" which can stop tracing on an event if a field of the event matches a certain value defined by the filter ("if" statement). Link: https://lore.kernel.org/linux-trace-kernel/20221020210056.0d8d0a5b@gandalf.local.home Signed-off-by: Steven Rostedt (Google) --- .../admin-guide/kernel-parameters.txt | 19 +++++ kernel/trace/trace_events.c | 72 ++++++++++++++++++- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a465d5242774..ccf91a4bf113 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6257,6 +6257,25 @@ See also Documentation/trace/ftrace.rst "trace options" section. + trace_trigger=[trigger-list] + [FTRACE] Add a event trigger on specific events. + Set a trigger on top of a specific event, with an optional + filter. + + The format is is "trace_trigger=.[ if ],..." + Where more than one trigger may be specified that are comma deliminated. + + For example: + + trace_trigger="sched_switch.stacktrace if prev_state == 2" + + The above will enable the "stacktrace" trigger on the "sched_switch" + event but only trigger it if the "prev_state" of the "sched_switch" + event is "2" (TASK_UNINTERUPTIBLE). + + See also "Event triggers" in Documentation/trace/events.rst + + traceoff_on_warning [FTRACE] enable this option to disable tracing when a warning is hit. This turns off "tracing_on". Tracing can diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index f71ea6e79b3c..3bfaf560ecc4 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -2796,6 +2796,44 @@ trace_create_new_event(struct trace_event_call *call, return file; } +#ifdef CONFIG_HIST_TRIGGERS +#define MAX_BOOT_TRIGGERS 32 + +static struct boot_triggers { + const char *event; + char *trigger; +} bootup_triggers[MAX_BOOT_TRIGGERS]; + +static char bootup_trigger_buf[COMMAND_LINE_SIZE]; +static int nr_boot_triggers; + +static __init int setup_trace_triggers(char *str) +{ + char *trigger; + char *buf; + int i; + + strlcpy(bootup_trigger_buf, str, COMMAND_LINE_SIZE); + ring_buffer_expanded = true; + disable_tracing_selftest("running event triggers"); + + buf = bootup_trigger_buf; + for (i = 0; i < MAX_BOOT_TRIGGERS; i++) { + trigger = strsep(&buf, ","); + if (!trigger) + break; + bootup_triggers[i].event = strsep(&trigger, "."); + bootup_triggers[i].trigger = strsep(&trigger, "."); + if (!bootup_triggers[i].trigger) + break; + } + + nr_boot_triggers = i; + return 1; +} +__setup("trace_trigger=", setup_trace_triggers); +#endif + /* Add an event to a trace directory */ static int __trace_add_new_event(struct trace_event_call *call, struct trace_array *tr) @@ -2812,6 +2850,28 @@ __trace_add_new_event(struct trace_event_call *call, struct trace_array *tr) return event_define_fields(call); } +#ifdef CONFIG_HIST_TRIGGERS +static void trace_early_triggers(struct trace_event_file *file, const char *name) +{ + int ret; + int i; + + for (i = 0; i < nr_boot_triggers; i++) { + if (strcmp(name, bootup_triggers[i].event)) + continue; + mutex_lock(&event_mutex); + ret = trigger_process_regex(file, bootup_triggers[i].trigger); + mutex_unlock(&event_mutex); + if (ret) + pr_err("Failed to register trigger '%s' on event %s\n", + bootup_triggers[i].trigger, + bootup_triggers[i].event); + } +} +#else +static inline void trace_early_triggers(struct trace_event_file *file, const char *name) { } +#endif + /* * Just create a descriptor for early init. A descriptor is required * for enabling events at boot. We want to enable events before @@ -2822,12 +2882,19 @@ __trace_early_add_new_event(struct trace_event_call *call, struct trace_array *tr) { struct trace_event_file *file; + int ret; file = trace_create_new_event(call, tr); if (!file) return -ENOMEM; - return event_define_fields(call); + ret = event_define_fields(call); + if (ret) + return ret; + + trace_early_triggers(file, trace_event_name(call)); + + return 0; } struct ftrace_module_file_ops; @@ -3735,6 +3802,8 @@ static __init int event_trace_enable(void) list_add(&call->list, &ftrace_events); } + register_trigger_cmds(); + /* * We need the top trace array to have a working set of trace * points at early init, before the debug files and directories @@ -3749,7 +3818,6 @@ static __init int event_trace_enable(void) register_event_cmds(); - register_trigger_cmds(); return 0; } From patchwork Thu Nov 24 14:50:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25608 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3443123wrr; Thu, 24 Nov 2022 06:56:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Go8yG1j9mFba5rAvCtJRIGljgcflwB5einXu4ACtZTWAxhcYvFJHF4ni3DhLYdKOCV+gq X-Received: by 2002:a17:907:2c49:b0:7ad:9891:8757 with SMTP id hf9-20020a1709072c4900b007ad98918757mr14577161ejc.335.1669301775503; Thu, 24 Nov 2022 06:56:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301775; cv=none; d=google.com; s=arc-20160816; b=BSxg7dKU+MSnXOWEGlmwjUXqW37CZxYRRtCYtz0UDTgvgepvGQZygO+GKXvyeIGP5P TYUxhxZg9HcD0pnNS6AcEwZk85MxERHy2ODUqOXSLU5jG5qnf44vnrRzfEMDbiZ9kydA oSwnhtWzfKdcOvwYqB0ABLdZN10qFhkNsppGJahE7bghqKUjlH7I+G5WRPzvx23stcc8 ZA5oze9jvBURzdW5Nwc9ASqM6UHGrYN4RZ6FlkDVhhtfBhWz1CDbvjgZC6wcBszBxcgv EQ0nbyPRHH6ucgHS82o+kPV7oxW5YbHT/jVq/yM7ENomF9ht/2DWA61zy2t5m42Kd1LZ +WLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=CDJE+TE4HXsYZb2yGYK69HMXayA0yC917LTQ+P1IkGc=; b=so1NckpE505ul6BvQr0Y/XeJFJ15VfsVTanv2m+ZUsZt8mpRz5QW/bHgwIrTTEzH4M DfBBCy3ywS4OZzQPtdExBfKfkKDoXboROFNLh2E8NtN6tvwohT9C1ISxOpqAwRYRcrJP ulhmpPFxK5Bq6hJHz6raTqWfyhGuqN2C55UsAloTwTLVzJJKaY9xLmh5aCNhNqx9qqKI VwGHFs79akXskkcGjoQHgP/ZHRI6e+vY5B72GFz368lFJk2VJ3MWFaJparS7bgMRQ+zh b5rjpGClSiBt9YNyutzCALOh/1f8LGwhNv0WeF6/8k+06w8TEC9lV9ooPlt8mihaPuT8 ay3g== 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 g10-20020a1709067c4a00b007b790c183d5si845165ejp.260.2022.11.24.06.55.51; Thu, 24 Nov 2022 06:56:15 -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 S229968AbiKXOvp (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbiKXOvE (ORCPT ); Thu, 24 Nov 2022 09:51:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 213001369C2 for ; Thu, 24 Nov 2022 06:50:52 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5AB3DB8284F for ; Thu, 24 Nov 2022 14:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08CADC433D6; Thu, 24 Nov 2022 14:50:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYs-001X42-0S; Thu, 24 Nov 2022 09:50:46 -0500 Message-ID: <20221124145046.017356789@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:23 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Song Chen Subject: [for-next][PATCH 04/11] ring_buffer: Remove unused "event" parameter References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1750389778925098318?= X-GMAIL-MSGID: =?utf-8?q?1750389778925098318?= From: Song Chen After commit a389d86f7fd0 ("ring-buffer: Have nested events still record running time stamp"), the "event" parameter is no longer used in either ring_buffer_unlock_commit() or rb_commit(). Best to remove it. Link: https://lkml.kernel.org/r/1666274811-24138-1-git-send-email-chensong_2000@189.cn Signed-off-by: Song Chen Signed-off-by: Steven Rostedt (Google) --- include/linux/ring_buffer.h | 3 +-- kernel/trace/ring_buffer.c | 12 +++++------- kernel/trace/ring_buffer_benchmark.c | 2 +- kernel/trace/trace.c | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h index 3c7d295746f6..782e14f62201 100644 --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h @@ -113,8 +113,7 @@ void ring_buffer_change_overwrite(struct trace_buffer *buffer, int val); struct ring_buffer_event *ring_buffer_lock_reserve(struct trace_buffer *buffer, unsigned long length); -int ring_buffer_unlock_commit(struct trace_buffer *buffer, - struct ring_buffer_event *event); +int ring_buffer_unlock_commit(struct trace_buffer *buffer); int ring_buffer_write(struct trace_buffer *buffer, unsigned long length, void *data); diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index b21bf14bae9b..843818ee4814 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -3180,8 +3180,7 @@ static inline void rb_event_discard(struct ring_buffer_event *event) event->time_delta = 1; } -static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer, - struct ring_buffer_event *event) +static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer) { local_inc(&cpu_buffer->entries); rb_end_commit(cpu_buffer); @@ -3383,15 +3382,14 @@ void ring_buffer_nest_end(struct trace_buffer *buffer) * * Must be paired with ring_buffer_lock_reserve. */ -int ring_buffer_unlock_commit(struct trace_buffer *buffer, - struct ring_buffer_event *event) +int ring_buffer_unlock_commit(struct trace_buffer *buffer) { struct ring_buffer_per_cpu *cpu_buffer; int cpu = raw_smp_processor_id(); cpu_buffer = buffer->buffers[cpu]; - rb_commit(cpu_buffer, event); + rb_commit(cpu_buffer); rb_wakeups(buffer, cpu_buffer); @@ -3977,7 +3975,7 @@ int ring_buffer_write(struct trace_buffer *buffer, memcpy(body, data, length); - rb_commit(cpu_buffer, event); + rb_commit(cpu_buffer); rb_wakeups(buffer, cpu_buffer); @@ -5998,7 +5996,7 @@ static __init int rb_write_something(struct rb_test_data *data, bool nested) } out: - ring_buffer_unlock_commit(data->buffer, event); + ring_buffer_unlock_commit(data->buffer); return 0; } diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c index 78e576575b79..aef34673d79d 100644 --- a/kernel/trace/ring_buffer_benchmark.c +++ b/kernel/trace/ring_buffer_benchmark.c @@ -258,7 +258,7 @@ static void ring_buffer_producer(void) hit++; entry = ring_buffer_event_data(event); *entry = smp_processor_id(); - ring_buffer_unlock_commit(buffer, event); + ring_buffer_unlock_commit(buffer); } } end_time = ktime_get(); diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 5cfc95a52bc3..5c97dbef741b 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -999,7 +999,7 @@ __buffer_unlock_commit(struct trace_buffer *buffer, struct ring_buffer_event *ev /* ring_buffer_unlock_commit() enables preemption */ preempt_enable_notrace(); } else - ring_buffer_unlock_commit(buffer, event); + ring_buffer_unlock_commit(buffer); } /** From patchwork Thu Nov 24 14:50:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3441449wrr; Thu, 24 Nov 2022 06:52:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf7OrXSC9FXacVUoqzFBn0YrAERmE0mx7zfcKRty06VFg1WECUMJbjTRlOPTiiCiLGCUTBhl X-Received: by 2002:a17:906:b749:b0:7b6:6e0a:17dd with SMTP id fx9-20020a170906b74900b007b66e0a17ddmr12433530ejb.590.1669301527950; Thu, 24 Nov 2022 06:52:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301527; cv=none; d=google.com; s=arc-20160816; b=aJSS1kY8So4XrSkzVT6jQ8xCE4oKCx3+OMZ7zeVHqrOAIGqmOtLopNWNmJqQtceTKx h2aChVE9mD5RpYbVvgNFWTa/p4JjVexAd8/3Oim8ezDP4spnESgY7XS8O8K7UJhyG1T0 Jku/R4adXy930mkO5g7oykqe8z+KMfQO/41medKBkIAhLcCXz7sifYjxLsjYcvf/qVOf f5MiWi8HQNqYQNiwQYLrcl+tifj1Vaa8820XXaogo4lUs566/Q4JUV+8wPKVOqoezNdu 5iYA8BT0OiB0vNg58xR0x0T0RXTlKZdMtLhvnYQMh3QKqGpBy1WsqXrHzLX9zJ8xMydF 16Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=3Ql1YSGKeW0amJbqhBT+qWxj2csPMbOU1qsNyvNE2FQ=; b=qZzdjHIYNbtUkofIttz06bEwZ30AqmjAYbhTezWMlX/x0F7N3I7lxOe281EOJR0ONy rVmpovdfmswELMYslmCgnGPGTcLOVMCqqu8RTmpwY6TMOcal+cb78gnUQEJ+saJT4OSY dIArlgxlO9v5hNZ3AJi4bR2uFmybJHiNeryESmXtP1W8x5ZrzhctrZiytUBk/alH/zXT uLfZFTuHeiL7ZVMkhl3XFZW25zO42xHnpWr40jV0ZhlkU37mHme+h+1WNPUnsNSB7YKi jwN9gByQbMDhxJYu+s4Hm8AHgg/lWbFtApP33/AABSTOz4NYv8fHljA8+vo5SCJa+1HI uMlA== 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 k24-20020a508ad8000000b0045c2e7e5532si1213151edk.585.2022.11.24.06.51.43; Thu, 24 Nov 2022 06:52:07 -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 S229798AbiKXOvR (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229719AbiKXOu5 (ORCPT ); Thu, 24 Nov 2022 09:50:57 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31D861255C6 for ; Thu, 24 Nov 2022 06:50:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BB50462161 for ; Thu, 24 Nov 2022 14:50:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C2DFC43149; Thu, 24 Nov 2022 14:50:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYs-001X4W-0u; Thu, 24 Nov 2022 09:50:46 -0500 Message-ID: <20221124145046.156919074@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:24 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Daniel Bristot de Oliveira , Jonathan Corbet Subject: [for-next][PATCH 05/11] tracing/osnoise: Add osnoise/options file References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1750389519037820855?= X-GMAIL-MSGID: =?utf-8?q?1750389519037820855?= From: Daniel Bristot de Oliveira Add the tracing/osnoise/options file to control osnoise/timerlat tracer features. It is a single file to contain multiple features, similar to the sched/features file. Reading the file displays a list of options. Writing the OPTION_NAME enables it, writing NO_OPTION_NAME disables it. The DEAFULTS is a particular option that resets the options to the default ones. It uses a bitmask to keep track of the status of the option. When needed, we can add a list of static keys, but for now it does not justify the memory increase. Link: https://lkml.kernel.org/r/f8d34aefdb225d2603fcb4c02a120832a0cd3339.1668692096.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Masami Hiramatsu Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_osnoise.c | 170 +++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 4300c5dc4e5d..17b77fe3950b 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -48,6 +48,19 @@ #define DEFAULT_TIMERLAT_PERIOD 1000 /* 1ms */ #define DEFAULT_TIMERLAT_PRIO 95 /* FIFO 95 */ +/* + * osnoise/options entries. + */ +enum osnoise_options_index { + OSN_DEFAULTS = 0, + OSN_MAX +}; + +static const char * const osnoise_options_str[OSN_MAX] = { "DEFAULTS" }; + +#define OSN_DEFAULT_OPTIONS 0 +unsigned long osnoise_options = OSN_DEFAULT_OPTIONS; + /* * trace_array of the enabled osnoise/timerlat instances. */ @@ -1860,6 +1873,150 @@ static void osnoise_init_hotplug_support(void) } #endif /* CONFIG_HOTPLUG_CPU */ +/* + * seq file functions for the osnoise/options file. + */ +static void *s_options_start(struct seq_file *s, loff_t *pos) +{ + int option = *pos; + + mutex_lock(&interface_lock); + + if (option >= OSN_MAX) + return NULL; + + return pos; +} + +static void *s_options_next(struct seq_file *s, void *v, loff_t *pos) +{ + int option = ++(*pos); + + if (option >= OSN_MAX) + return NULL; + + return pos; +} + +static int s_options_show(struct seq_file *s, void *v) +{ + loff_t *pos = v; + int option = *pos; + + if (option == OSN_DEFAULTS) { + if (osnoise_options == OSN_DEFAULT_OPTIONS) + seq_printf(s, "%s", osnoise_options_str[option]); + else + seq_printf(s, "NO_%s", osnoise_options_str[option]); + goto out; + } + + if (test_bit(option, &osnoise_options)) + seq_printf(s, "%s", osnoise_options_str[option]); + else + seq_printf(s, "NO_%s", osnoise_options_str[option]); + +out: + if (option != OSN_MAX) + seq_puts(s, " "); + + return 0; +} + +static void s_options_stop(struct seq_file *s, void *v) +{ + seq_puts(s, "\n"); + mutex_unlock(&interface_lock); +} + +static const struct seq_operations osnoise_options_seq_ops = { + .start = s_options_start, + .next = s_options_next, + .show = s_options_show, + .stop = s_options_stop +}; + +static int osnoise_options_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &osnoise_options_seq_ops); +}; + +/** + * osnoise_options_write - Write function for "options" entry + * @filp: The active open file structure + * @ubuf: The user buffer that contains the value to write + * @cnt: The maximum number of bytes to write to "file" + * @ppos: The current position in @file + * + * Writing the option name sets the option, writing the "NO_" + * prefix in front of the option name disables it. + * + * Writing "DEFAULTS" resets the option values to the default ones. + */ +static ssize_t osnoise_options_write(struct file *filp, const char __user *ubuf, + size_t cnt, loff_t *ppos) +{ + int running, option, enable, retval; + char buf[256], *option_str; + + if (cnt >= 256) + return -EINVAL; + + if (copy_from_user(buf, ubuf, cnt)) + return -EFAULT; + + buf[cnt] = 0; + + if (strncmp(buf, "NO_", 3)) { + option_str = strstrip(buf); + enable = true; + } else { + option_str = strstrip(&buf[3]); + enable = false; + } + + option = match_string(osnoise_options_str, OSN_MAX, option_str); + if (option < 0) + return -EINVAL; + + /* + * trace_types_lock is taken to avoid concurrency on start/stop. + */ + mutex_lock(&trace_types_lock); + running = osnoise_has_registered_instances(); + if (running) + stop_per_cpu_kthreads(); + + mutex_lock(&interface_lock); + /* + * avoid CPU hotplug operations that might read options. + */ + cpus_read_lock(); + + retval = cnt; + + if (enable) { + if (option == OSN_DEFAULTS) + osnoise_options = OSN_DEFAULT_OPTIONS; + else + set_bit(option, &osnoise_options); + } else { + if (option == OSN_DEFAULTS) + retval = -EINVAL; + else + clear_bit(option, &osnoise_options); + } + + cpus_read_unlock(); + mutex_unlock(&interface_lock); + + if (running) + start_per_cpu_kthreads(); + mutex_unlock(&trace_types_lock); + + return retval; +} + /* * osnoise_cpus_read - Read function for reading the "cpus" file * @filp: The active open file structure @@ -2042,6 +2199,14 @@ static const struct file_operations cpus_fops = { .llseek = generic_file_llseek, }; +static const struct file_operations osnoise_options_fops = { + .open = osnoise_options_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, + .write = osnoise_options_write +}; + #ifdef CONFIG_TIMERLAT_TRACER #ifdef CONFIG_STACKTRACE static int init_timerlat_stack_tracefs(struct dentry *top_dir) @@ -2128,6 +2293,11 @@ static int init_tracefs(void) if (!tmp) goto err; + tmp = trace_create_file("options", TRACE_MODE_WRITE, top_dir, NULL, + &osnoise_options_fops); + if (!tmp) + goto err; + ret = init_timerlat_tracefs(top_dir); if (ret) goto err; From patchwork Thu Nov 24 14:50:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25602 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3441726wrr; Thu, 24 Nov 2022 06:52:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf78DIhP6J9VRi7LWKNI5TVoTuxPSIt6HWtHpTOhme5ow18fRim6bxShDJKFQY0DbDkmc38E X-Received: by 2002:aa7:cb15:0:b0:458:e9c0:3e6f with SMTP id s21-20020aa7cb15000000b00458e9c03e6fmr31008139edt.61.1669301567922; Thu, 24 Nov 2022 06:52:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301567; cv=none; d=google.com; s=arc-20160816; b=RMshQV2zBZMG3OWGPG//31i7i5HZ6XEP2nL/zoGQkEUjSeAXPq4BUynDFEaeoG7F7x FDrh0+VhZdrKEfNtHXlx9iF5VbxbmzarL9VaPtCBRR1gl81Qikw08ydR0mZ8o8WQAJAj uFe33NZbW4MqoCvthYSkNfFRMmMIOqrE6+50HkU9tLaZHLxCUdUJ6k88XOnOZkTBwtzN YOqpWwTwmrqhNQAQbNPFoMuDgckotq+MtyI4LKpD7AH6lUiUNjjvixd7JdPYKzIXJorm 1ybHKweyx2bKvhd4r4b5UnemHu0pY5iUmC4OK2lk8aZJ/1QWDxMu+fV+NivukLOtENwt O2/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=PmWYUPmwS4yks9ZQ6q/Q7xhd3YVLpLcTv2GdQ5sPrDc=; b=Y+9qzcG39aQv/58fq8WaOwDMVZN4v8j8n+ltjoRy04QB09T2EsnU8D+H1J6m40mLCh 9XipkCeBWyI6fqzSTb87RhI/olB3p/4qdB5V2FFg26LGlibgFVpTcBZCf+z9Ag79exo5 JLPztgK+USzW62uXTXbfMlT8G71YpS4xOogjh1IkbQxLxbjthd8+6wM9eUeHYSwAPJwR dK+M51+EpRQbEmsxNGThy7Fijm3XupvAGmIfSvqhXGbU26OHvv+Q6sQVOHvYdx1WPqJG IvYCaz3gLhnf78NDkexegZc0C6h5peNAILSnaB2Hx3cB27Pabuj1pd2z/qXCmX3lskQl 6mHg== 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 xc1-20020a170907074100b007ae30b550e5si606137ejb.854.2022.11.24.06.52.21; Thu, 24 Nov 2022 06:52:47 -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 S229928AbiKXOv0 (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbiKXOvA (ORCPT ); Thu, 24 Nov 2022 09:51:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE6C4134118 for ; Thu, 24 Nov 2022 06:50:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AE47CB82846 for ; Thu, 24 Nov 2022 14:50:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A27CC4314D; Thu, 24 Nov 2022 14:50:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYs-001X50-1L; Thu, 24 Nov 2022 09:50:46 -0500 Message-ID: <20221124145046.301211304@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:25 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Daniel Bristot de Oliveira , Jonathan Corbet Subject: [for-next][PATCH 06/11] tracing/osnoise: Add OSNOISE_WORKLOAD option References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1750389560863123409?= X-GMAIL-MSGID: =?utf-8?q?1750389560863123409?= From: Daniel Bristot de Oliveira The osnoise tracer is not only a tracer, and a set of tracepoints, but also a workload dispatcher. In preparation for having other workloads, e.g., in user-space, add an option to avoid dispatching the workload. By not dispatching the workload, the osnoise: tracepoints become generic events to measure the execution time of *any* task on Linux. For example: # cd /sys/kernel/tracing/ # cat osnoise/options DEFAULTS OSNOISE_WORKLOAD # echo NO_OSNOISE_WORKLOAD > osnoise/options # cat osnoise/options NO_DEFAULTS NO_OSNOISE_WORKLOAD # echo osnoise > set_event # echo osnoise > current_tracer # tail -8 trace make-94722 [002] d..3. 1371.794507: thread_noise: make:94722 start 1371.794302286 duration 200897 ns sh-121042 [020] d..3. 1371.794534: thread_noise: sh:121042 start 1371.781610976 duration 8943683 ns make-121097 [005] d..3. 1371.794542: thread_noise: make:121097 start 1371.794481522 duration 60444 ns <...>-40 [005] d..3. 1371.794550: thread_noise: migration/5:40 start 1371.794542256 duration 7154 ns -0 [018] dNh2. 1371.794554: irq_noise: reschedule:253 start 1371.794553547 duration 40 ns -0 [018] dNh2. 1371.794561: irq_noise: local_timer:236 start 1371.794556222 duration 4890 ns -0 [018] .Ns2. 1371.794563: softirq_noise: SCHED:7 start 1371.794561803 duration 992 ns -0 [018] d..3. 1371.794566: thread_noise: swapper/18:0 start 1371.781368110 duration 13191798 ns In preparation for the rtla exec_time tracer/tool and rtla osnoise --user option. Link: https://lkml.kernel.org/r/f5cfbd37aefd419eefe9243b4d2fc38ed5753fe4.1668692096.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Masami Hiramatsu Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_osnoise.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 17b77fe3950b..3f10dd1f2f1c 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -53,12 +53,13 @@ */ enum osnoise_options_index { OSN_DEFAULTS = 0, + OSN_WORKLOAD, OSN_MAX }; -static const char * const osnoise_options_str[OSN_MAX] = { "DEFAULTS" }; +static const char * const osnoise_options_str[OSN_MAX] = { "DEFAULTS", "OSNOISE_WORKLOAD" }; -#define OSN_DEFAULT_OPTIONS 0 +#define OSN_DEFAULT_OPTIONS 0x2 unsigned long osnoise_options = OSN_DEFAULT_OPTIONS; /* @@ -1186,11 +1187,12 @@ trace_sched_switch_callback(void *data, bool preempt, unsigned int prev_state) { struct osnoise_variables *osn_var = this_cpu_osn_var(); + int workload = test_bit(OSN_WORKLOAD, &osnoise_options); - if (p->pid != osn_var->pid) + if ((p->pid != osn_var->pid) || !workload) thread_exit(osn_var, p); - if (n->pid != osn_var->pid) + if ((n->pid != osn_var->pid) || !workload) thread_entry(osn_var, n); } @@ -1723,9 +1725,16 @@ static void stop_kthread(unsigned int cpu) struct task_struct *kthread; kthread = per_cpu(per_cpu_osnoise_var, cpu).kthread; - if (kthread) + if (kthread) { kthread_stop(kthread); - per_cpu(per_cpu_osnoise_var, cpu).kthread = NULL; + per_cpu(per_cpu_osnoise_var, cpu).kthread = NULL; + } else { + if (!test_bit(OSN_WORKLOAD, &osnoise_options)) { + per_cpu(per_cpu_osnoise_var, cpu).sampling = false; + barrier(); + return; + } + } } /* @@ -1759,6 +1768,13 @@ static int start_kthread(unsigned int cpu) snprintf(comm, 24, "timerlat/%d", cpu); main = timerlat_main; } else { + /* if no workload, just return */ + if (!test_bit(OSN_WORKLOAD, &osnoise_options)) { + per_cpu(per_cpu_osnoise_var, cpu).sampling = true; + barrier(); + return 0; + } + snprintf(comm, 24, "osnoise/%d", cpu); } From patchwork Thu Nov 24 14:50:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25603 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3441772wrr; Thu, 24 Nov 2022 06:52:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf6NtkFq9EdRa/SSG1ijy+WJ5xoGMuTA3BQzZr2GLhN94f1wj9jBcMjSPq4z+GtYpsGv3sV5 X-Received: by 2002:a17:906:245a:b0:78d:857d:b4a8 with SMTP id a26-20020a170906245a00b0078d857db4a8mr6280587ejb.495.1669301575368; Thu, 24 Nov 2022 06:52:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301575; cv=none; d=google.com; s=arc-20160816; b=rjL/lUVIjpO29Fa0gAs4bHqCXffn8zL54CY8N0qAZ4VnGrocC4i0VF31iGgDYm126S w1XeDAWcy2EjNZWrLfIeGcJWcw9/BCN1bLQrnAoXw4x7dR/K5HXA0VKTQtuoVmomKo2r z5PiM56vaIuTWtpF/0cl7KKhl9FJBuWKcpmwJhG1WLSrj4yeJZviHDmvEKoU0nSlvPsu 4v+9EorBadmqodOQoVNzwzp5UVxlPXhyxHvPJ14draDSb/wRtl4GX84C0lChLQBf7KDA J488F+xQhES2Wjz/JdHphdJ4KYieMs3PjxSb4X+6b/455HuNR8AirnTFKWyxSYWB4IpS 685g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=v/9sQxb3u4F9IMFKeIaegN86+o0NmZ3LU7iFHvfqMUE=; b=E63g9QoexmFIZMqMI4ixfx2i7K91Vh40Ua4e5B8T5HnkXfhaaRJ2f6H+eNUs+0LQpx /+l2s8JQtqN/Rg3ThbPAvM6pYRsDsD9kkZ6eIkIPYlWWiWgkoWNzR1qa7qdT3Ppa2/8b MdsYIOSYeJDrYDY3g6QAy4CCZpTFk5WiZlQwFdFsT+tJiEO4bcOFUlYkHIwfSM6AmsQi qML+s0gzCKKW60CY9pjiZBLMz5JlOEpbWWfpNzucH6zYghONMq3ecoz7liSXOWPqviRT deMpdvcdL+KkMVupwpKhBY1C2b35wALWXa0K06gKq/jjPAbMe8LbBVsyh379FPnwGzy/ /txg== 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 di13-20020a170906730d00b00782e437a368si372270ejc.160.2022.11.24.06.52.30; Thu, 24 Nov 2022 06:52:55 -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 S229934AbiKXOv2 (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbiKXOvA (ORCPT ); Thu, 24 Nov 2022 09:51:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 065BA134128 for ; Thu, 24 Nov 2022 06:50:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B7905B82847 for ; Thu, 24 Nov 2022 14:50:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 706E4C4347C; Thu, 24 Nov 2022 14:50:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYs-001X5U-1n; Thu, 24 Nov 2022 09:50:46 -0500 Message-ID: <20221124145046.434583980@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:26 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Daniel Bristot de Oliveira , Jonathan Corbet Subject: [for-next][PATCH 07/11] Documentation/osnoise: Add osnoise/options documentation References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1750389568865412683?= X-GMAIL-MSGID: =?utf-8?q?1750389568865412683?= From: Daniel Bristot de Oliveira Add the documentation about the osnoise/options file, along with an explanation about the OSNOISE_WORKLOAD option. Link: https://lkml.kernel.org/r/777af8f3d87beedd304805f98eff6c8291d64226.1668692096.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Masami Hiramatsu Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- Documentation/trace/osnoise-tracer.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/trace/osnoise-tracer.rst b/Documentation/trace/osnoise-tracer.rst index 963def9f97c6..3c675ed82b27 100644 --- a/Documentation/trace/osnoise-tracer.rst +++ b/Documentation/trace/osnoise-tracer.rst @@ -109,6 +109,11 @@ The tracer has a set of options inside the osnoise directory, they are: - tracing_threshold: the minimum delta between two time() reads to be considered as noise, in us. When set to 0, the default value will be used, which is currently 5 us. + - osnoise/options: a set of on/off options that can be enabled by + writing the option name to the file or disabled by writing the option + name preceded with the 'NO_' prefix. For example, writing + NO_OSNOISE_WORKLOAD disables the OSNOISE_WORKLOAD option. The + special DEAFAULTS option resets all options to the default value. Additional Tracing ------------------ @@ -150,3 +155,10 @@ tracepoints is smaller than eight us reported in the sample_threshold. The reason roots in the overhead of the entry and exit code that happens before and after any interference execution. This justifies the dual approach: measuring thread and tracing. + +Running osnoise tracer without workload +--------------------------------------- + +By enabling the osnoise tracer with the NO_OSNOISE_WORKLOAD option set, +the osnoise: tracepoints serve to measure the execution time of +any type of Linux task, free from the interference of other tasks. From patchwork Thu Nov 24 14:50:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3442895wrr; Thu, 24 Nov 2022 06:55:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4lJseIglD0Wfr1OcRDDwNGxNCGNAxLFFMbJUw0nVEOqDGQUTigEvb8J/0cI6cksjgVBh7f X-Received: by 2002:a05:6402:1d87:b0:459:41fa:8e07 with SMTP id dk7-20020a0564021d8700b0045941fa8e07mr13168300edb.140.1669301742027; Thu, 24 Nov 2022 06:55:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301742; cv=none; d=google.com; s=arc-20160816; b=WMry6Xjqu1OGdnQWOBqGTSmcbBlo1ZT1RxUSidInihHCGkBraLMR0TvLbKfK9NwKk/ ocS1I31oiAMdFSZBUHIGhZPFJ3NV17BdPAA9Tx1sBz4eKyvQvtHmtnsUhSpBhm7aoncC +A7uX46YucFhG9t/lMRmkyAKf2mljxp54DHMa4KguTq5RQsPeE3ZiSK8nOT6Q8JsWQak 2/usfNaJIotdORhE7bUpbTlY8rXwewxtOPRccmyNQzdJgUgtnCdUP0orCUFcRo2eE9fz x7Y4aHb68QtCj7HZmC9RKvffulDdxgSdPAb+xNjO+4B/MjPAy31DXPlsXa/g8gh7fRjG /VOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=dNIofMo5INLTuJz6SlAcVPPKnJASktL6YfrzFbg9N7s=; b=DkzWHQBH55Ho11a0J/SY6irbdst1MRmuEMWE1PaGcILovYxPZ6Fig7YfQ3X2ExBoQS HajKU7TbRO1OquUNwqGvgEoiPFWwHWNpccL1sBD9r5KtwUab9B+oFAEpaKb9hix+kOLf kiLDttlRdo91MKl5qh6w3uN3S9ZaHvGwZRcJu1DLYONbwj5Ifxgaysg6OlWpoOgpDzY+ n0o9MHU/UyL00Wh+K5CnzHQHpSSgblOdXm19Lj6KP/G3dxT0jdYb3/MSj8uopOZwPJFS viHGGFr7o2byv73ciqUDXAUxLDbDU+ZOOgdexr7MaQgqTUtiuXRgJV8s/OReFTKMTss4 ZOjg== 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 sb29-20020a1709076d9d00b0078d9f1f72bcsi388501ejc.726.2022.11.24.06.55.15; Thu, 24 Nov 2022 06:55:42 -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 S229741AbiKXOvk (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229839AbiKXOvC (ORCPT ); Thu, 24 Nov 2022 09:51:02 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C604134F26 for ; Thu, 24 Nov 2022 06:50:52 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 11F13B8284A for ; Thu, 24 Nov 2022 14:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9251CC43146; Thu, 24 Nov 2022 14:50:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYs-001X5z-2F; Thu, 24 Nov 2022 09:50:46 -0500 Message-ID: <20221124145046.573437905@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:27 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Chuang Wang Subject: [for-next][PATCH 08/11] tracing/perf: Use strndup_user instead of kzalloc/strncpy_from_user References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1750389743004486151?= X-GMAIL-MSGID: =?utf-8?q?1750389743004486151?= From: Chuang Wang This patch uses strndup_user instead of kzalloc + strncpy_from_user, which makes the code more concise. Link: https://lkml.kernel.org/r/20221121080831.707409-1-nashuiliang@gmail.com Signed-off-by: Chuang Wang Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_event_perf.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index 61e3a2620fa3..05e791241812 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c @@ -251,16 +251,12 @@ int perf_kprobe_init(struct perf_event *p_event, bool is_retprobe) struct trace_event_call *tp_event; if (p_event->attr.kprobe_func) { - func = kzalloc(KSYM_NAME_LEN, GFP_KERNEL); - if (!func) - return -ENOMEM; - ret = strncpy_from_user( - func, u64_to_user_ptr(p_event->attr.kprobe_func), - KSYM_NAME_LEN); - if (ret == KSYM_NAME_LEN) - ret = -E2BIG; - if (ret < 0) - goto out; + func = strndup_user(u64_to_user_ptr(p_event->attr.kprobe_func), + KSYM_NAME_LEN); + if (IS_ERR(func)) { + ret = PTR_ERR(func); + return (ret == -EINVAL) ? -E2BIG : ret; + } if (func[0] == '\0') { kfree(func); From patchwork Thu Nov 24 14:50:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25606 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3442828wrr; Thu, 24 Nov 2022 06:55:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf57DNf5bhBmX7N3+A0O4onu576aO9UbWbSYFDsGv06hmjM2VkMgGcWeGJiIEyqj0l5AKhFg X-Received: by 2002:a05:6402:1399:b0:461:53b0:2ac0 with SMTP id b25-20020a056402139900b0046153b02ac0mr29740652edv.153.1669301732652; Thu, 24 Nov 2022 06:55:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301732; cv=none; d=google.com; s=arc-20160816; b=KQiJYw8Wvn7OnHWkCPRZjCWfWdnrm+QxkLBpeJ/RCmt7l2VeF8WP8y5XH+zq2KDvIi WDHPz1MQ4jFfttWOsdNz+s9M6o2l7TVq7Ezo587bBnqAJSBMtmcrK7yPypZmLq/oD0ny lVDGVs7zEspkhsMfJVb+0xDrmHbdIRr2iFtsAZm4akuHWkgrys2hJdQLjeyrjcfe8fzL B9B6FrP4MLFigJ1qbGgyU9AsBrG39tfPrmGCboCtI0/UvyUll+OfTIPIRLRcirgspbH5 EVViTsY50HeG2U2tEWVdLEiUIp1FNefRPFRMBbNxW0ByJYUEcx9LBxzo/xe1dYjYsz64 cFRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=wSi3HJ51/F803Q2W+aK0mFNrJkRhMEc3clpd+KOOrs0=; b=iq3oJwRL3QJkZaAHvIFV3A5Pl6GQpgQFrgzABxcg2HkZuRpE4l9bTKSVTJGxeTGT4s d+jfY4dWbGpBjsnxAK4+ETMl9RlM6cLzguEsqa/RA9X6psny9UejwtVxc2+LxZzB6HC1 qya8uhf/YWktNn4EM63lAGbHhilhcdADXI5oTjh/Ua3aHQqitPgfhD/towI4VW1+aNBV XJR2F9oxbrViHkS98yAUnTErl9hAOEspqEp0pXS3bxdVVfnvjQBACEQ7Qb2NHlQVhwr9 l2sir9n6OCS+1293nVQED25jf9ADn1WGiFvvtMISqqhxKGjHQ5Lrs8KwXzPVm9EUEHZl qxqQ== 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 k14-20020a50ce4e000000b00462e628189asi1155100edj.304.2022.11.24.06.55.08; Thu, 24 Nov 2022 06:55:32 -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 S229880AbiKXOvn (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229843AbiKXOvE (ORCPT ); Thu, 24 Nov 2022 09:51:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15514134F25 for ; Thu, 24 Nov 2022 06:50:52 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 17A9EB82839 for ; Thu, 24 Nov 2022 14:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4651C43151; Thu, 24 Nov 2022 14:50:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYs-001X6T-2h; Thu, 24 Nov 2022 09:50:46 -0500 Message-ID: <20221124145046.712465586@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:28 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Xiu Jianfeng Subject: [for-next][PATCH 09/11] tracing: Make tracepoint_print_iter static References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1750389733604770999?= X-GMAIL-MSGID: =?utf-8?q?1750389733604770999?= From: Xiu Jianfeng After change in commit 4239174570da ("tracing: Make tracepoint_printk a static_key"), this symbol is not used outside of the file, so mark it static. Link: https://lkml.kernel.org/r/20221122091456.72055-1-xiujianfeng@huawei.com Signed-off-by: Xiu Jianfeng Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 2 +- kernel/trace/trace.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 5c97dbef741b..93a75a97118f 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -85,7 +85,7 @@ void __init disable_tracing_selftest(const char *reason) #endif /* Pipe tracepoints to printk */ -struct trace_iterator *tracepoint_print_iter; +static struct trace_iterator *tracepoint_print_iter; int tracepoint_printk; static bool tracepoint_printk_stop_on_boot __initdata; static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key); diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index d42e24507152..48643f07bc01 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1942,8 +1942,6 @@ static inline void tracer_hardirqs_on(unsigned long a0, unsigned long a1) { } static inline void tracer_hardirqs_off(unsigned long a0, unsigned long a1) { } #endif -extern struct trace_iterator *tracepoint_print_iter; - /* * Reset the state of the trace_iterator so that it can read consumed data. * Normally, the trace_iterator is used for reading the data when it is not From patchwork Thu Nov 24 14:50:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3442251wrr; Thu, 24 Nov 2022 06:54:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf6dHUPuGWGXvq0rlsaQpnXRc7Vsi5QQq09Bni4QqqE4IAj6nS8nYZOpnFqanB0H8XTriLBg X-Received: by 2002:a05:6402:5290:b0:461:af68:9bcd with SMTP id en16-20020a056402529000b00461af689bcdmr13551214edb.67.1669301649533; Thu, 24 Nov 2022 06:54:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301649; cv=none; d=google.com; s=arc-20160816; b=IHRZMc5kU5de1BneaS+8xek1MkQt9MaWyCR9pdWGohIbaPsmJqiZvU2sIuqNLzgzeA qUbiAb9hB/fL/ukD+ngRJoixkRoR/4NsUkYWa1CQZ2m6OkO9IBhxwFVZAH64b/SpHuMa cCem8pwI+x8CIKGsLysTto0+eevl+kSuqOgSAy+j7XCS/fVzTrAEwUXWLb2Dp4sY9HvD aBEo2SLRtXBjcYagEIG8GxXXPZsY6XpbaVIwz7aurdcU1jZlQsjO00IjfIjGXtrX7DEE wHa8XzC/M1pkJ1Vjz7lTITv+P+WqxeKT9sBeNVVTpifHg3df9c93QKCUflqa7B2hkukw edYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=T7sFj9STfqpXPUwJ1BUl10NpH1W9KAHlRvGt5BNnxIc=; b=em3tnt7GuDvzUy7DQr7EBbXBWAKCUl2nqPLPaSJRceE89ePj5kM7Gg2w3ebI3ENJLS 1AuUwfxcxh+Wh7T6Lh9qot+OPZXnUiAqd8QSklulEWzLddoE6UtQvTs/3n04pGxCsAuV VdVE1TWvSKyHwnJuxWPkiTqbtzrMe2L9rkZt1nwigHtkY0InD+qtDf21KsPFkJLJLCCQ 961+vmXFB6pqg+7isokkjOVEcGo982Z9c+PjCmDPPEIpJzRHzbEUCkM/0BRZFCXBHyYP sN3jIWuM9gC/9Cu/DxMNENyMTjU0MSTxOi2QSC6ygTRdTMuFqYWU3TqwjhDu9bN5jyPo G75Q== 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 h5-20020a056402280500b0046885dfa380si595657ede.247.2022.11.24.06.53.45; Thu, 24 Nov 2022 06:54:09 -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 S229971AbiKXOvv (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbiKXOvE (ORCPT ); Thu, 24 Nov 2022 09:51:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 370131369C4 for ; Thu, 24 Nov 2022 06:50:52 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4B82FB8284D for ; Thu, 24 Nov 2022 14:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03FDCC433B5; Thu, 24 Nov 2022 14:50:48 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYt-001X7T-0O; Thu, 24 Nov 2022 09:50:47 -0500 Message-ID: <20221124145046.999511177@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:30 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Song Shuai Subject: [for-next][PATCH 11/11] ftrace: Avoid needless updates of the ftrace function call References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1750389646799599812?= X-GMAIL-MSGID: =?utf-8?q?1750389646799599812?= From: "Steven Rostedt (Google)" Song Shuai reported: The list func (ftrace_ops_list_func) will be patched first before the transition between old and new calls are set, which fixed the race described in this commit `59338f75`. While ftrace_trace_function changes from the list func to a ftrace_ops func, like unregistering the klp_ops to leave the only global_ops in ftrace_ops_list, the ftrace_[regs]_call will be replaced with the list func although it already exists. So there should be a condition to avoid this. And suggested using another variable to keep track of what the ftrace function is set to. But this could be simplified by using a helper function that does the same with a static variable. Link: https://lore.kernel.org/lkml/20221026132039.2236233-1-suagrfillet@gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20221122180905.737b6f52@gandalf.local.home Reported-by: Song Shuai Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 65a5d36463e0..d04552c0c275 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -2763,6 +2763,19 @@ void __weak ftrace_arch_code_modify_post_process(void) { } +static int update_ftrace_func(ftrace_func_t func) +{ + static ftrace_func_t save_func; + + /* Avoid updating if it hasn't changed */ + if (func == save_func) + return 0; + + save_func = func; + + return ftrace_update_ftrace_func(func); +} + void ftrace_modify_all_code(int command) { int update = command & FTRACE_UPDATE_TRACE_FUNC; @@ -2783,7 +2796,7 @@ void ftrace_modify_all_code(int command) * traced. */ if (update) { - err = ftrace_update_ftrace_func(ftrace_ops_list_func); + err = update_ftrace_func(ftrace_ops_list_func); if (FTRACE_WARN_ON(err)) return; } @@ -2799,7 +2812,7 @@ void ftrace_modify_all_code(int command) /* If irqs are disabled, we are in stop machine */ if (!irqs_disabled()) smp_call_function(ftrace_sync_ipi, NULL, 1); - err = ftrace_update_ftrace_func(ftrace_trace_function); + err = update_ftrace_func(ftrace_trace_function); if (FTRACE_WARN_ON(err)) return; }