From nobody Thu Nov 21 21:41:19 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B2427153BE4 for ; Mon, 18 Nov 2024 21:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731966077; cv=none; b=VYDJk6A6YCgTQTSU0xLd30ubPKJDlaXt4AHEOOTZwBN/iPVkTqH5yqwqdPKVQYE9n7h06wb6DqPTN1oFI0NpFX/dYujrCCGm9MXcQ8AoqNnO6qmaSmGaNg7TRSg9HYMc4i8tcUw+oX0WshPCX2TXdiy1MAE1AbnG3CK0sY0dmxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731966077; c=relaxed/simple; bh=MVdApGcyUkptaqX7YZykKxm5OO/+NabO5+9iyVWfb5o=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=hHc+ezhVRjirUqlAU5Ox59fptIuK8gRZ1e3XlxA6nedjJYwAjuo7T2n+p1HQj/0VH9EyNFAcK0krbJNB3wFoNBIOA9SLk2N0uqoLB3a1sDomTPZfia3QVb0qCMivEO50DsYaw9I7jrbp4O7FUxhf5fkpmYbo8zCt8XuZGcB0Zb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 779B3C4CECF; Mon, 18 Nov 2024 21:41:17 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tD9VF-0000000DO46-30yF; Mon, 18 Nov 2024 16:41:49 -0500 Message-ID: <20241118214149.568045181@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 18 Nov 2024 16:41:23 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Tomas Glozar , John Kacur Subject: [for-next][PATCH 1/5] rtla/timerlat: Do not set params->user_workload with -U References: <20241118214122.136581969@goodmis.org> 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" From: Tomas Glozar Since commit fb9e90a67ee9 ("rtla/timerlat: Make user-space threads the default"), rtla-timerlat has been defaulting to params->user_workload if neither that or params->kernel_workload is set. This has unintentionally made -U, which sets only params->user_hist/top but not params->user_workload, to behave like -u unless -k is set, preventing the user from running a custom workload. Example: $ rtla timerlat hist -U -c 0 & [1] 7413 $ python sample/timerlat_load.py 0 Error opening timerlat fd, did you run timerlat -U? $ ps | grep timerlatu 7415 pts/4 00:00:00 timerlatu/0 Fix the issue by checking for params->user_top/hist instead of params->user_workload when setting default thread mode. Link: https://lore.kernel.org/20241021123140.14652-1-tglozar@redhat.com Fixes: fb9e90a67ee9 ("rtla/timerlat: Make user-space threads the default") Signed-off-by: Tomas Glozar Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/src/timerlat_hist.c | 2 +- tools/tracing/rtla/src/timerlat_top.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index 01dd337da13a..8b66387e5f35 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -1073,7 +1073,7 @@ timerlat_hist_apply_config(struct osnoise_tool *tool,= struct timerlat_hist_param * If the user did not specify a type of thread, try user-threads first. * Fall back to kernel threads otherwise. */ - if (!params->kernel_workload && !params->user_workload) { + if (!params->kernel_workload && !params->user_hist) { retval =3D tracefs_file_exists(NULL, "osnoise/per_cpu/cpu0/timerlat_fd"); if (retval) { debug_msg("User-space interface detected, setting user-threads\n"); diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index fca0da3caa87..f7422948205d 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -839,7 +839,7 @@ timerlat_top_apply_config(struct osnoise_tool *top, str= uct timerlat_top_params * * If the user did not specify a type of thread, try user-threads first. * Fall back to kernel threads otherwise. */ - if (!params->kernel_workload && !params->user_workload) { + if (!params->kernel_workload && !params->user_top) { retval =3D tracefs_file_exists(NULL, "osnoise/per_cpu/cpu0/timerlat_fd"); if (retval) { debug_msg("User-space interface detected, setting user-threads\n"); --=20 2.45.2 From nobody Thu Nov 21 21:41:19 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 ECA541E7643 for ; Mon, 18 Nov 2024 21:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731966078; cv=none; b=bMhuIHuu1KC5BUrsc3YsVBdM4h4IIqfduBO5kCzH0IU/9R4p8ZvexDBIO87pSO7NGGeduV0v8fK0dQBmPD+79nftOdJJD8zTEc9BAvg/JkEbNSYlfALmpmBXiWMLe/82BH7Hgv9yLPSXfHyWV4t9p673J+oUGps5vg8EEEmCw9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731966078; c=relaxed/simple; bh=9vh/n3TLJf6SPuh2A+56vcj5XMn/yl800FwblNP07pY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=sbg1m/fLN+fpC3g8CG0Pt3iOa7V8L9FipcdYdIRmLjxKfQP7lpOvZN2p2mVVxHecvK09iFuDwR9+JYmh6ghy+FGKW1kW96VHG/dU7a3gOQPrBWajRNBDfdwFr6i8InWds2x2qMVQeq60FP+SJzr69aUZ4W3EL3sE3tb08KL+4+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90C25C4CED6; Mon, 18 Nov 2024 21:41:17 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tD9VF-0000000DO4b-3hP6; Mon, 18 Nov 2024 16:41:49 -0500 Message-ID: <20241118214149.736470998@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 18 Nov 2024 16:41:24 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Tomas Glozar , John Kacur , "lgoncalv@redhat.com" , Furkan Onder Subject: [for-next][PATCH 2/5] tools/rtla: Improve code readability in timerlat_load.py References: <20241118214122.136581969@goodmis.org> 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" From: furkanonder The enhancements made to timerlat_load.py are intended to improve the script's robustness and readability. Summary of the changes: - Unnecessary semicolons at the end of lines have been removed. - Parentheses surrounding the if statement checking args.prio have been eliminated. - String concatenation for constructing timerlat_path has been replaced with an f-string. - Spacing in a multiplication expression has been adjusted for improved clarity. Cc: "jkacur@redhat.com" Cc: "lgoncalv@redhat.com" Link: https://lore.kernel.org/j2B-ted7pv3TaldTyqfIHrMmjq2fVyBFgnu3TskiQJsyR= zy9loPTVVJoqHnrCWu5T88MDIFc612jUglH6Sxkdg9LN-I1XuITmoL70uECmus=3D@protonmai= l.com Signed-off-by: Furkan Onder Reviewed-by: Tomas Glozar Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/sample/timerlat_load.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/tracing/rtla/sample/timerlat_load.py b/tools/tracing/rtl= a/sample/timerlat_load.py index 8cc5eb2d2e69..785e9a83539a 100644 --- a/tools/tracing/rtla/sample/timerlat_load.py +++ b/tools/tracing/rtla/sample/timerlat_load.py @@ -37,12 +37,12 @@ except: exit(1) =20 try: - os.sched_setaffinity(0, affinity_mask); + os.sched_setaffinity(0, affinity_mask) except: print("Error setting affinity") exit(1) =20 -if (args.prio): +if args.prio: try: param =3D os.sched_param(int(args.prio)) os.sched_setscheduler(0, os.SCHED_FIFO, param) @@ -51,21 +51,21 @@ if (args.prio): exit(1) =20 try: - timerlat_path =3D "/sys/kernel/tracing/osnoise/per_cpu/cpu" + args.cpu= + "/timerlat_fd" + timerlat_path =3D f"/sys/kernel/tracing/osnoise/per_cpu/cpu{args.cpu}/= timerlat_fd" timerlat_fd =3D open(timerlat_path, 'r') except: print("Error opening timerlat fd, did you run timerlat -U?") exit(1) =20 try: - data_fd =3D open("/dev/full", 'r'); + data_fd =3D open("/dev/full", 'r') except: print("Error opening data fd") =20 while True: try: timerlat_fd.read(1) - data_fd.read(20*1024*1024) + data_fd.read(20 * 1024 * 1024) except: print("Leaving") break --=20 2.45.2 From nobody Thu Nov 21 21:41:19 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 69F821E8820 for ; Mon, 18 Nov 2024 21:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731966078; cv=none; b=aXgZ+TxiysLWsdg7J56DXSRTxeZAWy1iW27byGZouFpFtaeMWotx1N4sGDOhRNq4jOYwAJIe6UGG8n7ztGBD/py9QqqpqB5se3ZqkJlO4quq4P/78OHHG/z+lNOY5ROHkQHORk9Tb3sJ6N4zvN0zG4RdMc6IEyrccaH074anYys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731966078; c=relaxed/simple; bh=EFXGenEvq+97XtCagTbKXm70xIu/0FQ5mQXGq+OYBUs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=uHEBGqS1QwXA+il9wGAPICg3a+iO3NnmpWPAgJV1MfD/jsiIZvlQCH9i+LbGI3JeHZexKGk5ig6Q0B68gGtHBLXxy+hI9WLHOIBL/t57Jpsj68SIMg51VaL1IOPrCzN33RGxiyX6nzfESHWr/x8cPbJccsAq+doEAjMmLjIeJns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF0EFC4CED0; Mon, 18 Nov 2024 21:41:17 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tD9VG-0000000DO56-0CoM; Mon, 18 Nov 2024 16:41:50 -0500 Message-ID: <20241118214149.900721438@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 18 Nov 2024 16:41:25 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Tomas Glozar , John Kacur , "lgoncalv@redhat.com" , Furkan Onder Subject: [for-next][PATCH 3/5] tools/rtla: Enhance argument parsing in timerlat_load.py References: <20241118214122.136581969@goodmis.org> 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" From: furkanonder The enhancements made to timerlat_load.py are aimed at improving the clarit= y of argument parsing. Summary of Changes: - The cpu argument is now specified as an integer type in the argument parser to enforce input validation, and the construction of affinity_mask has been simplified to directly use the integer value of args.cpu. - The prio argument is similarly updated to be of integer type for consistency and validation, eliminating the need for the conversion of args.prio to an integer, as this is now handled by the argument parser. Cc: "jkacur@redhat.com" Cc: "lgoncalv@redhat.com" Link: https://lore.kernel.org/QfgO7ayKD9dsLk8_ZDebkAV0OF7wla7UmasbP9CBmui_s= ChOeizy512t3RqCHTjvQoUBUDP8dwEOVCdHQ5KvVNEiP69CynMY94SFDERWl94=3D@protonmai= l.com Signed-off-by: Furkan Onder Reviewed-by: Tomas Glozar Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/sample/timerlat_load.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/tracing/rtla/sample/timerlat_load.py b/tools/tracing/rtl= a/sample/timerlat_load.py index 785e9a83539a..d7341ed5127a 100644 --- a/tools/tracing/rtla/sample/timerlat_load.py +++ b/tools/tracing/rtla/sample/timerlat_load.py @@ -25,13 +25,12 @@ import sys import os =20 parser =3D argparse.ArgumentParser(description=3D'user-space timerlat thre= ad in Python') -parser.add_argument("cpu", help=3D'CPU to run timerlat thread') -parser.add_argument("-p", "--prio", help=3D'FIFO priority') - +parser.add_argument("cpu", type=3Dint, help=3D'CPU to run timerlat thread') +parser.add_argument("-p", "--prio", type=3Dint, help=3D'FIFO priority') args =3D parser.parse_args() =20 try: - affinity_mask =3D { int(args.cpu) } + affinity_mask =3D {args.cpu} except: print("Invalid cpu: " + args.cpu) exit(1) @@ -44,7 +43,7 @@ except: =20 if args.prio: try: - param =3D os.sched_param(int(args.prio)) + param =3D os.sched_param(args.prio) os.sched_setscheduler(0, os.SCHED_FIFO, param) except: print("Error setting priority") --=20 2.45.2 From nobody Thu Nov 21 21:41:19 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6A04A1E8823 for ; Mon, 18 Nov 2024 21:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731966078; cv=none; b=kZ1WPz/pu8rS+rZkilUb4pTa6RI9IJaC9AuN4txYIouG/TF2b+XMXAkLUpHzAND+2vZwK+z8XT8JdpviQnTRN73LHIzv7jgRdU1P12gjzR7DlurLDtNdJ6r1TAhLgXgmCO+kJdY8BQlYDHGfiZKn2F4xOY7b42PwNi9B0OI2b6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731966078; c=relaxed/simple; bh=1bsicQsClz2mA5LGmCCz633UWz8AMxCoyQFRdHoj6LQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=N12gaxEptRDe3Q17CoVBL4b2DICgh9BwjN3oOq0Vx6VGJeUJgaTMGkmSJWzCWXdfCmpr/D/MHc2Mgf5c20R99k+gy6AA8wabta13PKKhiOfHc/RnHBs/YRvvplIIl7X8BWIRgs4tGjJ6p2Dwwt9wKocO+bg7vtccupmSpnnWw8U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 031E3C4CECF; Mon, 18 Nov 2024 21:41:18 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tD9VG-0000000DO5d-0uGm; Mon, 18 Nov 2024 16:41:50 -0500 Message-ID: <20241118214150.069691382@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 18 Nov 2024 16:41:26 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Tomas Glozar , John Kacur , "lgoncalv@redhat.com" , Furkan Onder Subject: [for-next][PATCH 4/5] tools/rtla: Improve exception handling in timerlat_load.py References: <20241118214122.136581969@goodmis.org> 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" From: furkanonder The enhancements made to timerlat_load.py are intended to improve the scrip= t's exception handling. Summary of the changes: - Specific exceptions are now caught for CPU affinity and priority settings, with clearer error messages provided. - The timerlat file descriptor opening now includes handling for PermissionError and OSError, with informative messages. - In the infinite loop, generic exceptions have been replaced with specific types like KeyboardInterrupt and IOError, improving feedback. Before: $ sudo python timerlat_load.py 122 Error setting affinity After: $ sudo python timerlat_load.py 122 Error setting affinity: [Errno 22] Invalid argument Before: $ sudo python timerlat_load.py 1 -p 950 Error setting priority After: $ sudo python timerlat_load.py 1 -p 950 Error setting priority: [Errno 22] Invalid argument Before: $ python timerlat_load.py 1 Error opening timerlat fd, did you run timerlat -U? After: $ python timerlat_load.py 1 Permission denied. Please check your access rights. Cc: "lgoncalv@redhat.com" Cc: "jkacur@redhat.com" Link: https://lore.kernel.org/Q_k1s4hBtUy2px8ou0QKenjEK2_T_LoV8IxAE79aBakBo= gb-7uHp2fpET3oWtI1t3dy8uKjWeRzQOdKNzIzOOpyM4OjutJOriZ9TrGY6b-g=3D@protonmai= l.com Signed-off-by: Furkan Onder Reviewed-by: Tomas Glozar Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/sample/timerlat_load.py | 37 ++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/tools/tracing/rtla/sample/timerlat_load.py b/tools/tracing/rtl= a/sample/timerlat_load.py index d7341ed5127a..a819c3588073 100644 --- a/tools/tracing/rtla/sample/timerlat_load.py +++ b/tools/tracing/rtla/sample/timerlat_load.py @@ -31,43 +31,48 @@ args =3D parser.parse_args() =20 try: affinity_mask =3D {args.cpu} -except: - print("Invalid cpu: " + args.cpu) - exit(1) - -try: os.sched_setaffinity(0, affinity_mask) -except: - print("Error setting affinity") - exit(1) +except Exception as e: + print(f"Error setting affinity: {e}") + sys.exit(1) =20 if args.prio: try: param =3D os.sched_param(args.prio) os.sched_setscheduler(0, os.SCHED_FIFO, param) - except: - print("Error setting priority") - exit(1) + except Exception as e: + print(f"Error setting priority: {e}") + sys.exit(1) =20 try: timerlat_path =3D f"/sys/kernel/tracing/osnoise/per_cpu/cpu{args.cpu}/= timerlat_fd" timerlat_fd =3D open(timerlat_path, 'r') -except: +except PermissionError: + print("Permission denied. Please check your access rights.") + sys.exit(1) +except OSError: print("Error opening timerlat fd, did you run timerlat -U?") - exit(1) + sys.exit(1) =20 try: data_fd =3D open("/dev/full", 'r') -except: - print("Error opening data fd") +except Exception as e: + print(f"Error opening data fd: {e}") + sys.exit(1) =20 while True: try: timerlat_fd.read(1) data_fd.read(20 * 1024 * 1024) - except: + except KeyboardInterrupt: print("Leaving") break + except IOError as e: + print(f"I/O error occurred: {e}") + break + except Exception as e: + print(f"Unexpected error: {e}") + break =20 timerlat_fd.close() data_fd.close() --=20 2.45.2 From nobody Thu Nov 21 21:41:19 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 69FF61E8821 for ; Mon, 18 Nov 2024 21:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731966078; cv=none; b=fQ6h0wAtA12ZWG9LtLu5/kl2NL0/8yfw0SSF/NrUSocN3KNXEwA76y+2DUjcbH8/daHb0csaWQdOBCPMSAKmoeXnkBZo6dRhN0jN+EmmUJ1Y1iqFeg0fTOUgyO3Tgcvz2tYu3Xt8rNTamS52uRULRKkw96vghXpGMZJ5JMikXeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731966078; c=relaxed/simple; bh=9jmM3A4kv4i1p8BHzYN2KcQ+8Jhsx84dLmtKtiHkF6c=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=qqOVpWT1Vi0L3k21QsViev+hxiEBEHdqrTfGFOjLTfrWAiMmMuECjJO0Q+iP8aONtjx4I/PLR2plF4C5yD443wzVDWWx+Nd6/ztpjESxbnp/bZkpA9iPLXpiDmr/xMBZcj/5ZJ5x6ONsUatoO7ckBeik16EFyK4BNXok/wv71Vk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B230C4CECC; Mon, 18 Nov 2024 21:41:18 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tD9VG-0000000DO69-1cc8; Mon, 18 Nov 2024 16:41:50 -0500 Message-ID: <20241118214150.235297619@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 18 Nov 2024 16:41:27 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Tomas Glozar , John Kacur , Gabriele Monaco Subject: [for-next][PATCH 5/5] verification/dot2: Improve dot parser robustness References: <20241118214122.136581969@goodmis.org> 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" From: Gabriele Monaco This patch makes the dot parser used by dot2c and dot2k slightly more robust, namely: * allows parsing files with the gv extension (GraphViz) * correctly parses edges with any indentation * used to work only with a single character (e.g. '\t') Additionally it fixes a couple of warnings reported by pylint such as wrong indentation and comparison to False instead of `not ...` Link: https://lore.kernel.org/20241017064238.41394-2-gmonaco@redhat.com Signed-off-by: Gabriele Monaco Signed-off-by: Steven Rostedt (Google) --- tools/verification/dot2/automata.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/verification/dot2/automata.py b/tools/verification/dot2/= automata.py index baffeb960ff0..bdeb98baa8b0 100644 --- a/tools/verification/dot2/automata.py +++ b/tools/verification/dot2/automata.py @@ -29,11 +29,11 @@ class Automata: =20 def __get_model_name(self): basename =3D ntpath.basename(self.__dot_path) - if basename.endswith(".dot") =3D=3D False: + if not basename.endswith(".dot") and not basename.endswith(".gv"): print("not a dot file") raise Exception("not a dot file: %s" % self.__dot_path) =20 - model_name =3D basename[0:-4] + model_name =3D ntpath.splitext(basename)[0] if model_name.__len__() =3D=3D 0: raise Exception("not a dot file: %s" % self.__dot_path) =20 @@ -68,9 +68,9 @@ class Automata: def __get_cursor_begin_events(self): cursor =3D 0 while self.__dot_lines[cursor].split()[0] !=3D "{node": - cursor +=3D 1 + cursor +=3D 1 while self.__dot_lines[cursor].split()[0] =3D=3D "{node": - cursor +=3D 1 + cursor +=3D 1 # skip initial state transition cursor +=3D 1 return cursor @@ -94,11 +94,11 @@ class Automata: initial_state =3D state[7:] else: states.append(state) - if self.__dot_lines[cursor].__contains__("doublecircle") = =3D=3D True: + if "doublecircle" in self.__dot_lines[cursor]: final_states.append(state) has_final_states =3D True =20 - if self.__dot_lines[cursor].__contains__("ellipse") =3D=3D= True: + if "ellipse" in self.__dot_lines[cursor]: final_states.append(state) has_final_states =3D True =20 @@ -110,7 +110,7 @@ class Automata: # Insert the initial state at the bein og the states states.insert(0, initial_state) =20 - if has_final_states =3D=3D False: + if not has_final_states: final_states.append(initial_state) =20 return states, initial_state, final_states @@ -120,7 +120,7 @@ class Automata: cursor =3D self.__get_cursor_begin_events() =20 events =3D [] - while self.__dot_lines[cursor][1] =3D=3D '"': + while self.__dot_lines[cursor].lstrip()[0] =3D=3D '"': # transitions have the format: # "all_fired" -> "both_fired" [ label =3D "disable_irq" ]; # ------------ event is here ------------^^^^^ @@ -161,7 +161,7 @@ class Automata: # and we are back! Let's fill the matrix cursor =3D self.__get_cursor_begin_events() =20 - while self.__dot_lines[cursor][1] =3D=3D '"': + while self.__dot_lines[cursor].lstrip()[0] =3D=3D '"': if self.__dot_lines[cursor].split()[1] =3D=3D "->": line =3D self.__dot_lines[cursor].split() origin_state =3D line[0].replace('"','').replace(',','_') --=20 2.45.2