Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5903120pxb; Mon, 14 Feb 2022 10:14:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxilEHPlzZmn7ne9KZQoowLuc0Xih+xqXmmUQEausPpG++5DFo5impo8yWdGY/FdtvOXJMS X-Received: by 2002:a17:90b:1b0b:: with SMTP id nu11mr8569163pjb.211.1644862487417; Mon, 14 Feb 2022 10:14:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644862487; cv=none; d=google.com; s=arc-20160816; b=MDas/9MfQr1ZJP4/eY2yGeFlK9ixvhBfzdgSX2ablYsiMkUeAeRXTkLkLsicHngyWi x9XT96ERKgYE3wTtYvrDUvgemlfDTbpNE0EpGfKC97K2N1mErX/zOf1uf1Zo/Plz3Rff Bea3c5xaRCAJyiNFfV/XMOczztb96lAu7361ulW+WbwyeQx+Q8yHSvNp+ypYCUYO6zkN b+HfjpI9VsAiwkYPBnpE5vHzE9tbEpwu18gtPOcmmem1JL36sS2r3yGPOsKjTJk0nGR6 6FWbtahma7q2AdldZxjPkyBNZdf7EKg2mzEUJnUx+ygWt9AIRO/AcewkfuGjxclY8BW8 t4YA== 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; bh=8lMMXQQi/XOITBzwjjjQVw31eNqrbifN+gfDvL6sV+U=; b=BgzgeKOjXO5B6YXpZiuPlYBL7yv1O3Dup3Wp6ySRnhTv97r0vJfs2N9x0nYUCKjZ/I 2pPufKrV948nwZHqKYGOPxDz85Yxf7nIwWhVB5AR3kWDOaA9TrMMklDc9vDao2t7Gwai 12S/ofTv+Wc6cnwa5tfx3t/kkxK1kCA5WpOPWq4gAuEM5fC4VqtmukKOY1dvoeCG8j0O FdH8ewKmY9aUvCAm9RAFzWgzheCzKTeScl5oh8chT1N0TQZyQ0JMjES54qXU8cf88Rju myr1CrDIsY0w3GbXn4HbH6w5QIqi4JoLMqW4olfD1FiF1TPsW/UIskCKPyZUnlq/a4Nu D2VA== 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; 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 b7si28209156pff.301.2022.02.14.10.14.30; Mon, 14 Feb 2022 10:14: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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351035AbiBNLXS convert rfc822-to-8bit (ORCPT + 99 others); Mon, 14 Feb 2022 06:23:18 -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: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 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 = 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..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 events + * are translated into model's event. + * + */ + +void handle_switch_in(void *data, /* XXX: fill header */) +{ + pid_t pid = /* 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 = /* 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 = /* 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] = { + { + .probe = handle_switch_in, + .name = /* XXX: tracepoint name here */, + .registered = 0 + }, + { + .probe = handle_switch_out, + .name = /* XXX: tracepoint name here */, + .registered = 0 + }, + { + .probe = handle_wakeup, + .name = /* XXX: tracepoint name here */, + .registered = 0 + }, +}; + +static int start_wwnr(void) +{ + int retval; + + da_monitor_init_wwnr(); + + retval = 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 = 0; + thh_unhook_probes(tracepoints_to_hook, NR_TP); + return; +} + +/* + * 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 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 = 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.33.1