Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1264112iog; Thu, 16 Jun 2022 02:36:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sAqxyd7nf6bTQnC8s0MfqaYFBUhtDGC4DHjEKzmU7Txhc5Uk59ee/WoMDVUq4N2X8M1EtF X-Received: by 2002:a17:907:1620:b0:711:da21:d836 with SMTP id hb32-20020a170907162000b00711da21d836mr3757826ejc.427.1655372218673; Thu, 16 Jun 2022 02:36:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655372218; cv=none; d=google.com; s=arc-20160816; b=BhMFdcSJC1iUXROP5D3gjWoo+b/v+5ozpSJF35tzvyl3LjJT/b5fsdByZuLKPnlWG3 dyt8YTSI4wGzqf6naMQT5jTsQhf2Sfj3lfRWsP/CX45zq93Zi7civRs3Buub3ZdJaxVO XxmlNXDY6yEiYAXRJBh2FtRou0zHP6wPTndoR6bALe2erKaiFSWpbHxyFK/6diuRMBTh LmvTKa6GJY/72tZSUv1W5+MuTjzLqnUFTjDcSD3BNva9HKYeF3RYHIsw2mYhB7+ESsaN s0Cnk+hVPfD333mHWDSsVhgfZ7jJ3S+bKDt5d1+/JwMWGar5HyXHAZ+/kvncTenRVHl7 GwnQ== 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=Yx0Krib3/hP2VqunGLmJjPeFXeWZ2fXeRWFM9LDXtKo=; b=QODSF1LO7+uDm5YVKL2y0wuNfWKMBYBANfthTZF6xclSXCoHzZo1fHHQZXSEH5RuS4 gJpvna34OP9Yb6U2QermEQOvxdQyghixSfyk6FkBxp8QDPPwsbMoHBCck3MV8cwq1Jyj cg4foEhU+xUv0wG8Lg6ZVchLksReSAHShyLd+M1PJj+1piRT7ceRJSD3xE/tfQKDpvGx M6XLexfdYF4yyeX3hOhww/txI4LF9dGCgi59GyQVA3mz7DSV3Cva2Y7H6FdvwbHoqkQ/ aLE3Oz+/8aQHqE8mnaEKupJkaFJM0oofUsS9x2/S6sN76RnpTRmHl8aJSDtAC68pm4MB 46Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m2ZDSr+8; 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 o15-20020a170906974f00b006ff8cd702e8si1380279ejy.29.2022.06.16.02.36.33; Thu, 16 Jun 2022 02:36:58 -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=m2ZDSr+8; 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 S1359744AbiFPIpp (ORCPT + 99 others); Thu, 16 Jun 2022 04:45:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359726AbiFPIpa (ORCPT ); Thu, 16 Jun 2022 04:45:30 -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 CD5C45D641; Thu, 16 Jun 2022 01:45:29 -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 6959461D76; Thu, 16 Jun 2022 08:45:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80F91C341C7; Thu, 16 Jun 2022 08:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655369128; bh=n2qM9u0TQLUSVjUppzMp6Ophh/bAVGpgXwPtBN683xM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m2ZDSr+8gUOdjz63JyRCih5+vxxkTP+l4iEhhX6dd3WdtNYGmGNlc2Qy1Ohcwcn1P rQKsSUo5DzS0rwusvLT5ycpF+uQBTdcInV3CtxCFzFestLjT+sCG2ZogkOJNTdiyqa vmSjz/wVYxLISNI2GsoNXwX0phnzNhm6jfks5yTwPe/ArAddtHrLdMK5ZUMT7hPuWx SA54dSdA82gN3fIDEJa7nP5eLPnIcnSAyT3OIeWdMFjvC6laHt3Pfqs164kz8CUA8K wa8vTRBtqgwflX0bzNawDy71NH++0uD7HMPJoDcP1f/2QXGTQ85nP6cvuZ3ups3A1Y QsT+1BizoHHyQ== 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 03/20] rv/include: Add helper functions for deterministic automata Date: Thu, 16 Jun 2022 10:44:45 +0200 Message-Id: <2b5b14c821ee4b069f68571e7f78fbc2ee4e9626.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 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 + */ + +#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]; \ +} -- 2.35.1