Skip to content

Commit

Permalink
remove forcibly unchaining runlist hack (#254)
Browse files Browse the repository at this point in the history
Signed-off-by: Max Zhen <max.zhen@amd.com>
  • Loading branch information
maxzhen authored Sep 13, 2024
1 parent b902461 commit b326815
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 93 deletions.
2 changes: 0 additions & 2 deletions src/shim/bo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ alloc_bo()
amdxdna_drm_get_bo_info bo_info = {};
get_drm_bo_info(m_pdev, boh, &bo_info);
m_bo = std::make_unique<bo::drm_bo>(*this, bo_info);
m_pdev.insert_hdl_mapping(boh, reinterpret_cast<uint64_t>(this));
}

void
Expand All @@ -248,7 +247,6 @@ void
bo::
free_bo()
{
m_pdev.remove_hdl_mapping(get_drm_bo_handle());
m_bo.reset();
}

Expand Down
51 changes: 2 additions & 49 deletions src/shim/hwq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,7 @@ void
hw_q::
submit_command(xrt_core::buffer_handle *cmd)
{
auto pkt = get_chained_command_pkt(cmd);
if (!m_pdev.is_force_unchained_command() || !pkt) {
issue_command(cmd);
return;
}

// HACK: Forcibly unchain commands, to be removed later.
//
// Forcibly unchain commands and send to driver one by one.
auto payload = get_ert_cmd_chain_data(pkt);
for (size_t i = 0; i < payload->command_count; i++) {
auto boh = reinterpret_cast<xrt_core::buffer_handle*>(
m_pdev.lookup_hdl_mapping(static_cast<uint32_t>(payload->data[i])));
issue_command(boh);
}
issue_command(cmd);
}

int
Expand All @@ -119,40 +105,7 @@ wait_command(xrt_core::buffer_handle *cmd, uint32_t timeout_ms) const
{
if (poll_command(cmd))
return 1;

auto pkt = get_chained_command_pkt(cmd);
if (!m_pdev.is_force_unchained_command() || !pkt)
return wait_cmd(m_pdev, m_hwctx, cmd, timeout_ms);

// HACK: handling forcibly unchained commands, to be removed later.
//
// Wait for the last unchained command.
auto payload = get_ert_cmd_chain_data(pkt);
auto last_boh = reinterpret_cast<xrt_core::buffer_handle*>(
m_pdev.lookup_hdl_mapping(static_cast<uint32_t>(payload->data[payload->command_count-1])));
auto ret = wait_cmd(m_pdev, m_hwctx, last_boh, timeout_ms);
if (ret != 1)
return ret;

// Check the state of the last command.
auto cmdpkt = reinterpret_cast<ert_packet *>(last_boh->map(xrt_core::buffer_handle::map_type::read));
if (cmdpkt->state == ERT_CMD_STATE_COMPLETED) {
pkt->state = ERT_CMD_STATE_COMPLETED;
return 1;
}

// Find out the first command failed.
for (int i = 0; i < payload->command_count; i++) {
auto boh = reinterpret_cast<xrt_core::buffer_handle*>(
m_pdev.lookup_hdl_mapping(static_cast<uint32_t>(payload->data[i])));
cmdpkt = reinterpret_cast<ert_packet *>(boh->map(xrt_core::buffer_handle::map_type::read));
if (cmdpkt->state != ERT_CMD_STATE_COMPLETED) {
pkt->state = cmdpkt->state;
payload->error_index = i;
break;
}
}
return 1;
return wait_cmd(m_pdev, m_hwctx, cmd, timeout_ms);
}

void
Expand Down
16 changes: 2 additions & 14 deletions src/shim/pcidev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "pcidrv.h"
#include "shim_debug.h"
#include "drm_local/amdxdna_accel.h"
#include "core/common/config_reader.h"
#include "core/common/trace.h"

namespace {
Expand Down Expand Up @@ -71,10 +70,6 @@ namespace shim_xdna {
pdev::
pdev(std::shared_ptr<const drv> driver, std::string sysfs_name)
: xrt_core::pci::dev(driver, std::move(sysfs_name))
// Default of force_unchained_command should be false once command
// chaining is natively supported by driver/firmware.
, m_force_unchained_command(xrt_core::config::detail::get_bool_value(
"Debug.force_unchained_command", false))
{
m_is_ready = true; // We're always ready.
}
Expand All @@ -99,7 +94,7 @@ pdev::
open() const
{
int fd;
const std::lock_guard<std::recursive_mutex> lock(m_lock);
const std::lock_guard<std::mutex> lock(m_lock);

if (m_dev_users == 0) {
fd = xrt_core::pci::dev::open("", O_RDWR);
Expand All @@ -120,7 +115,7 @@ pdev::
close() const
{
int fd;
const std::lock_guard<std::recursive_mutex> lock(m_lock);
const std::lock_guard<std::mutex> lock(m_lock);

--m_dev_users;
if (m_dev_users == 0) {
Expand Down Expand Up @@ -162,12 +157,5 @@ munmap(void* addr, size_t len) const
::munmap(addr, len);
}

bool
pdev::
is_force_unchained_command() const
{
return m_force_unchained_command;
}

} // namespace shim_xdna

29 changes: 1 addition & 28 deletions src/shim/pcidev.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,6 @@ class pdev : public xrt_core::pci::dev
void
close() const;

bool
is_force_unchained_command() const;

// Below routines are for managing drm_bo_hdl -> buffer_handle* mapping.
// This is only a temporary hack for supporting forcibly unchained runlist.
void
insert_hdl_mapping(uint32_t hdl, uint64_t ptr) const
{
const std::lock_guard<std::recursive_mutex> lock(m_lock);
m_hdl_map[hdl] = ptr;
}
void
remove_hdl_mapping(uint32_t hdl) const
{
const std::lock_guard<std::recursive_mutex> lock(m_lock);
m_hdl_map.erase(hdl);
}
uint64_t
lookup_hdl_mapping(uint32_t hdl) const
{
const std::lock_guard<std::recursive_mutex> lock(m_lock);
return m_hdl_map[hdl];
}

private:
virtual void
on_first_open() const {}
Expand All @@ -75,10 +51,7 @@ class pdev : public xrt_core::pci::dev

mutable int m_dev_fd = -1;
mutable int m_dev_users = 0;
mutable std::recursive_mutex m_lock;
const bool m_force_unchained_command = true;
// Mark it as mutable since pdev does not look at what is saved in this map
mutable std::map<uint32_t, uint64_t> m_hdl_map;
mutable std::mutex m_lock;
};

} // namespace shim_xdna
Expand Down

0 comments on commit b326815

Please sign in to comment.