| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 |
|
| 23 | import argparse
|
| 24 | import sys
|
| 25 | import os
|
| 26 |
|
| 27 | parser = argparse.ArgumentParser(description='user-space timerlat thread in Python')
|
| 28 | parser.add_argument("cpu", type=int, help='CPU to run timerlat thread')
|
| 29 | parser.add_argument("-p", "--prio", type=int, help='FIFO priority')
|
| 30 | args = parser.parse_args()
|
| 31 |
|
| 32 | try:
|
| 33 | affinity_mask = {args.cpu}
|
| 34 | os.sched_setaffinity(0, affinity_mask)
|
| 35 | except Exception as e:
|
| 36 | print(f"Error setting affinity: {e}")
|
| 37 | sys.exit(1)
|
| 38 |
|
| 39 | if args.prio:
|
| 40 | try:
|
| 41 | param = os.sched_param(args.prio)
|
| 42 | os.sched_setscheduler(0, os.SCHED_FIFO, param)
|
| 43 | except Exception as e:
|
| 44 | print(f"Error setting priority: {e}")
|
| 45 | sys.exit(1)
|
| 46 |
|
| 47 | try:
|
| 48 | timerlat_path = f"/sys/kernel/tracing/osnoise/per_cpu/cpu{args.cpu}/timerlat_fd"
|
| 49 | timerlat_fd = open(timerlat_path, 'r')
|
| 50 | except PermissionError:
|
| 51 | print("Permission denied. Please check your access rights.")
|
| 52 | sys.exit(1)
|
| 53 | except OSError:
|
| 54 | print("Error opening timerlat fd, did you run timerlat -U?")
|
| 55 | sys.exit(1)
|
| 56 |
|
| 57 | try:
|
| 58 | data_fd = open("/dev/full", 'r')
|
| 59 | except Exception as e:
|
| 60 | print(f"Error opening data fd: {e}")
|
| 61 | sys.exit(1)
|
| 62 |
|
| 63 | while True:
|
| 64 | try:
|
| 65 | timerlat_fd.read(1)
|
| 66 | data_fd.read(20 * 1024 * 1024)
|
| 67 | except KeyboardInterrupt:
|
| 68 | print("Leaving")
|
| 69 | break
|
| 70 | except IOError as e:
|
| 71 | print(f"I/O error occurred: {e}")
|
| 72 | break
|
| 73 | except Exception as e:
|
| 74 | print(f"Unexpected error: {e}")
|
| 75 | break
|
| 76 |
|
| 77 | timerlat_fd.close()
|
| 78 | data_fd.close()
|