Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1152879imw; Wed, 13 Jul 2022 14:47:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sI4BHzPTBdChs1LF30nty+eF12AuY5c4KOECVrs0M73JsqqKU/g6Ae5bHhZjQUtG5tOIFs X-Received: by 2002:a05:6402:3591:b0:43a:9076:e2be with SMTP id y17-20020a056402359100b0043a9076e2bemr7862057edc.171.1657748864410; Wed, 13 Jul 2022 14:47:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657748864; cv=none; d=google.com; s=arc-20160816; b=AWRRSaLqmxThu684RB73RBUFivCL2Vy2DwFVdXIEqQCu9+oxYazDc3UPEIO4Tj4B11 R0FjPsO2TkgQ/kDYptfb8UZkzBVeLnbyuP55lCBG+zJ6bX/iGjWTjxquSiot1U4G7dVB gC2WaQP+6UNziCIS5pQbxlCysxBQhEpvM3ibYOz0hDk562bXa0GDcwZ1WHcwRo24ySkc /HP+UOpVRZiRtyoeolyBRSaS7u8pmTDvGCmdH9GL45DIAi55FC8nCfxM8+psvFdi9sCV g4xRvJwkdLVe4osLj/SIyXg30q5du0lX1cOB+e5X0fz/R6SX1BYQd0Q/1LhecOHJ5wYR ZgQQ== 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=kbz4QNH114GFa2BhCDaLw4nzFL8VrZQGHCB6Tc5ZQf8=; b=BpG9qD2atpi5r7UOK1jL7eOXBl9NHbiWH7wcA5QR8+kmN06M6DhC1RbLBNK/tpGEBR Q7jlwlV2Di5CACBWCtgp1VEIKJ6/sQWp0VxYWAArmgDNz4OJRRa8eAcKEs0xxnXwpPhU e2eNkl4z+sy1ySBHtrv1BuSz9N46BCAOEJoEuekZYdpy//7XKkGAborxjeZSvV5eQTvZ N/5zXglnsV8J3dfs2zlP4Yvy76UsGezeX8LVW0AKAgbgH+Pl2ceDcBP6oZc9EWz0Nv5k YnHKyDzWtX15CT0aJZGQf3tK1bUYJc4KUH0KoLhny52bbx+UagMujK+S0eTWjsJBgj43 VDqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FtbewGX8; 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 c14-20020a05640227ce00b0043ad08118aasi11648442ede.415.2022.07.13.14.47.18; Wed, 13 Jul 2022 14:47:44 -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=FtbewGX8; 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 S237388AbiGMVSO (ORCPT + 99 others); Wed, 13 Jul 2022 17:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237368AbiGMVSH (ORCPT ); Wed, 13 Jul 2022 17:18:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F217B1B7B6; Wed, 13 Jul 2022 14:18:06 -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 8DBC461E8C; Wed, 13 Jul 2022 21:18:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A411AC341C8; Wed, 13 Jul 2022 21:18:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657747086; bh=aS4EDskgQfDDMMDFP9Ws+Tjgi2/V9W9w/FWX20Sp6gs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FtbewGX8/YXdhgfDbGZ9F8DdxtMEPwl4RCb4+TTyYOWtgmbm0NFkzdvdreT8wxXE1 BItQ45q6xEx5Wm7soCuRK4R6HKgJ/HLOKmG7lCbF8YayAxilPMouo9WOXbb22DjvN1 dQjMooylfQuMJyvjQNcYex4Zu79RQGmQJPtuy45JAAzOfW46ruXHqX+6pWfC0Pvwu/ hdH2segWPja4uAiD62sTECm7Qn5LIPBYbE93gDQfFnKHZS8DcN392WNrc/hyFep1rb zmp+F7IkVKrNTz3WdblLn1zFSB+Jsa+0NxAX8PLtoa/q8cQeW4WEOOhJHSWQl4ebQw U82fRrMTdHlug== 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 V5 03/16] rv/include: Add helper functions for deterministic automata Date: Wed, 13 Jul 2022 23:17:19 +0200 Message-Id: <0d8463406169956ad994ab7c8adc520a4f7eba66.1657745645.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 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..7125c91df607 --- /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_init_state_##name - return the automaton's initial state \ + */ \ +static inline type model_get_init_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