Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1232992iog; Thu, 16 Jun 2022 01:49:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tTrYHYJ7UeUTqtIJNQ2VabmKa0I5qpVodkBNkEN2Z7DUHaYaSJTZlglWTnV5VNdM7u1wFK X-Received: by 2002:a17:907:6ea4:b0:711:d106:b93a with SMTP id sh36-20020a1709076ea400b00711d106b93amr3514456ejc.189.1655369359474; Thu, 16 Jun 2022 01:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655369359; cv=none; d=google.com; s=arc-20160816; b=RwhrWHAJkYKWETaGuFBjO5SQTWFFklAnz2MBgJXPDNkM7AVUOL8zIhqdgnzgv6/A28 GAMZpiCofONYP9ZLvw6iJyoxvC/V5jANb5su40j7N2olfAixgjfYkqPO3f5iQicj9Qjm 92NcsOB3/xn3mjh6OuVuvqtbLOJS9JspV7mr06OX2Cyrk0zz5N/DM9tktfFk9UOy5hYG XAkEFMpQP+SKKes407H/gbrnmYfM1zTx6HDQ7KM4iJaJ6A6N2mSUErJ2qU1UECOYXIAG 77KdYtE4rXh/R52fKXQvDqDPro30mTdFPuljgmJFCPSfO7rUmTlbHYF5m18SEWhSCUUg x8QA== 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=TqZBAsR0BAf8O+3aGpeAuhxxOSqhZNHR/i7W9tOvCBo=; b=CNcKKXkxwX+qtCIhJhhAEPUND6w4IvJ3Lxbocnmuif674Q35I0yiXjOCGxE5KAIHk8 lEQFjwpJLQ8i6vYwaKB9z28Chyi5wS8IMDxtO36M/54b7KMsRMGVjI51XFslWjsNlEij sTz4NwKhHJJNWvg2PlyLvZjQVnlvU318f0cxeSDGMwA0tTcgFquvbXlhEinQ/AVjIHLG 74mQ3J2HFK61E8IZNDAWvJ6CDImJRHXBESeVO1XSCMTAy5kikiGYEJkcO/64es/3fqhc UrtZrpncm06gWMo1jc9XN4y8dhS0nZDEUUSgrAMY0Gk2mCi1LOIrj09af5z9H80ViX1W phqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TA4JNrII; 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 g21-20020a1709065d1500b006febc5db63bsi989145ejt.888.2022.06.16.01.48.54; Thu, 16 Jun 2022 01:49:19 -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=TA4JNrII; 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 S1359745AbiFPIqy (ORCPT + 99 others); Thu, 16 Jun 2022 04:46:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359817AbiFPIqH (ORCPT ); Thu, 16 Jun 2022 04:46:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C89525DBCF; Thu, 16 Jun 2022 01:46:04 -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 ams.source.kernel.org (Postfix) with ESMTPS id 54CC4B81E20; Thu, 16 Jun 2022 08:46:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4031C341C0; Thu, 16 Jun 2022 08:45:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655369162; bh=QJ0oWYDc7OPYMH2YBsjWV6GFlgp05pic3QCtSoNMg0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TA4JNrII/Pxpf01tIQdJIhstCWVXVR2JAXyErTSf1rpdgdwniKmxVfad/mMY1NucH 0da+h9p2JRmZoK9gb9a1GlcVDoZQM3ycM4I+IW/vyyfBbbcJQ/GLwSVKkEeuItTuTw f8yyEgBC+DF8sQM0H18rNNuDIxh16JINOVXhkZqdn/Jk5cZ6ft5VQhwd1gppZigLwd dNwrcsK5KK8/MtN9R8XTDJE9YnPIFBcglAFHZCLC9Alzt/+bqvT51e9WLn2bm1kNek LEwkShhbDtcqjc7tQU+bSfSXroUlCNfddZvWbLspj+Uml9Ktd1HuuUcbDPPt+7R9oE p6A6vWCI27/ww== From: Daniel Bristot de Oliveira To: Steven Rostedt Cc: Daniel Bristot de Oliveira , Wim Van Sebroeck , Guenter Roeck , 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: [PATCH V4 10/20] rv/monitor: Add the wwnr monitor skeleton created by dot2k Date: Thu, 16 Jun 2022 10:44:52 +0200 Message-Id: <7d1b2238aa5c805501ae3dc80b213d06f6588cb3.1655368610.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: Wim Van Sebroeck Cc: Guenter Roeck 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/monitors/wwnr/wwnr.c | 115 +++++++++++++++++++++++++++ kernel/trace/rv/monitors/wwnr/wwnr.h | 38 +++++++++ 2 files changed, 153 insertions(+) create mode 100644 kernel/trace/rv/monitors/wwnr/wwnr.c create mode 100644 kernel/trace/rv/monitors/wwnr/wwnr.h diff --git a/kernel/trace/rv/monitors/wwnr/wwnr.c b/kernel/trace/rv/monitors/wwnr/wwnr.c new file mode 100644 index 000000000000..8ba01f0f0df8 --- /dev/null +++ b/kernel/trace/rv/monitors/wwnr/wwnr.c @@ -0,0 +1,115 @@ +// 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 + */ +#include + +/* + * This is the self-generated part of the monitor. Generally, there is no need + * to touch this section. + */ +#include "wwnr.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); + +/* + * 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_wwnr); +} + +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_wwnr); +} + +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_wwnr); +} + +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/monitors/wwnr/wwnr.h b/kernel/trace/rv/monitors/wwnr/wwnr.h new file mode 100644 index 000000000000..f3dc160642bf --- /dev/null +++ b/kernel/trace/rv/monitors/wwnr/wwnr.h @@ -0,0 +1,38 @@ +enum states_wwnr { + not_running_wwnr = 0, + running_wwnr, + state_max_wwnr +}; + +enum events_wwnr { + switch_in_wwnr = 0, + switch_out_wwnr, + wakeup_wwnr, + event_max_wwnr +}; + +struct automaton_wwnr { + char *state_names[state_max_wwnr]; + char *event_names[event_max_wwnr]; + char function[state_max_wwnr][event_max_wwnr]; + char initial_state; + char final_states[state_max_wwnr]; +}; + +struct automaton_wwnr automaton_wwnr = { + .state_names = { + "not_running", + "running" + }, + .event_names = { + "switch_in", + "switch_out", + "wakeup" + }, + .function = { + { running_wwnr, -1, not_running_wwnr }, + { -1, not_running_wwnr, -1 }, + }, + .initial_state = not_running_wwnr, + .final_states = { 1, 0 }, +}; -- 2.35.1