Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2651705iob; Fri, 6 May 2022 07:35:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3hgifJ1IsVIS0enczmg3MfG7saeI3fsrYNyuFhOmuOi9P2YB0UxDjnkIGmeueRL19oxH4 X-Received: by 2002:a17:907:60d3:b0:6f5:c4c3:2f96 with SMTP id hv19-20020a17090760d300b006f5c4c32f96mr1082967ejc.724.1651847728508; Fri, 06 May 2022 07:35:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651847728; cv=none; d=google.com; s=arc-20160816; b=gbkS2bqKQ99aZsghrP5mStjN4mTLUt3jZ/fRdkMRCzo/1vdkfpuOx+6kZZ2cwZft+6 B5WN+kczU2OU1pi/tFfUdMspQOZqcJZdnjj/ksClxn9Tc8/G6H4RMEMn3RGvq3YtNlIz S/T8oFA+DR8cr2vA55IwjavkScU4qF5Dumz75h/7wMDBg50VI0Tx3cMLNS0ewMm6usJE bFgh3oCL/UbvbO8vxyvjUZk3BAXdP1zCzuYTMXrnHFp6Qug+cMCSXyF/8VYYyDAiab/U ezJuwZuzmXeUinCIfLio6nLitA0TRqxMowHukino2lFD+MkjT8T93a2XZpL5eioLAIN9 HAOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sjx8RmZU/JAd1eGzfGkmRlxsKCcZcuxthoeVHmB6XJU=; b=TMl2NxRb2IjaDHLFhfqIDs0YxfjrBx59SCZmF2aLaWaywvrQjkwduYX/8YSL+gmq3+ SJPqYbHooZO4+r82Lfi/L92XqYduho+mW5QNVAGamO7LEaIFT96AZTl2Y6g9hkBJ9XuD 1c7Smp3nT3h4tY1OUoCetiCt9SBz1HrXRnol0uC5oc1l/zlVyo57gsMPN+IkXnm6fpiF 8oGRZ3L6JGQxO6XQtJkfB7kxeGZQYcy0DT507T7o1BN+Kv0bRg1PnOPVRgIs1SVJzQ9y +joSHzbDoE/A6cizWEbLNAmCtrn9nlterL7ptXCZ0grDKkBSwdAlcSrxa6Ro59FQyhw8 dO1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rxA6eiDq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mh18-20020a170906eb9200b006e893bdaefesi4701725ejb.884.2022.05.06.07.35.03; Fri, 06 May 2022 07:35:28 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rxA6eiDq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381749AbiEEQM1 (ORCPT + 99 others); Thu, 5 May 2022 12:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381787AbiEEQMB (ORCPT ); Thu, 5 May 2022 12:12:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A1255C743; Thu, 5 May 2022 09:08:03 -0700 (PDT) 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 2483661DE3; Thu, 5 May 2022 16:08:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3968C385A8; Thu, 5 May 2022 16:07:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651766882; bh=Whk5YJpHdCyxnpwzp/sUXfn6ZORNvXLgp8Xr1jnbHHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rxA6eiDqmmJCKR8GQW031uQ5nb6osQCTqhsm7YMOwl17IDtrbdRpIRpjz3x4zZg+q ZfnmZE0Jcecvmp2E3r1tJbNEIsPRiFK6CZSD+Qg3+ehsu9WjUkeGrg0DTchu6AzFZn rKKsYvvqZRuYRJc2CO5kLJOsSAiR7euReHI50+y5JABHPb+0oE7hSIIA8Ki5i9E4Kd +RnxTuhH3n385SjAORBFXjHTeeCJZK8DI+mBgb0dhoKe6Wc2zX07SAFsLYOB4XUfLY K9v84LRCXKZAS6U0e2/CaN0IafHPVtvsPaTLsjF43/dQ9kBQZaKaWq3g4K+755JRWi 5zNwkaIsVfMdA== From: Daniel Bristot de Oliveira To: Steven Rostedt , linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Jonathan Corbet , Ingo Molnar , Thomas Gleixner , Peter Zijlstra , Will Deacon , Catalin Marinas , Marco Elver , Dmitry Vyukov , "Paul E. McKenney" , Shuah Khan , Gabriele Paoloni , Juri Lelli , Clark Williams , linux-doc@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [RFC V3 10/20] rv/monitor: Add the wwnr monitor skeleton created by dot2k Date: Thu, 5 May 2022 18:06:50 +0200 Message-Id: <6ba97ca1d6bd265a573b39e9efe2a0c039e722f7.1651766361.git.bristot@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Per task wakeup while not running (wwnr) monitor, generated by dot2k with this command line: $ dot2k -d wwnr.dot -t per_task The model is: ----- %< ----- digraph state_automaton { center = true; size = "7,11"; {node [shape = plaintext, style=invis, label=""] "__init_not_running"}; {node [shape = ellipse] "not_running"}; {node [shape = plaintext] "not_running"}; {node [shape = plaintext] "running"}; "__init_not_running" -> "not_running"; "not_running" [label = "not_running", color = green3]; "not_running" -> "not_running" [ label = "wakeup" ]; "not_running" -> "running" [ label = "switch_in" ]; "running" [label = "running"]; "running" -> "not_running" [ label = "switch_out" ]; { rank = min ; "__init_not_running"; "not_running"; } } ----- >% ----- This model is broken, the reason is that a task can be running in the processor without being set as RUNNABLE. Think about a task about to sleep: 1: set_current_state(TASK_UNINTERRUPTIBLE); 2: schedule(); And then imagine an IRQ happening in between the lines one and two, waking the task up. BOOM, the wakeup will happen while the task is running. Q: Why do we need this model, so? A: To test the reactors. Cc: Jonathan Corbet Cc: Steven Rostedt Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Will Deacon Cc: Catalin Marinas Cc: Marco Elver Cc: Dmitry Vyukov Cc: "Paul E. McKenney" Cc: Shuah Khan Cc: Gabriele Paoloni Cc: Juri Lelli Cc: Clark Williams Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-trace-devel@vger.kernel.org Signed-off-by: Daniel Bristot de Oliveira --- kernel/trace/rv/monitor_wwnr/model.h | 38 +++++++++ kernel/trace/rv/monitor_wwnr/wwnr.c | 118 +++++++++++++++++++++++++++ kernel/trace/rv/monitor_wwnr/wwnr.h | 70 ++++++++++++++++ 3 files changed, 226 insertions(+) create mode 100644 kernel/trace/rv/monitor_wwnr/model.h create mode 100644 kernel/trace/rv/monitor_wwnr/wwnr.c create mode 100644 kernel/trace/rv/monitor_wwnr/wwnr.h diff --git a/kernel/trace/rv/monitor_wwnr/model.h b/kernel/trace/rv/monitor_wwnr/model.h new file mode 100644 index 000000000000..7840ffbda98d --- /dev/null +++ b/kernel/trace/rv/monitor_wwnr/model.h @@ -0,0 +1,38 @@ +enum states_wwnr { + not_running = 0, + running, + state_max +}; + +enum events_wwnr { + switch_in = 0, + switch_out, + wakeup, + event_max +}; + +struct automaton_wwnr { + char *state_names[state_max]; + char *event_names[event_max]; + char function[state_max][event_max]; + char initial_state; + char final_states[state_max]; +}; + +struct automaton_wwnr automaton_wwnr = { + .state_names = { + "not_running", + "running" + }, + .event_names = { + "switch_in", + "switch_out", + "wakeup" + }, + .function = { + { running, -1, not_running }, + { -1, not_running, -1 }, + }, + .initial_state = not_running, + .final_states = { 1, 0 }, +}; \ No newline at end of file diff --git a/kernel/trace/rv/monitor_wwnr/wwnr.c b/kernel/trace/rv/monitor_wwnr/wwnr.c new file mode 100644 index 000000000000..1ad3365c0d22 --- /dev/null +++ b/kernel/trace/rv/monitor_wwnr/wwnr.c @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "wwnr" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ + +/* + * This is the self-generated part of the monitor. Generally, there is no need + * to touch this section. + */ +#include "model.h" + +/* + * Declare the deterministic automata monitor. + * + * The rv monitor reference is needed for the monitor declaration. + */ +struct rv_monitor rv_wwnr; +DECLARE_DA_MON_PER_TASK(wwnr, char); + +#define CREATE_TRACE_POINTS +#include "wwnr.h" + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel events + * are translated into model's event. + * + */ +static void handle_switch_in(void *data, /* XXX: fill header */) +{ + struct task_struct *p = /* XXX: how do I get p? */; + da_handle_event_wwnr(p, switch_in); +} + +static void handle_switch_out(void *data, /* XXX: fill header */) +{ + struct task_struct *p = /* XXX: how do I get p? */; + da_handle_event_wwnr(p, switch_out); +} + +static void handle_wakeup(void *data, /* XXX: fill header */) +{ + struct task_struct *p = /* XXX: how do I get p? */; + da_handle_event_wwnr(p, wakeup); +} + + +static int start_wwnr(void) +{ + int retval; + + retval = da_monitor_init_wwnr(); + if (retval) + return retval; + + rv_attach_trace_probe("wwnr", /* XXX: tracepoint */, handle_switch_in); + rv_attach_trace_probe("wwnr", /* XXX: tracepoint */, handle_switch_out); + rv_attach_trace_probe("wwnr", /* XXX: tracepoint */, handle_wakeup); + + return 0; +} + +static void stop_wwnr(void) +{ + rv_wwnr.enabled = 0; + + rv_detach_trace_probe("wwnr", /* XXX: tracepoint */, handle_switch_in); + rv_detach_trace_probe("wwnr", /* XXX: tracepoint */, handle_switch_out); + rv_detach_trace_probe("wwnr", /* XXX: tracepoint */, handle_wakeup); + + da_monitor_destroy_wwnr(); +} + +/* + * This is the monitor register section. + */ +struct rv_monitor rv_wwnr = { + .name = "wwnr", + .description = "auto-generated wwnr", + .start = start_wwnr, + .stop = stop_wwnr, + .reset = da_monitor_reset_all_wwnr, + .enabled = 0, +}; + +int register_wwnr(void) +{ + rv_register_monitor(&rv_wwnr); + return 0; +} + +void unregister_wwnr(void) +{ + if (rv_wwnr.enabled) + stop_wwnr(); + + rv_unregister_monitor(&rv_wwnr); +} + +module_init(register_wwnr); +module_exit(unregister_wwnr); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("dot2k: auto-generated"); +MODULE_DESCRIPTION("wwnr"); diff --git a/kernel/trace/rv/monitor_wwnr/wwnr.h b/kernel/trace/rv/monitor_wwnr/wwnr.h new file mode 100644 index 000000000000..4af1827d2f16 --- /dev/null +++ b/kernel/trace/rv/monitor_wwnr/wwnr.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM rv + +#if !defined(_WWNR_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) +#define _WWNR_TRACE_H + +#include + +TRACE_EVENT(event_wwnr, + + TP_PROTO(pid_t pid, char state, char event, char next_state, bool safe), + + TP_ARGS(pid, state, event, next_state, safe), + + TP_STRUCT__entry( + __field( pid_t, pid ) + __field( char, state ) + __field( char, event ) + __field( char, next_state ) + __field( bool, safe ) + ), + + TP_fast_assign( + __entry->pid = pid; + __entry->state = state; + __entry->event = event; + __entry->next_state = next_state; + __entry->safe = safe; + ), + + TP_printk("%d: %s x %s -> %s %s", + __entry->pid, + model_get_state_name_wwnr(__entry->state), + model_get_event_name_wwnr(__entry->event), + model_get_state_name_wwnr(__entry->next_state), + __entry->safe ? "(safe)" : "") +); + +TRACE_EVENT(error_wwnr, + + TP_PROTO(pid_t pid, char state, char event), + + TP_ARGS(pid, state, event), + + TP_STRUCT__entry( + __field( pid_t, pid ) + __field( char, state ) + __field( char, event ) + ), + + TP_fast_assign( + __entry->pid = pid; + __entry->state = state; + __entry->event = event; + ), + + TP_printk("%d event %s not expected in the state %s", + __entry->pid, + model_get_event_name_wwnr(__entry->event), + model_get_state_name_wwnr(__entry->state)) +); + +#endif /* _WWNR_H */ + +/* This part ust be outside protection */ +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . +#define TRACE_INCLUDE_FILE wwnr +#include -- 2.35.1