Skip to content

Add get_aie_coredump_elf() API for generating coredump (ET_CORE) ELF - #9997

Open
sayyanna wants to merge 6 commits into
Xilinx:masterfrom
sayyanna:coredump_elf
Open

Add get_aie_coredump_elf() API for generating coredump (ET_CORE) ELF#9997
sayyanna wants to merge 6 commits into
Xilinx:masterfrom
sayyanna:coredump_elf

Conversation

@sayyanna

@sayyanna sayyanna commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Problem solved by the commit

Add get_aie_coredump_elf() API for generating coredump (ET_CORE) ELF

Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered

Add get_aie_coredump_elf() API for generating coredump (ET_CORE) ELF. Currently AIE coredump is generated as a raw bin file, but this PR enables generated of coredump in ELF format. The existing get_aie_coredump() raw blob API will be deprecated.

How problem was solved, alternative solutions (if any) and why they were rejected

Added new API that package a raw AIE coredump blob into an ET_CORE ELF using the AIEBU coredump ELF writer:
std::vector
get_aie_coredump_elf(std::optionalxrt::aie::coredump_meta meta = std::nullopt) const;

The AIE architecture is derived from the ELF loaded in this context. Metadata (timestamp, versions, device info, uuid) is always embedded. If @meta is provided it is used as-is; otherwise metadata is built internally from the hw_context and device.
The coredump ELF packaging logic lives in xrt_elf.cpp and is exposed internally via xrt_core::elf_int::make_aie_coredump_elf, keeping xrt_hw_context.cpp free of any direct aiebu dependency.

Packaging the dump as an ET_CORE ELF solves:

  • Self-describing: the ELF header encodes the AIE architecture via the OS/ABI byte, so debuggers and analysis tools can identify the target without extra context
  • Metadata-rich: a dedicated ELF note section carries timestamp, firmware version, device info, ELF UUID, and context state at capture time — critical for correlating a dump with the exact firmware image and system state
  • Integration: callers like XDP can call get_aie_coredump_elf() directly and hand off a self-contained artifact without needing to know anything about the underlying architecture

Risks (if any) associated the changes in the commit

None

What has been tested and how, request additional testing if necessary

Added below setting in xrt.ini
[Runtime]
aie_coredump_file = aie_coredump.elf

Enabled coredump: xrt-smi configure --advanced --auto-coredump --enable
then triggered ERT_COM_STATE_TIMEOUT, coredump is ELF generated.

Documentation impact (if any)

Signed-off-by: Sri Latha Ayyannagari <SriLatha.Ayyannagari@amd.com>
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@stsoe stsoe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment the code, structs, etc.

Comment on lines +1673 to +1678
case aiebu::osabi_aie2p: return aiebu::aiebu_assembler::buffer_type::coredump_aie2p;
case aiebu::osabi_aie2ps: return aiebu::aiebu_assembler::buffer_type::coredump_aie2ps;
case aiebu::osabi_aie4: return aiebu::aiebu_assembler::buffer_type::coredump_aie4;
case aiebu::osabi_aie4a: return aiebu::aiebu_assembler::buffer_type::coredump_aie4a;
case aiebu::osabi_aie4z: return aiebu::aiebu_assembler::buffer_type::coredump_aie4z;
default: throw std::runtime_error("AIE coredump not supported for this ELF architecture");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impossible to debug, please new line after case

Comment on lines +727 to +728
throw std::runtime_error("AIE coredump ELF not available: no ELF loaded in this context");
// All ELFs in one hw_context target the same AIE partition — any entry yields correct OS/ABI

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

Comment on lines +740 to +741
throw std::runtime_error("AIE coredump ELF not available: no ELF loaded in this context");
// All ELFs in one hw_context target the same AIE partition — any entry yields correct OS/ABI

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

Comment on lines +1696 to +1698
auto buf_type = osabi_to_coredump_type(elf.get_handle()->get_os_abi());
aiebu::aiebu_assembler a(buf_type, blob, aiebu::aiebu_assembler::no_meta);
return a.get_elf();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes this XRT code? Should it be in aiebu. Comments may help explain why it is here.

#include <vector>

namespace xrt::aie {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a public API, these structs need extensive comments.
I am not sure about the aie namespace within this file. I need to think about this.

Comment thread src/runtime_src/core/include/xrt/xrt_hw_context.h
@stsoe

stsoe commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

One more question, who is the consumer of these new APIs? If it is XDP, I would argue that they should add this code themselves. E.g. first get the raw coredump from XRT, then re-package it using aiebu.

@larry9523 larry9523 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few high level comments

