Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp209628imn; Mon, 25 Jul 2022 14:12:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vSrmnuMlmApiO2ZocjqiI+LtJ+m4b11nXGtIz38UKDttxrD7AIbu7V+2UXfxZkBT10j2Ny X-Received: by 2002:a05:6402:2919:b0:43b:c349:2138 with SMTP id ee25-20020a056402291900b0043bc3492138mr15574547edb.10.1658783524847; Mon, 25 Jul 2022 14:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658783524; cv=none; d=google.com; s=arc-20160816; b=x3Mg813G0SVcjw1UIyxsF4LEoTRvhtrIBxjK4UhmyFsoVYTtxSxV2OtRn8dg8bE4ae 2pDLQx2vc0b9PNx0W3RhOHIJ9TXeHmpqifXZ4ZYeBfSzJpREuHFvelkmL/cNSWlV44P8 MrjISo+qOF4LUbRLDznDndoBWqmR2KAhQjTHF89jTuNMbdLiTqz62cPA5WNEsRQF1DCr ZjkIEKVNnabxhzA+QpsLLT5K4VrPjvV+gyaSWjwh/RkrkCaoxrFu15OPHY03+mjzOcwd sry0XrqTnl13yUvWWtvPPwXgYElGwzOBbi9+kqdLXGlXKQszy8GSXAXHuND5KyEioDpU fmeA== 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=skxedw5QtmuFwD5rBRcEQAzx0V7KplClisWc0vIH79mqEUYh/p1tV1nwzss1dYYu13 6xPkav1x7ZQLF8deKXIrM0ySKVI01PBPPLRJpIqAPps7Fy3s6t47wCXWWYucbb/rzsMA ygH7vqwz/sX1StBNxf1VLvUq0WCrSiaMdNuVTYrTtCE9zxgAcYwBf5PI4LgtgiaYaWhP fpdwCE+FwYI7nMB6c3oLKQ44gavZhR8RfKJboHRefGrlwIZe5K39JDsEJCx3eA7bWuHc Ug966lMui37q312wYqqw8CrUlrFgPGpMpBaeKv53wHNr37l1DmlQ9zXniat3PFfgh02Z 6DEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HcwO8Tm9; 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 js11-20020a17090797cb00b0072b566dfeb9si18242489ejc.102.2022.07.25.14.11.39; Mon, 25 Jul 2022 14:12:04 -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=HcwO8Tm9; 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 S236799AbiGYUMQ (ORCPT + 99 others); Mon, 25 Jul 2022 16:12:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbiGYUMI (ORCPT ); Mon, 25 Jul 2022 16:12:08 -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 29CD821273; Mon, 25 Jul 2022 13:12: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 B824061151; Mon, 25 Jul 2022 20:12:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9746CC341CE; Mon, 25 Jul 2022 20:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658779925; bh=oWw25mtkJXkfmoetD7cNHKyHoDEVZWd1NhnSPh98QnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HcwO8Tm9ZJTKaPZVGOddAaLksbeOUE9btPmrPVD2Sxh73X+YxFG07FXlrNlsxz3Py PuvU1ld6p5GHNx+eMuzyg/HE8IXRMYFkK4ppYk4Bpg6BWFeiU//bA498dPJPdHR8w+ L3SMN6UZwpA2CNfrbJkwp6OyHnZt2tCKJjTEoRYt+5/BWKAyhLrRWxLk/XMwvnsu97 KfVsTfQ+nEGF6+Hl1vkEqRThaJxRl5XfqY0rtaycavUy8GsJo2aBNLjwLd6pZnNtnd n0xKKMVv4shJy03WeCIpVEzC49AaNK/srrH26dxKlWPFTQmlYQnPN4msZLetmd6gVD FUiYqieKmJ9Jw== 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 V7 03/16] rv/include: Add helper functions for deterministic automata Date: Mon, 25 Jul 2022 22:11:15 +0200 Message-Id: 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