From patchwork Mon Oct 21 15:09:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: furkanonder X-Patchwork-Id: 13844307 Received: from mail-43167.protonmail.ch (mail-43167.protonmail.ch [185.70.43.167]) (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 70FA11E7677 for ; Mon, 21 Oct 2024 15:09:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.167 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729523398; cv=none; b=FmpQ21xd1FCeYFUCzgn7xvZWkI2xqODk20FZg+dN8bOA589lrJKy7sIgST45kCNxPvfGaok8kLtwiama9vfzzcutaHJJ9a8vNiactpfwJYA2ijt3QyWO416tS+NrSB4J1O21nlpgBkMMl783SAOXKZ1l/ApOJYpkB5fusP8CtMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729523398; c=relaxed/simple; bh=OAKnrF9PbQPXN2zL+sd729+YEGzaw2BAleB0dTwGd8Q=; h=Date:To:From:Subject:Message-ID:MIME-Version:Content-Type; b=Y4g3q+Y55HUlTBUa0vtip4dN3gFV654nyis1jllFaA4WQa+OqhGz/5xGB5/pcNceLUWpIXMKY3JeS8bbwUdV10uKR0D3po7ncBQjspvXaEZGMzq2yiD+XiTnmbPHS/gSBp90pvGiPDpFjloOCwFsXnRaUZs5uOv3L7oD7A0eYcw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com; spf=pass smtp.mailfrom=protonmail.com; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b=Hc/JGGax; arc=none smtp.client-ip=185.70.43.167 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=protonmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="Hc/JGGax" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1729523394; x=1729782594; bh=l+mvs6tC4XZj5bklobGjgot0p9GYS0+sFbq/olZPyME=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=Hc/JGGaxsC1Oy3viwo1hbbhkq0sDRm/xKHFwt4idGxHa+Rcig8kXkKsd0mRDUNrzS x8yyZyX5pqG63HMypG+TPhgW300VdLf/4/nYNZ2rZGMOjGT9XYJcJXhA2QPQGMFZaJ 0j0CSD9XOwChxnq94LdYTAXL9g12BKwRY3dbKEUuHEdCaoWX5vPwmQ1gRKC3PkBAZy YEvZBzTJ57ksvxX+LVrvTjgbxHGKilE+08VBmXa5ZbFd3SD2yjbpmncahzV9IDtjXe TmIfJVLpFXed3ZifGBY96cElYSMulTjN9LMFcRi3pqmYIhXsmwger4eKeyaaFJ88jV giudi25wKRdVQ== Date: Mon, 21 Oct 2024 15:09:49 +0000 To: Steven Rostedt , "linux-trace-kernel@vger.kernel.org" , "jkacur@redhat.com" , "lgoncalv@redhat.com" From: furkanonder Subject: [PATCH 1/3] tools/rtla: Improve code readability in timerlat_load.py Message-ID: Feedback-ID: 14203677:user:proton X-Pm-Message-ID: 7cbe195337aa8ca8787a18a32bfba264c3c7ff9c Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Signed-off-by: Furkan Onder Reviewed-by: Tomas Glozar --- tools/tracing/rtla/sample/timerlat_load.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.46.2 diff --git a/tools/tracing/rtla/sample/timerlat_load.py b/tools/tracing/rtla/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) try: - os.sched_setaffinity(0, affinity_mask); + os.sched_setaffinity(0, affinity_mask) except: print("Error setting affinity") exit(1) -if (args.prio): +if args.prio: try: param = os.sched_param(int(args.prio)) os.sched_setscheduler(0, os.SCHED_FIFO, param) @@ -51,21 +51,21 @@ if (args.prio): exit(1) try: - timerlat_path = "/sys/kernel/tracing/osnoise/per_cpu/cpu" + args.cpu + "/timerlat_fd" + timerlat_path = f"/sys/kernel/tracing/osnoise/per_cpu/cpu{args.cpu}/timerlat_fd" timerlat_fd = open(timerlat_path, 'r') except: print("Error opening timerlat fd, did you run timerlat -U?") exit(1) try: - data_fd = open("/dev/full", 'r'); + data_fd = open("/dev/full", 'r') except: print("Error opening data fd") while True: try: timerlat_fd.read(1) - data_fd.read(20*1024*1024) + data_fd.read(20 * 1024 * 1024) except: print("Leaving") break From patchwork Mon Oct 21 15:12:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: furkanonder X-Patchwork-Id: 13844320 Received: from mail-40138.protonmail.ch (mail-40138.protonmail.ch [185.70.40.138]) (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 E78E2EEB3 for ; Mon, 21 Oct 2024 15:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729523557; cv=none; b=pM7OBkY3vnm3Hf454u9K5AiZD7yY92DItQWXlvbswgWfsDlS1ebZQqWcSJ+HYEcFGzpBgFfPMyVy6BOZ1U0FV9Lt5p9daciSnMfS2dkR3dZlDrj/gfaCXB6HY5qIG2vol6DhBYwDgJHkqHFzaMVxgiO8D1/HCsd3kNhZLF6UBLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729523557; c=relaxed/simple; bh=/7szG3PAqfXzV8t7UG4JaXhWW4TfaX18M2awcP+JgBc=; h=Date:To:From:Subject:Message-ID:MIME-Version:Content-Type; b=Z6moezD4DeENzDlb1STaEeLhTPFfoJuBwojql+3K2MROe4XT/9go4enSBf5RntFQOdprQcPTVIDTc+Gt8to3QviCIXmQJCkj4O7vP9wkR8ZXNvC3ntJglEfldsgM2WkEDN7CS4ka3WfVSwxoKxIqHGZMc4DlCUH/mUN2CsEjXiU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com; spf=pass smtp.mailfrom=protonmail.com; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b=GhfqOiPp; arc=none smtp.client-ip=185.70.40.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=protonmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="GhfqOiPp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1729523553; x=1729782753; bh=1F6nYZrULMrKSJtAH7AwqAAQMwKeUs78FTcF6trmiTA=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=GhfqOiPpwTF6iKZtesj/e98Zv11V5PN4594go76xxNq1k7Bt6SVBskgIRQkqbu+7t mezXdw2xEZ+lm6En1DOYQEe0uA/NgLdpXfIsl7Wf48J4PUM7u/ntRsY0XL8QK8VgQ+ DYkhIWv5NAJij0grznoJJb51odRqP/3naggf15OWMJZ+Sux87dYWdd3HZFnmbToXy+ 7SomkfI+XykW4bgvjfXk8PHDkoLHOBQ5P8FTE3HksF42GMaMAhBhQY57WhdNgp+hme 5sykoA1rhKRoxuJ5b9vIcdLOYIbXzQEBK3O7lZX+wdBDq4RDwoM5FZDnWYDqSwCPdJ w8PvWfC54HHDw== Date: Mon, 21 Oct 2024 15:12:30 +0000 To: Steven Rostedt , "linux-trace-kernel@vger.kernel.org" , "jkacur@redhat.com" , "lgoncalv@redhat.com" , Tomas Glozar From: furkanonder Subject: [PATCH 2/3] tools/rtla: Enhance argument parsing in timerlat_load.py Message-ID: Feedback-ID: 14203677:user:proton X-Pm-Message-ID: 2fe6d93847a806265c7ac52074f461d0af11be54 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The enhancements made to timerlat_load.py are aimed at improving the clarity 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. Signed-off-by: Furkan Onder Reviewed-by: Tomas Glozar --- tools/tracing/rtla/sample/timerlat_load.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) -- 2.46.2 diff --git a/tools/tracing/rtla/sample/timerlat_load.py b/tools/tracing/rtla/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 parser = argparse.ArgumentParser(description='user-space timerlat thread in Python') -parser.add_argument("cpu", help='CPU to run timerlat thread') -parser.add_argument("-p", "--prio", help='FIFO priority') - +parser.add_argument("cpu", type=int, help='CPU to run timerlat thread') +parser.add_argument("-p", "--prio", type=int, help='FIFO priority') args = parser.parse_args() try: - affinity_mask = { int(args.cpu) } + affinity_mask = {args.cpu} except: print("Invalid cpu: " + args.cpu) exit(1) @@ -44,7 +43,7 @@ except: if args.prio: try: - param = os.sched_param(int(args.prio)) + param = os.sched_param(args.prio) os.sched_setscheduler(0, os.SCHED_FIFO, param) except: print("Error setting priority") From patchwork Mon Oct 21 15:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: furkanonder X-Patchwork-Id: 13844325 Received: from mail-43166.protonmail.ch (mail-43166.protonmail.ch [185.70.43.166]) (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 208FD1F9AAA for ; Mon, 21 Oct 2024 15:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.166 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729523644; cv=none; b=qOZskcJTxcg2CDWPU50pqoJTDU4makfUBwSGjcJKc+1Tfc/K4fEbnsscU7xKtquQz9wVTiJxnhm7WZp9Vgt2J+rl8lQhFPA6T+MAdvUQHWddF7kwDC5rHzhReJxpPgRbYgSRvlwk92E7TjcrRrHdFt6n94ji2d+WoOvB2WucsFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729523644; c=relaxed/simple; bh=WqwyJPFrX14EIYPb8NlDkhijgJLXM1i58qlxJzwdzUI=; h=Date:To:From:Subject:Message-ID:MIME-Version:Content-Type; b=Hp8RcWImTaXMKhL1rFQ1HoE+VcmmWbeUe++EBV82OuJBxAvlofCzdNpa2g2bVw9m9e4xENJAmJtRSRoggOegetyNqzFPPO2PLGpEA5f4Ch/6oTd8gFCLiISKXNDRM6k2c/bPPVg3xdCACZWIIHiS0zw3ONO+sHTei+GY4ruIWyY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com; spf=pass smtp.mailfrom=protonmail.com; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b=LM42rcxd; arc=none smtp.client-ip=185.70.43.166 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=protonmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="LM42rcxd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1729523641; x=1729782841; bh=PVPeEX/Ul854Zb5vevT8sNbYHxTrQfiI9hsvWrSh50U=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=LM42rcxdqSbt1ZMdTDHIa/ea9frAWDq/1bwYrFGoyUZ5I1k1aTC8UPQqEeQaBFydz SbN9jJlJP4Y+8eF5s+vOXJIs6FkT9CEp8bgZStO8fCAlX7YgQXCJqvEXgbwFiWbei7 OErSlyrgvmQzUgzvfUzUH6vnqIjDOTFXYlI+6w5YNbm7QG/cUXrT/0N/wE5OqsAF+q ixWowGhxOJCjpFeDFHF3O3EasqNjl9t3dbQapCB0sCP3ZWFbIjVYOzQuFcoag8nMhh eStAkeXFASJzu1hXAYitee7f6xkYAQuFct+BEXWEmCWppah3WaVB8NVA2W4vFu28Xg Wwb2q9uUmsKKw== Date: Mon, 21 Oct 2024 15:13:57 +0000 To: Tomas Glozar , "lgoncalv@redhat.com" , "jkacur@redhat.com" , "linux-trace-kernel@vger.kernel.org" , Steven Rostedt From: furkanonder Subject: [PATCH 3/3] tools/rtla: Improve exception handling in timerlat_load.py Message-ID: Feedback-ID: 14203677:user:proton X-Pm-Message-ID: 7be97eec64c3fdebc1d45f9ab1d692f0aa8623d1 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The enhancements made to timerlat_load.py are intended to improve the script'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. Signed-off-by: Furkan Onder Reviewed-by: Tomas Glozar --- tools/tracing/rtla/sample/timerlat_load.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) -- 2.46.2 diff --git a/tools/tracing/rtla/sample/timerlat_load.py b/tools/tracing/rtla/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 = parser.parse_args() try: affinity_mask = {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) if args.prio: try: param = 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) try: timerlat_path = f"/sys/kernel/tracing/osnoise/per_cpu/cpu{args.cpu}/timerlat_fd" timerlat_fd = 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) try: data_fd = open("/dev/full", 'r') -except: - print("Error opening data fd") +except Exception as e: + print(f"Error opening data fd: {e}") + sys.exit(1) 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 timerlat_fd.close() data_fd.close()