From nobody Sat Jun 13 23:58:02 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 C9C773CF043; Tue, 5 May 2026 06:59:46 +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=1777964388; cv=none; b=IhK1m+nFiBJ0NeCODCOJFCPBzv0iLG1N4SL2Buogm7zeG0aLFbUSLXYdNrbu97FXs9keG99ZjuHfbDwof8h+HI12aah5n52x3KTO4VTZS3eLzJ73gUBrqMzrLTjrS0NR5o135C3/RoieEmS0tBaYzfGzB/MxWSukMYhprlR3cYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964388; c=relaxed/simple; bh=0CO/exRlfnI8S9HBp0VIqoVF0E3lIQNP1iYjsI79OYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=etwfEXJF6ORXohQzZ228zqVR1Iq0E7qtHvWabdndKPhgBDGA5PAn0x7WRzBGnxYnlfKDXyeWfcTzAxUNzZKQW6fDA/6yGpbXQNzT3BgjeYDyV2kOpuydmsVjp2b0HfDfdelsvYWhX6LjCtfugEDTC/hOGT8YJoGnTtmxXjr6ycI= 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=amxSmtgl; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=F7tK2fNu; 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="amxSmtgl"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="F7tK2fNu" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964385; 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=zRg03oBC0tvBjzWX+19jO3Bw7cf7L48zSREJwFUyBvA=; b=amxSmtglXLCeOdiYXJnqK3NY1GW5ulppiMiSfiIsbrhb1pzRnJp8+eC7mSnlNxeF5IER8v S4rQ+RFevDPZ75dc+cmCRwWbGzpRKUXcjmq7pjUxVHNJCczqNnfYXCgA36gdgesk6WCEK2 aquPXu/gVsclPnjjGvoI6ZcWPuLLgQddCaUk/1fzkMUoXBsKQ+aF9e9KPvY4j9qCbiOvO4 iXeXhjV8DawTUJ6ZhITfL+v4aUgPdYS01hasFx2jdvxKNVgY83yrL8aOAk+8w6dQOgZUU0 hmbNaQItZIkPMUfoJuw8zNfBckYRNZy5/JM82oIMCN9Y8n7BDHlZ7KH/w/OHBQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964385; 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=zRg03oBC0tvBjzWX+19jO3Bw7cf7L48zSREJwFUyBvA=; b=F7tK2fNuNkuwc0skMhNGrWJVk7BR3/ieYWil9Qq/O8plyddWdgI3f7WgPRAORE/QIeiI1E sWW6/PEis1rVOLDA== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 01/13] verification/rvgen: Switch LTL parser to Lark Date: Tue, 5 May 2026 08:59:22 +0200 Message-ID: <85aaa8cacb31cfc78619a07aeae9a86d059a4cc1.1777962130.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] Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/ltl2ba.py | 189 +++++++++-------------- 1 file changed, 70 insertions(+), 119 deletions(-) diff --git a/tools/verification/rvgen/rvgen/ltl2ba.py b/tools/verification/= rvgen/rvgen/ltl2ba.py index 7f538598a868..b2dee2dbe257 100644 --- a/tools/verification/rvgen/rvgen/ltl2ba.py +++ b/tools/verification/rvgen/rvgen/ltl2ba.py @@ -7,8 +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 +import lark from .automata import AutomataError =20 # Grammar: @@ -30,42 +29,38 @@ 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_0-9]+/ +LITERAL: "true" | "false" + +COMMENT: "#" /.*/ "\n" +%ignore COMMENT + +%import common.WS +%ignore WS +''' =20 class GraphNode: uid =3D 0 @@ -432,90 +427,46 @@ 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[1]) + + 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(Variable(args)) + + 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) + spec =3D Transform().transform(spec) =20 rule =3D None subexpr =3D {} --=20 2.47.3 From nobody Sat Jun 13 23:58:02 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 454933CF04B; Tue, 5 May 2026 06:59:47 +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=1777964388; cv=none; b=u2ijjSnGuavvRLRqc3P0udbCRWaTnRqS7/cPhyce4I5whknYPGslYbpHm/ETBnA1/R8Twy9b24cMre5jDrGPkwn88uICbfNxIhmn0m5e2kGcJ/x/dEVn2pbGypWNGXl2035FPfc8GGLaSqkQGi0Mnx6zl67B3y6me+yDlmn/830= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964388; c=relaxed/simple; bh=lP9sxk9YPuvkgRzbWRJpboDYXmOeMR5BcyEnMBhjrOg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nfnXBThy6eXstAdb4Thak9Grwol1yPAnr2RSFFzbMx++EU/7snJEfmIN9Qg6Io5izLqZdei0Mm2/zkttWXU78IJ7J2nx4p1FkmXYKJ6uCk9ROeUDx1eiFG4ttD+Ltt7i6E0L0IgEASEK/KxexORS1A5oi7EmMDqm7UFnwyVHxBU= 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=I0tr5cZ+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UU3wQbPa; 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="I0tr5cZ+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UU3wQbPa" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964385; 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=oJJAZkBiWokQUmBmNlrbyoY7XTYvx0s9iC5UuVXFrjM=; b=I0tr5cZ+7AcbG3qGhK8K+D70fjj3Oh43uRSfqSWIRnaz3nTXSLp7OdthBM+RsQNbsOHJOI ICzw2KkQXdPnq8bD00sXU5bR+H8wYd+zDBFF0fPl4ZLMGZjv11STbZAQJghZOsH/tGaTDs xS5Eg7nJkVBb/Djj3nbuCta4cvlq9Qbl0ThLdOdCm4pETwWI9X3VMydA9ex3dQUP/b3op8 EWVaJnOmoBLGLpVxXeLkq0mvHXiv4WuDVmMkb3itkh8Sckeq22VzylnuYuCBClePxcc6z0 zK7GcJyarHJz/CoCVk7EeKTga2YnQTnGMC6US1ipUpbZlNkTAFsSHsTP2bZ6zw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964385; 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=oJJAZkBiWokQUmBmNlrbyoY7XTYvx0s9iC5UuVXFrjM=; b=UU3wQbParlEy9JgHsbphWuPnuJn+UvjOaifkUsjCG/xVUnVRjwc1USxxQEjrl6xRWIAQ3D oB8vIayePTeugIBw== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 02/13] verification/rvgen: Introduce a parse tree for automata using Lark Date: Tue, 5 May 2026 08:59:23 +0200 Message-ID: <050ac3d7aeb1ece12a4deb91fc173de24ad147de.1777962130.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The DOT parsing scripts directly parse the raw text and they are quite fragile. If the input dot files' formats are slightly changed (for instance, by breaking long some lines which is allowed by the DOT language defined by graphviz), the scripts would fail. To make the scripts robust, the parser should be implemented based on the dot language specification, not based on how the existing dot files look. As a first step, use Lark to implement a Parser based on the graphviz dot language specification. The resulting parse tree is not used yet, but the existing scripts will be converted one by one to use this new parse tree in the follow-up commits. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/automata.py | 182 +++++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index b9f8149f7118..4e3d719a0952 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -13,6 +13,187 @@ 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: /[_a-zA-Z][_a-zA-Z0-9]+/ + | /-?(\.[0-9]+|[0-9]+(\.[0-9]*))/ + | /".*?"/ + + %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 dot_file: + tree =3D parser.parse(dot_file.read()) + attributes_parser.visit(tree) + node_parser.visit(tree) + edge_parser.visit(tree) + except OSError as exc: + raise AutomataError(exc.strerror) from 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 +247,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 13 23:58:02 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 632B93A1A5D; Tue, 5 May 2026 06:59:47 +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=1777964388; cv=none; b=E73E/H+tkeleL4BBmbs3D7aqJ9/tNYVUWwOGo7ZguVH7jsvlFwPY3rhz4f9ZXQ883rwthI+nsxxl7z4jomp5VGBwFmZH1zV70EPQixUobAYyx9kGUgQDxPc1cyrGlpWj3FOdlF5FhwU7TxwBuhgNXXtoBUtBaD0cvOI1Epc2gDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964388; c=relaxed/simple; bh=3Tc1VtSpaal8vA7z553+yAq6dlaFSiy8yVIdLyfgsXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ThK0lHrffqJjcLmwm8hy/HKrG2yaxoKT96DPxDYanLOq5WE6BtliaNB3EprHSExw5W+fca1IWcndzx2W9cBH1D2PYG1mWK5P8IOepeA7ClivUFZxg/P05wQbQH9gHn6VdklEU98N0s2/HKfnQzuDVrdThUqYkrqrCO/mc+NDiy0= 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=Rkjqg7u2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cdUZFZeW; 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="Rkjqg7u2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cdUZFZeW" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964386; 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=wNM8CyygL7FGiRGRnj6bzhGY0NXr/eH5Oqh3Z3mRgv4=; b=Rkjqg7u2VNpkXkjPUT5d84DbioZE8x66otCUpOsE5ISjeqOy9xOprMZChRKoH8V7C5PkEz SIebUKVONXV0Y/pK2TWxJdkbZ/VqN7/5VWKeESo0utXnklPaT+rRxYtYyDMEhKcDaC9Wp1 7msEeuAtZQbaaRIQWutIPvLZ3I0mFbNlXzTUVoJ7hScLYZ3wAwC3cD09xU1AEGYtOb8ZqH 91mUFt2zIQHNrA981ztTKr6DVulq74apeJC5PJADVKc1WyLngfg62f7qxWXlvTP+jKoiks MkVeS4NCp4rEd37xk1xRBLb7tJqH1ot6MwCWGzSBORBcqC6Ry9jxh/GLPELkvQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964386; 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=wNM8CyygL7FGiRGRnj6bzhGY0NXr/eH5Oqh3Z3mRgv4=; b=cdUZFZeWBl9fI60HQ0DU7mpcOfUDqw0DOgUlO6llx9PC0o17pVvJX/XcoFcBoWfmPW3m4t N/nV0dbEUVnNopBg== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 03/13] verification/rvgen: Implement state and transition parser based on Lark Date: Tue, 5 May 2026 08:59:24 +0200 Message-ID: <361efb610ba7c06b3668a953a6847ea80453c2e3.1777962130.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. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/automata.py | 207 +++++++++++++++++++++ 1 file changed, 207 insertions(+) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index 4e3d719a0952..32c16736a41b 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -194,6 +194,155 @@ class ParseTree: self.node_attrs =3D attributes_parser.node_attrs self.edge_attrs =3D attributes_parser.edge_attrs =20 +class ConstraintCondition: + def __init__(self, env: str, op: str, val: str, unit=3DNone): + self.env =3D env + self.op =3D op + self.val =3D val + self.unit =3D unit + if unit is None: + # try to infer unit from constants or parameters + val_for_unit =3D val.lower().replace("()", "") + if val_for_unit.endswith("_ns"): + self.unit =3D "ns" + if val_for_unit.endswith("_jiffies"): + self.unit =3D "j" + +class ConstraintRule: + grammar =3D r''' + rule: condition (OP condition)* + + OP: "&&" | "||" + + condition: ENV CMP_OP VAL UNIT? + + ENV: CNAME + + CMP_OP: "=3D=3D" | "<=3D" | "<" | ">=3D" | ">" + + VAL: /[0-9]+/ + | /[A-Z_]+\(\)/ + | /[A-Z_]+/ + | /[a-z_]+\(\)/ + | /[a-z_]+/ + + UNIT: "ns" | "us" | "ms" | "s" + ''' + + def __init__(self, c: ConstraintCondition): + ''' + A list of pairs of + - the condition (e.g. is_constr_dl =3D=3D 1) + - the logical operator ("||" or "&&") combining this + condition with the next one if it exists, otherwise None + + TODO: Perhaps use an abstract syntax tree instead, because + this representation cannot capture precedence + ''' + self.rules =3D [[c, None]] + + def chain(self, op: str, c: ConstraintCondition): + self.rules[-1][1] =3D op + self.rules.append((c, None)) + +class ConstraintReset: + def __init__(self, env): + self.env =3D env + +class StateLabelParser: + grammar =3D r''' + label: CNAME ("\\n" condition)? + + %import common.CNAME + %import common.WS + %ignore WS + ''' + ConstraintRule.grammar + + def __init__(self, label: str): + parser =3D lark.Lark(self.grammar, parser=3D'lalr', start=3D"label= ") + tree =3D parser.parse(label) + + 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 13 23:58:02 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 A456C3C2779; Tue, 5 May 2026 06:59:47 +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=1777964388; cv=none; b=FEhxHEhXXwtLCiW+wliSk8inRa98UAaLVvGHw/YuPgheWeW9dTDg+Dpc50srrjsMYpI05Exa7arIhXzdImVKembaaNI+nxdtNzkJGvEzBqDyxaOIT8CjfQTrmL1RZaLH1KxkfBuW8jC8LFnjMcm+6Jm+b5igFVf+MFcVEdCzjAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964388; c=relaxed/simple; bh=vti/rte8oRMfSLDEsrf5xMN3UZt/x1fjzYRhpYKlvak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fro9SMpcAcQqFeVmhbncsRC89MNQc6CsNwQwzslKHsFyiWdGaCrYhMYmkoK6/DAzSePq1AyE2MX5GL+Wzzy2wPm/SXk0REl6wi1tdWJygO9MsLyn/AWYqFhUGdRhUP3UFdB6MmqdHFDAntIK3qyGVmxINM+coBvEKskICgdGj7w= 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=gE+kTv7v; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=selyBx19; 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="gE+kTv7v"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="selyBx19" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964386; 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=VQXgIzbWeGU99kkevGp/pxf/2mcoG9yivLWfxbs3U3g=; b=gE+kTv7vJ+dYDs6ReVxUlxZYA6BV4TkxntoR+WGiidMq6sgwa8L+bnweU0FUE8BC499qEi ScVjUwXuhblVlCkk8j3m2x/SscPQpN+GK3tVXuz2w9mervbgW0hKA7wgl+12vnS1rKIvGr fPj5ycNubJ/6SbX9hsQRT/soVNyiOyMTekjLr2R2kNhi4R7dJiuqfV6+djFtSusB3OjfM4 qkoDxNstRAltm62TuK6jFb3l4zp5W/LYowGSZny3X/BUD82FJFTqOhdQ+ZKSUWC22FGAed qgv7eces/Yot6hg19G60J2ekaYh6ovzhjY1b1dGq5RboAetkBBPnNe1d3SWFJg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964386; 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=VQXgIzbWeGU99kkevGp/pxf/2mcoG9yivLWfxbs3U3g=; b=selyBx19L14gfhqPmECuBjUl6AEKvEBNyx/v9HZRj1WAqXLZwui6Fsrr1KSmfsMhFg5LLE 62ngR36+iD2oh/BQ== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 04/13] verification/rvgen: Convert __fill_verify_invariants_func() to Lark Date: Tue, 5 May 2026 08:59:25 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert __fill_verify_invariants_func() to use the parsed states information from Lark, prepare to remove the old raw text parsing code. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/dot2k.py | 32 ++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index e6f476b903b0..3e7040398a20 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -12,6 +12,7 @@ from collections import deque from .dot2c import Dot2c from .generator import Monitor from .automata import _EventConstraintKey, _StateConstraintKey, AutomataEr= ror +from .automata import ConstraintRule =20 =20 class dot2k(Monitor, Dot2c): @@ -177,6 +178,14 @@ class ha2k(dot2k): raise AutomataError("Detected deterministic automaton, use the= 'da' class") self.trace_h =3D self._read_template_file("trace_hybrid.h") self.__parse_constraints() + self.has_invariant =3D False + self.has_guard =3D False + for state in self._states: + if state.inv: + self.has_invariant =3D True + for transition in self.transitions: + if transition.rule or transition.reset: + self.has_guard =3D True =20 def fill_monitor_class_type(self) -> str: if self._is_id_monitor(): @@ -218,14 +227,13 @@ class ha2k(dot2k): assert env.rstrip(f"_{self.name}") in self.envs return env =20 - def __start_to_invariant_check(self, constr: str) -> str: + def __start_to_invariant_check(self, inv: ConstraintRule) -> str: # by default assume the timer has ns expiration - env =3D self.__get_constraint_env(constr) clock_type =3D "ns" - if self.env_types.get(env.rstrip(f"_{self.name}")) =3D=3D "j": + if inv.unit =3D=3D "j": clock_type =3D "jiffy" =20 - return f"return ha_check_invariant_{clock_type}(ha_mon, {env}, tim= e_ns)" + return f"return ha_check_invariant_{clock_type}(ha_mon, {inv.env}_= {self.name}, time_ns)" =20 def __start_to_conv(self, constr: str) -> str: """ @@ -320,20 +328,22 @@ class ha2k(dot2k): self.invariants[key] =3D rules[0] =20 def __fill_verify_invariants_func(self) -> list[str]: - buff =3D [] - if not self.invariants: + if not self.has_invariant: return [] =20 - buff.append( + buff =3D [ f"""static inline bool ha_verify_invariants(struct ha_monitor *ha_mon, \t\t\t\t\tenum {self.enum_states_def} curr_state, enum {self.enum_events_d= ef} event, \t\t\t\t\tenum {self.enum_states_def} next_state, u64 time_ns) -{{""") +{{"""] =20 _else =3D "" - for state, constr in sorted(self.invariants.items()): - check_str =3D self.__start_to_invariant_check(constr) - buff.append(f"\t{_else}if (curr_state =3D=3D {self.states[stat= e]}{self.enum_suffix})") + for state in self._states: + if not state.inv: + continue + + check_str =3D self.__start_to_invariant_check(state.inv) + buff.append(f"\t{_else}if (curr_state =3D=3D {state.name}{self= .enum_suffix})") buff.append(f"\t\t{check_str};") _else =3D "else " =20 --=20 2.47.3 From nobody Sat Jun 13 23:58:02 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 6502F3D170D; Tue, 5 May 2026 06:59:49 +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=1777964390; cv=none; b=FOYvfhZk8yAUXKNxK6hTHLfCsiDn1vPYa7NNPmg74TnseD3sRyjv4HzwhmFQjnPDu5qxxVlqPODbVDbYy8QXYIW4HSAl5dOTabFxPGHrzLWMkZZZD7ODy1GyAz1/5stnPlGb+CED0xx5EScIoPpwmCj7w9G/4GTP/ivhgcGC6bE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964390; c=relaxed/simple; bh=yOsBs3DkFMX0BsQrDiKY/RvPC/v+5k81reOajeGRoQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JYB15u5TRNU4pCbgvl4G7Z5YeQpf6XsBtrW1XlV14IIfiHZ7cLNeUJnlZIVD0DVk8oDpCa8oliKTpPfyvUVt31/s7trfGDX+maYA5qpbwlXq/LQ+W0QVW0t1iPDkij/8AupO1cFhMG/0V2p/vjDnE9R0eo+wlWHrIuCpEc9E53Y= 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=WUMtRlCo; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6JIgCZ4P; 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="WUMtRlCo"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6JIgCZ4P" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964386; 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=kag4q2URgPnqH3+6ewLWSFKjs+1QeBtay0Ac+Xb81Rw=; b=WUMtRlCouiV6WQdyv4ih4PSbaad2RLtZYAo1hDmA8SsUWbM1i30MDdeUTG+3OoCpTrcrVu 1lOm1VD5VXm/xrjWfqCcPSxDJ/tZ0+UqMNS7yi+peAbeuacTfZJnU17WdIwGbNaZgXr11+ V1S1RczD2RWtzqw60uXK8+aBPNWg7E8ONUGtMstFTyX+D9zbkTgU7HROjAgTCFyDTLFIg1 fPW2l6JX1icRKguscHuo8L3u2h6X8F+tTbdhqXUOikKcOhMNb4IEF/4iiBqkKJPCck1wlo BUXC7MPRmNj7ZgELZEsmkO7AE2wq7tlCd39RU7wnY6CSQRrxyP5x6Pm9OlIMVA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964386; 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=kag4q2URgPnqH3+6ewLWSFKjs+1QeBtay0Ac+Xb81Rw=; b=6JIgCZ4PVvmuw6tsdTIhDwhjAI6nHYJwV5/SYHtHgv+DqyARp05IvN9ypaZcuAqZ/9HIlS UTA8qOYClP0WFQAg== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 05/13] verification/rvgen: Convert __fill_setup_invariants_func() to Lark Date: Tue, 5 May 2026 08:59:26 +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" Prepare for self.invariants and __parse_constraints() to be removed. convert __fill_setup_invariants_func() to use the new parsed states from Lark. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/dot2k.py | 36 ++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index 3e7040398a20..3a39ae29e41e 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -250,6 +250,18 @@ class ha2k(dot2k): return (f"ha_start_timer_{clock_type}(ha_mon, {rule["env"]}{self.e= num_suffix}," f" {value}, time_ns)") =20 + def __parse_invariant(self, inv): + # by default assume the timer has ns expiration + clock_type =3D "ns" + if inv.unit =3D=3D "j": + clock_type =3D "jiffy" + + env =3D inv.env + self.enum_suffix + val =3D inv.val.replace("()", "(ha_mon)") + + 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 +475,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 +491,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 13 23:58:02 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 650B63D170E; Tue, 5 May 2026 06:59:49 +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=1777964390; cv=none; b=jjpb3pRKv0UDFM8uW5xG2xeGECdCKCuCMNxYJRksjWV1OtImjbdQOf1BP4bVUvxzuDMUjs1UFsyP3+wRDnFDEvLH4pA8t/t/7Zog0hjzenFZ0DGn+iwr/QMQiqlGQ3UjtFjnN8Z5iGmOKqUXzALM/p+kfshGpJY9Sa4zi+dXcb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964390; c=relaxed/simple; bh=IL1CJV37SnDlj7He/xBGqNLGEE6mSIvvEPCT1D3haac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=idGbjdWLq59twMgHv0gA0aRtE7ZtHsdM5MRCoFQFoP5WmxWtWgv5eeGM2ymNNOCZQFqXPQh3ej3kgKBr2J7+PN573a5ODP3ZQkXArMsWXAK7RRqvI1I5/yrdJDux2+U1D2tR0QH9SE+mFhTLbta8yj1ps6nNd6S2JcOJgUdm/rQ= 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=fuZgwdWh; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=z9iEnQWt; 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="fuZgwdWh"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="z9iEnQWt" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964387; 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=i5h1A1PZlfEvZC9waEvOsKerpl76J+NV3FZzV+7jV9I=; b=fuZgwdWh5AbMuaX7fqw+9PVe5Oa9Oru6dtyhruSLtJjv5IQ8QSVea0l11sqE6V5+bsYN7e B7GKjo2Satymau1Pacb3JPECyeLKXhurk2kkIy5cQF56nYj6O4mQbup2u0HQL91q7KO5Oj 3CpkIbMmIx5k5/GvayIQXwcaqy9p6q9daXRgzwCWuL2zooENBJYsd8DCsSJEPMExiH3FzN RdAjgbe6GhSnZkU8x9RqIVwBEeZ5ZHFLsVVKD48JdpTiLR3gl12TEl2OrqmhCdyFw7guKf fogo/5Q2soguCL5wiRVJFDVhF0Zk7Rb+xYodeX0kcLwueExNCauMABFccdInYA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964387; 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=i5h1A1PZlfEvZC9waEvOsKerpl76J+NV3FZzV+7jV9I=; b=z9iEnQWt7CvYqo5QhYy8Fu423edjRg9xbFXvN63pGQnF67T0LCuawFsATHzI76iCBA6QBk mopY5hJWMylJOaCQ== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 06/13] verification/rvgen: Convert __fill_verify_guards_func() to Lark Date: Tue, 5 May 2026 08:59:27 +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" Prepare to remove self.guards and self.__parse_constraints(), convert __fill_verify_guards_func() to use the parsed transitions from Lark. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/dot2k.py | 39 ++++++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index 3a39ae29e41e..cf7e5ddc649c 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -221,6 +221,20 @@ 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) -> 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) + buff[-1] +=3D ';' + 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(",") @@ -398,8 +412,9 @@ 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: - return [] + + if not self.has_guard: + return =20 buff.append( f"""static inline bool ha_verify_guards(struct ha_monitor *ha_mon, @@ -410,14 +425,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 13 23:58:02 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 775A33D1CA1; Tue, 5 May 2026 06:59:49 +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=1777964391; cv=none; b=L4jAf09HuQyj2yC4D+cRkhcfcbARCC8p4SPOP/IyTSNj4E9KoXnzmgJit9Eo2YrAZOIS3eV8LY3JnV2xqxXy+9zLzJEZhNbqLVk0SbxfqkpGbUdjTH8rlO3j4YbXlifs02VXNNJVT0iKa2t2WX03B93t9XDIfiam+Q3wBt1Ku5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964391; c=relaxed/simple; bh=JaRoNxBEjNCi23j5JtUMZhFqJMQmn3DMDLRsSwAqaZc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mzXR+9K7W7HN/EK/i9n9glsoLsE0+Q1VDR2/BISWZEOcYa8aEAvIsOXBfjQG4vwYbM+sILEBPnSZ+HM5KIYkcHVZbjf/9Qjen15Y0fUFle5YCtGkm/kgjFTudvYQecZh2AqLHzTpH8LugHvY3Ii8nSmXoY3GvTrzJ3a1oy9gqUU= 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=owRB2pbE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3Cv7zj+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="owRB2pbE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3Cv7zj+a" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964387; 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=ySQh632ogP8KARcLB6KPSQVzUCu17DlOdwaSQGNKIbk=; b=owRB2pbEUsHBz7ZwiiR1Zj/j/sl4XZeldl1JZlw3kvuKosvTaVwwBmWjTjmLvMnu4mWtGY r6XoFruxVndC3M5P3qGSlW2BAFipvM8aiLko/dMVZlLwif69uxFqU65G3LQP7+uicsOm0Y ng+NNdGPchemT8j4ZVwljqJUvjbyCnbIbxl67J4pci3FoF15V96gPLboFYILTzUi3zQr4L YKQ1s2bQdL/E+hFx4xDaHOtYAatzyMu6aPIgAO1250YRpH7SCyxDvuIqeyOmcQffCy9FmC RHwcNbOoaf4k0PbAl2orY9W8wSqTR5Qk7VKJSsbGFVNu9mANFchXvDzl2HuTxA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964387; 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=ySQh632ogP8KARcLB6KPSQVzUCu17DlOdwaSQGNKIbk=; b=3Cv7zj+a4q/PawdZimxSMvfFA6zzEfZVaaEx8HFTA8HpR5FwIZTKxJW2LPALLHnPHrYv9h o4CjrOh1mONfgNCQ== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 07/13] rv: Simply hybrid automata monitors's clock variables Date: Tue, 5 May 2026 08:59:28 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hybrid automata monitors's clock variables have two different representations: - The invariant representation, which is the timestamp when the invariant expires - The guard representation, which is the timestamp when the clock is last reset This dual representation makes the logic quite difficult to follow (well, at least for me). It also complicates the monitors and the generation tool, as it requires conversion back and forth between the representation. Simplify by using the clock variables for a single purpose: storing the time stamp since the clock is last reset. This also allows simplifying rvgen, which will be done in a follow-up commit. Signed-off-by: Nam Cao --- include/rv/ha_monitor.h | 60 ++++++------------------ kernel/trace/rv/monitors/nomiss/nomiss.c | 18 +------ kernel/trace/rv/monitors/stall/stall.c | 2 +- 3 files changed, 17 insertions(+), 63 deletions(-) diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h index d59507e8cb30..1ce3fd324d2c 100644 --- a/include/rv/ha_monitor.h +++ b/include/rv/ha_monitor.h @@ -253,19 +253,8 @@ static inline void __ha_monitor_timer_callback(struct = ha_monitor *ha_mon) } =20 /* - * The clock variables have 2 different representations in the env_store: - * - The guard representation is the timestamp of the last reset - * - The invariant representation is the timestamp when the invariant expi= res - * As the representations are incompatible, care must be taken when switch= ing - * between them: the invariant representation can only be used when starti= ng a - * timer when the previous representation was guard (e.g. no other invaria= nt - * started since the last reset operation). - * Likewise, switching from invariant to guard representation without a re= set - * can be done only by subtracting the exact value used to start the invar= iant. - * - * Reading the environment variable (ha_get_clk) also reflects this differ= ence - * any reads in states that have an invariant return the (possibly negativ= e) - * time since expiration, other reads return the time since last reset. + * The clock variables store the time epoch - the timestamp when the clock= was last reset. + * They are read by subtracting the time epoch from the current time. */ =20 /* @@ -279,31 +268,21 @@ static inline void ha_reset_clk_ns(struct ha_monitor = *ha_mon, enum envs env, u64 { WRITE_ONCE(ha_mon->env_store[env], time_ns); } -static inline void ha_set_invariant_ns(struct ha_monitor *ha_mon, enum env= s env, - u64 value, u64 time_ns) -{ - WRITE_ONCE(ha_mon->env_store[env], time_ns + value); -} -static inline bool ha_check_invariant_ns(struct ha_monitor *ha_mon, - enum envs env, u64 time_ns) +static inline bool ha_check_invariant_ns(struct ha_monitor *ha_mon, enum e= nvs env, + u64 time_ns, u64 expire_ns) { - return READ_ONCE(ha_mon->env_store[env]) >=3D time_ns; + return time_ns - READ_ONCE(ha_mon->env_store[env]) <=3D expire_ns; } /* * ha_invariant_passed_ns - prepare the invariant and return the time sinc= e reset */ -static inline u64 ha_invariant_passed_ns(struct ha_monitor *ha_mon, enum e= nvs env, - u64 expire, u64 time_ns) +static inline u64 ha_invariant_passed_ns(struct ha_monitor *ha_mon, enum e= nvs env, u64 time_ns) { - u64 passed =3D 0; - if (env < 0 || env >=3D ENV_MAX_STORED) return 0; if (ha_monitor_env_invalid(ha_mon, env)) return 0; - passed =3D ha_get_env(ha_mon, env, time_ns); - ha_set_invariant_ns(ha_mon, env, expire - passed, time_ns); - return passed; + return ha_get_env(ha_mon, env, time_ns); } =20 /* @@ -317,32 +296,21 @@ static inline void ha_reset_clk_jiffy(struct ha_monit= or *ha_mon, enum envs env) { WRITE_ONCE(ha_mon->env_store[env], get_jiffies_64()); } -static inline void ha_set_invariant_jiffy(struct ha_monitor *ha_mon, - enum envs env, u64 value) -{ - 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) +static inline bool ha_check_invariant_jiffy(struct ha_monitor *ha_mon, enu= m envs env, + u64 time_ns, u64 expire_jiffy) { - return time_after64(READ_ONCE(ha_mon->env_store[env]), get_jiffies_64()); - + return time_after64(READ_ONCE(ha_mon->env_store[env]) + expire_jiffy, get= _jiffies_64()); } /* * ha_invariant_passed_jiffy - prepare the invariant and return the time s= ince reset */ -static inline u64 ha_invariant_passed_jiffy(struct ha_monitor *ha_mon, enu= m envs env, - u64 expire, u64 time_ns) +static inline u64 ha_invariant_passed_jiffy(struct ha_monitor *ha_mon, enu= m envs env, u64 time_ns) { - u64 passed =3D 0; - if (env < 0 || env >=3D ENV_MAX_STORED) return 0; if (ha_monitor_env_invalid(ha_mon, env)) return 0; - passed =3D ha_get_env(ha_mon, env, time_ns); - ha_set_invariant_jiffy(ha_mon, env, expire - passed); - return passed; + return ha_get_env(ha_mon, env, time_ns); } =20 /* @@ -389,14 +357,14 @@ static inline void ha_setup_timer(struct ha_monitor *= ha_mon) static inline void ha_start_timer_jiffy(struct ha_monitor *ha_mon, enum en= vs env, u64 expire, u64 time_ns) { - u64 passed =3D ha_invariant_passed_jiffy(ha_mon, env, expire, time_ns); + u64 passed =3D ha_invariant_passed_jiffy(ha_mon, env, time_ns); =20 mod_timer(&ha_mon->timer, get_jiffies_64() + expire - passed); } static inline void ha_start_timer_ns(struct ha_monitor *ha_mon, enum envs = env, u64 expire, u64 time_ns) { - u64 passed =3D ha_invariant_passed_ns(ha_mon, env, expire, time_ns); + u64 passed =3D ha_invariant_passed_ns(ha_mon, env, time_ns); =20 ha_start_timer_jiffy(ha_mon, ENV_MAX_STORED, nsecs_to_jiffies(expire - passed + TICK_NSEC - 1), time_ns); diff --git a/kernel/trace/rv/monitors/nomiss/nomiss.c b/kernel/trace/rv/mon= itors/nomiss/nomiss.c index 31f90f3638d8..6b3f93866d56 100644 --- a/kernel/trace/rv/monitors/nomiss/nomiss.c +++ b/kernel/trace/rv/monitors/nomiss/nomiss.c @@ -57,24 +57,12 @@ static inline bool ha_verify_invariants(struct ha_monit= or *ha_mon, enum states next_state, u64 time_ns) { if (curr_state =3D=3D ready_nomiss) - return ha_check_invariant_ns(ha_mon, clk_nomiss, time_ns); + return ha_check_invariant_ns(ha_mon, clk_nomiss, time_ns, DEADLINE_NS(ha= _mon)); else if (curr_state =3D=3D running_nomiss) - return ha_check_invariant_ns(ha_mon, clk_nomiss, time_ns); + return ha_check_invariant_ns(ha_mon, clk_nomiss, time_ns, DEADLINE_NS(ha= _mon)); return true; } =20 -static inline void ha_convert_inv_guard(struct ha_monitor *ha_mon, - enum states curr_state, enum events event, - enum states next_state, u64 time_ns) -{ - if (curr_state =3D=3D next_state) - return; - if (curr_state =3D=3D ready_nomiss) - ha_inv_to_guard(ha_mon, clk_nomiss, DEADLINE_NS(ha_mon), time_ns); - else if (curr_state =3D=3D running_nomiss) - ha_inv_to_guard(ha_mon, clk_nomiss, DEADLINE_NS(ha_mon), time_ns); -} - static inline bool ha_verify_guards(struct ha_monitor *ha_mon, enum states curr_state, enum events event, enum states next_state, u64 time_ns) @@ -122,8 +110,6 @@ static bool ha_verify_constraint(struct ha_monitor *ha_= mon, if (!ha_verify_invariants(ha_mon, curr_state, event, next_state, time_ns)) return false; =20 - ha_convert_inv_guard(ha_mon, curr_state, event, next_state, time_ns); - if (!ha_verify_guards(ha_mon, curr_state, event, next_state, time_ns)) return false; =20 diff --git a/kernel/trace/rv/monitors/stall/stall.c b/kernel/trace/rv/monit= ors/stall/stall.c index 9ccfda6b0e73..1aa65d7e690d 100644 --- a/kernel/trace/rv/monitors/stall/stall.c +++ b/kernel/trace/rv/monitors/stall/stall.c @@ -38,7 +38,7 @@ static inline bool ha_verify_invariants(struct ha_monitor= *ha_mon, enum states next_state, u64 time_ns) { if (curr_state =3D=3D enqueued_stall) - return ha_check_invariant_jiffy(ha_mon, clk_stall, time_ns); + return ha_check_invariant_jiffy(ha_mon, clk_stall, time_ns, threshold_ji= ffies); return true; } =20 --=20 2.47.3 From nobody Sat Jun 13 23:58:02 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 777363D1CA4; Tue, 5 May 2026 06:59:49 +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=1777964391; cv=none; b=fqIrnUmdXV+JIOyI+iJDlz7uvJBgQcZ+WBErEgHQMINKMXpJlpWn/4VjPL7ORXHyJkrX7iuajwSh6Xdn9ZCi7bUTPIa0TickXoGd9j/suqMrvhHjme6A8yRu7Krq8ByhKm/EksV8CapkB28J0V2fDSSqNlNQQ06w27hGYie9U4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964391; c=relaxed/simple; bh=yTLgH36xEEmsymOpjtPNIIaA04EhIDtcCR6GSVjJPug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ndCLrDmsuif8DubJj2laCZMo+ZmOO1tH+W8BLiafqafGUoaD8/B5W1VdBv4Xj3F+RRuQQfT2L/zKL4vrnsDdg7rrEElhiYkEyT0xoGzgdValYcmVeTRvR5AWIc+naT4O2VvFAsTNFXzNpm+X1TFI+cMMCE60lXMcBni+MXAYLdM= 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=UOwSuNbU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4J2uLaZy; 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="UOwSuNbU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4J2uLaZy" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964387; 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=SVDUGSsyDe/fQYC75WnCgDJpQY9nDWTmvngJkI6bWUs=; b=UOwSuNbUEULSFCOo1gQpol/gsFmR7zGOC3NB0likL3N8H+qTQuyBdJSktrceEO1c+cJZLa DEl8Kg0GC6goKcnGG1Lrp9gS+CL55zL4IkRrsm1Q7XtNEfpla3KIP+V3bX2MMRhFRUfZQw aGGEIhWTByhosZOgFFRUyhKRk4ghVmjXwluFfF/e9CgirV7kxebLDDn8bm8sWUKLK+mzH2 pEx4VFAp5SjP/galjBrJonsAa52BilkM995O33+r0+hKWy9xdwWakJ/TkuFJiIWY2rhXqe iKsaK+z6IF0EiY1ATFRfQgtsHWZj17MPJqaI6BOTLBEVV/Ujnw/rnLE1jZBUPA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964387; 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=SVDUGSsyDe/fQYC75WnCgDJpQY9nDWTmvngJkI6bWUs=; b=4J2uLaZyiWIbGYvvgKO+dJHLACHYLC+MyV69mlD4k3D2y+sIE0Cx2OG+yHvwWzQIIXTCp6 Bjoh617uU/ODPJCw== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 08/13] verification/rvgen: Simplify the generation for clock variables Date: Tue, 5 May 2026 08:59:29 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hybrid automata monitors's clock variables have been changed to have only a single representation. Now there is no need to generate code to convert between the two representations. Delete __fill_convert_inv_guard_func() and its associates. Update __start_to_invariant_check() to how invariants now work. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/dot2k.py | 89 +------------------------ 1 file changed, 1 insertion(+), 88 deletions(-) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index cf7e5ddc649c..c662c888f991 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -247,7 +247,7 @@ 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)" + return f"return ha_check_invariant_{clock_type}(ha_mon, {inv.env}_= {self.name}, time_ns, {inv.val})" =20 def __start_to_conv(self, constr: str) -> str: """ @@ -376,40 +376,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 @@ -449,54 +415,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 [] @@ -555,8 +473,6 @@ f"""static inline void ha_setup_invariants(struct ha_mo= nitor *ha_mon, */""") =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 @@ -569,9 +485,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 13 23:58:02 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 3A1703D34AD; Tue, 5 May 2026 06:59:50 +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=1777964392; cv=none; b=J58xU2GP5avk9Sn5b7uoPbqjkuZl4RiqO/o3+8tfUmpDUQ4sxrbpGirS1N9Z9nWZeQx6L0jjGZzLT1XfNUZc3Sx+5n1j9vznRK33X7t3vBh6hdxAstoo5ApgDIYuhqOiOcCWxVYGoUzYe2XXjFjHufJZ/O5/bwWwUJc1MFtlIvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964392; c=relaxed/simple; bh=+vlfbP9wtJjQdiuEc769krkIO+AH0E4AaHb/RhWdtdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F9PaHtoiRLXLCTgoceN6J4xhoRnS6T2OH7BTRL51n4+pnGStFNgoJPPO/whr7MGnkDMmwz216HWRIeZjBiuEXMTjyXKIRkPaoeyuFb/nZyoubWT2jkjdkLLACnG/zoRkxyZrbcBq88Be1p+rqa4uGdcrG5bZHBjesRxHmmov4gA= 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=dcbXxCy/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=q8JLKzY+; 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="dcbXxCy/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="q8JLKzY+" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964388; 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=6hQ5fSqgW/J20rDjxD9UtlNXnVTCION75DNxFTYxzks=; b=dcbXxCy/1NbnMGm1m/QLqM/YnfgDbxrSofVo/9vJdAOd8it/977pQ2QdfMLKajx+2yPjQ7 WYGK75Zd6Stq+9eD+228MUik1YwlpAZRihgZUAdd/r2kkafb38/CnpkDzTFtkQVAaQrUg+ GlLgBTcZzMe4sgSmtQm7UoVN3WHLpnbrvbxsn0kYvAeECOhQziYggBWx3ym2ZwI6ueoY6X b0XGsA/cWZ0nAa+lxwcQyeGXYuTDwnWHxiToNa+AKTT/srGlD5t9QPywE1DX5k2RKYkTaP uecZCM1gX19iiTF+xYf+6vHJzZAuUu2fW0wFuyOmVjvO/xgO7TdaOFd49VVKyQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964388; 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=6hQ5fSqgW/J20rDjxD9UtlNXnVTCION75DNxFTYxzks=; b=q8JLKzY+RtLTS5vHpaUswAQOp2+9iYXSO/+F9helRb8UOTPCy7tbWREbjdC4ZoGvaJ1QVC BZza/rOBh8/9etBQ== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 09/13] verification/rvgen: Delete __parse_constraint() Date: Tue, 5 May 2026 08:59:30 +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 c662c888f991..5ea5d16df29b 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: @@ -295,64 +294,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 [] @@ -482,15 +423,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") @@ -567,7 +508,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 13 23:58:02 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 37F1F3D349D; Tue, 5 May 2026 06:59:50 +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=1777964392; cv=none; b=UtnLez/Q6I68yeIgG2fUaOvjQEy2Iw/sG+lrg36b2nAN2y6oWENU19aAaaf2dOAOQx47zM/3waV9X/T9d9OUuA0V4GAOdSfKTlAJp9jhqNuvBp9uxhhlTKBgJBmlIRVfYvrO1ZC7yPa813pBlzN1mbftZiC/bl204Vkdn3p27Fg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964392; c=relaxed/simple; bh=U8eo2ICz4lpIt8wpAs0vg9jNcPoWEgutttxGmPpTzXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pqtexaKFBVodlRC7FpXUUYeSzeLSCesPlWYLfrcSSt8Ibkomzn3wSrITPhvFwsqOb8F+qqQQJ8Pupht/HdfBw2sTCvtOia2v3m6PzC9J4y2Wken1URIBhmyjI1f98VPYA34T5X9VcR3HdONvecL7nNdn/fJc5GostrvuvB1sMmY= 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=RAd19UAY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6aNtSQUp; 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="RAd19UAY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6aNtSQUp" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964388; 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=HU+TvDDlCcsVI5W6j1TjtrcbzA0uGy58MDKdF8Z83eQ=; b=RAd19UAYGVPvbaUJMOEPa/TTOIg2PyHJ/SYeIAw1JRV0DxTd8+Z7wzkj136I+scCaHVaBA ppQtj7yRj0uCQ/3+KQduLofl4ClyWM1Oyn/dYEUQuQZbOHiIFv4v7f4XqSBgpjDu8vd5d/ olSf7tSgT5sxWY+Er2q4cWNlgMy/1XXyv/vpmnHd0NIt0EQZfMEWM0OGSYNlqrLmSPKOpG QI4tefp3qcAOkmepURdwsVK364lmtmpdVJooYQscqa/UprWTQHr9ErbuF83Dmoi6tAP+Iy YcunSzl5Lthc2cWnoNoV9oyg/O3UarvCfggCHbPhVv+I2jiT+72fYrlPGi/GQg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964388; 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=HU+TvDDlCcsVI5W6j1TjtrcbzA0uGy58MDKdF8Z83eQ=; b=6aNtSQUpSlu2wp/W7o09xvFWUjyp3ab6OCYR664CgiWu/W0gYjxbbfzx2vuclNWoSC3Ta5 qHkD2ZVuOFaQvdAA== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 10/13] verification/rvgen: Switch __get_event_variables() to Lark Date: Tue, 5 May 2026 08:59:31 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch __get_event_variables() to use the parsed results from Lark, instead of raw text processing. Signed-off-by: Nam Cao --- 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 32c16736a41b..a29dcde1348c 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -578,45 +578,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 @@ -640,28 +617,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) -> list[s= tr]: + 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 13 23:58:02 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 481D23D3CF9; Tue, 5 May 2026 06:59:50 +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=1777964392; cv=none; b=QIi2s5GbNj/e8SmgvS13RTKU+9tEJJAZUVpOIyHtm75fVbnQ5Wy79iuJxNF3IoQ/zGI1PYbzOWMNh+uilx6iqjzsAZd47k5mIsFeZJW9XA+2WNtDZwRVVfxfNoYkSOb2O0HqJrNBEtGM6p7FWq1ZQPGv1WUrdvf+lqHayUupDVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964392; c=relaxed/simple; bh=cf0RU3WuKYTIBA84jc5vxeb+yrm7cB8R+1pGLH+QHVI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HwDb4YyrQxKu9b0GUEy/x8IbJIV/XzTpEv8HI8K8ghKkdqDgkQ+CGg2N32+YkCxY9AsiCJq9Ia+q2eoW7tSFgBjm5HBNB4LPpIdkD1gyvhcrwMbzV1Z1dSIGRBI2Nn0Hxt9n5YLmMhP9Av9iJ/jc6/rELGu54gXTiS/Hqg3Vsm0= 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=L/jxJdlM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=FQMYuHTj; 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="L/jxJdlM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FQMYuHTj" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964389; 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=oZvAARUCbhbQc1m8VF8+lZ5KeiOG6Z8eMzvbhAMX89U=; b=L/jxJdlM2XKxIG76SD7voADiiW77ZpC1V/w8mf/gX5wNxdyt0bmHct7Ery6JX6R9bcbFJY Rv2DPrXyJgdUKxsH29eSZm5q2WpPTkxqrHpFC4jJeqPj5uXKey6h8Nf37y9Gudb5vkSpPc uIW9it7ezrIRvLV4trshJIeyHYKCzHyu3aFDp6pC42PbVkP2UGw46KINFgFTOMpAc9ZSDY aFuJFjYZLSdI3AZRuRaK0mNG+Phg1XpjpqWj87zP2TD/RHySTPXE5pjISOiZ69mMCF8HlK 1yuL0Jyo3uBk4X5yCLGLocMJEDDiv4y4Z6cpyjkGH3b4+ln42HBmS0ULM3vN+Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964389; 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=oZvAARUCbhbQc1m8VF8+lZ5KeiOG6Z8eMzvbhAMX89U=; b=FQMYuHTj3u+B+Ju0A2ca11HMsrPS8fnuP8ksaclIQbgGqD52begNLesrDqC+qdkvm1HcSX Z0dY2LGb0QOsDdDA== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 11/13] verification/rvgen: Switch __create_matrix() to Lark Date: Tue, 5 May 2026 08:59:32 +0200 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch __create_matrix() to use the transitions parsed by Lark to avoid all the raw text parsing. Also stop parsing constraints in __create_matrix(), that is not used anymore. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/automata.py | 47 ++++++---------------- tools/verification/rvgen/rvgen/dot2k.py | 2 +- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index a29dcde1348c..d40d037f4cfd 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -405,7 +405,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) @@ -623,10 +623,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 @@ -641,39 +641,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 5ea5d16df29b..708e1f223728 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -394,7 +394,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 13 23:58:02 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 B641A3D47B5; Tue, 5 May 2026 06:59:50 +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=1777964392; cv=none; b=AbKJUeodJqZmltwdSOa7K/cU8fLKXn1wVXXPEb5EPDFEhtZQQVrTq7FQJrxbV00mUfwF/vIWTgXfNKce0YLQev8wBy10dS47mSs+6Qk4F9/VZGYRxbKGcSCeG11V+dlR4Bz+zlk58lChgg406tPA15+MN9qjCHXo8q4smZQvZR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964392; c=relaxed/simple; bh=0tAq7CQBHPx0us+lD3DuEThVKIKBhdFVtDWsSs/FwlA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s3fPwXmHsWtwYwSfNYaMlK3cArdEkoqh9FUbdKAVzxLwL0mbc7BW9gH0qQPwekXo/hiLk/jO49TWhGn+j1VsN0sMfnJ/6qCBy20n6vwjUCr+2MhF7BezCTpDr9O/67pzHPeuWL/dqtwYnAQXWKx8D1nfC93AUQ6Z8UERXn0Xi44= 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=MjopkYT0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HsCbmMBm; 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="MjopkYT0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HsCbmMBm" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964389; 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=OvZccNxe7w2f8/qKwBVtd3LVm2MX2fiXB0AbdqeWY5k=; b=MjopkYT0g8NKNaoEnR2uRMa1G0n6hfE9lnMf+9ADNFFhx+m8JxrvAyIVSE0f36jFxct5ck 599a4GfVfuxbsy9jzUVNBEL7R7A862SOgzE8w/BLyBwAs1S8D6k9pY3WEeBjDU+soDQVik Ytea0CkATkNqYTQxA084U1uUWL42FN3j3RUA0xtEN26cM0Lzz/m7Vtw6HCOYj7IhdipQJk pczMwkSQ83JizRFMf1mQNnZnO7gUobrl3mR5SiBrsuABSAERyfh2h0X8DZDnr+tdlRIwJG QxhrGBironRaKZOpTPA18hFA6aCq+TkBfA2rXvy6kp0TIYeHJA9zljTkt2mz9A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964389; 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=OvZccNxe7w2f8/qKwBVtd3LVm2MX2fiXB0AbdqeWY5k=; b=HsCbmMBmFQmx8KPTuDE6JlzO014cEPOXZw4lPPFbkXcQA6HQ/XITUEnaVW+oPDbXol42pf 88ls7y8tEDQx1dDA== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 12/13] verification/rvgen: Remove the old state variables Date: Tue, 5 May 2026 08:59:33 +0200 Message-ID: <2cab668a726e20bde5b3e310aaa0036f3fe4c1ee.1777962130.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 state variables (states, initial_state, final_states) only capture the states' names and have less information than their Lark-based counterparts. Switch to use the new state variables and delete these old ones. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/automata.py | 9 ++++----- tools/verification/rvgen/rvgen/dot2c.py | 10 +++++----- tools/verification/rvgen/rvgen/dot2k.py | 8 ++++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index d40d037f4cfd..e0d3f83cbd3c 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -398,8 +398,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() @@ -590,7 +589,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) @@ -626,7 +625,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 @@ -662,7 +661,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 708e1f223728..12d944bcd6f3 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: @@ -305,7 +305,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 @@ -373,7 +373,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 @@ -382,7 +382,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 13 23:58:02 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 F40033D523F; Tue, 5 May 2026 06:59:50 +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=1777964393; cv=none; b=jVlgEvgjmmZ9bxC6nL746OKLSeyWGUf9LBcZ0erx0+9/x8pKv8A/S82AH7yHXbDG9MzGA6FBolzVF1wDGsnL86tmGtMXgLPNZYiBv0oO+XhF5oHMs1uA96gwg5q+gX9v2LoUSc5+u1gx3vwQXlPrQCP8GCpKS3uioEl11A6Ee6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777964393; c=relaxed/simple; bh=SgVtcrOQDVB0WvK8sUO0KSG4AKaYhoIwsvvuaBbN3EM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ISQ+lSFuW28tGwk/PDRKErThVxPDDlJjI3btMQWn4jgf+GxVZLxaUyYHpeh7aoywqWg11CqgK5iUARLdotQz34YD5DUrynOVSmzws/PgRE9M1pkcyFTi6LkCIuSkeO33sLjc6ApVlbf8oK45Ff4X98D2DOn2tKh/0543K0FBU0A= 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=lz5iBy0Y; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4GOOZ7eu; 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="lz5iBy0Y"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4GOOZ7eu" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777964389; 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=SlV6jNZ+HtFWnb4PS2KZaQfofKGi5CB3zbG46SMTWQo=; b=lz5iBy0YH47MRNi53bmGdPdssaR7fEA2L94Hq4bUgQp3swrbyL0Oj8/BrPEFvRp5KiRW58 iWKFhME76/VoEyPklbiKP6mfmgeaP7JEXh9ygk96UObY/sbNcR+bFAApsAiNqZAJjXcfQL TG2HhES3kFDy9SLyL7lvmAYoY44ZlmXDw36qBS8GrTb0Os98mP2Yf6oU/Ib/4JtXP8RLc/ JnTLiO84z6TPRGJlUJiRHWCFD1lO+4Yv9j51XmoYjQN5m9CRODAzK3ng38iBeCeG8X6nUS B97oS5kdFRjW2Ga/K5i1i8xt9BobLTGI9162yPJ9FtsyHNzf5CAMf2rfrBobjA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777964389; 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=SlV6jNZ+HtFWnb4PS2KZaQfofKGi5CB3zbG46SMTWQo=; b=4GOOZ7euP0/3D4tM+cJtX4YrelGP1CVN60J0+BBqiuKK0L70h/Kg26DUH4/IUh5tioFZlk JUb0I4dWCW0q4IDw== To: Gabriele Monaco , Steven Rostedt , Wander Lairson Costa , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 13/13] verification/rvgen: Remove dead code Date: Tue, 5 May 2026 08:59:34 +0200 Message-ID: <6c228bb209d9d55622497454368032befab4dda7.1777962130.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The conversion to use Lark left some dead code behind. Remove them. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/automata.py | 154 --------------------- tools/verification/rvgen/rvgen/dot2k.py | 28 +--- 2 files changed, 1 insertion(+), 181 deletions(-) diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index e0d3f83cbd3c..cc42b8127fc0 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -343,19 +343,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 @@ -374,28 +361,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() @@ -422,57 +391,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 @@ -529,51 +447,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 [] @@ -596,26 +469,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) -> list[s= tr]: if constraint.unit: self.env_types[constraint.env] =3D constraint.unit @@ -684,10 +537,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 12d944bcd6f3..12589fbb180c 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -11,9 +11,7 @@ from collections import deque from .dot2c import Dot2c from .generator import Monitor -from .automata import _EventConstraintKey, _StateConstraintKey, AutomataEr= ror -from .automata import ConstraintRule - +from .automata import ConstraintRule, AutomataError =20 class dot2k(Monitor, Dot2c): template_dir =3D "dot2k" @@ -217,9 +215,6 @@ class ha2k(dot2k): value *=3D 10**9 return str(value) + "ull" =20 - def __parse_single_constraint(self, rule: dict, value: str) -> str: - return f"ha_get_env(ha_mon, {rule["env"]}{self.enum_suffix}, time_= ns) {rule["op"]} {value}" - def __parse_guard_rule(self, rule) -> str: buff =3D [] for c, sep in rule.rules: @@ -234,12 +229,6 @@ class ha2k(dot2k): buff[-1] +=3D ';' return buff =20 - def __get_constraint_env(self, constr: str) -> str: - """Extract the second argument from an ha_ function""" - env =3D constr.split("(")[1].split()[1].rstrip(")").rstrip(",") - assert env.rstrip(f"_{self.name}") in self.envs - return env - def __start_to_invariant_check(self, inv: ConstraintRule) -> str: # by default assume the timer has ns expiration clock_type =3D "ns" @@ -248,21 +237,6 @@ class ha2k(dot2k): =20 return f"return ha_check_invariant_{clock_type}(ha_mon, {inv.env}_= {self.name}, time_ns, {inv.val})" =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