Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4218320iog; Tue, 28 Jun 2022 11:22:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s+2P+eseuv4tPTtBKoVp2EyiCCPFVoOuqXrCuHt/5ek4bi2LIqb+T3Jht+6f6xf2Mhhi9u X-Received: by 2002:a17:902:c2d5:b0:16a:1263:9313 with SMTP id c21-20020a170902c2d500b0016a12639313mr6280844pla.138.1656440543019; Tue, 28 Jun 2022 11:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656440543; cv=none; d=google.com; s=arc-20160816; b=QCplNWQD/x1bU8swYfCoAMdTsSZpnJ+LizPNrAkjaOM7nU36ooQmcZbeFF1ZbFL+xq 8iX6VXNwc5miGGZLe4EtpsKFXVoGzAoPVtIuTHuJDZJtUnIEGhdNSAS71K+vKAPf9RVT Ejnzf7rNUjLNS5TPyuOA1jhI44QHrCvqd6dQNelUxDXZPSJV4UvI4IkUNkf/GSHpdMob lRRkuzewGKJ5LG7je9A+tY31Qur8gt+BrwhioD3pzKNfU1ioLeJmSAs9HBJ6KHz3OrpO OsSK0hNQTu/w3md2692DK3tINqhGxMO3EPmG5UKI8F/bGx725emkwUKM8uqmfyeY+plt 2eRQ== 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:subject:cc:to:from:date; bh=GwucwZfYdfA5yjqkhtZLMTVfcM1pVy27crb7QlAMiko=; b=yKaV0LkWmHtbDTUnD6kPEREz6zIf370Lj70qc7rRJaHDA27+Fr6uIXCZQbMFnTj5OT QMVuSGwz16lfgkBHyhoP/mO02q7FavAVOH/Gn6/dZXHgSL5L0ti+digRsvH2ibshzWDQ BTEjcBdIcuqMpwH6/3NjDFetbLuHCDME0HOcqtLETpBJLA1zT33HYDelHNiPGVE2wxMK +zBWQtXWkIvIg6WJT2rptNBZyKC/pSQG7ul1g8Y3GN2Q25N6Spl09QjH4BbujJTOGaSu F/C94OWW2XwwSJhA2bKhaW9A8Y7nlnDIpcu0Zr1A4k7zqDCFCyQ1c3w+JZruu901L8v6 06wg== 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 r17-20020a634411000000b00408d94d8198si184244pga.119.2022.06.28.11.22.10; Tue, 28 Jun 2022 11:22:23 -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; 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 S229955AbiF1RtX (ORCPT + 99 others); Tue, 28 Jun 2022 13:49:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233346AbiF1Rsy (ORCPT ); Tue, 28 Jun 2022 13:48:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 561ECAE4F; Tue, 28 Jun 2022 10:48:37 -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 4B86F619B3; Tue, 28 Jun 2022 17:48:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B45E3C341C8; Tue, 28 Jun 2022 17:48:34 +0000 (UTC) Date: Tue, 28 Jun 2022 13:48:33 -0400 From: Steven Rostedt To: Daniel Bristot de Oliveira Cc: 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: Re: [PATCH V4 03/20] rv/include: Add helper functions for deterministic automata Message-ID: <20220628134833.60b69f9f@gandalf.local.home> In-Reply-To: <2b5b14c821ee4b069f68571e7f78fbc2ee4e9626.1655368610.git.bristot@kernel.org> References: <2b5b14c821ee4b069f68571e7f78fbc2ee4e9626.1655368610.git.bristot@kernel.org> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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, 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 On Thu, 16 Jun 2022 10:44:45 +0200 Daniel Bristot de Oliveira wrote: > Formally, a deterministic automaton, denoted by G, is defined as a > quintuple: > > G = { X, E, f, x_0, X_m } > > where: > - X is the set of states; > - E is the finite set of events; > - x_0 is the initial state; > - X_m (subset of X) is the set of marked states. > - f : X x E -> X $ is the transition function. It defines the > state transition in the occurrence of a event from E in > the state X. In the special case of deterministic automata, > the occurrence of the event in E in a state in X has a > deterministic next state from X. > > An automaton can also be represented using a graphical format of > vertices (nodes) and edges. The open-source tool Graphviz can produce > this graphic format using the (textual) DOT language as the source code. > > The dot2c tool presented in this paper: > > DE OLIVEIRA, Daniel Bristot; CUCINOTTA, Tommaso; DE OLIVEIRA, Romulo > Silva. Efficient formal verification for the Linux kernel. In: > International Conference on Software Engineering and Formal Methods. > Springer, Cham, 2019. p. 315-332. > > Translates a deterministic automaton in the DOT format into a C > source code representation that to be used for monitoring. > > This header file implements helper functions to facilitate the usage > of the C output from dot2c for monitoring. > > 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 > --- > include/rv/automata.h | 49 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 49 insertions(+) > create mode 100644 include/rv/automata.h > > diff --git a/include/rv/automata.h b/include/rv/automata.h > new file mode 100644 > index 000000000000..0c0aa54bd820 > --- /dev/null > +++ b/include/rv/automata.h > @@ -0,0 +1,49 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Deterministic automata helper functions, to be used with the automata > + * models in C generated by the dot2k tool. > + * > + * Copyright (C) 2019-2022 Daniel Bristot de Oliveira Copyright before the description. > + */ > + There should be comments here describing how the helper functions are used. -- Steve > +#define DECLARE_AUTOMATA_HELPERS(name, type) \ > + \ > +static inline void *model_get_model_##name(void) \ > +{ \ > + return (void *) &automaton_##name; \ > +} \ > + \ > +static char *model_get_state_name_##name(enum states_##name state) \ > +{ \ > + return automaton_##name.state_names[state]; \ > +} \ > + \ > +static char *model_get_event_name_##name(enum events_##name event) \ > +{ \ > + return automaton_##name.event_names[event]; \ > +} \ > + \ > +static inline type model_get_init_state_##name(void) \ > +{ \ > + return automaton_##name.initial_state; \ > +} \ > + \ > +static inline type model_get_next_state_##name(enum states_##name curr_state, \ > + enum events_##name event) \ > +{ \ > + if ((curr_state < 0) || (curr_state > state_max_##name)) \ > + return -1; \ > + \ > + if ((event < 0) || (event > event_max_##name)) \ > + return -1; \ > + \ > + return automaton_##name.function[curr_state][event]; \ > +} \ > + \ > +static inline bool model_is_final_state_##name(enum states_##name state) \ > +{ \ > + if ((state < 0) || (state > state_max_##name)) \ > + return 0; \ > + \ > + return !!automaton_##name.final_states[state]; \ > +}