Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5978043pxb; Mon, 14 Feb 2022 12:10:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFekk42FJwVXkLUkKmPnhwAJzsQABT3S1anpphbwpYV5HJXf9h+byq6YVmYEgTIKgaxy4B X-Received: by 2002:a63:4641:: with SMTP id v1mr555585pgk.283.1644869445632; Mon, 14 Feb 2022 12:10:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644869445; cv=none; d=google.com; s=arc-20160816; b=UkVMEB4HCIkDi1TMrCfNnE6jxebtB8uMfvUzeZ9Lpwis0GSi+d7yPmaO4/Nm+QJ2TO sd6luEq2FLylGtu7/rSZ8QviTVoF1B/bQEPu5mnTiwtM4MwzIfrQLtt3XrxzOAX0LIHZ 2a5PK57OFXhFVnpf4rTuoxdL8RcRNABzC32JeF4yDFzu/7ESZy6QeSJwLq1oEbCrUAEj WLEzC2jhUXN1EkvzVutS9MO/z77vtza7lTt0nU/1KtbWXbAUdclIgyCqaHGl4N4vD2Ox 4oIgom8VzLrfm1WiTFSpZXwFXXovxD8AKN2pDrRb9tpubtNmGLQ6z9w4nG0TTVxE1gN6 YX3Q== 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; bh=Zovrzer8NGMUdsGXQaMs5i6UtIn0vwm2d7Jm/hp6W/A=; b=RIZn6RSnsU2zeN/mvxx/o18HjHFqm1h68pkDI7LnEZkvVm80yXnfEwq3JyGBxSPTo/ c5P5O0zrgA2YVqpaHQlwDP43EhtwVFI5MXELSCX46CkvKBWMGifJuy6KORIkFrWL2qRb 5P2+KtGvteZVts7NOuJ/aPg7+Q5Sk8v6yEhxpMGIABCB1/GxjLrDXgzDvKqjEM21mq54 T1gpgSpBbP4bQbaGnKQyzmugCxbPXYTWF+HlsfIpsjgWOCmGMHvxun7qZSSsJ4LWj2AL O15FfZl9CnV3gfYy+KEtfqB5lL8UBW4PXipZ76tPEiwTZGRKQjov+v4cNGknwF8xTD7c 0jhQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j11si15525540plx.12.2022.02.14.12.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 12:10:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 95ABA15F096; Mon, 14 Feb 2022 11:47:54 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350597AbiBNLQB convert rfc822-to-8bit (ORCPT + 99 others); Mon, 14 Feb 2022 06:16:01 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:45108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350708AbiBNLPv (ORCPT ); Mon, 14 Feb 2022 06:15:51 -0500 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C9D61ADAA for ; Mon, 14 Feb 2022 02:46:21 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-279-ZudAjQ0CNHCf-dvDlDPUSw-1; Mon, 14 Feb 2022 05:46:17 -0500 X-MC-Unique: ZudAjQ0CNHCf-dvDlDPUSw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F3DF980573C; Mon, 14 Feb 2022 10:46:14 +0000 (UTC) Received: from x1.com (unknown [10.22.16.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 374E126DFB; Mon, 14 Feb 2022 10:46:06 +0000 (UTC) From: Daniel Bristot de Oliveira To: Steven Rostedt 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-kernel@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [RFC V2 03/21] rv/include: Add helper functions for deterministic automata Date: Mon, 14 Feb 2022 11:44:54 +0100 Message-Id: <43ef0d4b96c67af1a9f4b41cceae46ccbffd93ce.1644830251.git.bristot@kernel.org> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=bristot@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 occurence 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 | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 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..dfd0bbf0dc5c --- /dev/null +++ b/include/rv/automata.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Deterministic automata helper functions, to be used with the automata + * models in C generated by the dot2k tool. + * + * The dot2k tool is available at https://gitlab.com/linux-rv-tools/dot2/. + * + * 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; \ +} \ + \ +char *model_get_state_name_##name(enum states_##name state) \ +{ \ + return automaton_##name.state_names[state]; \ +} \ + \ +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.33.1