Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp500517imn; Wed, 27 Jul 2022 11:58:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sgxeBEmtNv9ATSaplIaXPkTHNcS4qaWpDlhAGV4Uy2QRI9lpH0SvfVqpi0zPNZtoPq1HOx X-Received: by 2002:a17:907:b590:b0:72e:dba4:86b3 with SMTP id qx16-20020a170907b59000b0072edba486b3mr17873428ejc.376.1658948327572; Wed, 27 Jul 2022 11:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658948327; cv=none; d=google.com; s=arc-20160816; b=z4c3K10+pi/C3gbv+Q5YwhLTa7Id0MCNgWk/pV5ZTH+C/3gYdk8CRyT0ndUI9w24O3 VJbY4RoTn6tolN0cn/bn9szGXLJoSfrZTis2dteXMK/Jp+MjQY8PDeo/9vzFDO+mP3zA bkGqJ3LlAZxYUhn4AJNPXIFQdZoBIhXFhOvIRZt5pDiXe0PWTJmM/lZQNqowj1fzMWd0 uyzS8qdOQqW7AdKQtuIXuhx1Ob4i0hqCwIQ078IfZ7OCfqby9ZaLCmfeXux+7cs0dFHz D7uEiXhYiS7oOCc3gHES2Ray1gCA6UhA4+0DrSvs4Y6rKNT9hmcVoCmWBQ+IzPPmv6T8 08DQ== 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=iAj5ZioNRRrLuEcSWmuk8N3I6ARoUaGz+UrSV1kSGSo=; b=iYpvXq3uX8qIlLG8uqX3y1scnA8DiEj1bpIWP+U5YOlD6iZ77ZcBqptxJeGX+iwSu7 bX7xO398+g23bG2o+k/UhW2sU41k51k0TlFAM/AfYDIEZJrWqPIqpAga8kHTEfur2PaG CM/b8+4dMHskj2qWIIsWit2gnxxNCXJeNLbj0FtPh0J5WxCCz1FlXaEOsBNeYyoP30fk 725P6W3C8rTO8L8GnN6tjoDEy/l9ce33SRqkdNiToonMmp6C7PNRtxG859oxJfKEODA6 ehhvn5HvcucWJQFObocTVG0+v5P6u01ikC4mzyxkfkgTfMW4FIV+U1EWBqAcyas5jjBm C6kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=P9vcZN3F; 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 y12-20020a056402270c00b0043bc6013b81si20966487edd.67.2022.07.27.11.58.22; Wed, 27 Jul 2022 11:58:47 -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=P9vcZN3F; 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 S243341AbiG0SJq (ORCPT + 99 others); Wed, 27 Jul 2022 14:09:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243362AbiG0SJM (ORCPT ); Wed, 27 Jul 2022 14:09:12 -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 2397274DC8; Wed, 27 Jul 2022 10:12:23 -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 AC55461961; Wed, 27 Jul 2022 17:12:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B5DDC433C1; Wed, 27 Jul 2022 17:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658941942; bh=oWw25mtkJXkfmoetD7cNHKyHoDEVZWd1NhnSPh98QnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P9vcZN3FoAoJ8F2upTHEp2AHINmm2QaNnKUJneD2BZMtNh7kXRG88BJX4ta1ljzI6 DkrkCWp0li9jMxidIPfXl4sUTvsz7rw7iXjKNrd0eBqu4btS0bijX42VQpKkAYY8rb CaEPKmv47BI03qwYLz3ou+IBFv0NQf7+RlRN3HDI78Q6D1d50ie6habokawnPqUxY5 Qnd4ZZtaXlM8U5nwZR5993o1FjZnIvGtJ4dyKzvgLXTQYSxj689I6oDrFSQUB7TE8N x6uE79WmypOlwvBmU4MaF/QGIm1ogk+KXDCZy0SgvGAAd07d8A1FP9qUkwnuEGkW+D BpMaxH1XPtmAw== 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 , Tao Zhou , Randy Dunlap , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH V8 03/16] rv/include: Add helper functions for deterministic automata Date: Wed, 27 Jul 2022 19:11:31 +0200 Message-Id: <848de944f3949714eb2f4fb2e27ffc972519ded2.1658940828.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 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 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/k 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: Tao Zhou Cc: Randy Dunlap 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 | 75 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 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..eb9e636809a0 --- /dev/null +++ b/include/rv/automata.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2019-2022 Red Hat, Inc. Daniel Bristot de Oliveira + * + * Deterministic automata helper functions, to be used with the automata + * models in C generated by the dot2k tool. + */ + +/* + * DECLARE_AUTOMATA_HELPERS - define a set of helper functions for automata + * + * Define a set of helper functions for automata. The 'name' argument is used + * as suffix for the functions and data. These functions will handle automaton + * with data type 'type'. + */ +#define DECLARE_AUTOMATA_HELPERS(name, type) \ + \ +/* \ + * model_get_state_name_##name - return the (string) name of the given state \ + */ \ +static char *model_get_state_name_##name(enum states_##name state) \ +{ \ + if ((state < 0) || (state >= state_max_##name)) \ + return "INVALID"; \ + \ + return automaton_##name.state_names[state]; \ +} \ + \ +/* \ + * model_get_event_name_##name - return the (string) name of the given event \ + */ \ +static char *model_get_event_name_##name(enum events_##name event) \ +{ \ + if ((event < 0) || (event >= event_max_##name)) \ + return "INVALID"; \ + \ + return automaton_##name.event_names[event]; \ +} \ + \ +/* \ + * model_get_initial_state_##name - return the automaton's initial state \ + */ \ +static inline type model_get_initial_state_##name(void) \ +{ \ + return automaton_##name.initial_state; \ +} \ + \ +/* \ + * model_get_next_state_##name - process an automaton event occurrence \ + * \ + * Given the current state (curr_state) and the event (event), returns \ + * the next state, or INVALID_STATE in case of error. \ + */ \ +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 INVALID_STATE; \ + \ + if ((event < 0) || (event >= event_max_##name)) \ + return INVALID_STATE; \ + \ + return automaton_##name.function[curr_state][event]; \ +} \ + \ +/* \ + * model_is_final_state_##name - check if the given state is a final state \ + */ \ +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]; \ +} -- 2.35.1