From cafdef9f4d6063d2ef3b4c9bdbfcec0c6f5476fc Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Wed, 18 Sep 2024 20:13:40 +0300 Subject: [PATCH] debug: debug_stream: Access debug slot directly using cavstool.py Access debug slot directly using cavstool.py, by specifying the debug slot number where the debug_stream data is transferred. Adds one command line parameter for selecting the debug slot directly, adds an alternative mainloop for polling the slot through cavstool.py direct access, and relaxes some often occurring warning print. The warning prints happen when the FW boots and the cavstool code wakes up before the init code has initialized the slot. Signed-off-by: Jyri Sarha --- tools/debug_stream/debug_stream.py | 45 ++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/tools/debug_stream/debug_stream.py b/tools/debug_stream/debug_stream.py index 717845dc49e5..ab621378a8cd 100644 --- a/tools/debug_stream/debug_stream.py +++ b/tools/debug_stream/debug_stream.py @@ -286,7 +286,7 @@ def catch_up(self, slot): self.decode_past_records(slot, circ.w_ptr, circ.next_seqno) self.prev_w_ptr = circ.w_ptr self.prev_seqno = circ.next_seqno - 1 - logging.info("seqno %u w_ptr %u", self.prev_seqno, self.prev_w_ptr) + logging.debug("seqno %u w_ptr %u", self.prev_seqno, self.prev_w_ptr) def decode_past_records(self, slot, pos, seqno): """ @@ -393,6 +393,12 @@ def update_slot(self): self.file.seek(0) self.slot = self.file.read(self.file_size) + def set_slot(self, buf): + """ + Update slot contents + """ + self.slot = buf + def get_descriptors(self): """ Read the core specific descriptors and initialize core @@ -403,7 +409,7 @@ def get_descriptors(self): return False hdr = ctypes.cast(self.slot, ctypes.POINTER(DebugStreamSlotHdr)) if hdr.contents.hdr.magic != DEBUG_STREAM_PAYLOAD_MAGIC: - logging.warning("Debug Slot has bad magic 0x%08x", hdr.contents.hdr.magic) + logging.info("Debug Slot has bad magic 0x%08x", hdr.contents.hdr.magic) return False num_sections = hdr.contents.num_sections if num_sections == len(self.descs): @@ -473,6 +479,32 @@ def reset(self): self.file = None self.slot = None +def cavstool_main_loop(my_args): + import cavstool + try: + (hda, sd, dsp, hda_ostream_id) = cavstool.map_regs(True) + except Exception as e: + logging.error("Could not map device in sysfs; run as root?") + logging.error(e) + sys.exit(1) + + decoder = DebugStreamDecoder() + while True: + if not cavstool.fw_is_alive_dsp(dsp): + cavstool.wait_fw_entered_dsp(dsp, timeout_s=None) + try: + offset = cavstool.debug_slot_offset(my_args.direct_access_slot); + buf = cavstool.win_read(offset, 0, 4096) + decoder.set_slot(buf) + if not decoder.get_descriptors(): + time.sleep(my_args.update_interval) + continue + decoder.catch_up_all() + if decoder.poll(): + time.sleep(my_args.update_interval) + except: + logging.error("win_read() failed") + continue def main_f(my_args): """ @@ -483,6 +515,8 @@ def main_f(my_args): about the host CPU load. That is why there where no synchronous mechanism done and the host simply polls for new records. """ + if my_args.direct_access_slot >= 0: + return cavstool_main_loop(my_args) decoder = DebugStreamDecoder() prev_error = None while True: @@ -527,6 +561,13 @@ def parse_params(): help="File to read the DebugStream data from, default /sys/kernel/debug/sof/debug_stream", default="/sys/kernel/debug/sof/debug_stream", ) + parser.add_argument( + "-c", + "--direct-access-slot", + help="Access specified debug window slot directly, no need for debugfs file", + type=int, + default=-1, + ) parsed_args = parser.parse_args() return parsed_args