From bfaa683c37f82a67aa9e0e2bced48949c8db0e76 Mon Sep 17 00:00:00 2001 From: Hayden Laccabue Date: Mon, 13 Jan 2025 12:13:17 -0800 Subject: [PATCH] Fixing umq log metadata to be inside umq src files Signed-off-by: Hayden Laccabue --- src/shim/hwctx.cpp | 40 ---------------------------------------- src/shim/hwctx.h | 31 ++----------------------------- src/shim/umq/hwctx.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- src/shim/umq/hwctx.h | 24 ++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 70 deletions(-) diff --git a/src/shim/hwctx.cpp b/src/shim/hwctx.cpp index c67fe309..0b61af6d 100644 --- a/src/shim/hwctx.cpp +++ b/src/shim/hwctx.cpp @@ -45,7 +45,6 @@ hw_ctx(const device& dev, const qos_type& qos, std::unique_ptr q, const xr : m_device(dev) , m_q(std::move(q)) , m_doorbell(0) - , m_log_buf(nullptr) , m_syncobj(AMDXDNA_INVALID_FENCE_HANDLE) { shim_debug("Creating HW context..."); @@ -240,45 +239,6 @@ delete_ctx_on_device() struct amdxdna_drm_destroy_hwctx arg = {}; arg.handle = m_handle; m_device.get_pdev().ioctl(DRM_IOCTL_AMDXDNA_DESTROY_HWCTX, &arg); - - fini_log_buf(); -} - -void -hw_ctx:: -set_metadata(int num_cols, size_t size, uint64_t bo_paddr, uint8_t flag) -{ - m_metadata.magic_no = CERT_MAGIC_NO; - m_metadata.major = 0; - m_metadata.minor = 1; - m_metadata.cert_log_flag = flag; - m_metadata.num_cols = num_cols; - for (int i = 0; i < num_cols; i++) { - m_metadata.col_paddr[i] = bo_paddr + size * i + sizeof(m_metadata); - m_metadata.col_size[i] = size; - } -} - -void -hw_ctx:: -init_log_buf() -{ - size_t column_size = 1024; - auto log_buf_size = m_num_cols * column_size + sizeof(m_metadata); - m_log_bo = alloc_bo(nullptr, log_buf_size, XCL_BO_FLAGS_EXECBUF); - m_log_buf = m_log_bo->map(bo::map_type::write); - uint64_t bo_paddr = m_log_bo->get_properties().paddr; - set_metadata(m_num_cols, column_size, bo_paddr, 1); - std::memset(m_log_buf, 0, log_buf_size); - std::memcpy(m_log_buf, &m_metadata, sizeof(m_metadata)); -} - -void -hw_ctx:: -fini_log_buf(void) -{ - if (m_log_bo) - m_log_bo->unmap(m_log_buf); } void diff --git a/src/shim/hwctx.h b/src/shim/hwctx.h index 7693728b..6da1a9ff 100644 --- a/src/shim/hwctx.h +++ b/src/shim/hwctx.h @@ -67,6 +67,8 @@ class hw_ctx : public xrt_core::hwctx_handle protected: const device& get_device(); + uint32_t m_num_cols; + std::unique_ptr m_log_bo; struct cu_info { std::string m_name; @@ -74,25 +76,6 @@ class hw_ctx : public xrt_core::hwctx_handle std::vector m_pdi; }; - enum cert_log_flag { - debug_buffer = 0, - trace_buffer - }; - - struct cert_log_metadata { - #define CERT_MAGIC_NO 0x43455254 // "CERT" - uint32_t magic_no; - uint8_t major; - uint8_t minor; - uint8_t cert_log_flag; - uint8_t num_cols; // how many valid cols, up to 8 for now - uint64_t col_paddr[8]; // device accessible address array for each valid col - uint32_t col_size[8]; // bo size for each valid col - }; - - void - set_metadata(int num_cols, size_t size, uint64_t bo_paddr, uint8_t flag); - const std::vector& get_cu_info() const; @@ -108,25 +91,15 @@ class hw_ctx : public xrt_core::hwctx_handle void create_ctx_on_device(); - void - init_log_buf(); - - void - fini_log_buf(); - private: const device& m_device; slot_id m_handle = AMDXDNA_INVALID_CTX_HANDLE; amdxdna_qos_info m_qos = {}; std::vector m_cu_info; - struct cert_log_metadata m_metadata; std::unique_ptr m_q; uint32_t m_ops_per_cycle; - uint32_t m_num_cols; uint32_t m_doorbell; uint32_t m_syncobj; - std::unique_ptr m_log_bo; - void *m_log_buf; void delete_ctx_on_device(); diff --git a/src/shim/umq/hwctx.cpp b/src/shim/umq/hwctx.cpp index 2d6ab6b3..93cc68c5 100644 --- a/src/shim/umq/hwctx.cpp +++ b/src/shim/umq/hwctx.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright (C) 2023-2024, Advanced Micro Devices, Inc. All rights reserved. +#include "bo.h" #include "hwctx.h" #include "hwq.h" @@ -12,8 +13,9 @@ namespace shim_xdna { hw_ctx_umq:: hw_ctx_umq(const device& device, const xrt::xclbin& xclbin, const xrt::hw_context::qos_type& qos) : hw_ctx(device, qos, std::make_unique(device, 8), xclbin) + , m_metadata() { - hw_ctx::init_log_buf(); + init_log_buf(); hw_ctx::create_ctx_on_device(); shim_debug("Created UMQ HW context (%d)", get_slotidx()); @@ -23,6 +25,7 @@ hw_ctx_umq:: ~hw_ctx_umq() { shim_debug("Destroying UMQ HW context (%d)...", get_slotidx()); + fini_log_buf(); } std::unique_ptr @@ -35,4 +38,41 @@ alloc_bo(void* userptr, size_t size, uint64_t flags) return dev.alloc_bo(userptr, AMDXDNA_INVALID_CTX_HANDLE, size, flags); } +void +hw_ctx_umq:: +init_log_buf() +{ + size_t column_size = 1024; + auto log_buf_size = hw_ctx::m_num_cols * column_size + sizeof(m_metadata); + hw_ctx::m_log_bo = alloc_bo(nullptr, log_buf_size, XCL_BO_FLAGS_EXECBUF); + m_log_buf = hw_ctx::m_log_bo->map(xrt_core::buffer_handle::map_type::write); + uint64_t bo_paddr = hw_ctx::m_log_bo->get_properties().paddr; + set_metadata(hw_ctx::m_num_cols, column_size, bo_paddr, UMQ_DEBUG_BUFFER); + std::memset(m_log_buf, 0, log_buf_size); + std::memcpy(m_log_buf, &m_metadata, sizeof(m_metadata)); +} + +void +hw_ctx_umq:: +fini_log_buf(void) +{ + if (hw_ctx::m_log_bo) + hw_ctx::m_log_bo->unmap(m_log_buf); +} + +void +hw_ctx_umq:: +set_metadata(int num_cols, size_t size, uint64_t bo_paddr, enum umq_log_flag flag) +{ + m_metadata.magic_no = LOG_MAGIC_NO; + m_metadata.major = 0; + m_metadata.minor = 1; + m_metadata.umq_log_flag = flag; + m_metadata.num_cols = num_cols; + for (int i = 0; i < num_cols; i++) { + m_metadata.col_paddr[i] = bo_paddr + size * i + sizeof(m_metadata); + m_metadata.col_size[i] = size; + } +} + } // shim_xdna diff --git a/src/shim/umq/hwctx.h b/src/shim/umq/hwctx.h index ee4ccbc6..141a3895 100644 --- a/src/shim/umq/hwctx.h +++ b/src/shim/umq/hwctx.h @@ -17,6 +17,30 @@ class hw_ctx_umq : public hw_ctx { std::unique_ptr alloc_bo(void* userptr, size_t size, uint64_t flags) override; +private: + #define LOG_MAGIC_NO 0x43455254 + + enum umq_log_flag { + UMQ_DEBUG_BUFFER = 0, + UMQ_TRACE_BUFFER + }; + + struct umq_log_metadata { + uint32_t magic_no; + uint8_t major; + uint8_t minor; + uint8_t umq_log_flag; + uint8_t num_cols; // how many valid cols, up to 8 for now + uint64_t col_paddr[8]; // device accessible address array for each valid col + uint32_t col_size[8]; // bo size for each valid col + }; + + struct umq_log_metadata m_metadata; + void *m_log_buf; + + void init_log_buf(); + void fini_log_buf(); + void set_metadata(int num_cols, size_t size, uint64_t bo_paddr, enum umq_log_flag flag); }; } // shim_xdna