Linux Trace Kernel
 help / color / mirror / Atom feed
From: Gabriele Monaco <gmonaco@redhat.com>
To: Nam Cao <namcao@linutronix.de>,
	Wander Lairson Costa <wander@redhat.com>,
	 Steven Rostedt <rostedt@goodmis.org>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 05/13] verification/rvgen: Convert __fill_setup_invariants_func() to Lark
Date: Wed, 03 Jun 2026 17:24:44 +0200	[thread overview]
Message-ID: <2cebee30d54bf5ac7bc963396d0ce80cfa8428f9.camel@redhat.com> (raw)
In-Reply-To: <0b2cf5e1bb03d0e3a667b0fc2c7093123ef0a78c.1779956342.git.namcao@linutronix.de>

On Thu, 2026-05-28 at 10:27 +0200, Nam Cao wrote:
> Prepare for self.invariants and __parse_constraints() to be removed.
> convert __fill_setup_invariants_func() to use the new parsed states
> from Lark.
> 
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> ---

Reviewed-by: Gabriele Monaco <gmonaco@redhat.com>

> v2: add missing time conversion [Sashiko]
> ---
>  tools/verification/rvgen/rvgen/dot2k.py | 44 ++++++++++++++++++++---
> --
>  1 file changed, 35 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/verification/rvgen/rvgen/dot2k.py
> b/tools/verification/rvgen/rvgen/dot2k.py
> index a344cbbcb346..d9f8e1c7737a 100644
> --- a/tools/verification/rvgen/rvgen/dot2k.py
> +++ b/tools/verification/rvgen/rvgen/dot2k.py
> @@ -250,6 +250,26 @@ class ha2k(dot2k):
>          return (f"ha_start_timer_{clock_type}(ha_mon,
> {rule["env"]}{self.enum_suffix},"
>                  f" {value}, time_ns)")
>  
> +    def __parse_invariant(self, inv):
> +        # by default assume the timer has ns expiration
> +        clock_type = "ns"
> +        if inv.unit == "j":
> +            clock_type = "jiffy"
> +
> +        env = inv.env + self.enum_suffix
> +        val = inv.val.replace("()", "(ha_mon)")
> +
> +        match inv.unit:
> +            case "us":
> +                val *= 10**3
> +            case "ms":
> +                val *= 10**6
> +            case "s":
> +                val *= 10**9
> +
> +        return (f"ha_start_timer_{clock_type}(ha_mon, {env},"
> +                f" {val}, time_ns)")
> +
>      def __format_guard_rules(self, rules: list[str]) -> list[str]:
>          """
>          Merge guard constraints as a single C return statement.
> @@ -463,15 +483,14 @@ f"""static inline bool ha_verify_guards(struct
> ha_monitor *ha_mon,
>          return conflict_guards, conflict_invs
>  
>      def __fill_setup_invariants_func(self) -> list[str]:
> -        buff = []
> -        if not self.invariants:
> +        if not self.has_invariant:
>              return []
>  
> -        buff.append(
> +        buff = [
>  f"""static inline void ha_setup_invariants(struct ha_monitor
> *ha_mon,
>  \t\t\t\t       enum {self.enum_states_def} curr_state, enum
> {self.enum_events_def} event,
>  \t\t\t\t       enum {self.enum_states_def} next_state, u64 time_ns)
> -{{""")
> +{{"""]
>  
>          conditions = ["next_state == curr_state"]
>          conditions += [f"event != {e}{self.enum_suffix}"
> @@ -480,13 +499,20 @@ f"""static inline void
> ha_setup_invariants(struct ha_monitor *ha_mon,
>          buff.append(f"\tif ({condition_str})\n\t\treturn;")
>  
>          _else = ""
> -        for state, constr in sorted(self.invariants.items()):
> -            buff.append(f"\t{_else}if (next_state ==
> {self.states[state]}{self.enum_suffix})")
> -            buff.append(f"\t\t{constr};")
> +        for state in self._states:
> +            inv = state.inv
> +            if not inv:
> +                continue
> +            inv = self.__parse_invariant(inv)
> +            buff.append(f"\t{_else}if (next_state ==
> {state.name}{self.enum_suffix})")
> +            buff.append(f"\t\t{inv};")
>              _else = "else "
>  
> -        for state in self.invariants:
> -            buff.append(f"\telse if (curr_state ==
> {self.states[state]}{self.enum_suffix})")
> +        for state in self._states:
> +            inv = state.inv
> +            if not inv:
> +                continue
> +            buff.append(f"\telse if (curr_state ==
> {state.name}{self.enum_suffix})")
>              buff.append("\t\tha_cancel_timer(ha_mon);")
>  
>          buff.append("}\n")


  reply	other threads:[~2026-06-03 15:24 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-28  8:27 [PATCH v2 00/13] rv: Convert rvgen to Lark Nam Cao
2026-05-28  8:27 ` [PATCH v2 01/13] verification/rvgen: Switch LTL parser " Nam Cao
2026-06-03 14:49   ` Gabriele Monaco
2026-05-28  8:27 ` [PATCH v2 02/13] verification/rvgen: Introduce a parse tree for automata using Lark Nam Cao
2026-06-03 14:55   ` Gabriele Monaco
2026-05-28  8:27 ` [PATCH v2 03/13] verification/rvgen: Implement state and transition parser based on Lark Nam Cao
2026-06-03 14:55   ` Gabriele Monaco
2026-05-28  8:27 ` [PATCH v2 04/13] verification/rvgen: Convert __fill_verify_invariants_func() to Lark Nam Cao
2026-06-03 14:56   ` Gabriele Monaco
2026-05-28  8:27 ` [PATCH v2 05/13] verification/rvgen: Convert __fill_setup_invariants_func() " Nam Cao
2026-06-03 15:24   ` Gabriele Monaco [this message]
2026-05-28  8:27 ` [PATCH v2 06/13] verification/rvgen: Convert __fill_verify_guards_func() " Nam Cao
2026-06-03 16:00   ` Gabriele Monaco
2026-05-28  8:27 ` [PATCH v2 07/13] rv: Simply hybrid automata monitors's clock variables Nam Cao
2026-06-03  9:27   ` Gabriele Monaco
2026-05-28  8:27 ` [PATCH v2 08/13] verification/rvgen: Simplify the generation for " Nam Cao
2026-05-28  8:27 ` [PATCH v2 09/13] verification/rvgen: Delete __parse_constraint() Nam Cao
2026-05-28  8:27 ` [PATCH v2 10/13] verification/rvgen: Switch __get_event_variables() to Lark Nam Cao
2026-05-28  8:27 ` [PATCH v2 11/13] verification/rvgen: Switch __create_matrix() " Nam Cao
2026-05-28  8:28 ` [PATCH v2 12/13] verification/rvgen: Remove the old state variables Nam Cao
2026-05-28  8:28 ` [PATCH v2 13/13] verification/rvgen: Remove dead code Nam Cao
2026-06-03 15:36   ` Gabriele Monaco
2026-06-08  8:29     ` Nam Cao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2cebee30d54bf5ac7bc963396d0ce80cfa8428f9.camel@redhat.com \
    --to=gmonaco@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=namcao@linutronix.de \
    --cc=rostedt@goodmis.org \
    --cc=wander@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox