tools/tracing/rtla/example/timerlat_load.py
Source file repositories/reference/linux-study-clean/tools/tracing/rtla/example/timerlat_load.py
File Facts
- System
- Linux kernel
- Corpus path
tools/tracing/rtla/example/timerlat_load.py- Extension
.py- Size
- 2368 bytes
- Lines
- 79
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/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:
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.