Skip to contentSkip to conversation

tools/tracing: Last minute updates for 6.13

PATCH New Steven Rostedt 1 participant 6 messages Nov 18, 2024

Subsystems (2)
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: 5f99dca95f3c208abb2b8757a2a2bd671d04d7e0

Gabriele Monaco (1):
verification/dot2: Improve dot parser robustness

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 +-
 tools/verification/dot2/automata.py        | 18 +++++-----
 4 files changed, 41 insertions(+), 37 deletions(-)
author maintainer
#1 lore raw

PATCH 1/5 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/5 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/5 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/5 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
author maintainer
#5 lore raw

PATCH 5/5 verification/dot2: Improve dot parser robustness

In reply to Steven Rostedt

From: Gabriele Monaco <[email protected]>

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 ...

---
 tools/verification/dot2/automata.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
tools/verification/dot2/automata.py +9 -9
index baffeb960ff0..bdeb98baa8b0 100644
@@ -29,11 +29,11 @@ class Automata:
 
     def __get_model_name(self):
         basename = ntpath.basename(self.__dot_path)
-        if basename.endswith(".dot") == 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)
 
-        model_name = basename[0:-4]
+        model_name = ntpath.splitext(basename)[0]
         if model_name.__len__() == 0:
             raise Exception("not a dot file: %s" % self.__dot_path)
 
@@ -68,9 +68,9 @@ class Automata:
     def __get_cursor_begin_events(self):
         cursor = 0
         while self.__dot_lines[cursor].split()[0] != "{node":
-           cursor += 1
+            cursor += 1
         while self.__dot_lines[cursor].split()[0] == "{node":
-           cursor += 1
+            cursor += 1
         # skip initial state transition
         cursor += 1
         return cursor
@@ -94,11 +94,11 @@ class Automata:
                 initial_state = state[7:]
             else:
                 states.append(state)
-                if self.__dot_lines[cursor].__contains__("doublecircle") == True:
+                if "doublecircle" in self.__dot_lines[cursor]:
                     final_states.append(state)
                     has_final_states = True
 
-                if self.__dot_lines[cursor].__contains__("ellipse") == True:
+                if "ellipse" in self.__dot_lines[cursor]:
                     final_states.append(state)
                     has_final_states = True
 
@@ -110,7 +110,7 @@ class Automata:
         # Insert the initial state at the bein og the states
         states.insert(0, initial_state)
 
-        if has_final_states == False:
+        if not has_final_states:
             final_states.append(initial_state)
 
         return states, initial_state, final_states
@@ -120,7 +120,7 @@ class Automata:
         cursor = self.__get_cursor_begin_events()
 
         events = []
-        while self.__dot_lines[cursor][1] == '"':
+        while self.__dot_lines[cursor].lstrip()[0] == '"':
             # transitions have the format:
             # "all_fired" -> "both_fired" [ label = "disable_irq" ];
             #  ------------ event is here ------------^^^^^
@@ -161,7 +161,7 @@ class Automata:
         # and we are back! Let's fill the matrix
         cursor = self.__get_cursor_begin_events()
 
-        while self.__dot_lines[cursor][1] == '"':
+        while self.__dot_lines[cursor].lstrip()[0] == '"':
             if self.__dot_lines[cursor].split()[1] == "->":
                 line = self.__dot_lines[cursor].split()
                 origin_state = line[0].replace('"','').replace(',','_')
Signature · 1 line
2.45.2