Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp4953488rwb; Tue, 17 Jan 2023 07:28:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXsglbaB/hrs81gCr7uaLvkRu9IfRyILFzShC1Bg5deU8qfsxU+kBL6d1AXs+/yLH0Blavi+ X-Received: by 2002:a17:903:11c7:b0:194:58c7:ab79 with SMTP id q7-20020a17090311c700b0019458c7ab79mr3655954plh.63.1673969304897; Tue, 17 Jan 2023 07:28:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673969304; cv=none; d=google.com; s=arc-20160816; b=WJja3/U90YTXCWs/uMh05b3zcTMaNX10bOquS99OC0akOB+EwL35j+OIfZXoUVkLow COiFFDfZO3f4IzSB8F4Lajhy0vFW2jwUPP2Yi5i7fB4UUYYoi0Inqn+rEUatUtKW0Hf1 sWOqCdIH8E9Qc+zw5dBr6kjjc83Xk78VZP2/R6qg/59L0VIX6xUHnsRc6POpL0BqduIU DyoBElku6rG0V++/MrrECNZxUB7ThfBbK5nEsna0mhRDNqrIIvJKCnB7LKNMfTYXkHoz p8O8+xxVSlWSVpYdPjegpmJ0dyquUYJxsh718YLtheiQWUO4R5SwXniyYTDeofJS2UI0 nfDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:user-agent:message-id; bh=FXjLbd1L9VqflR51rD3NAHltoQshoFRM89I6xY1UacY=; b=S9n5A7Y7sNJmFXctsOm45uDUCMUQbcgQdpYM901UdIIDTL0FEOIILsf9svE99g7paL WPV43uGUCoAU81EXNe5yFEZgcFKzFAZU8D+RWz5bNptT3dtKd83gZlORG5awDY+dIX/h LPkg2b5yK+bSUTxcSTcNs3XuQ/THuYbpA5gozSLofbsgIZwvNYLWVMmY2rrnlhspDJWN WKkMLe784KgdCBWhG46EuyNbmTVO8uChTfL/hcb9GRH0pT+8MwWtdRYws/Dk2OhyED9R /lCN/XSKlwQ4ZtqPpfIgSP9Sc1o0OGXOz9VXAE3uaEXoQjLZFLKWlbueA+jSOWn6Meg5 n/hQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a170902cecb00b0019484efdff8si7109191plg.483.2023.01.17.07.28.18; Tue, 17 Jan 2023 07:28:24 -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 S231673AbjAQPXF (ORCPT + 48 others); Tue, 17 Jan 2023 10:23:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbjAQPWk (ORCPT ); Tue, 17 Jan 2023 10:22:40 -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 643AC302A0; Tue, 17 Jan 2023 07:22:39 -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 21C01B8164F; Tue, 17 Jan 2023 15:22:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C17B7C433EF; Tue, 17 Jan 2023 15:22:36 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pHnnH-001vhB-2A; Tue, 17 Jan 2023 10:22:35 -0500 Message-ID: <20230117152125.268986282@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 17 Jan 2023 10:21:25 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Tom Zanussi , Ross Zwisler , Ching-lin Yu Subject: [PATCH 0/6 v2] tracing/histograms: Pass stacktrace from synthetic start event to end event 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 I finally got around to implementing what I've been wanting to do for a long time! That is to pass stacktraces from the start to the end event of a synthetic event. Specifically, I need to get the stacktrace of a task as it schedules out, but I don't want to see it until it schedules back in and I check the timings to show that it is longer than normal. That is now done with: # echo 's:block_lat pid_t pid; u64 delta; unsigned long[] stack;' > dynamic_events # echo 'hist:keys=next_pid:ts=common_timestamp.usecs,st=stacktrace if prev_state == 2' >> events/sched/sched_switch/trigger # echo 'hist:keys=prev_pid:delta=common_timestamp.usecs-$ts,s=$st:onmax($delta).trace(block_lat,prev_pid,$delta,$s)' >> events/sched/sched_switch/trigger The above creates a synthetic event that will trigger on the max delta of a task blocked in an uninterruptible state. It will show you the stack trace of where that occurred! # echo 1 > events/synthetic/block_lat/enable # ls -lR > /dev/null # cat trace # tracer: nop # # entries-in-buffer/entries-written: 2/2 #P:8 # # _-----=> irqs-off/BH-disabled # / _----=> need-resched # | / _---=> hardirq/softirq # || / _--=> preempt-depth # ||| / _-=> migrate-disable # |||| / delay # TASK-PID CPU# ||||| TIMESTAMP FUNCTION # | | | ||||| | | -0 [005] d..4. 521.164922: block_lat: pid=0 delta=8322 stack=STACK: => __schedule+0x448/0x7b0 => schedule+0x5a/0xb0 => io_schedule+0x42/0x70 => bit_wait_io+0xd/0x60 => __wait_on_bit+0x4b/0x140 => out_of_line_wait_on_bit+0x91/0xb0 => jbd2_journal_commit_transaction+0x1679/0x1a70 => kjournald2+0xa9/0x280 => kthread+0xe9/0x110 => ret_from_fork+0x2c/0x50 <...>-2 [004] d..4. 525.184257: block_lat: pid=2 delta=76 stack=STACK: => __schedule+0x448/0x7b0 => schedule+0x5a/0xb0 => schedule_timeout+0x11a/0x150 => wait_for_completion_killable+0x144/0x1f0 => __kthread_create_on_node+0xe7/0x1e0 => kthread_create_on_node+0x51/0x70 => create_worker+0xcc/0x1a0 => worker_thread+0x2ad/0x380 => kthread+0xe9/0x110 => ret_from_fork+0x2c/0x50 Changes since v1: https://lore.kernel.org/linux-trace-kernel/20230117044010.838685230@goodmis.org/ - Fixed an issue with passing a stacktrace variable to another variable. - Can now use the stacktrace in the histogram as well: # echo 'hist:delta.buckets=100,stack.stacktrace:sort=delta' > events/synthetic/block_lat/trigger # cat events/synthetic/block_lat/hist # event histogram # # trigger info: hist:keys=delta.buckets=100,stacktrace:vals=hitcount:sort=delta.buckets=100:size=2048 [active] # { delta: ~ 0-99, stacktrace: event_hist_trigger+0x464/0x480 event_triggers_call+0x52/0xe0 trace_event_buffer_commit+0x193/0x250 trace_event_raw_event_sched_switch+0xfc/0x150 __traceiter_sched_switch+0x41/0x60 __schedule+0x448/0x7b0 schedule_idle+0x26/0x40 cpu_startup_entry+0x19/0x20 start_secondary+0xed/0xf0 secondary_startup_64_no_verify+0xe0/0xeb } hitcount: 6 { delta: ~ 0-99, stacktrace: event_hist_trigger+0x464/0x480 event_triggers_call+0x52/0xe0 trace_event_buffer_commit+0x193/0x250 trace_event_raw_event_sched_switch+0xfc/0x150 __traceiter_sched_switch+0x41/0x60 __schedule+0x448/0x7b0 schedule_idle+0x26/0x40 cpu_startup_entry+0x19/0x20 __pfx_kernel_init+0x0/0x10 arch_call_rest_init+0xa/0x24 start_kernel+0x964/0x98d secondary_startup_64_no_verify+0xe0/0xeb } hitcount: 3 [..] { delta: ~ 8500-8599, stacktrace: event_hist_trigger+0x464/0x480 event_triggers_call+0x52/0xe0 trace_event_buffer_commit+0x193/0x250 trace_event_raw_event_sched_switch+0xfc/0x150 __traceiter_sched_switch+0x41/0x60 __schedule+0x448/0x7b0 schedule_idle+0x26/0x40 cpu_startup_entry+0x19/0x20 start_secondary+0xed/0xf0 secondary_startup_64_no_verify+0xe0/0xeb } hitcount: 1 Totals: Hits: 89 Entries: 11 Dropped: 0 Steven Rostedt (Google) (6): tracing: Simplify calculating entry size using struct_size() tracing: Allow stacktraces to be saved as histogram variables tracing: Allow synthetic events to pass around stacktraces tracing/histogram: Add stacktrace type tracing/histogram: Document variable stacktrace tracing/histogram: Add simple tests for stacktrace usage of synthetic events ---- Documentation/trace/histogram.rst | 129 +++++++++++++++++++++ kernel/trace/trace.c | 2 +- kernel/trace/trace.h | 4 + kernel/trace/trace_events_hist.c | 63 +++++++--- kernel/trace/trace_events_synth.c | 83 ++++++++++++- kernel/trace/trace_synth.h | 1 + .../inter-event/trigger-synthetic-event-stack.tc | 24 ++++ .../inter-event/trigger-synthetic-event-syntax.tc | 6 + 8 files changed, 294 insertions(+), 18 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-stack.tc