From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4478D36BCCA; Thu, 28 May 2026 08:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956896; cv=none; b=B1Mb2eDeeC9C4yihzSXlZmiI5z7MeWv/ZNOB/TySX85MdzRAJVdhbFHEu1YFa9XRio3O5Uj+HcaDkcSK16UJZrqB4EYkzf9nVqyT+AHtyvY57ooJMoXyUtjCABDtfChg6/guloS7rdUoGaCbQGSM9czGViWVew6NpkUoqk40Mrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956896; c=relaxed/simple; bh=fQt5DCBSpd6+pDUb/X+6/aQEMs3Cq36JM4B5pYgq2qY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rtj8d5lS/zhJ8Uo8jFzmRPU4O5yT4Az5iZ4f1EXeZMZV8NvNdg2/i8H3FpMnIDGTO/5e0dFtcZwuIWVMMkiS/kbcoGz2G43katbB8vdr4dEuCuE0b8dr2T90MEnuthy7AV6j1aKYdJanPg8JVkPIgLrw+nmVMB0Thmml+280jcQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=CQ1Zk2yX; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6JOQElxh; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CQ1Zk2yX"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6JOQElxh" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0oNFRHrZHt1izQ2CFWnJ1COKgvowMlvpEoBv1jafdII=; b=CQ1Zk2yXiQQIAwFeREQsvne5tNW0uVPm+6N3UtMvHpZ7Wws8TM2g10O06uLr3FE6XqyMNF muzmWjB0K75t+3uRYEdzRqa5WoNYosObEpPASmbYczyVa7WtkBt+XJgNs4YkP5noBJHPEx MI5w5ZN+Fm5eQ0Vb1hcjpw5PbnypdXUw72B+qCq1jx0GZ0s+4PSU2RZRuv6Cxkz8J/sQ0U 6kmDKkzPYDmn2fiKe0mtuSmN0N8/7/7lJVSiqJ/cO0ZMf9J681dp/4KWCaqHoocNUOJNqJ j6zfjbIqBAiaJUfxMcbdtFy5yLucaff63swCYFoBfCMhixN0OpX7WXjOqJ6WGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0oNFRHrZHt1izQ2CFWnJ1COKgvowMlvpEoBv1jafdII=; b=6JOQElxhV7BpKz9ERJYM0zwnPDj/r7EMbbhF4Gr1rUdkj1zrG8hyyhT3kt8eZ74TwwRc2H F2IdrIIJ+ZO+3XDA== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 01/13] verification/rvgen: Switch LTL parser to Lark Date: Thu, 28 May 2026 10:27:49 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The LTL parser is built using Ply. However, Ply is no longer maintained [1]. Switch to use Lark instead. In addition to being actively maintained, Lark also offers additional features (namely, automatically creating the abstract syntax tree) which make the parser simpler. Link: https://github.com/dabeaz/ply/commit/9d7c40099e23ff78f9d86ef69a26c1e8= a83e706a [1] Signed-off-by: Nam Cao Reviewed-by: Gabriele Monaco --- v2: - fix identifier starting with a digit is allowed [Wander] - fixup ast node uid [Gabriele] - Fix up Literal AST node construction [Wander, Sashiko] - FIx up unary op error message [Sashiko] - Add nice exception handling [Gabriele] --- tools/verification/rvgen/__main__.py | 5 +- tools/verification/rvgen/rvgen/ltl2ba.py | 202 +++++++++-------------- 2 files changed, 82 insertions(+), 125 deletions(-) diff --git a/tools/verification/rvgen/__main__.py b/tools/verification/rvge= n/__main__.py index 5c923dc10d0f..0915cf86e43b 100644 --- a/tools/verification/rvgen/__main__.py +++ b/tools/verification/rvgen/__main__.py @@ -14,6 +14,7 @@ if __name__ =3D=3D '__main__': from rvgen.container import Container from rvgen.ltl2k import ltl2k from rvgen.automata import AutomataError + from rvgen.ltl2ba import LTLError import argparse import sys =20 @@ -57,8 +58,8 @@ if __name__ =3D=3D '__main__': sys.exit(1) else: monitor =3D Container(vars(params)) - except AutomataError as e: - print(f"There was an error processing {params.spec}: {e}", file=3D= sys.stderr) + except (AutomataError, LTLError) as e: + print(f"There was an error processing {params.spec}:\n{e}", file= =3Dsys.stderr) sys.exit(1) =20 print(f"Writing the monitor into the directory {monitor.name}") diff --git a/tools/verification/rvgen/rvgen/ltl2ba.py b/tools/verification/= rvgen/rvgen/ltl2ba.py index 016e7cf93bbb..7cebda61bce8 100644 --- a/tools/verification/rvgen/rvgen/ltl2ba.py +++ b/tools/verification/rvgen/rvgen/ltl2ba.py @@ -7,9 +7,7 @@ # https://doi.org/10.1007/978-0-387-34892-6_1 # With extra optimizations =20 -from ply.lex import lex -from ply.yacc import yacc -from .automata import AutomataError +import lark =20 # Grammar: # ltl ::=3D opd | ( ltl ) | ltl binop ltl | unop ltl @@ -30,42 +28,41 @@ from .automata import AutomataError # imply # equivalent =20 -tokens =3D ( - 'AND', - 'OR', - 'IMPLY', - 'UNTIL', - 'ALWAYS', - 'EVENTUALLY', - 'NEXT', - 'VARIABLE', - 'LITERAL', - 'NOT', - 'LPAREN', - 'RPAREN', - 'ASSIGN', -) - -t_AND =3D r'and' -t_OR =3D r'or' -t_IMPLY =3D r'imply' -t_UNTIL =3D r'until' -t_ALWAYS =3D r'always' -t_NEXT =3D r'next' -t_EVENTUALLY =3D r'eventually' -t_VARIABLE =3D r'[A-Z_0-9]+' -t_LITERAL =3D r'true|false' -t_NOT =3D r'not' -t_LPAREN =3D r'\(' -t_RPAREN =3D r'\)' -t_ASSIGN =3D r'=3D' -t_ignore_COMMENT =3D r'\#.*' -t_ignore =3D ' \t\n' - -def t_error(t): - raise AutomataError(f"Illegal character '{t.value[0]}'") - -lexer =3D lex() +GRAMMAR =3D r''' +start: assign+ + +assign: VARIABLE "=3D" _ltl + +_ltl: _opd | binop | unop + +_opd : VARIABLE + | LITERAL + | "(" _ltl ")" + +unop: UNOP _ltl +UNOP: "always" + | "eventually" + | "next" + | "not" + +binop: _opd BINOP _ltl +BINOP: "until" + | "and" + | "or" + | "imply" + +VARIABLE: /[A-Z_][A-Z0-9_]*/ +LITERAL: "true" | "false" + +COMMENT: "#" /.*/ "\n" +%ignore COMMENT + +%import common.WS +%ignore WS +''' + +class LTLError(Exception): + "Exception raised for malformed linear temporal logic" =20 class GraphNode: uid =3D 0 @@ -97,7 +94,7 @@ class GraphNode: return self.id < other.id =20 class ASTNode: - uid =3D 1 + uid =3D 0 =20 def __init__(self, op): self.op =3D op @@ -433,90 +430,49 @@ class Literal: node.old |=3D {n} return node.expand(node_set) =20 -def p_spec(p): - ''' - spec : assign - | assign spec - ''' - if len(p) =3D=3D 3: - p[2].append(p[1]) - p[0] =3D p[2] - else: - p[0] =3D [p[1]] - -def p_assign(p): - ''' - assign : VARIABLE ASSIGN ltl - ''' - p[0] =3D (p[1], p[3]) - -def p_ltl(p): - ''' - ltl : opd - | binop - | unop - ''' - p[0] =3D p[1] - -def p_opd(p): - ''' - opd : VARIABLE - | LITERAL - | LPAREN ltl RPAREN - ''' - if p[1] =3D=3D "true": - p[0] =3D ASTNode(Literal(True)) - elif p[1] =3D=3D "false": - p[0] =3D ASTNode(Literal(False)) - elif p[1] =3D=3D '(': - p[0] =3D p[2] - else: - p[0] =3D ASTNode(Variable(p[1])) - -def p_unop(p): - ''' - unop : ALWAYS ltl - | EVENTUALLY ltl - | NEXT ltl - | NOT ltl - ''' - if p[1] =3D=3D "always": - op =3D AlwaysOp(p[2]) - elif p[1] =3D=3D "eventually": - op =3D EventuallyOp(p[2]) - elif p[1] =3D=3D "next": - op =3D NextOp(p[2]) - elif p[1] =3D=3D "not": - op =3D NotOp(p[2]) - else: - raise AutomataError(f"Invalid unary operator {p[1]}") - - p[0] =3D ASTNode(op) - -def p_binop(p): - ''' - binop : opd UNTIL ltl - | opd AND ltl - | opd OR ltl - | opd IMPLY ltl - ''' - if p[2] =3D=3D "and": - op =3D AndOp(p[1], p[3]) - elif p[2] =3D=3D "until": - op =3D UntilOp(p[1], p[3]) - elif p[2] =3D=3D "or": - op =3D OrOp(p[1], p[3]) - elif p[2] =3D=3D "imply": - op =3D ImplyOp(p[1], p[3]) - else: - raise AutomataError(f"Invalid binary operator {p[2]}") - - p[0] =3D ASTNode(op) - -parser =3D yacc() +class Transform(lark.visitors.Transformer): + def unop(self, node): + if node[0] =3D=3D "always": + return ASTNode(AlwaysOp(node[1])) + if node[0] =3D=3D "eventually": + return ASTNode(EventuallyOp(node[1])) + if node[0] =3D=3D "next": + return ASTNode(NextOp(node[1])) + if node[0] =3D=3D "not": + return ASTNode(NotOp(node[1])) + raise ValueError("Unknown operator %s" % node[0]) + + def binop(self, node): + if node[1] =3D=3D "until": + return ASTNode(UntilOp(node[0], node[2])) + if node[1] =3D=3D "and": + return ASTNode(AndOp(node[0], node[2])) + if node[1] =3D=3D "or": + return ASTNode(OrOp(node[0], node[2])) + if node[1] =3D=3D "imply": + return ASTNode(ImplyOp(node[0], node[2])) + raise ValueError("Unknown operator %s" % node[1]) + + def VARIABLE(self, args): + return ASTNode(Variable(args)) + + def LITERAL(self, args): + return ASTNode(Literal(args =3D=3D "true")) + + def start(self, node): + return node + + def assign(self, node): + return node[0].op.name, node[1] + +parser =3D lark.Lark(GRAMMAR) =20 def parse_ltl(s: str) -> ASTNode: - spec =3D parser.parse(s) + try: + spec =3D parser.parse(s) + except lark.exceptions.UnexpectedInput as e: + raise LTLError(str(e)) + spec =3D Transform().transform(spec) =20 rule =3D None subexpr =3D {} @@ -528,7 +484,7 @@ def parse_ltl(s: str) -> ASTNode: subexpr[assign[0]] =3D assign[1] =20 if rule is None: - raise AutomataError("Please define your specification in the \"RUL= E =3D \" format") + raise LTLError("Please define your specification in the \"RULE =3D= \" format") =20 for node in rule: if not isinstance(node.op, Variable): --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12CFF3254A2; Thu, 28 May 2026 08:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956894; cv=none; b=eghHyChBvppH1RgddisJ42vKorerg7urp08HY4UgK0nmjJqSVq244xTS6/u735MV1PEyy8kSIj57ykqCfrqBEA4yR0A9F3U5422INRYPZ1CJEObBwiYIKRkBHgHE0xuLY1RSyus9gwxrYZdegnw9BLw0M6JJONyG+tpIEnwF4fM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956894; c=relaxed/simple; bh=4cDPxgkiUx8eA2XubeKOcrKhfafUsPKfDm/JX+QhJyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ui6FvpGw28t088LEEKAlalJl02RKUZnimxMHfykiehfoFt3Km4rIEKCpc8eFY7iR2XPAKky0r6PfC6WeOMzE1GCCd7bdmQLJvOLUvkX9Ci0AIeZ2J8LLSNFy7KhdwKzHebOy6X8VTXnAJw3wErhfwIUcTWnvhakcusIC3Rr5Gp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fyuP6YUc; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WFhMu+T0; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fyuP6YUc"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WFhMu+T0" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZDkqmO5QVsaiUG+cmH8pQA2/DVSqeiCm9rHoyjU+5A=; b=fyuP6YUccOIpCE+/rY8sVkXfi0ZhI6WfMxmv2qIootDtiK9whya9RYMteigZfeMyjeOVXi pUDjyxf2qbCLUbMKstt7nREwf3rzF7vtALOEGnjK8D921HfFjjiYn5mflhk8vbrZq7V+iX IpkTmX/eyFWASGwI48qedJ9pbNQXsYFzWaX0yyRfBcE0hRjkNw9GS7ExaqgwjVlF0vPGC5 g4LcNUC/tfwZEyuWOw6GlrkgTNKLi1aWK2RIOGG4UKK3SnEkZKE1tCiOh+6BvKrk9F5c2Z LbSlpyBIzvMMoADxA9AzpPOq2q9MqLFlJgPjz7f9M445TtHvNY3Zs+2CiecW/g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZDkqmO5QVsaiUG+cmH8pQA2/DVSqeiCm9rHoyjU+5A=; b=WFhMu+T0aeD6WImctdnYvJRuccMYQ7wLoNytTKjwP9Y6iC/4OZ/XG/+VXVqDvPwTjLjxIN Mdmle42xaWrxwJCA== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 02/13] verification/rvgen: Introduce a parse tree for automata using Lark Date: Thu, 28 May 2026 10:27:50 +0200 Message-ID: <13a2f241b74e02b13efa7fe188be3fa7e6148b4a.1779956342.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The DOT parsing scripts directly parse the raw text and they are quite fragile. If the input dot files' formats are slightly changed (for instance, by breaking long some lines which is allowed by the DOT language defined by graphviz), the scripts would fail. To make the scripts robust, the parser should be implemented based on the dot language specification, not based on how the existing dot files look. As a first step, use Lark to implement a Parser based on the graphviz dot language specification. The resulting parse tree is not used yet, but the existing scripts will be converted one by one to use this new parse tree in the follow-up commits. Signed-off-by: Nam Cao Reviewed-by: Gabriele Monaco --- v2: - switch to use Lark's CNAME for identifier [Wander] - switch to use Lark's ESCAPED_STRING for string [Sashiko] - clean up variable name shadowing [Sashiko] - Properly catch Lark exception --- tools/verification/rvgen/rvgen/automata.py | 186 +++++++++++++++++++++ 1 file changed, 186 insertions(+) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index b9f8149f7118..8649d982383d 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -13,6 +13,191 @@ import re from typing import Iterator from itertools import islice =20 +import lark + +class ParseTree: + # based on https://graphviz.org/doc/info/lang.html + # with the irrelevant stuffs (port and compass) removed + grammar =3D r''' + start: "strict"? ("graph" | "digraph") ID? "{" stmt_list "}" + + stmt_list: (stmt ";"? stmt_list)? + + stmt: node_stmt + | edge_stmt + | attr_stmt + | ID "=3D" ID + | subgraph + + attr_stmt: attr_type attr_list + + attr_type: "graph" -> graph + | "node" -> node + | "edge" -> edge + + attr_list: "[" a_list? "]" attr_list? + + a_list: ID "=3D" ID (";" | ",")? a_list? + + edge_stmt: (node_id | subgraph) edgerhs attr_list? + + edgerhs: edgeop (node_id | subgraph) edgerhs? + + edgeop: "->" | "--" + + node_stmt: node_id attr_list? + + node_id: ID + + subgraph: ("subgraph" ID?)? "{" stmt_list "}" + + ID: CNAME + | /-?(\.[0-9]+|[0-9]+(\.[0-9]*))/ + | ESCAPED_STRING + + %import common.CNAME + %import common.ESCAPED_STRING + %import common.WS + %ignore WS + ''' + + @staticmethod + def parse_edge(tree: lark.Tree) -> tuple[str, str]: + # only support a simple node-to-node edge + nodes =3D [] + for node in tree.iter_subtrees_topdown(): + if node.data =3D=3D "node_id": + nodes.append(node.children[0].strip('"')) + + if len(nodes) !=3D 2: + raise AutomataError("Only state-to-state transition is support= ed") + + return tuple(nodes) + + class ParseNodes(lark.visitors.Visitor): + def __init__(self, *args, **kwargs): + self.nodes =3D set() + super().__init__(*args, **kwargs) + + def node_stmt(self, tree): + node_id =3D tree.children[0] + node =3D node_id.children[0].strip('"') + self.nodes.add(node) + + class ParseEdges(lark.visitors.Visitor): + def __init__(self, *args, **kwargs): + self.edges =3D set() + super().__init__(*args, **kwargs) + + def edge_stmt(self, tree): + edge =3D ParseTree.parse_edge(tree) + self.edges.add(edge) + + class ParseAttributes(lark.visitors.Interpreter): + def __init__(self, *args, **kwargs): + ''' + Stacks of default attributes. [0] is the default + attributes for the outermost scope, while [-1] is the + default attributes for the current scope. + ''' + self.default_node_attrs =3D [{}] + self.default_edge_attrs =3D [{}] + + self.node_attrs =3D {} + self.edge_attrs =3D {} + + super().__init__(*args, **kwargs) + + @staticmethod + def __get_attrs(stmt: lark.Tree) -> dict[str, str]: + attrs =3D {} + + for node in stmt.iter_subtrees(): + if node.data =3D=3D "a_list": + attrs[node.children[0]] =3D node.children[1].strip('"') + + return attrs + + + def subgraph(self, tree): + # We are entering a new scope, inherit the default + # attributes of the outer scope + self.default_node_attrs.append(self.default_node_attrs[-1].cop= y()) + self.default_edge_attrs.append(self.default_edge_attrs[-1].cop= y()) + + children =3D self.visit_children(tree) + + # Exiting the scope + del self.default_node_attrs[-1] + del self.default_edge_attrs[-1] + + return children + + def node_stmt(self, tree): + node_id =3D tree.children[0] + node =3D node_id.children[0].strip('"') + + attrs =3D self.default_node_attrs[-1].copy() + attrs |=3D self.__get_attrs(tree) + + if attrs: + if node in self.node_attrs: + self.node_attrs[node] =3D attrs | self.node_attrs[node] + else: + self.node_attrs[node] =3D attrs + + return self.visit_children(tree) + + def edge_stmt(self, tree): + edge =3D ParseTree.parse_edge(tree) + + attrs =3D self.default_edge_attrs[-1].copy() + attrs |=3D self.__get_attrs(tree) + + if attrs: + if edge in self.edge_attrs: + self.edge_attrs[edge] =3D attrs | self.edge_attrs[edge] + else: + self.edge_attrs[edge] =3D attrs + + return self.visit_children(tree) + + def attr_stmt(self, tree): + attr_type =3D tree.children[0].data + attrs =3D self.__get_attrs(tree) + + if attr_type =3D=3D "node": + self.default_node_attrs[-1] |=3D attrs + elif attr_type =3D=3D "edge": + self.default_edge_attrs[-1] |=3D attrs + else: + # graph attributes are irrelevant + pass + + self.visit_children(tree) + + def __init__(self, dot_file): + parser =3D lark.Lark(self.grammar, parser=3D'lalr') + node_parser =3D self.ParseNodes() + edge_parser =3D self.ParseEdges() + attributes_parser =3D self.ParseAttributes() + + try: + with open(dot_file, "r") as f: + tree =3D parser.parse(f.read()) + attributes_parser.visit(tree) + node_parser.visit(tree) + edge_parser.visit(tree) + except OSError as exc: + raise AutomataError(exc.strerror) from exc + except lark.exceptions.UnexpectedInput as exc: + raise AutomataError(str(exc)) + + self.nodes =3D node_parser.nodes + self.edges =3D edge_parser.edges + self.node_attrs =3D attributes_parser.node_attrs + self.edge_attrs =3D attributes_parser.edge_attrs + class _ConstraintKey: """Base class for constraint keys.""" =20 @@ -66,6 +251,7 @@ class Automata: self.__dot_path =3D file_path self.name =3D model_name or self.__get_model_name() self.__dot_lines =3D self.__open_dot() + self.__parse_tree =3D ParseTree(file_path) self.states, self.initial_state, self.final_states =3D self.__get_= state_variables() self.env_types =3D {} self.env_stored =3D set() --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA07A378D86; Thu, 28 May 2026 08:28:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956895; cv=none; b=IZ7HEJ8ovA6MMc+ir7sW9PlSSGafqx/UBepoPNwJ+X44etPz56JGOqJEoCb7h+OO06YUz7d7QeenPaBnLIyaAY4otYKZin7Mljy+jpwPhHmmhA4J7HS/XPL2noKfKsRE5EktmesHIK25HSf4yGCNqwDbuvIuGbbpGpOPz7vxLYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956895; c=relaxed/simple; bh=Fv4TVPC1QQXiVJDLCPqfartIjb4SwsdTYlNIDEFSZxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZhKWDqg9RXhGJxK8WYjdNzR4FoeVfp61vVh0cNk05WcuIJXx9Q1jJ6efrV5ncIx5T3Xeg/QZguCg2ydgxAMyrepoaNYimgRCK3vtGXWIY/wHk8cRkmmQAUIAKUDuocmxdJqdzU1GeiP29BYME3pdleUlc6ijJ/QYKeBKk/yG6Cc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=DUDF8nRL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OlqH9qQI; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DUDF8nRL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OlqH9qQI" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956892; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UsoWyUh+iFiOgtu/fAtU2KwGjjQuIFRjIxwJ4HbkFvo=; b=DUDF8nRL8e5jppJgLWnbVPNn5VotGvEadCbGzrVLWK2SP9F2O/mXdfd+uUWSxAYci2A6V0 zyV8wv3YqxNjQ6HTXmSE+iG2/c6d7vCA0xSswGutWi6cDwpNBKzLachtrVb32pYhFe3jJA 0Q2WVyTP4QGkZBbVBrdGgctbYF4SCBo4SQwUOu9qVLBH1bmd4HOCjYvBzyc13EMDgZUBh/ XTMw0LaMYtFpRzixduxhcBkppReJH3RLiS6lis9WEljXjCepOGDImRtzrNUC/Nvj+oOru2 dzVg/iGtTA75R1YCQ/FVltVDOcYitsMvgGpZN6fFZISlx5gKgrH/L/OuT5Irng== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956892; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UsoWyUh+iFiOgtu/fAtU2KwGjjQuIFRjIxwJ4HbkFvo=; b=OlqH9qQIcm/yJk/zBHWy0zHrtZ34JUFXXyGlpfxZXcH3B7KykP5Bqfoa1xI1pR38LpohZX ozHRZq2Re9Nm8FCQ== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 03/13] verification/rvgen: Implement state and transition parser based on Lark Date: Thu, 28 May 2026 10:27:51 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The DOT parsing scripts directly parse the raw text and they are quite fragile. If the input dot files' formats are slightly changed (for instance, by breaking long some lines which is allowed by the DOT language), the scripts would fail. Prepare to move away from the raw text processing, implement parsers based on Lark which parse states, transitions and constraints. The parse results are not used yet. The existing scripts will be converted one by one to them, and the raw text processing will eventually be removed. Signed-off-by: Nam Cao Reviewed-by: Gabriele Monaco --- v2: - fixup guard grammar [Gabriele] - fixup inconsistent types in a list [Wander] - compiling the parsers only once to avoid overhead [Sashiko] - fix up the signature of State.__init__() [Sashiko] - gracefully handle node statement without label [Sashiko] - lark parse exception handling --- tools/verification/rvgen/rvgen/automata.py | 216 +++++++++++++++++++++ 1 file changed, 216 insertions(+) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index 8649d982383d..b86275e7bf28 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -198,6 +198,164 @@ class ParseTree: self.node_attrs =3D attributes_parser.node_attrs self.edge_attrs =3D attributes_parser.edge_attrs =20 +class ConstraintCondition: + def __init__(self, env: str, op: str, val: str, unit=3DNone): + self.env =3D env + self.op =3D op + self.val =3D val + self.unit =3D unit + if unit is None: + # try to infer unit from constants or parameters + val_for_unit =3D val.lower().replace("()", "") + if val_for_unit.endswith("_ns"): + self.unit =3D "ns" + if val_for_unit.endswith("_jiffies"): + self.unit =3D "j" + +class ConstraintRule: + grammar =3D r''' + rule: condition (OP condition)* + + OP: "&&" | "||" + + condition: ENV CMP_OP VAL UNIT? + + ENV: CNAME + + CMP_OP: "=3D=3D" | "<=3D" | "<" | ">=3D" | ">" + + VAL: /[0-9]+/ + | /[A-Z_]+\(\)/ + | /[A-Z_]+/ + | /[a-z_]+\(\)/ + | /[a-z_]+/ + + UNIT: "ns" | "us" | "ms" | "s" + ''' + + def __init__(self, c: ConstraintCondition): + ''' + A list of pairs of + - the condition (e.g. is_constr_dl =3D=3D 1) + - the logical operator ("||" or "&&") combining this + condition with the next one if it exists, otherwise None + + TODO: Perhaps use an abstract syntax tree instead, because + this representation cannot capture precedence + ''' + self.rules =3D [[c, None]] + + def chain(self, op: str, c: ConstraintCondition): + self.rules[-1][1] =3D op + self.rules.append([c, None]) + +class ConstraintReset: + def __init__(self, env): + self.env =3D env + +class StateLabelParser: + grammar =3D r''' + label: CNAME ("\\n" condition)? + + %import common.CNAME + %import common.WS + %ignore WS + ''' + ConstraintRule.grammar + + parser =3D lark.Lark(grammar, parser=3D'lalr', start=3D"label") + + def __init__(self, label: str): + try: + tree =3D self.parser.parse(label) + except lark.exceptions.UnexpectedInput as exc: + raise(AutomataError(f"Unrecognised state \"{label}\"\n{exc}")) + + self.state =3D tree.children[0] + self.constraint =3D None + + if len(tree.children) =3D=3D 2: + self.constraint =3D ConstraintCondition(*tree.children[1].chil= dren) + if self.constraint.op not in ("<", "<=3D"): + raise AutomataError("State constraints must be clock expir= ations like" + f" clk tuple[list[str], str, list[str]]: # wait for node declaration states =3D [] --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 319E53793BA; Thu, 28 May 2026 08:28:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956895; cv=none; b=pOJsPZQS/uYi/jUcc0F72Q60dnV/8lx4Fao7evJwz53bAP/I4Cx+oBAOugPuMHQQKH7CONzEsXuN9/dDClIsutY+fmfxh8lsBivAN4FPHfVFcgOGX7td35vV8V6hMmX089FELPkiRvVh+IKonAwb2qYytXY6/gbt3NvkOJEAg+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956895; c=relaxed/simple; bh=GgICHejSaCgbia1L+eRITR6BjR+aHeGi1DpftCmBGVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QGhkLE6dhLQiAmhF7vOy7WDjiCcr1D3MaNI5iDd4f8kWlDDCeippObnlE3YQWiZGVDLrcPDag3k8XpfqeTuXXsN6qCuFINKkX0f4saSMNxCczKC0/yVs16Dy0hmJ5/vNQb9wY1hUDbq7aSPgKLwTi+Fn7mvJduaOOFGcwvF/SZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4vMLuLz/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hsab9iVI; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4vMLuLz/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hsab9iVI" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956892; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UzJsvUcVtDli60hQAurseNA0wOO48E4RfuNSOgFkTys=; b=4vMLuLz/+2aIRV7k0+o1UDlaGk0IKthdefshFa2tIPweThYvlo0iSY00kUMTYGEHIwQzyE QYHOIBaUUr7M/MEZrzQXGOUSHnUV5QSSy2zvYjGdXbS2Vacxss5euVkYFFZvRzEjJCRAex aj51uQNsisapZz2av9WAvXvHEKeQDMFwb8A5gZ5Jg5Ef1L8vNSEC9mznvjF1KWnqlfQZo/ lJkmkK9i3802LyWNoPjGqAxTZpUbabsARXWSSgEHkjpbC7KZM68w5tmT9roWUz7Vy59Mq2 2sPLLq5yvsmiIhNTH0Cg6x5m2TI/WgOjyiGKx0H/A6QOvrA85A0CFCBttLpnyA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956892; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UzJsvUcVtDli60hQAurseNA0wOO48E4RfuNSOgFkTys=; b=hsab9iVIjC9JenJYdja7ngVkhCu9cSDVcSwst2yfpI83pcas+1TZsr/uYe3jls6he0FlOF o7DfWLUD7EJFebAQ== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 04/13] verification/rvgen: Convert __fill_verify_invariants_func() to Lark Date: Thu, 28 May 2026 10:27:52 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert __fill_verify_invariants_func() to use the parsed states information from Lark, prepare to remove the old raw text parsing code. Signed-off-by: Nam Cao Reviewed-by: Gabriele Monaco --- v2: fix up __start_to_invariant_check()'s signature [Sashiko] --- tools/verification/rvgen/rvgen/dot2k.py | 32 ++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index e6f476b903b0..a344cbbcb346 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -12,6 +12,7 @@ from collections import deque from .dot2c import Dot2c from .generator import Monitor from .automata import _EventConstraintKey, _StateConstraintKey, AutomataEr= ror +from .automata import ConstraintRule, ConstraintCondition =20 =20 class dot2k(Monitor, Dot2c): @@ -177,6 +178,14 @@ class ha2k(dot2k): raise AutomataError("Detected deterministic automaton, use the= 'da' class") self.trace_h =3D self._read_template_file("trace_hybrid.h") self.__parse_constraints() + self.has_invariant =3D False + self.has_guard =3D False + for state in self._states: + if state.inv: + self.has_invariant =3D True + for transition in self.transitions: + if transition.rule or transition.reset: + self.has_guard =3D True =20 def fill_monitor_class_type(self) -> str: if self._is_id_monitor(): @@ -218,14 +227,13 @@ class ha2k(dot2k): assert env.rstrip(f"_{self.name}") in self.envs return env =20 - def __start_to_invariant_check(self, constr: str) -> str: + def __start_to_invariant_check(self, inv: ConstraintCondition) -> str: # by default assume the timer has ns expiration - env =3D self.__get_constraint_env(constr) clock_type =3D "ns" - if self.env_types.get(env.rstrip(f"_{self.name}")) =3D=3D "j": + if inv.unit =3D=3D "j": clock_type =3D "jiffy" =20 - return f"return ha_check_invariant_{clock_type}(ha_mon, {env}, tim= e_ns)" + return f"return ha_check_invariant_{clock_type}(ha_mon, {inv.env}_= {self.name}, time_ns)" =20 def __start_to_conv(self, constr: str) -> str: """ @@ -320,20 +328,22 @@ class ha2k(dot2k): self.invariants[key] =3D rules[0] =20 def __fill_verify_invariants_func(self) -> list[str]: - buff =3D [] - if not self.invariants: + if not self.has_invariant: return [] =20 - buff.append( + buff =3D [ f"""static inline bool ha_verify_invariants(struct ha_monitor *ha_mon, \t\t\t\t\tenum {self.enum_states_def} curr_state, enum {self.enum_events_d= ef} event, \t\t\t\t\tenum {self.enum_states_def} next_state, u64 time_ns) -{{""") +{{"""] =20 _else =3D "" - for state, constr in sorted(self.invariants.items()): - check_str =3D self.__start_to_invariant_check(constr) - buff.append(f"\t{_else}if (curr_state =3D=3D {self.states[stat= e]}{self.enum_suffix})") + for state in self._states: + if not state.inv: + continue + + check_str =3D self.__start_to_invariant_check(state.inv) + buff.append(f"\t{_else}if (curr_state =3D=3D {state.name}{self= .enum_suffix})") buff.append(f"\t\t{check_str};") _else =3D "else " =20 --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A12FD3793DE; Thu, 28 May 2026 08:28:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956896; cv=none; b=qbY3loHEIK7ipBwAgqmNcjii6BThFODMxUXW01OpeDQ/45loHFCFGytUzu2MQfWSlACkmcMfbohZeN54MeaMi2VzUDHaHUMVsslYTfiar2CAlaZpDuBY0toclSD7TQRHldmuymymmNRqvZUwilwmd3fQXnBDdN60SsxLTs4IdWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956896; c=relaxed/simple; bh=QdsMQkekA1xOWQtjwhVjq/QjcJvm4QD4xcTebmKgsL4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bm8hSjrbxiGjQWgo4dtWl8YHmAMLMJjt5WMlEvgeefX0racYubx+waCt3kkMM5oiELmaiGy6ld+TxVzeKzGPmS2BqBWslYcjeMucQNUmeWPbgBGiAvWtkVbMW3gREBtM0HpgH9uT5fCpLDamPhHvBwsqFcMqhaS9LNnSGTPtOO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HVdeF07/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3sNXKcAl; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HVdeF07/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3sNXKcAl" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8SCEqGaXpDy5iQ9SddZqF6yn9bfsxhrj30i6jVH/uEQ=; b=HVdeF07/uVVnkZ2nqfQsE2Dw0SpagHB5UVu3wQ6R4/kENQhaX7wqx07jk6/Z5m84fd00NC U8egDaIdnZshiREf6+vjtoogfjUoOAXLZuXtXiSv4x7lDm6xxJSCCW6d47NSJmBs0TxYYw j/n0AT4Tg6Vdy0JZ0Ahb4NdWJt0Bj76bEtXZwNTEooghkjJlHdFw09PdXe+QmR0cPrwXhy hIPcpI3YW/erpX9xVGEzC/7Hy+JjTtE0pYavb3J2BxJzgsZqINr7kfH8fP7plA8QN5OHHT wIjWvnsHpj6fr6lwNoE+uX7g+LHlufwHoScbe5t5f8k27pyeaBT6QqLkucseIA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8SCEqGaXpDy5iQ9SddZqF6yn9bfsxhrj30i6jVH/uEQ=; b=3sNXKcAluMRltkKw/Lwlu8KGoc/sa0qF4sKa+QZLerb33eOmmN5YDD0WYXUqAF5kLZJ128 PW9YsBdMh4cscICA== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 05/13] verification/rvgen: Convert __fill_setup_invariants_func() to Lark Date: Thu, 28 May 2026 10:27:53 +0200 Message-ID: <0b2cf5e1bb03d0e3a667b0fc2c7093123ef0a78c.1779956342.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Gabriele Monaco --- 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/r= vgen/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.e= num_suffix}," f" {value}, time_ns)") =20 + def __parse_invariant(self, inv): + # by default assume the timer has ns expiration + clock_type =3D "ns" + if inv.unit =3D=3D "j": + clock_type =3D "jiffy" + + env =3D inv.env + self.enum_suffix + val =3D inv.val.replace("()", "(ha_mon)") + + match inv.unit: + case "us": + val *=3D 10**3 + case "ms": + val *=3D 10**6 + case "s": + val *=3D 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_mon= itor *ha_mon, return conflict_guards, conflict_invs =20 def __fill_setup_invariants_func(self) -> list[str]: - buff =3D [] - if not self.invariants: + if not self.has_invariant: return [] =20 - buff.append( + buff =3D [ 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_eve= nts_def} event, \t\t\t\t enum {self.enum_states_def} next_state, u64 time_ns) -{{""") +{{"""] =20 conditions =3D ["next_state =3D=3D curr_state"] conditions +=3D [f"event !=3D {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;") =20 _else =3D "" - for state, constr in sorted(self.invariants.items()): - buff.append(f"\t{_else}if (next_state =3D=3D {self.states[stat= e]}{self.enum_suffix})") - buff.append(f"\t\t{constr};") + for state in self._states: + inv =3D state.inv + if not inv: + continue + inv =3D self.__parse_invariant(inv) + buff.append(f"\t{_else}if (next_state =3D=3D {state.name}{self= .enum_suffix})") + buff.append(f"\t\t{inv};") _else =3D "else " =20 - for state in self.invariants: - buff.append(f"\telse if (curr_state =3D=3D {self.states[state]= }{self.enum_suffix})") + for state in self._states: + inv =3D state.inv + if not inv: + continue + buff.append(f"\telse if (curr_state =3D=3D {state.name}{self.e= num_suffix})") buff.append("\t\tha_cancel_timer(ha_mon);") =20 buff.append("}\n") --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B03A4378D71; Thu, 28 May 2026 08:28:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956896; cv=none; b=Yk8+RJFTgvqQH+d3rK4hScnhQjDbVvD4yYVJkB4QijGagN1AqnKHt/PM56Otc2rFmjnnPQ3yxykf8jBpc5PLuNjm3zneIYWs3HcyeeCAy9nSlsK+8DKR6RuD6IoJPktdzDKfaXUSnHKwIDcZOSC5GToSoQMiUjOK+VtczQH6dCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956896; c=relaxed/simple; bh=vTFq3foTdNB6zeqaaZE7I9ZzLyhSfOY5UPD91dH1uH4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hlTreLD/QDVb+5YB7giRawuzerCrv+CT2Rzq/tYrJ4QkSAheD+Fkup3ihvRnPsd9Xe4KesMqWXr2UXZMIiNXeRYlO+AcKh69a7P+DyETG/QP0s4c1+ugvfYtm7dgEuvrJE1DK3qKcqwZwKr8gsCtIdQjDTVs1gJVj9R3hdNznGY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tlT465i0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=SALIK9SN; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tlT465i0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="SALIK9SN" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q3Mjdyvr7ihVKGai3Yxy6L8TVjmUfr9blfcOpHVW6Fo=; b=tlT465i0rSq7duiydyd6nlcxM+lx+dNx5//wIMsTxAe8Mru632rvTeKCoEVQMqwWRUkcwa +0owNMWtOK3kwITgjcj8A0mkHrlQz928q3i1CLHagn2X6LfaMHGnH5w9toKzSJt4Gfquys 0BGuaF/xL5g9I+jkIGb5PDyKSSiM/bzwZnvt7ijO7sQW4Hg1iwtK1rUtbhHyDO7IRCW8fr N88W9AkPgA4/brQU3vk/QtRrlWoGJdFtrFyqIPXjj3QGcHI1uIoRt06vcqJsj5h5XheLkq FKBdW11sPxN+8WDDjXjECpx/QG6pBpTpBjjHTRbCbHT5EcLHXrsuENsgzeV07w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q3Mjdyvr7ihVKGai3Yxy6L8TVjmUfr9blfcOpHVW6Fo=; b=SALIK9SNigRdB54CyXKKtQOYYRDm8K2YRt+OZzsZ3Q2j6PdJqTTOGG65U4UWdn3/dpuhBM 6rg7Odf86+9zoGDw== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 06/13] verification/rvgen: Convert __fill_verify_guards_func() to Lark Date: Thu, 28 May 2026 10:27:54 +0200 Message-ID: <2157c2e5fe34251c403604f0d58a3a686a6f6a8b.1779956342.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Prepare to remove self.guards and self.__parse_constraints(), convert __fill_verify_guards_func() to use the parsed transitions from Lark. Signed-off-by: Nam Cao Reviewed-by: Gabriele Monaco --- v2: - fix up the ';' separator [Gabriele] - make return type consistent with the function's signature [Wander] - fix up __parse_guard_rule()'s signature --- tools/verification/rvgen/rvgen/dot2k.py | 38 +++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index d9f8e1c7737a..ebaa6c9135c2 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -221,6 +221,19 @@ class ha2k(dot2k): def __parse_single_constraint(self, rule: dict, value: str) -> str: return f"ha_get_env(ha_mon, {rule["env"]}{self.enum_suffix}, time_= ns) {rule["op"]} {value}" =20 + def __parse_guard_rule(self, rule) -> list[str]: + buff =3D [] + for c, sep in rule.rules: + env =3D c.env + self.enum_suffix + op =3D c.op + val =3D self.__adjust_value(c.val, c.unit) + + cond =3D f"ha_get_env(ha_mon, {env}, time_ns) {op} {val}" + if sep: + cond +=3D f" {sep}" + buff.append(cond) + return buff + def __get_constraint_env(self, constr: str) -> str: """Extract the second argument from an ha_ function""" env =3D constr.split("(")[1].split()[1].rstrip(")").rstrip(",") @@ -287,7 +300,7 @@ class ha2k(dot2k): rules =3D invalid_checks + rules =20 separator =3D "\n\t\t " if sum(len(r) for r in rules) > 80 el= se " " - return ["res =3D " + separator.join(rules)] + return ["res =3D " + separator.join(rules) + ";"] =20 def __validate_constraint(self, key: tuple[int, int] | int, constr: st= r, rule, reset) -> None: @@ -406,7 +419,8 @@ f"""static inline void ha_convert_inv_guard(struct ha_m= onitor *ha_mon, =20 def __fill_verify_guards_func(self) -> list[str]: buff =3D [] - if not self.guards: + + if not self.has_guard: return [] =20 buff.append( @@ -418,14 +432,22 @@ f"""static inline bool ha_verify_guards(struct ha_mon= itor *ha_mon, """) =20 _else =3D "" - for edge, constr in sorted(self.guards.items()): + for transition in self.transitions: + if not transition.rule and not transition.reset: + continue + buff.append(f"\t{_else}if (curr_state =3D=3D " - f"{self.states[edge[0]]}{self.enum_suffix} && " - f"event =3D=3D {self.events[edge[1]]}{self.enum_su= ffix})") - if constr.count(";") > 0: + f"{transition.src}{self.enum_suffix} && " + f"event =3D=3D {transition.event}{self.enum_suffix= })") + rule =3D transition.rule + reset =3D transition.reset + if rule and reset: buff[-1] +=3D " {" - buff +=3D [f"\t\t{c};" for c in constr.split(";")] - if constr.count(";") > 0: + if rule: + buff.append("\t\t" + self.__format_guard_rules(self.__pars= e_guard_rule(rule))[0]) + if reset: + buff.append(f"\t\tha_reset_env(ha_mon, {reset.env}{self.en= um_suffix}, time_ns);") + if rule and reset: _else =3D "} else " else: _else =3D "else " --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8D0B379EC6; Thu, 28 May 2026 08:28:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956898; cv=none; b=os6JrgXEEbFKMP3sPSq90JrvTYzO1grsvaYpJQmwcg7s/6s40GTEPPjuCZgp2xQxBTJ44AvWCezippEd6wWNz2TTYzKXnOPDGnGcibDS9kZM4DhVX6ADOZsO1TPB1VuXHClroT3DciBhGKXX/AgJhJB/HPushLPJq5gBrZhKNYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956898; c=relaxed/simple; bh=+S+Uef0jvzDOQgQQQqT/cKpTqlJkZ0A8ufHfhwo/Hes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zml8Xq+BvpbSK+sLtZzWO60RLmHIXd/iaa8v4CiTeEpWM2netM+Bd4sdPbJlmk1HEeQaVXDaxTFyvvklKZ/NXS190AHOo0d3MaFBBpsHha5LIkOrw15J3k+KQlb7LFr/tnfP6jLiDhxKaoicdCw5cbf/x3tbqxHStSqXNVtRh08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=O5nI63ra; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=un/s5W7N; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="O5nI63ra"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="un/s5W7N" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pl1OiSu4mTrs8VCrdsTHAFixp1xMV6Yyidh2CL4VUPE=; b=O5nI63raGSA6nH2gSUYcTG+g61wLSKh3kbhFgdcmC7sftHd04CyJVB9M8mT6alRVHPsftZ MzE0xDNVgbkFtkcBAi2ilOseyK4Budbb/7sMsSkp2iZD97iKHU1vArJdPGicM/rpO95Ach kYObbOovaIFDZwM+BZ+Cx71NnQpTu4CKFGDmIA3Gx0sACrutjuzp4X+zPrTIMaZ1XsniaX jfGXtFn/Y1Aa9BPYAJmLGzg3rpdCyK0rfrePrC+zkYfP1OA9Hcj/Moy3gn7WACI6m+RcYn G6/Bz3AGzpO3n2Bd/b51a247UeHBSZOSx+E01WyNulg3UOt977+2VDFV+RB4dg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pl1OiSu4mTrs8VCrdsTHAFixp1xMV6Yyidh2CL4VUPE=; b=un/s5W7Nmd0+n8zM+3y8utNfPITDYtJ9eN5qykQykpnmm6vjqW9he5aByYls4YDY8TQYOo AYjlWZFoT+chUjDA== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 07/13] rv: Simply hybrid automata monitors's clock variables Date: Thu, 28 May 2026 10:27:55 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hybrid automata monitors's clock variables have two different representations: - The invariant representation, which is the timestamp when the invariant expires - The guard representation, which is the timestamp when the clock is last reset This dual representation makes the logic quite difficult to follow (well, at least for me). It also complicates the monitors and the generation tool, as it requires conversion back and forth between the representation. Simplify by using the clock variables for a single purpose: storing the time stamp since the clock is last reset. This also allows simplifying rvgen, which will be done in a follow-up commit. Signed-off-by: Nam Cao Reviewed-by: Gabriele Monaco --- v2: - fix up invariant check when the env is not initialized [Gabriele] - keep the two invariant check functions consistent [Gabriele] - fix build failure [Gabriele, Sashiko] --- include/rv/ha_monitor.h | 62 ++++++------------------ kernel/trace/rv/monitors/nomiss/nomiss.c | 18 +------ kernel/trace/rv/monitors/stall/stall.c | 2 +- 3 files changed, 18 insertions(+), 64 deletions(-) diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h index d59507e8cb30..3b607a247768 100644 --- a/include/rv/ha_monitor.h +++ b/include/rv/ha_monitor.h @@ -253,19 +253,8 @@ static inline void __ha_monitor_timer_callback(struct = ha_monitor *ha_mon) } =20 /* - * The clock variables have 2 different representations in the env_store: - * - The guard representation is the timestamp of the last reset - * - The invariant representation is the timestamp when the invariant expi= res - * As the representations are incompatible, care must be taken when switch= ing - * between them: the invariant representation can only be used when starti= ng a - * timer when the previous representation was guard (e.g. no other invaria= nt - * started since the last reset operation). - * Likewise, switching from invariant to guard representation without a re= set - * can be done only by subtracting the exact value used to start the invar= iant. - * - * Reading the environment variable (ha_get_clk) also reflects this differ= ence - * any reads in states that have an invariant return the (possibly negativ= e) - * time since expiration, other reads return the time since last reset. + * The clock variables store the time epoch - the timestamp when the clock= was last reset. + * They are read by subtracting the time epoch from the current time. */ =20 /* @@ -279,31 +268,21 @@ static inline void ha_reset_clk_ns(struct ha_monitor = *ha_mon, enum envs env, u64 { WRITE_ONCE(ha_mon->env_store[env], time_ns); } -static inline void ha_set_invariant_ns(struct ha_monitor *ha_mon, enum env= s env, - u64 value, u64 time_ns) -{ - WRITE_ONCE(ha_mon->env_store[env], time_ns + value); -} -static inline bool ha_check_invariant_ns(struct ha_monitor *ha_mon, - enum envs env, u64 time_ns) +static inline bool ha_check_invariant_ns(struct ha_monitor *ha_mon, enum e= nvs env, + u64 time_ns, u64 expire_ns) { - return READ_ONCE(ha_mon->env_store[env]) >=3D time_ns; + return READ_ONCE(ha_mon->env_store[env]) >=3D time_ns - expire_ns; } /* * ha_invariant_passed_ns - prepare the invariant and return the time sinc= e reset */ -static inline u64 ha_invariant_passed_ns(struct ha_monitor *ha_mon, enum e= nvs env, - u64 expire, u64 time_ns) +static inline u64 ha_invariant_passed_ns(struct ha_monitor *ha_mon, enum e= nvs env, u64 time_ns) { - u64 passed =3D 0; - if (env < 0 || env >=3D ENV_MAX_STORED) return 0; if (ha_monitor_env_invalid(ha_mon, env)) return 0; - passed =3D ha_get_env(ha_mon, env, time_ns); - ha_set_invariant_ns(ha_mon, env, expire - passed, time_ns); - return passed; + return ha_get_env(ha_mon, env, time_ns); } =20 /* @@ -317,32 +296,21 @@ static inline void ha_reset_clk_jiffy(struct ha_monit= or *ha_mon, enum envs env) { WRITE_ONCE(ha_mon->env_store[env], get_jiffies_64()); } -static inline void ha_set_invariant_jiffy(struct ha_monitor *ha_mon, - enum envs env, u64 value) +static inline bool ha_check_invariant_jiffy(struct ha_monitor *ha_mon, enu= m envs env, + u64 time_ns, u64 expire_jiffy) { - WRITE_ONCE(ha_mon->env_store[env], get_jiffies_64() + value); -} -static inline bool ha_check_invariant_jiffy(struct ha_monitor *ha_mon, - enum envs env, u64 time_ns) -{ - return time_after64(READ_ONCE(ha_mon->env_store[env]), get_jiffies_64()); - + return time_after64(READ_ONCE(ha_mon->env_store[env]), get_jiffies_64() -= expire_jiffy); } /* * ha_invariant_passed_jiffy - prepare the invariant and return the time s= ince reset */ -static inline u64 ha_invariant_passed_jiffy(struct ha_monitor *ha_mon, enu= m envs env, - u64 expire, u64 time_ns) +static inline u64 ha_invariant_passed_jiffy(struct ha_monitor *ha_mon, enu= m envs env, u64 time_ns) { - u64 passed =3D 0; - if (env < 0 || env >=3D ENV_MAX_STORED) return 0; if (ha_monitor_env_invalid(ha_mon, env)) return 0; - passed =3D ha_get_env(ha_mon, env, time_ns); - ha_set_invariant_jiffy(ha_mon, env, expire - passed); - return passed; + return ha_get_env(ha_mon, env, time_ns); } =20 /* @@ -389,14 +357,14 @@ static inline void ha_setup_timer(struct ha_monitor *= ha_mon) static inline void ha_start_timer_jiffy(struct ha_monitor *ha_mon, enum en= vs env, u64 expire, u64 time_ns) { - u64 passed =3D ha_invariant_passed_jiffy(ha_mon, env, expire, time_ns); + u64 passed =3D ha_invariant_passed_jiffy(ha_mon, env, time_ns); =20 mod_timer(&ha_mon->timer, get_jiffies_64() + expire - passed); } static inline void ha_start_timer_ns(struct ha_monitor *ha_mon, enum envs = env, u64 expire, u64 time_ns) { - u64 passed =3D ha_invariant_passed_ns(ha_mon, env, expire, time_ns); + u64 passed =3D ha_invariant_passed_ns(ha_mon, env, time_ns); =20 ha_start_timer_jiffy(ha_mon, ENV_MAX_STORED, nsecs_to_jiffies(expire - passed + TICK_NSEC - 1), time_ns); @@ -438,7 +406,7 @@ static inline void ha_start_timer_ns(struct ha_monitor = *ha_mon, enum envs env, u64 expire, u64 time_ns) { int mode =3D HRTIMER_MODE_REL_HARD; - u64 passed =3D ha_invariant_passed_ns(ha_mon, env, expire, time_ns); + u64 passed =3D ha_invariant_passed_ns(ha_mon, env, time_ns); =20 if (RV_MON_TYPE =3D=3D RV_MON_PER_CPU) mode |=3D HRTIMER_MODE_PINNED; diff --git a/kernel/trace/rv/monitors/nomiss/nomiss.c b/kernel/trace/rv/mon= itors/nomiss/nomiss.c index a0b5641a1858..19d0e9aa4d58 100644 --- a/kernel/trace/rv/monitors/nomiss/nomiss.c +++ b/kernel/trace/rv/monitors/nomiss/nomiss.c @@ -57,24 +57,12 @@ static inline bool ha_verify_invariants(struct ha_monit= or *ha_mon, enum states next_state, u64 time_ns) { if (curr_state =3D=3D ready_nomiss) - return ha_check_invariant_ns(ha_mon, clk_nomiss, time_ns); + return ha_check_invariant_ns(ha_mon, clk_nomiss, time_ns, DEADLINE_NS(ha= _mon)); else if (curr_state =3D=3D running_nomiss) - return ha_check_invariant_ns(ha_mon, clk_nomiss, time_ns); + return ha_check_invariant_ns(ha_mon, clk_nomiss, time_ns, DEADLINE_NS(ha= _mon)); return true; } =20 -static inline void ha_convert_inv_guard(struct ha_monitor *ha_mon, - enum states curr_state, enum events event, - enum states next_state, u64 time_ns) -{ - if (curr_state =3D=3D next_state) - return; - if (curr_state =3D=3D ready_nomiss) - ha_inv_to_guard(ha_mon, clk_nomiss, DEADLINE_NS(ha_mon), time_ns); - else if (curr_state =3D=3D running_nomiss) - ha_inv_to_guard(ha_mon, clk_nomiss, DEADLINE_NS(ha_mon), time_ns); -} - static inline bool ha_verify_guards(struct ha_monitor *ha_mon, enum states curr_state, enum events event, enum states next_state, u64 time_ns) @@ -122,8 +110,6 @@ static bool ha_verify_constraint(struct ha_monitor *ha_= mon, if (!ha_verify_invariants(ha_mon, curr_state, event, next_state, time_ns)) return false; =20 - ha_convert_inv_guard(ha_mon, curr_state, event, next_state, time_ns); - if (!ha_verify_guards(ha_mon, curr_state, event, next_state, time_ns)) return false; =20 diff --git a/kernel/trace/rv/monitors/stall/stall.c b/kernel/trace/rv/monit= ors/stall/stall.c index 9ccfda6b0e73..1aa65d7e690d 100644 --- a/kernel/trace/rv/monitors/stall/stall.c +++ b/kernel/trace/rv/monitors/stall/stall.c @@ -38,7 +38,7 @@ static inline bool ha_verify_invariants(struct ha_monitor= *ha_mon, enum states next_state, u64 time_ns) { if (curr_state =3D=3D enqueued_stall) - return ha_check_invariant_jiffy(ha_mon, clk_stall, time_ns); + return ha_check_invariant_jiffy(ha_mon, clk_stall, time_ns, threshold_ji= ffies); return true; } =20 --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8C7C379C5E; Thu, 28 May 2026 08:28:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956897; cv=none; b=jNKPnqgqHv5PU1y+lj6T/vmSWOIfMXrxjl/odgTl25cNDlooJa5seU5Tlsygq1ivClUvkbcBRUUCK8WVcVFmkR3zK8EEFb7f8M3Z6yCYqJ7wCpLVxfQDk68KZQcf9f5+yZRxWqGZyr45KSqxM4fb7MkKHHTGGVT0gQmkI/vEgI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956897; c=relaxed/simple; bh=+ACcNI4umuGPeXyl+kAJFeIoTbOgnWI7f9VK6dhZXME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rLINANTATYCuIypZ4uzZQWbcJUsCmFKmfe2OOsBZvv6fmb10+qzRwsUEnWMRZz45ieFOpz6e6DdAAsYqQS2NpzlkS8DZRSe/dAH1mdM7l09Min+MRc9W7+nFEn7tejaiD/2mAU4eU6ul14dmHsvMTo61qjtLqnbSw/Hd7r0DIa4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aoccr8Lc; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mPsKaLaZ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aoccr8Lc"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mPsKaLaZ" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c3wk/oudCLpunKRbWUDb9KPkrIFOQfBgbbh4ZHb+baE=; b=aoccr8LcrXc/APh0Pw403QF+4mYgDdwzwpH6lFTmG6Fp7X+O2SR8bSlLEn1pajkIn3va/u uP2BgHtEB+UxR02JU5WrqB5fSDTHiSDZCIP17Xng/v1wdFiolw31D0LjEt8orh8fuKpOEH bVyxUbSifeOcMFqeqt2KPVXKSEnnNzXakoKbbrEuEKBffRHfnvFKT/S79LHaMaNiNMR8ES AL2T8VRk/qyoK6FAYUmhxIdelcKJbxNPKOEOHIHEUyqjifOu9AeTtqH0AqxEhttijmD0z1 TbDlZgCmbWpyElmSsx8AzG5s0QubTFyy8+j2XL7Wl66dhn9+jZBF/e1kQVECvQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c3wk/oudCLpunKRbWUDb9KPkrIFOQfBgbbh4ZHb+baE=; b=mPsKaLaZuXuA7V8zmizidSXd32GC0u15QzJ+YfvnftJlWtqtYMqG53EEKcAMXE0rqL5xYH TYh/QbmfxdbzgrAQ== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 08/13] verification/rvgen: Simplify the generation for clock variables Date: Thu, 28 May 2026 10:27:56 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hybrid automata monitors's clock variables have been changed to have only a single representation. Now there is no need to generate code to convert between the two representations. Delete __fill_convert_inv_guard_func() and its associates. Update __start_to_invariant_check() to how invariants now work. Signed-off-by: Nam Cao --- v2: - add missing __adjust_value() in __start_to_invariant_check() [Sashiko] - remove obsolete comment about dual clock representation [Sashiko] --- tools/verification/rvgen/rvgen/dot2k.py | 96 +------------------------ 1 file changed, 3 insertions(+), 93 deletions(-) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index ebaa6c9135c2..3aee2e44ba7d 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -246,7 +246,9 @@ class ha2k(dot2k): if inv.unit =3D=3D "j": clock_type =3D "jiffy" =20 - return f"return ha_check_invariant_{clock_type}(ha_mon, {inv.env}_= {self.name}, time_ns)" + value =3D self.__adjust_value(inv.val, inv.unit) + + return f"return ha_check_invariant_{clock_type}(ha_mon, {inv.env}_= {self.name}, time_ns, {value})" =20 def __start_to_conv(self, constr: str) -> str: """ @@ -383,40 +385,6 @@ f"""static inline bool ha_verify_invariants(struct ha_= monitor *ha_mon, buff.append("\treturn true;\n}\n") return buff =20 - def __fill_convert_inv_guard_func(self) -> list[str]: - buff =3D [] - if not self.invariants: - return [] - - conflict_guards, conflict_invs =3D self.__find_inv_conflicts() - if not conflict_guards and not conflict_invs: - return [] - - buff.append( -f"""static inline void ha_convert_inv_guard(struct ha_monitor *ha_mon, -\t\t\t\t\tenum {self.enum_states_def} curr_state, enum {self.enum_events_d= ef} event, -\t\t\t\t\tenum {self.enum_states_def} next_state, u64 time_ns) -{{""") - buff.append("\tif (curr_state =3D=3D next_state)\n\t\treturn;") - - _else =3D "" - for state, constr in sorted(self.invariants.items()): - # a state with invariant can reach us without reset - # multiple conflicts must have the same invariant, otherwise w= e cannot - # know how to reset the value - conf_i =3D [start for start, end in conflict_invs if end =3D= =3D state] - # we can reach a guard without reset - conf_g =3D [e for s, e in conflict_guards if s =3D=3D state] - if not conf_i and not conf_g: - continue - buff.append(f"\t{_else}if (curr_state =3D=3D {self.states[stat= e]}{self.enum_suffix})") - - buff.append(f"\t\t{self.__start_to_conv(constr)};") - _else =3D "else " - - buff.append("}\n") - return buff - def __fill_verify_guards_func(self) -> list[str]: buff =3D [] =20 @@ -456,54 +424,6 @@ f"""static inline bool ha_verify_guards(struct ha_moni= tor *ha_mon, buff.append("\treturn res;\n}\n") return buff =20 - def __find_inv_conflicts(self) -> tuple[set[tuple[int, _EventConstrain= tKey]], - set[tuple[int, _StateConstrain= tKey]]]: - """ - Run a breadth first search from all states with an invariant. - Find any conflicting constraints reachable from there, this can be - another state with an invariant or an edge with a non-reset guard. - Stop when we find a reset. - - Return the set of conflicting guards and invariants as tuples of - conflicting state and constraint key. - """ - conflict_guards: set[tuple[int, _EventConstraintKey]] =3D set() - conflict_invs: set[tuple[int, _StateConstraintKey]] =3D set() - for start_idx in self.invariants: - queue =3D deque([(start_idx, 0)]) # (state_idx, distance) - env =3D self.__get_constraint_env(self.invariants[start_idx]) - - while queue: - curr_idx, distance =3D queue.popleft() - - # Check state condition - if curr_idx !=3D start_idx and curr_idx in self.invariants: - conflict_invs.add((start_idx, _StateConstraintKey(curr= _idx))) - continue - - # Check if we should stop - if distance > len(self.states): - break - if curr_idx !=3D start_idx and distance > 1: - continue - - for event_idx, next_state_name in enumerate(self.function[= curr_idx]): - if next_state_name =3D=3D self.invalid_state_str: - continue - curr_guard =3D self.guards.get((curr_idx, event_idx), = "") - if "reset" in curr_guard and env in curr_guard: - continue - - if env in curr_guard: - conflict_guards.add((start_idx, - _EventConstraintKey(curr_idx,= event_idx))) - continue - - next_idx =3D self.states.index(next_state_name) - queue.append((next_idx, distance + 1)) - - return conflict_guards, conflict_invs - def __fill_setup_invariants_func(self) -> list[str]: if not self.has_invariant: return [] @@ -554,16 +474,9 @@ f"""static inline void ha_setup_invariants(struct ha_m= onitor *ha_mon, * the next state has a constraint, cancel it in any other case and to che= ck * that it didn't expire before the callback run. Transitions to the same = state * without a reset never affect timers. - * Due to the different representations between invariants and guards, the= re is - * a function to convert it in case invariants or guards are reachable from - * another invariant without reset. Those are not present if not required = in - * the model. This is all automatic but is worth checking because it may s= how - * errors in the model (e.g. missing resets). */""") =20 buff +=3D self.__fill_verify_invariants_func() - inv_conflicts =3D self.__fill_convert_inv_guard_func() - buff +=3D inv_conflicts buff +=3D self.__fill_verify_guards_func() buff +=3D self.__fill_setup_invariants_func() =20 @@ -576,9 +489,6 @@ f"""static bool ha_verify_constraint(struct ha_monitor = *ha_mon, if self.invariants: buff.append("\tif (!ha_verify_invariants(ha_mon, curr_state, " "event, next_state, time_ns))\n\t\treturn false;\n= ") - if inv_conflicts: - buff.append("\tha_convert_inv_guard(ha_mon, curr_state, event,= " - "next_state, time_ns);\n") =20 if self.guards: buff.append("\tif (!ha_verify_guards(ha_mon, curr_state, event= , " --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBCB337AA9A; Thu, 28 May 2026 08:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956901; cv=none; b=V4OaEUoPY5bHNTdFJjGLNomHwmaBRy2mqLrzjIvDVnSIWh4tOYFhu5hZnl42zCEnRihi954K1GU9TXLa49dWlCnQlqQ9L36HXOaEPU0uDJgxtoM804/mZKG8hfjUftnIfxvDlsD4PTRQKz7jZDpeI1TWAx1Hjpg2qbDJqQArROk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956901; c=relaxed/simple; bh=4eH8TJkA2UToILE+6LBqgCIsspjF8TJPaWC3e92TeuQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q/FssmuJ2CLVPCjO9sjUT+2OERS0e93QT3bgO5l+h1aaTDbmPwE1+2C+mtZ85d2Cv2liYjQJSaYDZYzYJC37Lh9wKmdOK3iKPckq+R8loYZRaU04IR4r5DlZzyi6OtMQ3i7qNoEjQyH3Iw6tYDNuQ0haw0jXsLfMzkxz+2J2jv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=W6EGXjlB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oX/4V29R; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="W6EGXjlB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oX/4V29R" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RyMKOAlM5S9chs+xuHs5LYwdy3dWYwckXB+MKCbbEfM=; b=W6EGXjlBadsGMisjpbMwwL/Ot6MTn7YtwC9ozS8MdV8g0eu+TThWNbWzzvdi8IVwDAowur iBjA3M39C9uunW5qsCWgD+9mHFYUXpCZg7qfhezeYJpiyOS7xYdO4DmJmD2HvLqYlN9Unj vOAfDySaT5En9gxDxVDBYzIxLA/deIzd0Ei5dZM4tuueaXLHxfRsVMQutlRpYyIviT2qI8 5ZgtWgCqRDH55gS4zClKIXkayAMikWK3R9cUxOEvrCSju49ff6vRpd7fHt3644hax+iTRz yQywWnVm09Z0/aM5RNGrS5KRoGUWi9BeJMYMhw0/A+oA0ewKGmD7CuTc0hbMVA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RyMKOAlM5S9chs+xuHs5LYwdy3dWYwckXB+MKCbbEfM=; b=oX/4V29Rk9x7ZdidMiW4nbu23A0hT083MfapCEk57liW7rA4KY2u4KB0xoYmYunyErM96J uF2xff1XDMlbMCDQ== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 09/13] verification/rvgen: Delete __parse_constraint() Date: Thu, 28 May 2026 10:27:57 +0200 Message-ID: <74963b576565c218dd171aaea2c63401968e499c.1779956342.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" All previous users of self.invariants and self.guards have been converted to the Lark parser, delete __parse_constraints() and its associates. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/dot2k.py | 67 ++----------------------- 1 file changed, 4 insertions(+), 63 deletions(-) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index 3aee2e44ba7d..cafa19b318da 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -177,7 +177,6 @@ class ha2k(dot2k): if not self.is_hybrid_automata(): raise AutomataError("Detected deterministic automaton, use the= 'da' class") self.trace_h =3D self._read_template_file("trace_hybrid.h") - self.__parse_constraints() self.has_invariant =3D False self.has_guard =3D False for state in self._states: @@ -304,64 +303,6 @@ class ha2k(dot2k): separator =3D "\n\t\t " if sum(len(r) for r in rules) > 80 el= se " " return ["res =3D " + separator.join(rules) + ";"] =20 - def __validate_constraint(self, key: tuple[int, int] | int, constr: st= r, - rule, reset) -> None: - # event constrains are tuples and allow both rules and reset - # state constraints are only used for expirations (e.g. clk None: - self.guards: dict[_EventConstraintKey, str] =3D {} - self.invariants: dict[_StateConstraintKey, str] =3D {} - for key, constraint in self.constraints.items(): - rules =3D [] - resets =3D [] - for c, sep in self._split_constraint_expr(constraint): - rule =3D self.constraint_rule.search(c) - reset =3D self.constraint_reset.search(c) - self.__validate_constraint(key, c, rule, reset) - if rule: - value =3D rule["val"] - value_len =3D len(rule["val"]) - unit =3D None - if rule.groupdict().get("unit"): - value_len +=3D len(rule["unit"]) - unit =3D rule["unit"] - c =3D c[:-(value_len)] - value =3D self.__adjust_value(value, unit) - if self.is_event_constraint(key): - c =3D self.__parse_single_constraint(rule, value) - if sep: - c +=3D f" {sep}" - else: - c =3D self.__parse_timer_constraint(rule, value) - rules.append(c) - if reset: - c =3D f"ha_reset_env(ha_mon, {reset["env"]}{self.enum_= suffix}, time_ns)" - resets.append(c) - if self.is_event_constraint(key): - res =3D self.__format_guard_rules(rules) + resets - self.guards[key] =3D ";".join(res) - else: - self.invariants[key] =3D rules[0] - def __fill_verify_invariants_func(self) -> list[str]: if not self.has_invariant: return [] @@ -486,15 +427,15 @@ f"""static bool ha_verify_constraint(struct ha_monito= r *ha_mon, \t\t\t\t enum {self.enum_states_def} next_state, u64 time_ns) {{""") =20 - if self.invariants: + if self.has_invariant: buff.append("\tif (!ha_verify_invariants(ha_mon, curr_state, " "event, next_state, time_ns))\n\t\treturn false;\n= ") =20 - if self.guards: + if self.has_guard: buff.append("\tif (!ha_verify_guards(ha_mon, curr_state, event= , " "next_state, time_ns))\n\t\treturn false;\n") =20 - if self.invariants: + if self.has_invariant: buff.append("\tha_setup_invariants(ha_mon, curr_state, event, = next_state, time_ns);\n") =20 buff.append("\treturn true;\n}\n") @@ -571,7 +512,7 @@ f"""static bool ha_verify_constraint(struct ha_monitor = *ha_mon, return self.__fill_hybrid_get_reset_functions() + self.__fill_cons= tr_func() =20 def _fill_timer_type(self) -> list: - if self.invariants: + if self.has_invariant: return [ "/* XXX: If the monitor has several instances, conside= r HA_TIMER_WHEEL */", "#define HA_TIMER_TYPE HA_TIMER_HRTIMER" --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEF6537AA98; Thu, 28 May 2026 08:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956898; cv=none; b=T+yLir+dh/uskysQlQZE9V+kWQXOPJjGHhc7LmPdBr9XJYVFNAqqJMuBEwIFk+oks/FpGo8Crmf1K3Z6pc8ASGXxLGaeEOlNiFFCOnRs92ON42e64xe9LSmze0Ros9GgVzef9YGk+VDlowvPQhMpDECVb8CcrviXAN6TXOQ2mCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956898; c=relaxed/simple; bh=K5fwrSZGylYLMkwZcrKxbHEp98473OuIN+NXFnfcf78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YSVPzy7jMP+E8HsZmurdjEk12tennTqNWchpteWDocjpQl552R6JI8P0Lo1cTGzHmz/b0irxt8XQ/NUvxaJXU3RTuUHyvml4NzjOtcrAlKNaI5TwpQenJAudXAPOT++P1LXa0Nl7gAXpXEZY0hfhvmbpHneNjje1IUD8DPs5Tw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3dL9xx83; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XW5J2av3; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3dL9xx83"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XW5J2av3" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6+nnq705hVbcWfH7CMo1OsAqE06nWmeNhrUGcdPYvZ0=; b=3dL9xx83LoLxPsSSF2ZFqpn9/I9oKshldv9OPzLapstE+Kg2Zvikh6vVag+GbLnYD09rOO DhVrqIXwJGpKNM4DCTz54WkbdWVtLXgugUt/uDhHhvj1d3kncLHN/Cp39aMV+TTaT2SHsO ZRL5hmBc+nLaY3k96nL3Ug0TRRDIQ3fJhspA7kLqkqlgMyghf/jdTjc45lIu6gRmoFfocm 7iE4AT0Qw9ticb9vrHaYB/FtVrma8/YcGO4eScWKnmVWwe+eQdEdCxt/Ee+0DBJYnSxeu1 +78NIME/p/CgxHkWGUHzS5H2A1Lu7L8lN/O3Fwa/qE51xHJmK6MtKkrk5tL4ew== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6+nnq705hVbcWfH7CMo1OsAqE06nWmeNhrUGcdPYvZ0=; b=XW5J2av38v75MKkIRcXCU315RfojxVCez+4cucATq26JSAlVJLSq5evVhSdASYz/JVwTux Ix+Td+K+BZwZDiCQ== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 10/13] verification/rvgen: Switch __get_event_variables() to Lark Date: Thu, 28 May 2026 10:27:58 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch __get_event_variables() to use the parsed results from Lark, instead of raw text processing. Signed-off-by: Nam Cao --- v2: fix signature of __extract_env_var() --- tools/verification/rvgen/rvgen/automata.py | 78 ++++++---------------- 1 file changed, 19 insertions(+), 59 deletions(-) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index b86275e7bf28..2e26bb863245 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -591,45 +591,22 @@ class Automata: def __get_event_variables(self) -> tuple[list[str], list[str]]: events: list[str] =3D [] envs: list[str] =3D [] - # here we are at the begin of transitions, take a note, we will re= turn later. - cursor =3D self.__get_cursor_begin_events() =20 - for line in map(str.lstrip, islice(self.__dot_lines, cursor, None)= ): - if not line.startswith('"'): - break + for transition in self.transitions: + events.append(transition.event) =20 - # transitions have the format: - # "all_fired" -> "both_fired" [ label =3D "disable_irq" ]; - # ------------ event is here ------------^^^^^ - split_line =3D line.split() - if len(split_line) > 1 and split_line[1] =3D=3D "->": - event =3D "".join(split_line[split_line.index("label") + 2= :-1]).replace('"', '') - - # when a transition has more than one label, they are like= this - # "local_irq_enable\nhw_local_irq_enable_n" - # so split them. - - for i in event.split("\\n"): - # if the event contains a constraint (hybrid automata), - # it will be separated by a ";": - # "sched_switch;x<1000;reset(x)" - ev, *constr =3D i.split(";") - if constr: - if len(constr) > 2: - raise AutomataError("Only 1 constraint and 1 r= eset are supported") - envs +=3D self.__extract_env_var(constr) - events.append(ev) - else: - # state labels have the format: - # "enable_fired" [label =3D "enable_fired\ncondition"]; - # ----- label is here -----^^^^^ - # label and node name must be the same, condition is optio= nal - state =3D line.split("label")[1].split('"')[1] - _, *constr =3D state.split("\\n") - if constr: - if len(constr) > 1: - raise AutomataError("Only 1 constraint is supporte= d in the state") - envs +=3D self.__extract_env_var([constr[0].replace(" = ", "")]) + if transition.reset: + envs.append(transition.reset.env) + self.env_stored.add(transition.reset.env) + if transition.rule: + for c, _ in transition.rule.rules: + envs.append(c.env) + self.__extract_env_var(c) + + for state in self._states: + if state.inv: + envs.append(state.inv.env) + self.__extract_env_var(state.inv) =20 return sorted(set(events)), sorted(set(envs)) =20 @@ -653,28 +630,11 @@ class Automata: seps.append(None) return zip(exprs, seps) =20 - def __extract_env_var(self, constraint: list[str]) -> list[str]: - env =3D [] - for c, _ in self._split_constraint_expr(constraint): - rule =3D self.constraint_rule.search(c) - reset =3D self.constraint_reset.search(c) - if rule: - env.append(rule["env"]) - if rule.groupdict().get("unit"): - self.env_types[rule["env"]] =3D rule["unit"] - if rule["val"][0].isalpha(): - self.constraint_vars.add(rule["val"]) - # try to infer unit from constants or parameters - val_for_unit =3D rule["val"].lower().replace("()", "") - if val_for_unit.endswith("_ns"): - self.env_types[rule["env"]] =3D "ns" - if val_for_unit.endswith("_jiffies"): - self.env_types[rule["env"]] =3D "j" - if reset: - env.append(reset["env"]) - # environment variables that are reset need a storage - self.env_stored.add(reset["env"]) - return env + def __extract_env_var(self, constraint: ConstraintCondition): + if constraint.unit: + self.env_types[constraint.env] =3D constraint.unit + if constraint.val[0].isalpha(): + self.constraint_vars.add(constraint.val) =20 def __create_matrix(self) -> tuple[list[list[str]], dict[_ConstraintKe= y, list[str]]]: # transform the array into a dictionary --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17AE537998A; Thu, 28 May 2026 08:28:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956900; cv=none; b=rIhaPLsiKp6aFI+Q4sSL+RnmITb8RurMbp/UvVy95pcW0nGFf/EiDtV2Pw1zhmsVeO3fkzcLzlIb7kzB/yrFKrAvaw2YYOBBsXgAnR0MbHMxdeeUNNa8bXm40H2Z0qXuTpVER06gTeA2nNF1pDfMNh81zg0f+l8wCS9aTn9pAfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956900; c=relaxed/simple; bh=u23CMk6UrIinOqYIcko/uxEK5BIutUwrTVeMrKXVkts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZUcVrBrlmV0c34QnCs8ThOr/O0nsR0O+nbkxUThwHGaiNa5qeOHrVqe44FylyRc+DMuYxOCzpVEEmlYb/YhH4XsvMruwyDQTZD9sgIO/NiJLExyA+69a8RY198LbgObTfiWMFYYdgsdFFoHG7rkn+hK80JomMNmZ1dbPz6mMlHY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wel7kGMd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=AfBY8cn6; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wel7kGMd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="AfBY8cn6" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oePYxlVVdSb8m0OjKTmwP2HrlEOM8fNONeBXwllufP0=; b=wel7kGMdbm6G6JC4A30LfmcfIILrmwCXLRYXJl4Z3AHf4EbiNlUKDgts6cmvIPJosTX/Cp zblIFNA1c2azvldD35RmkM2yyYRs+glAKXsFgiy1U1Bi/FhkW02TQNgAZgTDVYe9mdARR0 SmM6DSvSYMGQBWUHYygc7AVmLSMbgCLzblgU5bKuKNXNQNDJCHS8GdGxE6wrhpZW4kZWgQ RQdLC3d2tQIrU4FMPCvNe8VoChjizVa9n2nypydSB8l7E3y/961JDdz5/NzO/4rbcJ2f4D rdElg6p0/GGUP78aJAE0H64aoI/Ndtonbu4NkmfAt3Xt6RXKq4x1DwGB8EA76A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oePYxlVVdSb8m0OjKTmwP2HrlEOM8fNONeBXwllufP0=; b=AfBY8cn6rZAcF5D6KN8spGLbNwLeIdUxGz5BwfihmA+rCslSRmjggJAP6VAW/7cWW3olp0 q46uF37YnQbfcXBQ== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 11/13] verification/rvgen: Switch __create_matrix() to Lark Date: Thu, 28 May 2026 10:27:59 +0200 Message-ID: <630700f7e821a9804da029f8a889477d293e5974.1779956342.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch __create_matrix() to use the transitions parsed by Lark to avoid all the raw text parsing. Also stop parsing constraints in __create_matrix(), that is not used anymore. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/automata.py | 47 ++++++---------------- tools/verification/rvgen/rvgen/dot2k.py | 2 +- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index 2e26bb863245..4c302f5cba68 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -418,7 +418,7 @@ class Automata: self.constraint_vars =3D set() self.self_loop_reset_events =3D set() self.events, self.envs =3D self.__get_event_variables() - self.function, self.constraints =3D self.__create_matrix() + self.function =3D self.__create_matrix() self.events_start, self.events_start_run =3D self.__store_init_eve= nts() self.env_stored =3D sorted(self.env_stored) self.constraint_vars =3D sorted(self.constraint_vars) @@ -636,10 +636,10 @@ class Automata: if constraint.val[0].isalpha(): self.constraint_vars.add(constraint.val) =20 - def __create_matrix(self) -> tuple[list[list[str]], dict[_ConstraintKe= y, list[str]]]: + def __create_matrix(self) -> list[list[str]]: # transform the array into a dictionary events =3D self.events - states =3D self.states + states =3D [s.name for s in self._states] events_dict =3D {} states_dict =3D {} nr_event =3D 0 @@ -654,39 +654,16 @@ class Automata: =20 # declare the matrix.... matrix =3D [[self.invalid_state_str for _ in range(nr_event)] for = _ in range(nr_state)] - constraints: dict[_ConstraintKey, list[str]] =3D {} =20 - # and we are back! Let's fill the matrix - cursor =3D self.__get_cursor_begin_events() - - for line in map(str.lstrip, - islice(self.__dot_lines, cursor, None)): - - if not line or line[0] !=3D '"': - break - - split_line =3D line.split() - - if len(split_line) > 2 and split_line[1] =3D=3D "->": - origin_state =3D split_line[0].replace('"', '').replace(',= ', '_') - dest_state =3D split_line[2].replace('"', '').replace(',',= '_') - possible_events =3D "".join(split_line[split_line.index("l= abel") + 2:-1]).replace('"', '') - for event in possible_events.split("\\n"): - event, *constr =3D event.split(";") - if constr: - key =3D _EventConstraintKey(states_dict[origin_sta= te], events_dict[event]) - constraints[key] =3D constr - # those events reset also on self loops - if origin_state =3D=3D dest_state and "reset" in "= ".join(constr): - self.self_loop_reset_events.add(event) - matrix[states_dict[origin_state]][events_dict[event]] = =3D dest_state - else: - state =3D line.split("label")[1].split('"')[1] - state, *constr =3D state.replace(" ", "").split("\\n") - if constr: - constraints[_StateConstraintKey(states_dict[state])] = =3D constr - - return matrix, constraints + for transition in self.transitions: + src, dst =3D transition.src, transition.dst + event =3D transition.event + if src =3D=3D dst and transition.reset: + # those events reset also on self loops + self.self_loop_reset_events.add(event) + matrix[states_dict[src]][events_dict[event]] =3D dst + + return matrix =20 def __store_init_events(self) -> tuple[list[bool], list[bool]]: events_start =3D [False] * len(self.events) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index cafa19b318da..8fa7494846a3 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -403,7 +403,7 @@ f"""static inline void ha_setup_invariants(struct ha_mo= nitor *ha_mon, =20 def __fill_constr_func(self) -> list[str]: buff =3D [] - if not self.constraints: + if not self.has_invariant and not self.has_guard: return [] =20 buff.append( --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17BD637B3F2; Thu, 28 May 2026 08:28:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956899; cv=none; b=fq8rBVHJLzUHNGoPr4w9LmVqyJTlrvVU6uEjpm5qkPpr3rjSeidY3Yu8XTvIl6c3Y5FZoK12HplZUku3nsNC1tRdMM9lJSmMsZMGSnYxEIPZsdvBJ1UsmEphq1SHogQn2luKOvoXsG6SLwrxSBT2wZS4IuxaGP7Tv1MASNXHbIg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956899; c=relaxed/simple; bh=WD8UkgpIzxOhbmnHWTXpgWqmukU6mPLth2IbYdVWEFI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=naV6LYXrwwyjN6em5dYK2PWatPEnikbRVL9pQav9HmqlWJlxoaKdpbwXcoWidEB2OhOFDCrl+vSmGCCA9nc9uf1qynRnFGfjjQwtOgqGNNmY6HFZZ0PWFjFb5puYno8OkJbeTd/n777xDQctKR/nF/JJx90RVGKIXSpfx62/lcg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jXmiqWDF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=byudeXV5; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jXmiqWDF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="byudeXV5" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eA33C1vCAngK2GdSJijc3hLWCxvkKQ+Ktjn/5o1BBa8=; b=jXmiqWDFAx5aXlo2CgMABkLd3k6vWGX8iINTzVSLkSHIqKu59odcrebt2VLns0ySu4sFSp jEuMSWkq451mYd5T8KEgiqF3+qeuMb4G/ntyor1l2p8CITTLUrNycVYgqDradi5a7nAYzm sufdnIgzGl68qM/fZhye8HOT+7jgP9x8TQoW4Q8Tp+6WgVUkYCzfTnREU3vfkC45woFFG9 6dSbsrz5nbk6upesnKM9iJPcuMch+/K5axb2RfPMY0PibR5i8CKFBe2NpLTz0R3t/QIAmj 0I89gJ6RZTg8hwqokf92kEGiBeHEDxd004E5Dy3+R6ChXuWDdMIRXTD936/4yQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eA33C1vCAngK2GdSJijc3hLWCxvkKQ+Ktjn/5o1BBa8=; b=byudeXV5qmvVqp42mXYDu7EAm3mSzDp/wSWLr37UuMmM2D4IvW50LiUTwh0ADp5QkqjF3a GLmMT5OhgTqEbGCg== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 12/13] verification/rvgen: Remove the old state variables Date: Thu, 28 May 2026 10:28:00 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The state variables (states, initial_state, final_states) only capture the states' names and have less information than their Lark-based counterparts. Switch to use the new state variables and delete these old ones. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/automata.py | 9 ++++----- tools/verification/rvgen/rvgen/dot2c.py | 10 +++++----- tools/verification/rvgen/rvgen/dot2k.py | 8 ++++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index 4c302f5cba68..a3be327c2a73 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -411,8 +411,7 @@ class Automata: self.__dot_lines =3D self.__open_dot() self.__parse_tree =3D ParseTree(file_path) self.transitions =3D self.__parse_transitions() - self._states, self._initial_state, self._final_states =3D self.__p= arse_states() - self.states, self.initial_state, self.final_states =3D self.__get_= state_variables() + self.states, self.initial_state, self.final_states =3D self.__pars= e_states() self.env_types =3D {} self.env_stored =3D set() self.constraint_vars =3D set() @@ -603,7 +602,7 @@ class Automata: envs.append(c.env) self.__extract_env_var(c) =20 - for state in self._states: + for state in self.states: if state.inv: envs.append(state.inv.env) self.__extract_env_var(state.inv) @@ -639,7 +638,7 @@ class Automata: def __create_matrix(self) -> list[list[str]]: # transform the array into a dictionary events =3D self.events - states =3D [s.name for s in self._states] + states =3D [s.name for s in self.states] events_dict =3D {} states_dict =3D {} nr_event =3D 0 @@ -675,7 +674,7 @@ class Automata: for j in range(len(self.states)): if self.function[j][i] !=3D self.invalid_state_str: curr_event_used +=3D 1 - if self.function[j][i] =3D=3D self.initial_state: + if self.function[j][i] =3D=3D self.initial_state.name: curr_event_will_init +=3D 1 if self.function[0][i] !=3D self.invalid_state_str: curr_event_from_init =3D True diff --git a/tools/verification/rvgen/rvgen/dot2c.py b/tools/verification/r= vgen/rvgen/dot2c.py index fc85ba1f649e..22938ce1bf6c 100644 --- a/tools/verification/rvgen/rvgen/dot2c.py +++ b/tools/verification/rvgen/rvgen/dot2c.py @@ -29,10 +29,10 @@ class Dot2c(Automata): =20 def __get_enum_states_content(self) -> list[str]: buff =3D [] - buff.append(f"\t{self.initial_state}{self.enum_suffix},") + buff.append(f"\t{self.initial_state.name}{self.enum_suffix},") for state in self.states: if state !=3D self.initial_state: - buff.append(f"\t{state}{self.enum_suffix},") + buff.append(f"\t{state.name}{self.enum_suffix},") buff.append(f"\tstate_max{self.enum_suffix},") =20 return buff @@ -142,7 +142,7 @@ class Dot2c(Automata): def format_aut_init_states_string(self) -> list[str]: buff =3D [] buff.append("\t.state_names =3D {") - buff.append(self.__get_string_vector_per_line_content(self.states)) + buff.append(self.__get_string_vector_per_line_content([s.name for = s in self.states])) buff.append("\t},") =20 return buff @@ -159,7 +159,7 @@ class Dot2c(Automata): return buff =20 def __get_max_strlen_of_states(self) -> int: - max_state_name =3D len(max(self.states, key=3Dlen)) + max_state_name =3D max((len(s.name) for s in self.states)) return max(max_state_name, len(self.invalid_state_str)) =20 def get_aut_init_function(self) -> str: @@ -199,7 +199,7 @@ class Dot2c(Automata): return buff =20 def get_aut_init_initial_state(self) -> str: - return self.initial_state + return self.initial_state.name =20 def format_aut_init_initial_state(self) -> list[str]: buff =3D [] diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index 8fa7494846a3..49cb3e724a93 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -179,7 +179,7 @@ class ha2k(dot2k): self.trace_h =3D self._read_template_file("trace_hybrid.h") self.has_invariant =3D False self.has_guard =3D False - for state in self._states: + for state in self.states: if state.inv: self.has_invariant =3D True for transition in self.transitions: @@ -314,7 +314,7 @@ f"""static inline bool ha_verify_invariants(struct ha_m= onitor *ha_mon, {{"""] =20 _else =3D "" - for state in self._states: + for state in self.states: if not state.inv: continue =20 @@ -382,7 +382,7 @@ f"""static inline void ha_setup_invariants(struct ha_mo= nitor *ha_mon, buff.append(f"\tif ({condition_str})\n\t\treturn;") =20 _else =3D "" - for state in self._states: + for state in self.states: inv =3D state.inv if not inv: continue @@ -391,7 +391,7 @@ f"""static inline void ha_setup_invariants(struct ha_mo= nitor *ha_mon, buff.append(f"\t\t{inv};") _else =3D "else " =20 - for state in self._states: + for state in self.states: inv =3D state.inv if not inv: continue --=20 2.47.3 From nobody Mon Jun 8 15:36:53 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C0F137BE93; Thu, 28 May 2026 08:28:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956900; cv=none; b=B8YMKJg5KCIwGomz4etL9nDZdx7PAVgapYG9b6FE9ePGa+TjTRInI4T6VpDxpcWa9SOgH9dcEYmNIgSIsp4Z7VmaEIhjMxsMinLJ9qctPfSlUuBMsObh5wxQkF4P+N1eDuzk2Oqn9TIkyeF3M08i2BYt3BOXQpKe3tCxTp4Xrrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956900; c=relaxed/simple; bh=YMnJ0bDTgxP05Ho/krWIEQlWaug9miNgKuxukAvKcbE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XmHjvZtdM7v86CUZVpufBAKefSC9Cf6a3hIjDpuo7eu+obN7FNokGmO9Aq6AzXAdjmdm4laCrhegS74jr99ag1EoFMqnhsznUya306O4tclUWShH+9o8WSpBUvCvrvFEUtRc5t0azbxVtLYWg0rl7dlP46T/v5489NZajH5QW5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rqW8+Kv2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qYcUv2VN; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rqW8+Kv2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qYcUv2VN" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779956895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KXs11Cl8SMxhlkwqsr5BWeZFDF6ettb7K0b3+Y32PCA=; b=rqW8+Kv2QpKNWh/U3JJ7eq6pATMbugLxewgXnttTsr38IVvewTnwwy6QxOUvQSyH7o8Z1c THsiqM7Lh6suGKz+RI3/pHhERfvSf4nYUnL/ZX/z0uOyCBMsJ3ldz5pXssCw291WgAdu8s /yree8XcM5VZkvuZbBJ3rlMMi0AZGTd8+kTc2u2mkZ+50hqKABvA6PSsSXBtG0GZVHnMV9 1P8plhv4TYY088bD4vwKP+b/4FzlxtYZrK/UyX3+SHaiqszwIETgEOLuvzROeaH4wKmQIL D3SBUt+qw0aQIKPfBZs+omIV0vCdbdvMs1SQjq5pm71SlTIx7OAU0D69GESePA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779956895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KXs11Cl8SMxhlkwqsr5BWeZFDF6ettb7K0b3+Y32PCA=; b=qYcUv2VNoGSd0BMLzYz+0HTMaRZ60ii53d/WsrTuoWqg5H/np+WKwWbrY4szqMmPMtWDXx zNXZ0EvoxZwyoXAg== To: Gabriele Monaco , Wander Lairson Costa , Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 13/13] verification/rvgen: Remove dead code Date: Thu, 28 May 2026 10:28:01 +0200 Message-ID: <9120d2a5987b79b646dde4001381581b703c0dd7.1779956342.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The conversion to use Lark left some dead code behind. Remove them. Signed-off-by: Nam Cao Reviewed-by: Gabriele Monaco --- tools/verification/rvgen/rvgen/automata.py | 154 --------------------- tools/verification/rvgen/rvgen/dot2k.py | 28 +--- 2 files changed, 1 insertion(+), 181 deletions(-) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index a3be327c2a73..b6ff5fceb820 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -356,19 +356,6 @@ class State: self.name =3D name self.inv =3D inv =20 -class _ConstraintKey: - """Base class for constraint keys.""" - -class _StateConstraintKey(_ConstraintKey, int): - """Key for a state constraint. Under the hood just state_id.""" - def __new__(cls, state_id: int): - return super().__new__(cls, state_id) - -class _EventConstraintKey(_ConstraintKey, tuple): - """Key for an event constraint. Under the hood just tuple(state_id,eve= nt_id).""" - def __new__(cls, state_id: int, event_id: int): - return super().__new__(cls, (state_id, event_id)) - class AutomataError(Exception): """Exception raised for errors in automata parsing and validation. =20 @@ -387,28 +374,10 @@ class Automata: =20 invalid_state_str =3D "INVALID_STATE" init_marker =3D "__init_" - node_marker =3D "{node" - # val can be numerical, uppercase (constant or macro), lowercase (para= meter or function) - # only numerical values should have units - constraint_rule =3D re.compile(r""" - ^ - (?P[a-zA-Z_][a-zA-Z0-9_]+) # C-like identifier for the env v= ar - (?P[!<=3D>]{1,2}) # operator - (?P - [0-9]+ | # numerical value - [A-Z_]+\(\) | # macro - [A-Z_]+ | # constant - [a-z_]+\(\) | # function - [a-z_]+ # parameter - ) - (?P[a-z]{1,2})? # optional unit for numerical val= ues - """, re.VERBOSE) - constraint_reset =3D re.compile(r"^reset\((?P[a-zA-Z_][a-zA-Z0-9_= ]+)\)") =20 def __init__(self, file_path, model_name=3DNone): self.__dot_path =3D file_path self.name =3D model_name or self.__get_model_name() - self.__dot_lines =3D self.__open_dot() self.__parse_tree =3D ParseTree(file_path) self.transitions =3D self.__parse_transitions() self.states, self.initial_state, self.final_states =3D self.__pars= e_states() @@ -435,57 +404,6 @@ class Automata: =20 return model_name =20 - def __open_dot(self) -> list[str]: - dot_lines =3D [] - try: - with open(self.__dot_path) as dot_file: - dot_lines =3D dot_file.readlines() - except OSError as exc: - raise AutomataError(exc.strerror) from exc - - if not dot_lines: - raise AutomataError(f"{self.__dot_path} is empty") - - # checking the first line: - line =3D dot_lines[0].split() - - if len(line) < 2 or line[0] !=3D "digraph" or line[1] !=3D "state_= automaton": - raise AutomataError(f"Not a valid .dot format: {self.__dot_pat= h}") - - return dot_lines - - def __get_cursor_begin_states(self) -> int: - for cursor, line in enumerate(self.__dot_lines): - split_line =3D line.split() - - if len(split_line) and split_line[0] =3D=3D self.node_marker: - return cursor - - raise AutomataError("Could not find a beginning state") - - def __get_cursor_begin_events(self) -> int: - state =3D 0 - cursor =3D 0 # make pyright happy - - for cursor, line in enumerate(self.__dot_lines): - line =3D line.split() - if not line: - continue - - if state =3D=3D 0: - if line[0] =3D=3D self.node_marker: - state =3D 1 - elif line[0] !=3D self.node_marker: - break - else: - raise AutomataError("Could not find beginning event") - - cursor +=3D 1 # skip initial state transition - if cursor =3D=3D len(self.__dot_lines): - raise AutomataError("Dot file ended after event beginning") - - return cursor - def __parse_transitions(self): transitions =3D [] =20 @@ -542,51 +460,6 @@ class Automata: states.insert(0, initial_state) return states, initial_state, final_states =20 - def __get_state_variables(self) -> tuple[list[str], str, list[str]]: - # wait for node declaration - states =3D [] - final_states =3D [] - initial_state =3D "" - - has_final_states =3D False - cursor =3D self.__get_cursor_begin_states() - - # process nodes - for line in islice(self.__dot_lines, cursor, None): - split_line =3D line.split() - if not split_line or split_line[0] !=3D self.node_marker: - break - - raw_state =3D split_line[-1] - - # "enabled_fired"}; -> enabled_fired - state =3D raw_state.replace('"', '').replace('};', '').replace= (',', '_') - if state.startswith(self.init_marker): - initial_state =3D state[len(self.init_marker):] - else: - states.append(state) - if "doublecircle" in line: - final_states.append(state) - has_final_states =3D True - - if "ellipse" in line: - final_states.append(state) - has_final_states =3D True - - if not initial_state: - raise AutomataError("The automaton doesn't have an initial sta= te") - - states =3D sorted(set(states)) - states.remove(initial_state) - - # Insert the initial state at the beginning of the states - states.insert(0, initial_state) - - if not has_final_states: - final_states.append(initial_state) - - return states, initial_state, final_states - def __get_event_variables(self) -> tuple[list[str], list[str]]: events: list[str] =3D [] envs: list[str] =3D [] @@ -609,26 +482,6 @@ class Automata: =20 return sorted(set(events)), sorted(set(envs)) =20 - def _split_constraint_expr(self, constr: list[str]) -> Iterator[tuple[= str, - = str | None]]: - """ - Get a list of strings of the type constr1 && constr2 and returns a= list of - constraints and separators: [[constr1,"&&"],[constr2,None]] - """ - exprs =3D [] - seps =3D [] - for c in constr: - while "&&" in c or "||" in c: - a =3D c.find("&&") - o =3D c.find("||") - pos =3D a if o < 0 or 0 < a < o else o - exprs.append(c[:pos].replace(" ", "")) - seps.append(c[pos:pos + 2].replace(" ", "")) - c =3D c[pos + 2:].replace(" ", "") - exprs.append(c) - seps.append(None) - return zip(exprs, seps) - def __extract_env_var(self, constraint: ConstraintCondition): if constraint.unit: self.env_types[constraint.env] =3D constraint.unit @@ -697,10 +550,3 @@ class Automata: =20 def is_hybrid_automata(self) -> bool: return bool(self.envs) - - def is_event_constraint(self, key: _ConstraintKey) -> bool: - """ - Given the key in self.constraints return true if it is an event - constraint, false if it is a state constraint - """ - return isinstance(key, _EventConstraintKey) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index 49cb3e724a93..d6779ac6b7dd 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -11,9 +11,7 @@ from collections import deque from .dot2c import Dot2c from .generator import Monitor -from .automata import _EventConstraintKey, _StateConstraintKey, AutomataEr= ror -from .automata import ConstraintRule, ConstraintCondition - +from .automata import ConstraintRule, ConstraintCondition, AutomataError =20 class dot2k(Monitor, Dot2c): template_dir =3D "dot2k" @@ -217,9 +215,6 @@ class ha2k(dot2k): value *=3D 10**9 return str(value) + "ull" =20 - def __parse_single_constraint(self, rule: dict, value: str) -> str: - return f"ha_get_env(ha_mon, {rule["env"]}{self.enum_suffix}, time_= ns) {rule["op"]} {value}" - def __parse_guard_rule(self, rule) -> list[str]: buff =3D [] for c, sep in rule.rules: @@ -233,12 +228,6 @@ class ha2k(dot2k): buff.append(cond) return buff =20 - def __get_constraint_env(self, constr: str) -> str: - """Extract the second argument from an ha_ function""" - env =3D constr.split("(")[1].split()[1].rstrip(")").rstrip(",") - assert env.rstrip(f"_{self.name}") in self.envs - return env - def __start_to_invariant_check(self, inv: ConstraintCondition) -> str: # by default assume the timer has ns expiration clock_type =3D "ns" @@ -249,21 +238,6 @@ class ha2k(dot2k): =20 return f"return ha_check_invariant_{clock_type}(ha_mon, {inv.env}_= {self.name}, time_ns, {value})" =20 - def __start_to_conv(self, constr: str) -> str: - """ - Undo the storage conversion done by ha_start_timer_ - """ - return "ha_inv_to_guard" + constr[constr.find("("):] - - def __parse_timer_constraint(self, rule: dict, value: str) -> str: - # by default assume the timer has ns expiration - clock_type =3D "ns" - if self.env_types.get(rule["env"]) =3D=3D "j": - clock_type =3D "jiffy" - - return (f"ha_start_timer_{clock_type}(ha_mon, {rule["env"]}{self.e= num_suffix}," - f" {value}, time_ns)") - def __parse_invariant(self, inv): # by default assume the timer has ns expiration clock_type =3D "ns" --=20 2.47.3