summaryrefslogtreecommitdiff
path: root/tools/tracing/rtla/sample
diff options
context:
space:
mode:
authorTomas Glozar <tglozar@redhat.com>2025-11-26 15:42:01 +0100
committerTomas Glozar <tglozar@redhat.com>2026-01-07 15:57:16 +0100
commit0304a3b7ec9a207637ab6f360a41af5fb25e1f44 (patch)
treef14918df75d14e2ea124d3f527cfe0b74984f8c9 /tools/tracing/rtla/sample
parentf967d1eca7d0bde7c896014577ea876096831c6e (diff)
rtla/timerlat: Add example for BPF action program
Add an example BPF action program that prints the measured latency to the tracefs buffer via bpf_printk(). A new Makefile target, "examples", is added to build the example. In addition, "sample/" subfolder is renamed to "example". If BPF skeleton support is unavailable or disabled, a warning will be displayed when building the BPF action program example. Link: https://lore.kernel.org/r/20251126144205.331954-4-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
Diffstat (limited to 'tools/tracing/rtla/sample')
-rw-r--r--tools/tracing/rtla/sample/timerlat_load.py78
1 files changed, 0 insertions, 78 deletions
diff --git a/tools/tracing/rtla/sample/timerlat_load.py b/tools/tracing/rtla/sample/timerlat_load.py
deleted file mode 100644
index a819c3588073..000000000000
--- a/tools/tracing/rtla/sample/timerlat_load.py
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/usr/bin/env python3
-# SPDX-License-Identifier: GPL-2.0-only
-#
-# Copyright (C) 2024 Red Hat, Inc. Daniel Bristot de Oliveira <bristot@kernel.org>
-#
-# This is a sample code about how to use timerlat's timer by any workload
-# so rtla can measure and provide auto-analysis for the overall latency (IOW
-# the response time) for a task.
-#
-# Before running it, you need to dispatch timerlat with -U option in a terminal.
-# Then # run this script pinned to a CPU on another terminal. For example:
-#
-# timerlat_load.py 1 -p 95
-#
-# The "Timerlat IRQ" is the IRQ latency, The thread latency is the latency
-# for the python process to get the CPU. The Ret from user Timer Latency is
-# the overall latency. In other words, it is the response time for that
-# activation.
-#
-# This is just an example, the load is reading 20MB of data from /dev/full
-# It is in python because it is easy to read :-)
-
-import argparse
-import sys
-import os
-
-parser = argparse.ArgumentParser(description='user-space timerlat thread in Python')
-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 = {args.cpu}
- os.sched_setaffinity(0, affinity_mask)
-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 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 PermissionError:
- print("Permission denied. Please check your access rights.")
- sys.exit(1)
-except OSError:
- print("Error opening timerlat fd, did you run timerlat -U?")
- sys.exit(1)
-
-try:
- data_fd = open("/dev/full", 'r')
-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 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()