  1. please add some detail in the PR description about why are we doing this.
  2. I would suggest we only provide one public API get_aie_coredump_elf() internally it will create an ELF coredump with metadata. It does not hurt to add metadata into ELF. (Thanks @stsoe for the input)
  3. I think there is no consumer of xrt.ini path to create aie coredump (I confirm this with @IshitaGhosh and @jvillarre). So while we keep our xrt::hw_context::get_aie_coredump() API, we should generate ELF format coredump with metadata for the xrt,ini path.

Signed-off-by: Sri Latha Ayyannagari <SriLatha.Ayyannagari@amd.com>
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@sayyanna
sayyanna requested review from larry9523 and stsoe August 27, 2026 19:03
Comment thread src/runtime_src/core/include/xrt/xrt_hw_context.h Outdated
Comment thread src/runtime_src/core/common/api/xrt_hw_context.cpp
Comment thread src/runtime_src/core/include/xrt/experimental/xrt_aie_coredump.h Outdated
Signed-off-by: Sri Latha Ayyannagari <SriLatha.Ayyannagari@amd.com>
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Signed-off-by: Sri Latha Ayyannagari <SriLatha.Ayyannagari@amd.com>
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Comment thread src/runtime_src/core/common/api/xrt_elf.cpp
Comment on lines +1733 to +1739
for (const auto& entry : data) {
if (std::stoi(entry.metadata.id) == islot) {
meta.context_status = entry.is_suspended
? aiebu::aie_context_status::idle
: aiebu::aie_context_status::running;
break;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One less scope with early-continue

Suggested change
for (const auto& entry : data) {
if (std::stoi(entry.metadata.id) == islot) {
meta.context_status = entry.is_suspended
? aiebu::aie_context_status::idle
: aiebu::aie_context_status::running;
break;
}
for (const auto& entry : data) {
if (std::stoi(entry.metadata.id) != islot)
continue;
meta.context_status = entry.is_suspended
? aiebu::aie_context_status::idle
: aiebu::aie_context_status::running;
break;
}

Comment on lines +1671 to +1692
namespace {

aiebu::aiebu_assembler::buffer_type
osabi_to_coredump_type(uint8_t os_abi)
{
switch (os_abi) {
case aiebu::osabi_aie2p:
return aiebu::aiebu_assembler::buffer_type::coredump_aie2p;
case aiebu::osabi_aie2ps:
return aiebu::aiebu_assembler::buffer_type::coredump_aie2ps;
case aiebu::osabi_aie4:
return aiebu::aiebu_assembler::buffer_type::coredump_aie4;
case aiebu::osabi_aie4a:
return aiebu::aiebu_assembler::buffer_type::coredump_aie4a;
case aiebu::osabi_aie4z:
return aiebu::aiebu_assembler::buffer_type::coredump_aie4z;
default:
throw std::runtime_error("AIE coredump not supported for this ELF architecture");
}
}

} // namespace

@stsoe stsoe Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't scope the anonymous namespace inside a named namespace, move it out, or make this a static function within current namespace to keep the proximity to where it is used.

Comment thread src/runtime_src/core/common/api/xrt_hw_context.cpp
if (!ostr)
throw std::runtime_error("Could not open '" + file + "' for writing");
ostr.write(core.data(), static_cast<std::streamsize>(core.size()));
std::abort();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was a mention that we should not abort on coredump, but the original spec said we should. I want to make sure remove std::abort() is indeed correct.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the std::abort() to make sure driver clean up hw_context after timeout. We don't have to get the exception message and coredump() at one run. When usesrs set xrt.ini to save aie coredump, they already see the timeout and exception message.

Signed-off-by: Sri Latha Ayyannagari <SriLatha.Ayyannagari@amd.com>
@sayyanna
sayyanna requested a review from stsoe August 28, 2026 21:51
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Signed-off-by: Sri Latha Ayyannagari <SriLatha.Ayyannagari@amd.com>
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@stsoe stsoe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Minor corrections.

: "";
}

aiebu::aiebu_assembler::buffer_type

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was previously in a nested unnamed namespace, I suggested either moving the namespace or making the function static,

Suggested change
aiebu::aiebu_assembler::buffer_type
static aiebu::aiebu_assembler::buffer_type

Comment on lines +1709 to +1710
for (const auto& kv : *drivers) {
const auto& drv = kv.second;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is generally preferred to use structured bindings for anything return tuples.

Suggested change
for (const auto& kv : *drivers) {
const auto& drv = kv.second;
for (const auto& [dummy, drv] : *drivers) {

Comment on lines +733 to +734
return xrt_core::elf_int::make_aie_coredump_elf(
elf, get_aie_coredump(), m_core_device.get(), m_hdl->get_slotidx(), "");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You defaulted the uuid string in make_aie_coredump_elf, which I think is fine, but then this function should not mention anything about UUID and not call with the empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants