Skip to contentSkip to conversation

tools/tracing: Last minute updates for 6.13

PATCH New Steven Rostedt 1 participant 5 messages Nov 18, 2024 Real-time Linux Analysis (rtla) tools

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover tools/tracing: Last minute updates for 6.13

git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
tools/for-next

Head SHA1: 355e9195bf25b828efc853417600179678c85ac0

Tomas Glozar (1):

      rtla/timerlat: Do not set params->user_workload with -U

furkanonder (3):
tools/rtla: Improve code readability in timerlat_load.py tools/rtla: Enhance argument parsing in timerlat_load.py tools/rtla: Improve exception handling in timerlat_load.py

----

 tools/tracing/rtla/sample/timerlat_load.py | 56 ++++++++++++++++--------------
 tools/tracing/rtla/src/timerlat_hist.c     |  2 +-
 tools/tracing/rtla/src/timerlat_top.c      |  2 +-
 3 files changed, 32 insertions(+), 28 deletions(-)
author maintainer
#1 lore raw

PATCH 1/4 rtla/timerlat: Do not set params->user_workload with -U

From: Tomas Glozar <[email protected]>

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.

Fixes fb9e90a67ee9 ("rtla/timerlat: Make user-space threads

the default")

---
 tools/tracing/rtla/src/timerlat_hist.c | 2 +-
 tools/tracing/rtla/src/timerlat_top.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/tracing/rtla/src/timerlat_hist.c +1 -1
index 01dd337da13a..8b66387e5f35 100644
@@ -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 = tracefs_file_exists(NULL, "osnoise/per_cpu/cpu0/timerlat_fd");
 		if (retval) {
 			debug_msg("User-space interface detected, setting user-threads\n");
tools/tracing/rtla/src/timerlat_top.c +1 -1
index fca0da3caa87..f7422948205d 100644
@@ -839,7 +839,7 @@ timerlat_top_apply_config(struct osnoise_tool *top, struct 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 = tracefs_file_exists(NULL, "osnoise/per_cpu/cpu0/timerlat_fd");
 		if (retval) {
 			debug_msg("User-space interface detected, setting user-threads\n");
Signature · 1 line
2.45.2
author maintainer
#2 lore raw

PATCH 2/4 tools/rtla: Improve code readability in timerlat_load.py

In reply to Steven Rostedt

From: furkanonder <[email protected]>

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.

---
 tools/tracing/rtla/sample/timerlat_load.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/tracing/rtla/sample/timerlat_load.py +5 -5
index 8cc5eb2d2e69..785e9a83539a 100644
@@ -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
Signature · 1 line
2.45.2
author maintainer
#3 lore raw

PATCH 3/4 tools/rtla: Enhance argument parsing in timerlat_load.py

In reply to Steven Rostedt

From: furkanonder <[email protected]>

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.

---
 tools/tracing/rtla/sample/timerlat_load.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
tools/tracing/rtla/sample/timerlat_load.py +4 -5
index 785e9a83539a..d7341ed5127a 100644
@@ -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")
Signature · 1 line
2.45.2
author maintainer
#4 lore raw

PATCH 4/4 tools/rtla: Improve exception handling in timerlat_load.py

In reply to Steven Rostedt

From: furkanonder <[email protected]>

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.
---
 tools/tracing/rtla/sample/timerlat_load.py | 37 ++++++++++++----------
 1 file changed, 21 insertions(+), 16 deletions(-)
tools/tracing/rtla/sample/timerlat_load.py +21 -16
index d7341ed5127a..a819c3588073 100644
@@ -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()
Signature · 1 line
2.45.2