Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1013516imw; Wed, 13 Jul 2022 12:09:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1thYBak1LNfWR8w2o7ON5I4vSq935qPwFLrt4TKtJhxC3mtJMBlyrYvq9Yg2fDPepbkIyyG X-Received: by 2002:a05:6402:520c:b0:43a:aba8:84ae with SMTP id s12-20020a056402520c00b0043aaba884aemr7162816edd.198.1657739342206; Wed, 13 Jul 2022 12:09:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657739342; cv=none; d=google.com; s=arc-20160816; b=YM+3zUylu+SYMNlMsw2YpSxFTjMf6bW00ZKBGECkCz8j7cHt3gX8PiBBdf8LMffM3Q AyqDkLbdju9La2u6GyvUCyyB9LZ3X+NlNpbD2+nR2Rqc9Eb0cFf0aH2OSJZ6dHeO9jV8 dSRalmGmJsBLmtb+p3UeSKGVOyEZcLylMF0wVtn8H7IH0suoHrgiNESyJO3ITc6y6dP0 j8+sy0Eo7anwpsBfKGiOa3JuNvCmI6F4COJzMlge8qawy0srCk8l/pWdzLvkQRZGg66U j1dTmVZSu/P+LOzKE6GCtyiK3g4LXj8JBUZAEMCGuhVlF2qs774nFSNHAOwClWy32Bg5 NMjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=S+Say744A334BqgxIx6rSRdsPaHsuZnoIeOdU44nOtg=; b=VyoE+h2cfHJI6MhCIdbqZfoYZ2lnjBgR5MWgHzJYZTcZZzVx+L8E6AAWssnRP3NLyE W0pg3dbOVRn20wbsHtlBibkHQPXGmZQe1yUKrRUJsuX+c6LSr6HeO8ubRGVEoAoLRNMy Ih9hQh92LHrPrhMfru++0a2CW4JuR1wLp2qnd8U0UYcOHYJBLucruQMAB9MYSzysyLye ezMk4JBoNtOYcwW8X7eUr6cvXsk+8X0sUHkotRigs1mHjrMFPWOvfq5wksX5rJuyiqMK uKMjWp+E7HBzwdjMkNdIoVhGz4NTNqjyVq9wgPx3UjbmWb3OF7PhW9IgYchRftK76La0 GMeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="u/XRi340"; 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 rn13-20020a170906d92d00b0072b1b1c3f22si8154758ejb.125.2022.07.13.12.08.36; Wed, 13 Jul 2022 12:09:02 -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="u/XRi340"; 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 S236756AbiGMSjO (ORCPT + 99 others); Wed, 13 Jul 2022 14:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236732AbiGMSjL (ORCPT ); Wed, 13 Jul 2022 14:39:11 -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 416F0201AE; Wed, 13 Jul 2022 11:39:10 -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 E069BB82123; Wed, 13 Jul 2022 18:39:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39028C34114; Wed, 13 Jul 2022 18:39:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657737547; bh=tO5x8vlQaYbiXWOT1V2EnWLVdJW7QJQ7UgkTW94PdK8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=u/XRi340W0jDA+Jvki+5euQb2QKoxeniHCg2XsOQ8H/brEetZ5U3cAtVXp3p2nLDp 4/Qi37pTrI48NCfk8C8uwNHQYr41UNgmDkw5E0q6qrEtM0rImfZPWsXfn5mQ/kkEcD 7VOIeY6JWN+pBxpjBhUeG5Fh4XXdwCIvorJ1ov9drIb6XNQ7MyclHdIi49JIjfR7Be GoQW9mAkdMyyGjhVXzECDbCm2wjbYC91ohOqWBhdkdT6Y9Ij8P5Gle+i8LB3tt2VZ1 FqBX4MGmGIIMEkwJiakKJzsGhEzuxGXW38hdSqJMlEkyrF/vkYzgUAoIbL5RVz9lHr dyfkWg0r6+EHA== Message-ID: <9cf7711a-f36a-608d-1605-179f3037b644@kernel.org> Date: Wed, 13 Jul 2022 20:38:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH V4 03/20] rv/include: Add helper functions for deterministic automata Content-Language: en-US To: Tao Zhou Cc: Steven Rostedt , 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 References: <2b5b14c821ee4b069f68571e7f78fbc2ee4e9626.1655368610.git.bristot@kernel.org> From: Daniel Bristot de Oliveira In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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,NICE_REPLY_A, 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 On 7/6/22 20:35, Tao Zhou wrote: > On Thu, Jun 16, 2022 at 10:44:45AM +0200, Daniel Bristot de Oliveira wrote: > >> 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 >> surce 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; \ > > curr_state can not be state_max_xxx. curr_state must be not bigger > than state_max_xxx. Or am I miss something? > >> + if ((event < 0) || (event > event_max_##name)) \ >> + return -1; \ >> + \ > > Same here for the event boundary check. > >> + 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; \ >> + \ > > Same here. > >> + return !!automaton_##name.final_states[state]; \ > > If the value of .final_states[state] is 0 or 1, can the type of > .final_states[state] be befined to bool. Or not need to use !! to > explicitly transfer the type to bool. I remember that you define > this as char array and the matrix model value of this array is 0 or 1 > see from the next patche. 1 delegate the state it is the initial state. > 0 for others. All points addressed! -- Daniel