Skip to content

Commit

Permalink
Initial changes to remove hardcoded cu size check in shim.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Manoj Takasi <[email protected]>
(cherry picked from commit 2e4cc90)
  • Loading branch information
Manoj Takasi committed Aug 5, 2024
1 parent 390bb02 commit 6e83fe4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/runtime_src/core/edge/user/shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ shim(unsigned index)
: mCoreDevice(xrt_core::edge_linux::get_userpf_device(this, index))
, mBoardNumber(index)
, mKernelClockFreq(100)
, mCuMaps(128, nullptr)
, mCuMaps(128, {nullptr, 0})
{
xclLog(XRT_INFO, "%s", __func__);

Expand Down Expand Up @@ -151,8 +151,8 @@ shim::
}

for (auto p : mCuMaps) {
if (p)
(void) munmap(p, mCuMapSize);
if (p.first)
(void) munmap(p.first, p.second);
}
}

Expand Down Expand Up @@ -1169,10 +1169,10 @@ xclCloseContext(const uuid_t xclbinId, unsigned int ipIndex)

if (ipIndex < mCuMaps.size()) {
// Make sure no MMIO register space access when CU is released.
uint32_t *p = mCuMaps[ipIndex];
uint32_t *p = mCuMaps[ipIndex].first;
if (p) {
(void) munmap(p, mCuMapSize);
mCuMaps[ipIndex] = nullptr;
(void) munmap(p, mCuMaps[ipIndex].second);
mCuMaps[ipIndex] = {nullptr, 0};
}
}

Expand Down Expand Up @@ -1201,16 +1201,17 @@ xclRegRW(bool rd, uint32_t ipIndex, uint32_t offset, uint32_t *datap)
return -EINVAL;
}

if (mCuMaps[ipIndex] == nullptr) {
if (mCuMaps[ipIndex].first == nullptr) {
drm_zocl_info_cu info = {0, -1, (int)ipIndex};
int result = ioctl(mKernelFD, DRM_IOCTL_ZOCL_INFO_CU, &info);
void *p = mmap(0, mCuMapSize, PROT_READ | PROT_WRITE, MAP_SHARED,
mKernelFD, info.apt_idx * getpagesize());
if (p != MAP_FAILED)
mCuMaps[ipIndex] = (uint32_t *)p;
mCuMaps[ipIndex].first = (uint32_t *)p;
mCuMaps[ipIndex].second = mCuMapSize;
}

uint32_t *cumap = mCuMaps[ipIndex];
uint32_t *cumap = mCuMaps[ipIndex].first;
if (cumap == nullptr) {
xclLog(XRT_ERROR, "%s: can't map CU: %d", __func__, ipIndex);
return -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/edge/user/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class shim {
* Mapped CU register space for xclRegRead/Write(). We support at most
* 128 CUs and each map is of 64k bytes. Does not support debug IP access.
*/
std::vector<uint32_t*> mCuMaps;
std::vector<std::pair<uint32_t*, uint32_t>> mCuMaps;
const size_t mCuMapSize = 64 * 1024;
std::mutex mCuMapLock;
int xclRegRW(bool rd, uint32_t cu_index, uint32_t offset, uint32_t *datap);
Expand Down

0 comments on commit 6e83fe4

Please sign in to comment.