From nobody Sun Dec 14 06:20:10 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CF2DC433F5 for ; Mon, 14 Feb 2022 11:23:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245154AbiBNLXV convert rfc822-to-8bit (ORCPT ); Mon, 14 Feb 2022 06:23:21 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351050AbiBNLVt (ORCPT ); Mon, 14 Feb 2022 06:21:49 -0500 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 70FE325C7F for ; Mon, 14 Feb 2022 02:58:01 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-586-eWrSgEUiP0Oe6xi_Lo_XQw-1; Mon, 14 Feb 2022 05:47:05 -0500 X-MC-Unique: eWrSgEUiP0Oe6xi_Lo_XQw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47AFA81424A; Mon, 14 Feb 2022 10:47:03 +0000 (UTC) Received: from x1.com (unknown [10.22.16.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70AC526DFB; Mon, 14 Feb 2022 10:46:59 +0000 (UTC) From: Daniel Bristot de Oliveira To: Steven Rostedt 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-kernel@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [RFC V2 10/21] rv/monitor: Add the wwnr monitor skeleton created by dot2k Date: Mon, 14 Feb 2022 11:45:01 +0100 Message-Id: <57f0c4ed581aab9b4099c9d359259f9dd831cd58.1644830251.git.bristot@kernel.org> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=bristot@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D true; size =3D "7,11"; {node [shape =3D plaintext, style=3Dinvis, label=3D""] "__init_not_running= "}; {node [shape =3D ellipse] "not_running"}; {node [shape =3D plaintext] "not_running"}; {node [shape =3D plaintext] "running"}; "__init_not_running" -> "not_running"; "not_running" [label =3D "not_running", color =3D green3]; "not_running" -> "not_running" [ label =3D "wakeup" ]; "not_running" -> "running" [ label =3D "switch_in" ]; "running" [label =3D "running"]; "running" -> "not_running" [ label =3D "switch_out" ]; { rank =3D 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 | 127 +++++++++++++++++++++++++++ kernel/trace/rv/monitor_wwnr/wwnr.h | 70 +++++++++++++++ 3 files changed, 235 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 =3D 0, + running, + state_max +}; + +enum events_wwnr { + switch_in =3D 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 =3D { + .state_names =3D { + "not_running", + "running" + }, + .event_names =3D { + "switch_in", + "switch_out", + "wakeup" + }, + .function =3D { + { running, -1, not_running }, + { -1, not_running, -1 }, + }, + .initial_state =3D not_running, + .final_states =3D { 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..91cb3b70a6a7 --- /dev/null +++ b/kernel/trace/rv/monitor_wwnr/wwnr.c @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "wwnr" + +/* + * 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 even= ts + * are translated into model's event. + * + */ + +void handle_switch_in(void *data, /* XXX: fill header */) +{ + pid_t pid =3D /* XXX how do I get the pid? */; + da_handle_event_wwnr(pid, switch_in); +} + +void handle_switch_out(void *data, /* XXX: fill header */) +{ + pid_t pid =3D /* XXX how do I get the pid? */; + da_handle_event_wwnr(pid, switch_out); +} + +void handle_wakeup(void *data, /* XXX: fill header */) +{ + pid_t pid =3D /* XXX how do I get the pid? */; + da_handle_event_wwnr(pid, wakeup); +} + +#define NR_TP 3 +static struct tracepoint_hook_helper tracepoints_to_hook[NR_TP] =3D { + { + .probe =3D handle_switch_in, + .name =3D /* XXX: tracepoint name here */, + .registered =3D 0 + }, + { + .probe =3D handle_switch_out, + .name =3D /* XXX: tracepoint name here */, + .registered =3D 0 + }, + { + .probe =3D handle_wakeup, + .name =3D /* XXX: tracepoint name here */, + .registered =3D 0 + }, +}; + +static int start_wwnr(void) +{ + int retval; + + da_monitor_init_wwnr(); + + retval =3D thh_hook_probes(tracepoints_to_hook, NR_TP); + if (retval) + goto out_err; + + return 0; + +out_err: + return -EINVAL; +} + +static void stop_wwnr(void) +{ + rv_wwnr.enabled =3D 0; + thh_unhook_probes(tracepoints_to_hook, NR_TP); + return; +} + +/* + * This is the monitor register section. + */ +struct rv_monitor rv_wwnr =3D { + .name =3D "wwnr", + .description =3D "auto-generated wwnr", + .start =3D start_wwnr, + .stop =3D stop_wwnr, + .reset =3D da_monitor_reset_all_wwnr, + .enabled =3D 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 v2"); +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 =3D pid; + __entry->state =3D state; + __entry->event =3D event; + __entry->next_state =3D next_state; + __entry->safe =3D 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 =3D pid; + __entry->state =3D state; + __entry->event =3D 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 --=20 2.33.1