Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2107544iob; Thu, 5 May 2022 16:05:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwib8/yxV8Re11Wk7+S5A4Zq7dbcvECJ624tA5V/uJFtDkKm4Zav7uTQt/kek4i6X8+9zxe X-Received: by 2002:a05:6402:1694:b0:425:ae5e:4843 with SMTP id a20-20020a056402169400b00425ae5e4843mr517475edv.415.1651791922326; Thu, 05 May 2022 16:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651791922; cv=none; d=google.com; s=arc-20160816; b=y7OPVu6uZbstW+6OQvMqQ3eoPNnF53gzVxub1I0kkfZvgAaqNop99MhmpnM3j5nUER +q8XQ5rgIGt3nflf/1ECnXiGZg8gWi7WLK296+l164QR4NA6nHAncRhsGTYxje5aX897 cphLz2KprkwE72YVd/ssjzoMyJoJ83Cg4pvH6vHZYC1G3+Bw1fpcZJ64EjfJHUa7GRXu MEcwNpbN6nN+vXTg++gyCc73X+tOEwTC7oSmL3KAIHJDqVzQOvkt1EiBtTyliyAaB37E LjanaMRBWjUPgTdsVH5ccLaY9+vIpnUMrujGAg84dcsYoTfn2Ih4Gcq4uxA/NXj41Cj+ gHig== 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=XEG2xiTwEHC3jSReftue1cVWtjwSau7dKs6oVSjpD8Y=; b=dT+jtatr4BHaysHyHOcqQiv0oQNKPKgWWSjzvTrh02HsM+n/l87tQ1peph+fIxpuKn 4l+9Xj8+/rkkYpvhHnm9wh3p7ScVP+hUMYxaDYTwjZaLwQ+rw1nOK1zaNQXq7VHjIwIA 52xXt6kM2RiP0uzD2HzXrxDqfxWZA3T04ZhUwoA1X35sj3su2amrDIffL7ooBD6pK08d cAs7JeAgI0UjNrXnrQDfoeAOXRpc8uhUfsG+jOBabzCiVRyCKdDtL3+b8h91N8rXlaQE zIWIPMmV4zNCTZ9qZdUV27Zzb2hpDAK3ODSE4OndEo+b8PM1w4aYak9/5tRaiPlrJjgQ /i7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ojslhMYX; 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 s16-20020a170906455000b006e89f45ee23si3317646ejq.893.2022.05.05.16.04.58; Thu, 05 May 2022 16:05:22 -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=ojslhMYX; 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 S235722AbiEEQL0 (ORCPT + 99 others); Thu, 5 May 2022 12:11:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348873AbiEEQLY (ORCPT ); Thu, 5 May 2022 12:11:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECA885C652; Thu, 5 May 2022 09:07:35 -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 ams.source.kernel.org (Postfix) with ESMTPS id 9D257B82DF6; Thu, 5 May 2022 16:07:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FB5DC385B2; Thu, 5 May 2022 16:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651766853; bh=4te1Bd+VH7D/hV8R2OCebEM13y3PtjE0NQc1V1XOvJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ojslhMYXFeVMKID15yyDysFN8N03Qd7iivzyaOXVmzoRSoozUO1cUlFKuDo3z9DJJ FV5U+k+K96NoPzgraY9lXxKopXfVlNQR2dQ74QMvhOBF2eZwEOsSTsgrM0X0KO0WgK XplWkf7dH08CqiQcq2ce4j1o9I7wd8lCoO6uVJP7oCpoLGkBLyCbGD/WZYZCD6s6Vi 7KeYWRotXfNj2gwrmbmTvieJDwEY4Yvas9Oipr6JuSrdnnfAnWZzKL8w+zNX/K7kKS fI/aQmZ+1ZAi6auy0A4r49MJz/KVyvKI5PgKK2VEDcHbaMnMIBK4EggLCp522GTSF4 XUxcWhf+hBE4A== From: Daniel Bristot de Oliveira To: Steven Rostedt , linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , 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-trace-devel@vger.kernel.org Subject: [RFC V3 03/20] rv/include: Add helper functions for deterministic automata Date: Thu, 5 May 2022 18:06:43 +0200 Message-Id: <8bf4ec82431ab1e5983c4436463aba9ce77ca5d0.1651766361.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: 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..39a1cfda17e6 --- /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)) \ + return -1; \ + \ + if ((event < 0) || (event > event_max)) \ + 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)) \ + return 0; \ + \ + return !!automaton_##name.final_states[state]; \ +} -- 2.35.1