From nobody Sat Jun 20 07:01:35 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 A07163321D4; Fri, 19 Jun 2026 05:52:32 +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=1781848357; cv=none; b=ECzBpy4nrKp/mvE+MADXZc1gLUUQSwJRL1ssarBmxxrDQvEhC9I1cpp7Q6cZg8Osz0H/BqRFN49wnA6zZDiujYhwfc9+RV/uf0FXdtjkpQv9vuFVjlDRtEV7NmNeWvNl5+3pLim9WB6K+X+RK2mDzgQ7r9IblY9uRhT6aAmC9sA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848357; c=relaxed/simple; bh=I0RFHaJ0uyVjD8Y4yb61W3Sq9/JxOY6uGz6HtaofIoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EqpOYcqsbapuqzaaopkTq86ecmVBR5DZNoRE1qAGfu2rCLzz0kLO2V7tdmpyyrhK5pVoS7RUKPHYXV1QVrYUr2WyWZS48EymhQaVgKiS0W0sycTZklrG2mXZ6SKZSoaMEMo8EyxdWTQruvLwlgF7r24PkzSd5ad/V6mPsmW6Z+0= 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=Oe/BnC1c; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VK70XB26; 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="Oe/BnC1c"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VK70XB26" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848351; 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=CmzKqFGh0o8uVtWZjNM4SQj84FV9pp6B5uCmDnjQf6k=; b=Oe/BnC1cnHPNqy5jxLmsrndldy0/3nGj0hqyi/wZF4GzG9Ypd/W/RP7TTDqL328Hg9imFZ QPYJI7WnMVCNkRTBww8ASFwC2w29GvnWBXB33+xsOzFiyY/IH5TdQF0l/Pn0G3BCUDe7qT TyQalCf/H7GNQl6haajVImFV3tik49fRnCawveuduwIGTeJGbZS/m6uBkpqSN2AwMn67lV 8s4j8sY9+OkHL2vXeuczJCRgk2FD6zXNAhNbHB6fTI0XcvSf+eyXuDXnRyhHwdHb4pQoB7 FyYNTOAIam0dwe9tEqHVGbfImHZEHvSYPsX+Gcb+e4mC1a8YacEMAeB+EZeWYw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848351; 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=CmzKqFGh0o8uVtWZjNM4SQj84FV9pp6B5uCmDnjQf6k=; b=VK70XB26iHzMlfzDUqoZCUlzAMHGM7pnM9vEWQfQ16caCVjI15OimYG6oEs55X3Niwyj51 PiYWK/tbVmyazWAg== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 01/13] verification/rvgen: Switch LTL parser to Lark Date: Fri, 19 Jun 2026 07:52:04 +0200 Message-ID: <73d149221d96090342c7de408d032573de9cb6c4.1781847583.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 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] Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- 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 Sat Jun 20 07:01:35 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 A07C0340410; Fri, 19 Jun 2026 05:52:32 +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=1781848354; cv=none; b=tRSmslNIxU6YCYqgOVGAHHiBlR1qRJfiSGQv9t8YAr9/1fK81k1mXRTt1a3xMLy6mob3+hF9EzLQRcQivzjfeBto0KEI1U68D/OTzCZDmx3YjqzUz8/z9xPA6yc4me+YIeKAG2SCO2D4VKQ+kCjxi+Zyq2oBxnPa+zPUMlKpLiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848354; c=relaxed/simple; bh=axik62hu9fRkZUmDyzJ4xqvLwHa8J79mHVN6BX3Pm/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uMFYSLpcQouvh8Tp0YVdofTAycv5lZS0l+pH06MHAipqVE3/o0elxOaBlM/dqk8gLrIMUGKTCGV2Ogvmvo+TqxJ4XU9x3ULac5WdQSSm34lXZaAUNk+LgVd7aRPNvzdjTTZ85ZpPyrZlQusUGFln/X9zp7CvsBQT9g0JnEdfe8s= 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=dDudhBZ8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dzWc3Dar; 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="dDudhBZ8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dzWc3Dar" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848351; 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=wxi1srjPJPML219bqJzQ0+WNJaQw3+gcjWnYqs0hQWs=; b=dDudhBZ83Wc570kS54T5sXuwpLpHlrHVpD8VDUlbrstJjV8EzuqitZrWJEMCstFrOHP8ln X8eysC/yKUY2pMJ4cSctRNKnhsGVdkJQ/POTXlcHUtgge2mFwWE9u/UNUx0AYN53SQOI8Z KicD+VBksHRi0B0Y75+QuTgGVA6RKRJWu0/QNJfSZlwtmEj4UXw5gYlrcHhizskrxHSXu1 Clt+IW0+Qam3dVRfHqiehZsBuu57B+xGbuGaZmCjnjI4bHL5Tdmk6q8TdYW93r1lbPxgPO rbki7nN/uWt29tCJLVvrWjE4z+mWHXk5vhRna7E9Liwjb+DbYbBCTV0OFbcikw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848351; 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=wxi1srjPJPML219bqJzQ0+WNJaQw3+gcjWnYqs0hQWs=; b=dzWc3Dars+FDA1J3WUi96jvcnrfnxisch3De2vyS6hvXC3SVLYqUnRpbJwYF8aAcJ7h0kK nS11j3Zwbi38UuCQ== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 02/13] verification/rvgen: Introduce a parse tree for automata using Lark Date: Fri, 19 Jun 2026 07:52:05 +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 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. Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- 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 Sat Jun 20 07:01:35 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 F1ACE3438BE; Fri, 19 Jun 2026 05:52:32 +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=1781848354; cv=none; b=uKA4jQGq2DgL5etAoTvumJvD0rRWDPIJ9hi4svKTVC21PtKABMTjS4ZcwxCfgU2cx0SwwqaPuZLQ2TDWnycyAiS1OxBs13mwuZVJkEizQ2UfxGTzWfoAT00L5em1gXiaZLIFYKsGBp4nThsiNwlDkL4UXm9VQ8D9Qr+B+DK3uOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848354; c=relaxed/simple; bh=AAlhp7VoVu7HHuVau79YY0BcBaJCVsw7Ja9nAbD4vD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I15wAJBMBjj8NazF+YnTeEbqaawp8DrqLizCjHKuIdBjH7iF04IjR+RZA9jM3+x/yzHiBTgRnYFv+Px47QmTJkb/w3ooQinQ0ciwztzlORNvUkKFfPdCGibwQHSOEhB5/MIsDzGgXtRZ/cVLzyWbKf/HEmoSUJL2U136nkYphOM= 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=WEPJQVVm; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jroGh7sG; 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="WEPJQVVm"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jroGh7sG" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848351; 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=zOnLPczkmXyHS1iO4LUuEcN0zaio+n4pD25q327+YVs=; b=WEPJQVVmVbz4HK6U7Vd+a+570q1rxgRAcwY5buneOgAAaq6wfQBM8NWX8KOLoM+b3+Xck9 eurTyW2zwE16xRSDdzerFDOb6aOkzqwkiXBXU6REoIu0CqulRKMRdPkbDeZXFrtQeoMKgq FuP4jWlCIV8EhUYnPnHz7xGkchTm2Nz41opz1DEOeoOmMhSQN/P9jYGELoc6IYEihWlvJN UGdFMdazZnV56EoX+PybJEweP1o8NxPOXKGwzKglCwng2Y7LZF+Gy9Hm+6QqAJ6XbkBFPx LUzxhgEqcqLQz/tBj6ojDhVFPWeKurELFROEoWkd3SeQ9awaq42sQDYlT17t5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848351; 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=zOnLPczkmXyHS1iO4LUuEcN0zaio+n4pD25q327+YVs=; b=jroGh7sG44/CpCpufJoeVR393HtYB9r6MaR+3vQTHOPSlMRrwB5pH+J2lYSzTgIPvOYZWg qZnk6iBv3MeqauAQ== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 03/13] verification/rvgen: Implement state and transition parser based on Lark Date: Fri, 19 Jun 2026 07:52:06 +0200 Message-ID: <3ef60fdb03154abb9d9718ea106484213e1a4598.1781847583.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), 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. Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- v4: add missing !=3D operator add missing 'j' as a time unit --- 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..ea7eabd4c173 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" | "<" | ">=3D" | ">" + + VAL: /[0-9]+/ + | /[A-Z_]+\(\)/ + | /[A-Z_]+/ + | /[a-z_]+\(\)/ + | /[a-z_]+/ + + UNIT: "ns" | "us" | "ms" | "s" | "j" + ''' + + 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 Sat Jun 20 07:01:35 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 5DDD9344021; Fri, 19 Jun 2026 05:52:33 +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=1781848354; cv=none; b=l9gjceMLDB2Ok9xPQzUA04YBmzlmskCXcYkIPjoqdaAiIT3Jwu0I2RQSj0yEG3Z97fB6SOUoi2E4zDI/uGoaJnyEatFxJ0siPpJKWz6MMjI5x0WNFwiqug+4u/7jJCaaEzUxgeWaehe3kMesgKkVKK2woy3kIqEOnXHqq7zk6kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848354; c=relaxed/simple; bh=aB5xrn3ePA/snS8ytKs5WkWGVJuxgMXu8R/xZ9iuvhY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z/lj5inQQ14e02cQ5QZEvgBXoftMoti0jeOR0BB5UPmAcND2mOFznAN84oGpoiwsd7tQBQgszsCExG2oNnfZbUBbKZ0U9SFGIX70Opt5qPY7L00+kzoiIx8rsvXP5Tu0pqQRumGO7Dowuz3h5UGHjrPD/nA409YqvJLABWDO94c= 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=0bsFhyer; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=u9Vpa7Bq; 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="0bsFhyer"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="u9Vpa7Bq" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848352; 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=jZopRQ2mNu7tziqyP4YAuiiiQOmUSlFWugPLx141Pso=; b=0bsFhyerXnuYa169/mP5D8XCHhHopoPJ+L3YwbV/v4394V/QBLfL2kvozXwk2gNH5+3G7n +7UqX5U3eNqOfUFHg5hjouO36eayvPdVrn4HjgbnQtQZltrWX6Shfkx1HEELQjCMj7cApB 02AWT0ZHmqaPz/CYh5W5AWjuieLXn/firmCHLWoyMs3iYMy6KDG8+14sI61QvgXL/fU+ZS ABT/ijH5qok4guu8xuZDdCYdNeEZDDlNI+Lff2ZI4EolIEegn1xhFXSKhpTDZDQqfk6z+g sbc81uyMfrYwIVNz4NlF4Oj1d8jddvSF3p200rCv48PgCUqyUtG0wsq+jd3YWg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848352; 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=jZopRQ2mNu7tziqyP4YAuiiiQOmUSlFWugPLx141Pso=; b=u9Vpa7Bqq9nyBndUCE4ZeHW2O9JyuwQI5BOFICOUNLKJFTTp31Y2TnUXByebUHw4IAiMMY zszIciC3d3XfsmBw== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 04/13] verification/rvgen: Convert __fill_verify_invariants_func() to Lark Date: Fri, 19 Jun 2026 07:52:07 +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. Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- 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 110cfd69e53a..0595bfcd232e 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 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.removesuffix(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.removesuffix(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 Sat Jun 20 07:01:35 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 87AFE348445; Fri, 19 Jun 2026 05:52:35 +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=1781848357; cv=none; b=j5oqNa1SksthvNsofK5Bo63MmB8X3TE7kxyiGH6P4bGixPKMXRTDT5jPpTIxRfv+L0cZj13RL5IKjvdx4SeyU8wUiFsQxzIMb7JVOmmmag4YEWvI2p5JE/AgTHb9p6aRkURHzXMlqqR78NGAHdkXB05AiYgA144K2ma3NsxNSw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848357; c=relaxed/simple; bh=BzdFvwO1OGfvgPqhIXiVI11xuvNS7lDC/RAO5tF8ad4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rEwrSH5CHouM2dGinzLhOd0A/EJfiFnXtvVVSzZL97lD+LRIBfH3+vfan8y7//s0gx8lG4DJIoYuThjoQqpTO2oUjk3GGsx33CLoEeBohLqdgmL3gjgFTyMDxdyC7Ll0N8r+A0RoqAAijlxp5KCff3e5eOSRYzUGVyawqZHOYNU= 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=wWOsRJcO; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IhSoYRgh; 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="wWOsRJcO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IhSoYRgh" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848352; 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=d9UCfs9PLSNkLNgiPRjXfqwxODwxnfunJjfemTNE/40=; b=wWOsRJcOoPG1M/T/6XDiUFJilCAiEjqk9y7rZ1JRNX7xr2ef2Q4yLdDFRXw9QX/fHI/gA8 SkBfDO20cRG/rWZ0eoSbZwFuS8zUaQp5rMwMAXsL70TKmPTsIL83cptVIsU4CF3GKXRVtS MzPV+ez42gJ9MQOy8r50dRoekcMs8WAgR2AzLWSIIc8MnPGXHu/JLu6PhU5KyVUzqruvwE uHgLuG0FfLRXKNj78PCyxA7OaLRzm/EihK7pTNGEGBXtlA2hK95TscUUIJBAB6ZxfvRGbj CVe8tjtYbv2GhXUGi+rDmx1jTXlIFrC7H9RyUKkKk4bXkBIElU0xdCE7LoQ5Qg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848352; 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=d9UCfs9PLSNkLNgiPRjXfqwxODwxnfunJjfemTNE/40=; b=IhSoYRghuQ5tZaGRAt6yDgoKl4viNpdtQr1D4KynBBTMJrnDIzC35TJGyYrzymOjh7cYbb oypx4fXFqQcHL9BA== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 05/13] verification/rvgen: Convert __fill_setup_invariants_func() to Lark Date: Fri, 19 Jun 2026 07:52:08 +0200 Message-ID: <1e6e95ae085b21155f9ba97359659fa231d1b803.1781847583.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. Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- v4: fix bug when the time value has a unit --- tools/verification/rvgen/rvgen/dot2k.py | 48 ++++++++++++++++++++----- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index 0595bfcd232e..93674505f07b 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -250,6 +250,30 @@ 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 + try: + val =3D int(inv.val) + except ValueError: + # it's a constant, a parameter or a function + 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 +487,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 +503,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 Sat Jun 20 07:01:35 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 87C14348866; Fri, 19 Jun 2026 05:52:35 +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=1781848357; cv=none; b=jdRwXuKm/bqKLq61BmRAeEjJfxptN6HsXKDHaBCz1taJt6BX+wzFUIJ8HmXMlpsURzYKjkXOrROeLI8wVHhbH9wbn51WD400+toZdDoD7yswD4vV+HX+wpYMndXqjCVAoMYsZfoJeYuUz7kyBySUC5SwPkLlM9Z2Jt3OSOmDVoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848357; c=relaxed/simple; bh=J/ofVX/ZZ405Eucvmh0fYA2epdgpVfWN8hByac00wNI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LHLtd+e27ex/x6kUzJeO8X7mT+gKtOgp2wPwx0N278pQ4U7em0UDpAZs1qf2NvxWentguVQePfiWgRTSyg/Uxvj9uGM2YbMPQQuAy8GYarmydYr0YUDr1n8adzjJvyrpG4g9M07K30sweB8mINkW2SuW0O0Mn3cc1YeD5H1KV3E= 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=mG2EHsFV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yi9EUH8T; 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="mG2EHsFV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yi9EUH8T" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848352; 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=Iiwh70JgxsikzDg1LiLIFrWCTDNoi+RW5hKt9uDqw2g=; b=mG2EHsFV3nPxD83Z6ZPV1P2wzPLFYaUPnHivncYax9go5RSw+qIT2zOmkNelsRKViFyqzi +Tc+dpOJ1axNdo/e9KQqWqSgqdQhWCqgVtiN8OpipLKFVV5W+KdQT9uk4g4Q8vOSFzC74y eRUZccnULUAsgQk7tkAK4QZBCQ5cb6j7WkqOVBiPJGr6c+sprHbI5iMQu6Xz55IU/u96em ydtBe7tolv8lTSy0q1olHgVcT6xeF3UR7eEpFpFm/rLKzG3fllVGvwcuG44YwFcQrIcUic nOwdC7e9K6x3+zL3KFoEEEBQELiKYhpjSD+aDIxOSPgUHpQXHAX+Ha0MHI9AfA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848352; 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=Iiwh70JgxsikzDg1LiLIFrWCTDNoi+RW5hKt9uDqw2g=; b=yi9EUH8T72mjpOaBkz0JBcLkphbKlg6Rzl7z54T8CAloy6BcYNgtamv+YcQx485xU9xqaG c5EpCnEX6F2xvrDg== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 06/13] verification/rvgen: Convert __fill_verify_guards_func() to Lark Date: Fri, 19 Jun 2026 07:52:09 +0200 Message-ID: <4f18c30b60d7c7138c0016cd6985d14a898b1eec.1781847583.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. Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- 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 93674505f07b..ced4e6288ff4 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(",") @@ -291,7 +304,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: @@ -410,7 +423,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( @@ -422,14 +436,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 Sat Jun 20 07:01:35 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 8799D347FEC; Fri, 19 Jun 2026 05:52:35 +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=1781848358; cv=none; b=WdOHQqkIc3Luq/W9dsLhFFFSDHTX3T75NQ0+kJC4Xhq6bbGPE03uig43peMKIumPHRI5V1s3jCF8KHZfsPDWMxi/1mYTBwIrAIb5TfSeKLJjPgfQdCwV8iE2C4/7NnhupRSzMV3pFDcOqi52iLOIYWrS/IwEpxGvmtowllLFxlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848358; c=relaxed/simple; bh=ZkGR3RFK4hvJYiauN/Qs1nA2eMQvTkSHTEv1AD32830=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=byogmdPhhx6dNx9PVS4PmCzXYf3WA5R3NTZSZ0pCGUQMWL7gr+MibkOlXmIt8HGAcqFEbgUOWuSBFZNsIq6mXzpMCUOEBeIARcC9kDmXmw+/QUZ32CNs2qeDwgF/epK9EqkJbg9wGQ6QVGtRRQJ1Z0VywstYfi0chqSky5NBtcQ= 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=vio1T60M; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=d95vGU4V; 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="vio1T60M"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="d95vGU4V" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848353; 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=TLuQdn53pO1VED59D4ZX48Gyw19o5NbS1MrwLW8+ThE=; b=vio1T60MJrCjBtnnLZSpc4eRN9yniTpOwi+6B3hVKJAsNNRw9UiDvBF28qW85wd7X3swMN cHuGAl9E/gULQhQgmnTgxLO2ZXbMjeDP9TwXNpIXXbm36H7XR60N3eddn9XLM5ncpT5/6R xeW8EtWayF1uBoPZRgkJP3vLtGh/+HHnfDhQO4pdHr112XyXXNEZpoZtGD4AvQMcKDpIEd RFy7DFl5ODrXeQH7jGApI7954RMywXXRgLVbioqCxtXiGe/FnnESNDCtg9wQ8yzbTYfL6D XW52zJDbqSWi8GwC/ITeyo8hRqCX/l7ymj1WqTgvZb8QLIfuHsEwsRSIQntx1Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848353; 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=TLuQdn53pO1VED59D4ZX48Gyw19o5NbS1MrwLW8+ThE=; b=d95vGU4VT7EOFAwQWvtNBk6fgPvgx2FRYAOxaQTEq0GhC9QUXZbpaCJTcKyz4Yncv0t9yF iBsIUiNuvsOo2pDw== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 07/13] rv: Simplify hybrid automata monitors's clock variables Date: Fri, 19 Jun 2026 07:52:10 +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. Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- include/rv/ha_monitor.h | 64 ++++++------------------ kernel/trace/rv/monitors/nomiss/nomiss.c | 18 +------ kernel/trace/rv/monitors/stall/stall.c | 2 +- 3 files changed, 19 insertions(+), 65 deletions(-) diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h index 28d3c74cabfc..9144b4c06f3f 100644 --- a/include/rv/ha_monitor.h +++ b/include/rv/ha_monitor.h @@ -327,19 +327,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 /* @@ -353,31 +342,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 /* @@ -391,32 +370,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 /* @@ -463,14 +431,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); @@ -516,7 +484,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; @@ -525,7 +493,7 @@ static inline void ha_start_timer_ns(struct ha_monitor = *ha_mon, enum envs env, 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 ha_start_timer_ns(ha_mon, ENV_MAX_STORED, jiffies_to_nsecs(expire - passed), time_ns); diff --git a/kernel/trace/rv/monitors/nomiss/nomiss.c b/kernel/trace/rv/mon= itors/nomiss/nomiss.c index 8ead8783c29f..515ece5ce0ca 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 3c38fb1a0159..b265578f845c 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 Sat Jun 20 07:01:35 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 87913347FCD; Fri, 19 Jun 2026 05:52:35 +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=1781848357; cv=none; b=UdtyCVcYqItkDDwuGewjlUAOENXdq1nn5kfa3XCnKS299x3qQSjP8Fqhw6tizk9UtwhgDlvy/tyXQURaYUO4jja0yVGyGTWrJqK7vHuIZ092EGz5fvJCBpmgG0fw+aXLvHZTcj0FcwgDtTaJ5l4XXieg098UQqUhN7BD7qLayU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848357; c=relaxed/simple; bh=FZMw88bA4IwMs2nyEyPD6+iWiax17PjXzoo4KlsepsE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I+opfcrWTW3mqn07oDye76xQkgtbz6PUg4HTp2sTxRUDDxTtJD4p9lwob3kEBW32A2vt0r10FWckqvo75HsIzY9CGrXX+EpwhPg3t1nwV/Wuv4kIaXBKxwJ23lkMx/fmu5W1Ucw6KppSTqtnAA593kg6HvQgdgj7FB+rY6RcrPk= 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=PSJWrQeq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=D+se1ht7; 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="PSJWrQeq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="D+se1ht7" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848353; 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=ZlW1G1bz7uDEmvbtIPPHEMHKc1AW/B9gdDKuCf4BZiw=; b=PSJWrQeqhWv3ISeYDtKabcAl1Mzwwb+CcJBXp76CF1ZsrahYOHRjB7sf20wZ7sDaYPNtHv yDUnZxx9625/cUMnLzGa6UsMeyCagzmkZmzbKygrUn7ImbSfK3lN6TGPJFqJDZFjhhdcgf mg7jmw3T+lOX5il6rG/2I7AGgPU4SMu0EZKMjfbflugRW7ttjHf4/JNOsmwsB9DasyKd8a lVCm0KTf5pI3ylOZed0cvziSZ0XVl9nwGumWSxWh4i6jogYeUdzmq/hKQqVwjCY33s5ztW E9rYhT+TJrEcW0XPs1vBF+AtkVBjGr5ju20VyTA5a540PeXM/OFCsGmk1Jt1NA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848353; 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=ZlW1G1bz7uDEmvbtIPPHEMHKc1AW/B9gdDKuCf4BZiw=; b=D+se1ht70Qm2bczJuDbQZpgnjUbZg5zE9eNmwf4mBGnGDHID5bz8E6yaLTJMP0meqZlz5b 8ml1beywf6mCE6Aw== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 08/13] verification/rvgen: Simplify the generation for clock variables Date: Fri, 19 Jun 2026 07:52:11 +0200 Message-ID: <0d2a8e4bf90a9ed959289ddd2190b1152e4bbadf.1781847583.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" 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. Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- 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 ced4e6288ff4..4ea1ecc55c80 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: """ @@ -387,40 +389,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 @@ -460,54 +428,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 [] @@ -558,16 +478,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 @@ -580,9 +493,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 Sat Jun 20 07:01:35 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 ABCBF344D8D; Fri, 19 Jun 2026 05:52:35 +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=1781848357; cv=none; b=TLpi5zNGcQHA8Tj8cGr23jHBfOMsZ6Lqh61T0bzCVqnjRVCkhK8S6Ltf5NK1LtoBCJjX6bid/JGSVxuf1bXenVQ5wjI8PSH4Ee8+rp7sLUfHbRn8gd2Jup4127gjYxLmc1c+qPpwIargzfBJTRIG7YF511PNzwGLCQHuSUANKRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848357; c=relaxed/simple; bh=IbNeFUEvkBSptwEM2OKLLVTBsarwSX3UHFk2pP+B1VE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pI0Ycm/RNbn6yGSYfiHGYNM/8GisfwDFWQetjpbT4Qi9loCtx3bgBnj3k++F1XO5NDk5VuGT54P4WAs2n/q4iECmrzjBD3zN7Y6cgzWWg6WAOm6mKnqYVmyuH9spCxJtoDySFC8e9K8MSKP+VD6y9vRlzYUN4lQP+7gL2qyKG3E= 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=LcDRsVYk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=TlfsHo+a; 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="LcDRsVYk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TlfsHo+a" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848353; 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=D6hVS8j2Jqn44Md6huLFXb0ylpLn5a4klhUJDXmasGg=; b=LcDRsVYkMqrUu+JFWk6HVe+Utj3zw9HJxhVpJR4Z6uzyGjX0LxaMvtyf/DKgWVkT6Wybxr Hh10iJcZL8bn4PbVQOh4ovLB18qYsTiCXByuGzBGspQpIaUvOIl+YZodjrErtbC5g6EYs8 hMsj8YxEuTsEYwtxl8ygpUop+YC7UPLhSdzCeaql/V527zQMd/oWbTG7UbKStpN7SZZTuv 24UVvrB/xwzYFL6L6nUJf8wai7DLtyDq93rnCGgA86+a3oqE1sAAlqtY6XzN5VYtfWXgtI YBeEz8pZDBhIAhUI4nwb6nvxgGRDXUW2IqSdMBfXXnvBn+M2NE5BOKJKoH//EQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848353; 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=D6hVS8j2Jqn44Md6huLFXb0ylpLn5a4klhUJDXmasGg=; b=TlfsHo+apwaCuBns1DwYlnYW+aWV0G+uqPyQvcIYkEy2n/kVGOzDMxN2kmebsPP0o4wBlI 8mY8pPD3XEZr9CAw== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 09/13] verification/rvgen: Delete __parse_constraint() Date: Fri, 19 Jun 2026 07:52:12 +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" 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 4ea1ecc55c80..f1f5fa297adb 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: @@ -308,64 +307,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 [] @@ -490,15 +431,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") @@ -575,7 +516,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 Sat Jun 20 07:01:35 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 BBBD3348C52; Fri, 19 Jun 2026 05:52:35 +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=1781848359; cv=none; b=MiFaAJ1h/AA+AiIBf7N87lMx0JHMYR5sgdf/FBeGQiv5UmqjTOtdlqOkV9HsYj9tACDuCE+xeAJcV74Lrt2Id6O6dsDKXLdJLTuvQUSzXK2fWHRIrZmKi93zbyE4xuUeFBbs8G4jX4kp1rbYY2Eeys3EP46ppnd01J65DyY8qlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848359; c=relaxed/simple; bh=AgKczjzZ5VQ6/xQl8nNSBgb+Gj52Wze360PMaJLHjKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LOZtxNE2wR5pHmLx+SCxFlKeUmGFOsj9OK+I3316kzZMPHIIOpY+AebinEiKNTtjZt81ybDe1Ttv1WL2/EpaOWJC4IJln4FuOqr6BYOXBivBnBCnIKjnPCCMrLmwO4knfMJW7H3x/B828U2JbDQ0hHrM0jOtUxVpVwjXiQQXcbk= 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=G2UW5mv/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6j9oyPl3; 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="G2UW5mv/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6j9oyPl3" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848354; 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=4nPoyRhySyrOxX+5k4qEqycTCSX/Wj3yuuYmXawbrG4=; b=G2UW5mv/Omsf/T+685dGaUvdQmjADn8lQaqtE36k6K5W5DsGJAGjCEujOmRCyGvHSDxB4e mGnufy5vpRlkUZBRxWGa/6RZ+9Zq6JX6EJcFXvmgr4v7kRo33U2cH4QShPPRRmq33uUrAx dg5ggQT5bz5chkAL4zj15/QiFeiPFZKLb+EAwklJoGzF2zlpBZ3KtL+0nU/vUCzbsN80sO fyc/w3MG0GQ1F+jHBdf4bzywc2qYlLrkAYTtgYygjCNdCiQk37aEpOFmZo0/sH8VCzHvwk uV77Ivc/esHBlYv+y/f+vojnviBYvclc8jPKpTNOuoDS2pRmEvEVVG7EWX2+JA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848354; 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=4nPoyRhySyrOxX+5k4qEqycTCSX/Wj3yuuYmXawbrG4=; b=6j9oyPl37iWCWqNw0AOtAukwZIJw8SruUyMWtDac5OwFjiXq98GguYFqStFjEdF30gUCVZ 04QmiK/Gco9lmQAQ== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 10/13] verification/rvgen: Switch __get_event_variables() to Lark Date: Fri, 19 Jun 2026 07:52:13 +0200 Message-ID: <03f6457b4fcaa64199ffe73edb2a9fc48e76a839.1781847583.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 __get_event_variables() to use the parsed results from Lark, instead of raw text processing. Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- 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 ea7eabd4c173..c34e916516ba 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 Sat Jun 20 07:01:35 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 3AAE43491D0; Fri, 19 Jun 2026 05:52:36 +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=1781848359; cv=none; b=LUteaX7+blVOeosIfmNeLKaRxIq3ZuR7+94p63FBLFISzUA4hG7rPZx/SuGcvUup9w8MGgnsTVY811qDMxRTwxH9hPETTefSOiKGK3HsXY6YgRkmzl/jFtUGexBerFTRZGnkVQC94Yk5vTd8DouF0iJXVeALMYuXIKuzlUbxWpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848359; c=relaxed/simple; bh=h3of0wxgzSDDJXreuefzvdltkUpy+vFJourPkJTUkFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XDXDnPgpiL9J2l1OkASrfSQBrykW934oV7qbm9f8g2DxPON3Np++GmqV8HvBz03Nijeh0OJqGSqh4AulpvKDaCXz9s1wUEXdkOIlrHZL+hwsVjHNoTAkocRxF3nValjKNWoD+CQjtHpE1/bG0OqUO5kaiIaEd72QqTJt06Xf70Q= 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=jwdy1sPk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7sNJRd22; 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="jwdy1sPk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7sNJRd22" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848354; 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=2re1CrwPeWA42+Pff8Mg41Ujjm+UUHmnktJ+QlHrnpU=; b=jwdy1sPkSerdrczW7/3Ozo82bIAaRsI4SGmMLyvIT255q+Sa1GYJmemV/0G0kExyOVHTad Um667qJFPGpDSTJKCEPJhNnoKd+v91lVy4DWHzdv17aczxL/bqB5FYuGOS+4XCsbxXAou9 ROlY6dCk/UtN1sExWCfP+r8iK3sNZchup9Xm9Izk0p0RLclMIWu1e3i4RdyNpKX53NrGQV HwdxtfIBB6seTIWh5u76nfH7jG0acgKNj6YnxysHALnx1Ut5m+oS/w7SAy04IZsUgUVEOk jsqE5pFterw4QzyrTUkhCduhdBXnSv64r7M/OaN6l3iFJL4vSbu+/MEeb3vtDQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848354; 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=2re1CrwPeWA42+Pff8Mg41Ujjm+UUHmnktJ+QlHrnpU=; b=7sNJRd22BffscXKG2U2+KXUdvQ9TPDgTqqJnalrMNW+ATJsqJRsZZ14+kKnyVGljYT22iL ljFk4ITU6SyHx8Cw== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 11/13] verification/rvgen: Switch __create_matrix() to Lark Date: Fri, 19 Jun 2026 07:52:14 +0200 Message-ID: <36e76b64049b7fef1cf5c2855fea310c0452ee38.1781847583.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. Reviewed-by: Gabriele Monaco 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 c34e916516ba..1726e82546a7 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 f1f5fa297adb..03141e9ef45d 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -407,7 +407,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 Sat Jun 20 07:01:35 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 921F2346A0D; Fri, 19 Jun 2026 05:52:36 +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=1781848358; cv=none; b=AW6nIgekj/YZxNRwnA7Ziw7OnetJHA3BsRgvHjeZH43GmCDoBx5Mn9KshQICqtKtanFRDTgp7Y68cBq3uta1GigardGoHzgQ1CrkV0Tvty2aFJEMMHYpUpnihIRY7Jrx4OavJIx15pkh4IeWCUPgsDy0rWOCnXBwWRoT6sbwrWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848358; c=relaxed/simple; bh=YlJyi9cXXjLRV0PmiriSyzWiXV169BqUijDO6lAAlwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PTyQG1b16S9NL4uGhusKEzqH/IGcZ5F7f6lSa4HB8Lgx+6OmzA82zIuqeytiuaIlJ30wcAgQbfd8k4QXATA4vE0X+fV+GkJjHa51uO8FGcx68je2+bH0IawTotnhwFS7i6GjxhTsf2PiCIyTczf5oHufSdDJGmu8tT4HuuVgJR8= 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=z175FU6v; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Bvz4yRPK; 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="z175FU6v"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Bvz4yRPK" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848355; 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=1Kb0HXTPx4bF29N9tO228/xomtGu38HCmAjNNKrPVHo=; b=z175FU6vmdoRLcKjcOmYYcfa/GiN2Km1hbMQasruGiUpEwrdiUG7lmMuhgvddofN2FgAS6 N4uiTBxKK46LHc7okHkUAKspRlnsAZJL035IpDQ8dZ58A8koVeeBPMyepbBLPG6QoXH2lX TgQXpxxUXuRVa1KK6isu3lTMwDz+sIA6R+77sCjiS2VQiJsMW/FhH6urlK30nL5iGZsMgf g5PHBBTpKCieumxToj31XaAnw4NJHkJjjPDh/+s4YtQwZ6elMjNRVDuBXNerS9baZVWPhc 6xx4flAAC1kdmFnXCPA25ZntPbgcgg/m03ouN/xc+v2aufaBIFfRdQjv6daR+A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848355; 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=1Kb0HXTPx4bF29N9tO228/xomtGu38HCmAjNNKrPVHo=; b=Bvz4yRPKlxjGBmh5iQFbBCPa0T3Ifu8l5lJ5tVmNGIexJKGfTdpHo1nrBnphadwUfMD3Jg 1O2/cr/rq6CqfNCA== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 12/13] verification/rvgen: Remove the old state variables Date: Fri, 19 Jun 2026 07:52:15 +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. Reviewed-by: Gabriele Monaco 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 1726e82546a7..2cb7443ea00f 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 03141e9ef45d..b93d0ccc9bdf 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: @@ -318,7 +318,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 @@ -386,7 +386,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 @@ -395,7 +395,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 Sat Jun 20 07:01:35 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 9305134E745; Fri, 19 Jun 2026 05:52:38 +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=1781848360; cv=none; b=dI6xV9aVxlBqhZujX48/znXC6Owf3dpEilQKynFR4sM/IiceFaOReo730H8coNsyrywq08L2XQnwGgBTkD8GAvGeOuJ87Q7wxpSb43Dijwi7Z6JrwnsLAwiLnvPrDaFbZXqduLBNDT6QVienHsZab/JnVQq3HKb2vbJEz/HzeDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781848360; c=relaxed/simple; bh=JvGJMQj0IJA0qZYVwYQv5WyhtrYwPw7iNLrHaOx3/DQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FhUUqMjRGDbfpm6WD1g4CAtVbDVNJczdGVvtX4T4C4QxpkUJCNC6IbfjXEIDKlhSWHQplXFr5dpr2wKxmsFwpsz0c7vPstxWMfTytAu4huUVs8lFWpCklpKhU10iaL/9BNMa9Zoi6fDlkPdIw2zsv/MpdwfMEtkJikIUBgrnlUM= 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=4Oxsaww9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4VXde350; 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="4Oxsaww9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4VXde350" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1781848355; 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=iXXdUwuDmJp+7XU1Vque+SSP9QlSkw02L0ySSS65kuM=; b=4Oxsaww98SZ1FBqLn7DaPNe+W7CfHkH1K+R+AI6BSpTyrfqihoZ7lQdPpBu6nJApbUJJzE 47Wb0FJcyWkKlNlB8AkWGahl3MlC2m02OaMd/9Dmo3LC3y8bRPpabAA04nTgGBq4u0Feg8 BAJ/Cn0G07ENcmZiMAGodWFcCackxKPq0HsSlsyDfFwme3WQNg6R5/yS6Dih25UCzRBiBE EMtKhzaSDBjE0ilWEQE+N8PR8JU5H4HFCY2B6hMZMMmqFDkTQG1Uv968WTpAosf3o0L2UH 96/0khtq33isBMBl5b8V5h6TOais98TNh94VJ2hz2gsg8Z83ic2LKgFhUO3BDg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1781848355; 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=iXXdUwuDmJp+7XU1Vque+SSP9QlSkw02L0ySSS65kuM=; b=4VXde350muwUwNfBcb/V+Y2X5v2lhxJlSDlD713NW8/V17utDSLXuwZkyGINxhjgzlojcr A0Ny8BXHXOBrsWCA== To: Steven Rostedt , Gabriele Monaco , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v4 13/13] verification/rvgen: Remove dead code Date: Fri, 19 Jun 2026 07:52:16 +0200 Message-ID: <98115605a49c819adae9329823d4010bf181c3b7.1781847583.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. Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/automata.py | 157 --------------------- tools/verification/rvgen/rvgen/dot2k.py | 29 +--- 2 files changed, 1 insertion(+), 185 deletions(-) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index 2cb7443ea00f..fd37ce304276 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -9,9 +9,6 @@ # Documentation/trace/rv/deterministic_automata.rst =20 import ntpath -import re -from typing import Iterator -from itertools import islice =20 import lark =20 @@ -356,19 +353,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 +371,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 +401,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 +457,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 +479,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 +547,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 b93d0ccc9bdf..4d39f229c970 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -8,12 +8,9 @@ # For further information, see: # Documentation/trace/rv/da_monitor_synthesis.rst =20 -from collections import deque from .dot2c import Dot2c from .generator import Monitor -from .automata import _EventConstraintKey, _StateConstraintKey, AutomataEr= ror -from .automata import ConstraintCondition - +from .automata import ConstraintCondition, AutomataError =20 class dot2k(Monitor, Dot2c): template_dir =3D "dot2k" @@ -217,9 +214,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 +227,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.removesuffix(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 +237,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