Skip to content

Commit

Permalink
debug: debug_stream: Access debug slot directly using cavstool.py
Browse files Browse the repository at this point in the history
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 <jyri.sarha@linux.intel.com>
  • Loading branch information
Jyri Sarha committed Sep 20, 2024
1 parent 88cde10 commit cafdef9
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions tools/debug_stream/debug_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit cafdef9

Please sign in to comment.