From 38303cdc2fe4fafe3812e43b99ebe8b50b287a83 Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Wed, 9 Sep 2020 17:53:31 -0400 Subject: [PATCH] vlsim: host_buffer optimization --- driver/opae/vlsim/opae_sim.cpp | 29 ++++++++++------------------- driver/opae/vlsim/opae_sim.h | 5 ++--- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/driver/opae/vlsim/opae_sim.cpp b/driver/opae/vlsim/opae_sim.cpp index bddb9f79..dcfbd9f2 100644 --- a/driver/opae/vlsim/opae_sim.cpp +++ b/driver/opae/vlsim/opae_sim.cpp @@ -65,21 +65,24 @@ int opae_sim::prepare_buffer(uint64_t len, void **buf_addr, uint64_t *wsid, int host_buffer_t buffer; buffer.data = (uint64_t*)alloc; buffer.size = len; - buffer.ioaddr = intptr_t(alloc) / CACHE_BLOCK_SIZE; + buffer.ioaddr = uintptr_t(alloc); auto index = host_buffers_.size(); - host_buffers_.push_back(buffer); + host_buffers_.emplace(index, buffer); *buf_addr = alloc; *wsid = index; return 0; } void opae_sim::release_buffer(uint64_t wsid) { - free(host_buffers_[wsid].data); - host_buffers_.erase(host_buffers_.begin() + wsid); + auto it = host_buffers_.find(wsid); + if (it != host_buffers_.end()) { + free(it->second.data); + host_buffers_.erase(it); + } } void opae_sim::get_io_address(uint64_t wsid, uint64_t *ioaddr) { - *ioaddr = host_buffers_[wsid].ioaddr * CACHE_BLOCK_SIZE; + *ioaddr = host_buffers_[wsid].ioaddr; } void opae_sim::write_mmio64(uint32_t mmio_num, uint64_t offset, uint64_t value) { @@ -201,7 +204,7 @@ void opae_sim::sTxPort_bus() { cci_rd_req_t cci_req; cci_req.cycles_left = CCI_LATENCY + (timestamp % CCI_RAND_MOD); cci_req.mdata = vortex_afu_->af2cp_sTxPort_c0_hdr_mdata; - auto host_ptr = this->to_host_ptr(vortex_afu_->af2cp_sTxPort_c0_hdr_address); + auto host_ptr = (uint64_t*)(vortex_afu_->af2cp_sTxPort_c0_hdr_address * CACHE_BLOCK_SIZE); memcpy(cci_req.block.data(), host_ptr, CACHE_BLOCK_SIZE); cci_reads_.push_back(cci_req); } @@ -211,7 +214,7 @@ void opae_sim::sTxPort_bus() { cci_wr_req_t cci_req; cci_req.cycles_left = CCI_LATENCY + (timestamp % CCI_RAND_MOD); cci_req.mdata = vortex_afu_->af2cp_sTxPort_c1_hdr_mdata; - auto host_ptr = this->to_host_ptr(vortex_afu_->af2cp_sTxPort_c1_hdr_address); + auto host_ptr = (uint64_t*)(vortex_afu_->af2cp_sTxPort_c1_hdr_address * CACHE_BLOCK_SIZE); memcpy(host_ptr, vortex_afu_->af2cp_sTxPort_c1_data, CACHE_BLOCK_SIZE); cci_writes_.push_back(cci_req); } @@ -273,16 +276,4 @@ void opae_sim::avs_bus() { } vortex_afu_->avs_waitrequest = dram_stalled; -} - -uint64_t* opae_sim::to_host_ptr(uint64_t ioaddr) { - for (auto& buffer : host_buffers_) { - if (ioaddr >= buffer.ioaddr - && ioaddr < (buffer.ioaddr + buffer.size)) { - return buffer.data + (ioaddr - buffer.ioaddr) * (CACHE_BLOCK_SIZE / 8); - } - } - printf("error: to_host_ptr(0x%lx) failed\n", ioaddr); - std::abort(); - return nullptr; } \ No newline at end of file diff --git a/driver/opae/vlsim/opae_sim.h b/driver/opae/vlsim/opae_sim.h index 1c03075f..9a4906eb 100644 --- a/driver/opae/vlsim/opae_sim.h +++ b/driver/opae/vlsim/opae_sim.h @@ -14,6 +14,7 @@ #include #include #include +#include #define CACHE_BLOCK_SIZE 64 @@ -70,12 +71,10 @@ private: void sTxPort_bus(); void avs_bus(); - uint64_t* to_host_ptr(uint64_t addr); - std::future future_; bool stop_; - std::vector host_buffers_; + std::unordered_map host_buffers_; std::vector dram_reads_;