Skip to content

Commit fbe0825

Browse files
committed
Add cmd bo restore header in umq shim
Signed-off-by: Hayden Laccabue <hlaccabu@amd.com>
1 parent 3a1f2ed commit fbe0825

File tree

7 files changed

+94
-161
lines changed

7 files changed

+94
-161
lines changed

src/shim/umq/hwq.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ hwq_umq::
185185
issue_single_exec_buf(const cmd_buffer *cmd_bo, bool last_of_chain)
186186
{
187187
auto cmd = reinterpret_cast<ert_start_kernel_cmd *>(cmd_bo->vaddr());
188+
auto handle = cmd_bo->id().handle;
189+
190+
// Restore header if this is a resubmission
191+
auto it = m_cmd_header_cache.find(handle);
192+
if (it != m_cmd_header_cache.end()) {
193+
cmd->header = it->second;
194+
}
195+
188196
auto dpu = get_ert_dpu_data(cmd);
189197

190198
// Sanity check
@@ -198,6 +206,10 @@ issue_single_exec_buf(const cmd_buffer *cmd_bo, bool last_of_chain)
198206
shim_err(EINVAL, "No dpu data, invalid exec buf");
199207
}
200208

209+
if (it == m_cmd_header_cache.end()) {
210+
m_cmd_header_cache[handle] = cmd->header;
211+
}
212+
201213
auto slot_idx = get_next_avail_slot();
202214

203215
if (get_ert_dpu_data_next(dpu))
@@ -316,6 +328,14 @@ issue_command(const cmd_buffer *cmd_bo)
316328
return issue_single_exec_buf(cmd_bo, true);
317329

318330
// Runlist command submission.
331+
auto handle = cmd_bo->id().handle;
332+
333+
// Restore chain BO header is this is a resubmission
334+
auto it = m_cmd_header_cache.find(handle);
335+
if (it != m_cmd_header_cache.end()) {
336+
cmd->header = it->second;
337+
}
338+
319339
auto payload = get_ert_cmd_chain_data(cmd);
320340
if (payload->command_count == 0 || payload->command_count > 100)
321341
shim_err(EINVAL, "Runlist exec buf with bad num of subcmds: %zx", payload->command_count);
@@ -329,6 +349,12 @@ issue_command(const cmd_buffer *cmd_bo)
329349
seq = issue_single_exec_buf(subcmd, i == payload->command_count - 1);
330350
subcmds.push_back(subcmd);
331351
}
352+
353+
// Cache chain BO header on first submission
354+
if (it == m_cmd_header_cache.end()) {
355+
m_cmd_header_cache[handle] = cmd->header;
356+
}
357+
332358
return seq;
333359
}
334360

src/shim/umq/hwq.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class hwq_umq : public hwq
5656

5757
uint64_t
5858
issue_single_exec_buf(const cmd_buffer *cmd_bo, bool last_of_chain);
59+
60+
// Cache for command buffer headers (firmware corrupts them)
61+
// Key: BO handle, Value: cached header word
62+
std::map<uint32_t, uint32_t> m_cmd_header_cache;
5963
};
6064

6165
}

test/shim_test/dev_info.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ xclbin_info xclbin_infos[] = {
7474
.type = KERNEL_TYPE_TXN_FULL_ELF,
7575
},
7676
{
77-
.name = "nop.xclbin",
77+
.name = "nop.elf",
7878
.device = npu3_device_id,
7979
.revision_id = npu_any_revision_id,
8080
.ip_name2idx = {
@@ -96,7 +96,7 @@ xclbin_info xclbin_infos[] = {
9696
.type = KERNEL_TYPE_TXN_FULL_ELF,
9797
},
9898
{
99-
.name = "nop.xclbin",
99+
.name = "nop.elf",
100100
.device = npu3_device_id1,
101101
.revision_id = npu_any_revision_id,
102102
.ip_name2idx = {

test/shim_test/io.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -948,32 +948,6 @@ get_preemption_checkpoints()
948948
return 0;
949949
}
950950

951-
void
952-
io_test_bo_set_base::
953-
cache_cmd_header()
954-
{
955-
auto cbo = m_bo_array[IO_TEST_BO_CMD].tbo.get();
956-
if (!cbo)
957-
return;
958-
auto pkt = reinterpret_cast<ert_packet *>(cbo->map());
959-
if (!m_cached_cmd_header)
960-
m_cached_cmd_header = pkt->header;
961-
}
962-
963-
void
964-
io_test_bo_set_base::
965-
restore_cmd_header()
966-
{
967-
auto cbo = m_bo_array[IO_TEST_BO_CMD].tbo.get();
968-
if (!cbo || !m_cached_cmd_header)
969-
return;
970-
971-
auto pkt = reinterpret_cast<ert_packet *>(cbo->map());
972-
pkt->header = m_cached_cmd_header;
973-
pkt->state = ERT_CMD_STATE_NEW;
974-
std::atomic_thread_fence(std::memory_order_seq_cst);
975-
}
976-
977951
unsigned long
978952
elf_preempt_io_test_bo_set::
979953
get_preemption_checkpoints()

test/shim_test/io.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ class io_test_bo_set_base
7070
virtual void
7171
verify_result();
7272

73-
void
74-
cache_cmd_header();
75-
76-
void
77-
restore_cmd_header();
78-
7973
static const char *
8074
bo_type2name(int type);
8175

@@ -96,7 +90,6 @@ class io_test_bo_set_base
9690
const int m_FLAG_OPT = 1 << 1;
9791
const int m_FLAG_NO_FILL = 1 << 2;
9892
const int m_FLAG_DEV_BUF = 1 << 3;
99-
uint32_t m_cached_cmd_header = 0;
10093

10194
void
10295
create_data_bo_from_file(io_test_bo& ibo, const std::string filename, int flags);

0 commit comments

Comments
 (0)