Skip to content

Commit

Permalink
Slot reuse (#8587)
Browse files Browse the repository at this point in the history
* Initial changes for reusing slots

Signed-off-by: bisingha <bikash.singha@amd.com>

* Releasing a slot only if no hwctx alive on it

Signed-off-by: bisingha <bikash.singha@amd.com>

* Adjusted previous commits

Signed-off-by: bisingha <bikash.singha@amd.com>

---------

Signed-off-by: bisingha <bikash.singha@amd.com>
  • Loading branch information
bisingha-xilinx authored Nov 10, 2024
1 parent 771bc00 commit 9edc3a0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ static int zocl_pr_slot_init(struct drm_zocl_dev *zdev,
zocl_slot->partial_overlay_id = -1;
zocl_slot->slot_idx = i;
zocl_slot->slot_type = ZOCL_SLOT_TYPE_PHY;
zocl_slot->hwctx_ref_cnt = 0;

zdev->pr_slot[i] = zocl_slot;
}
Expand Down
65 changes: 36 additions & 29 deletions src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ get_legacy_slot(struct drm_zocl_dev *zdev, struct axlf *axlf, int* slot_id)
static int
get_free_slot(struct drm_zocl_dev *zdev, struct axlf *axlf, int* slot_id)
{
int s_id = -1;
/* xclbin contains PL section use fixed slot */
if (xrt_xclbin_get_section_num(axlf, IP_LAYOUT)) {
DRM_WARN("Xclbin contains PL section Using Slot-0");
Expand All @@ -92,17 +93,38 @@ get_free_slot(struct drm_zocl_dev *zdev, struct axlf *axlf, int* slot_id)

struct drm_zocl_slot *slot = NULL;
for (int i = 1; i < MAX_PR_SLOT_NUM; i++) {
if (!(zdev->slot_mask & (1 << i))) {
zdev->slot_mask |= 1 << i;
*slot_id = i;
if (zdev->slot_mask & (1 << i)) {
slot = zdev->pr_slot[i];
if (!slot) {
DRM_ERROR("Slot[%d] doesn't exists or Invaid slot", i);
return -EINVAL;
if (slot) {
mutex_lock(&slot->slot_xclbin_lock);
if (zocl_xclbin_same_uuid(slot, &axlf->m_header.uuid)) {
// xclbin already downloaded to ith slot
DRM_INFO("The XCLBIN %pUb already loaded to slot %d", &axlf->m_header.uuid, i);
*slot_id = i;
mutex_unlock(&slot->slot_xclbin_lock);
return 0;
}
mutex_unlock(&slot->slot_xclbin_lock);
}
DRM_INFO("Found free Slot-%d is selected for xclbin \n", i);
return 0;
}
else if (!(zdev->slot_mask & (1 << i)) && (s_id < 0)) {
// found a free slot
s_id = i;
}
}

if (s_id > 0) {
slot = zdev->pr_slot[s_id];
if (!slot) {
DRM_ERROR("%s: slot %d doesn't exists or invalid", __func__, s_id);
return -EINVAL;
}
DRM_INFO("Found a free slot %d for XCLBIN %pUb", s_id, &axlf->m_header.uuid);
// acquiring the free slot
zdev->slot_mask |= 1 << s_id;
*slot_id = s_id;
return 0;

}
return -ENOMEM; // All bits are set
}
Expand Down Expand Up @@ -175,11 +197,11 @@ zocl_read_axlf_ioctl(struct drm_device *ddev, void *data, struct drm_file *filp)
int slot_id = -1;
int ret = 0;
ret = zocl_identify_slot(zdev, axlf_obj, client, &slot_id, false /*hw_ctx_flow*/);
if (ret < 0) {
if (ret < 0 || slot_id < 0) {
DRM_WARN("Unable to allocate slot for xclbin.");
return ret;
}
DRM_INFO(" Allocated slot %d to load xclbin in device\n.", slot_id);
DRM_INFO("Allocated slot %d to load xclbin in device.\n", slot_id);

return zocl_xclbin_read_axlf(zdev, axlf_obj, client, slot_id);
}
Expand All @@ -201,11 +223,11 @@ int zocl_create_hw_ctx_ioctl(struct drm_device *dev, void *data, struct drm_file
return -EFAULT;
}
ret = zocl_identify_slot(zdev, &axlf_obj, client, &slot_id, true /*hw_ctx_flow*/);
if (ret < 0) {
if (ret < 0 || slot_id < 0) {
DRM_WARN("Unable to allocate slot for xclbin.");
return ret;
}
DRM_INFO(" Allocated slot %d to load xclbin in hw_context\n.", slot_id);
DRM_INFO("Allocated slot %d to load xclbin in hw_context.\n", slot_id);

ret = zocl_xclbin_read_axlf(zdev, &axlf_obj, client, slot_id);
if (ret) {
Expand All @@ -223,23 +245,8 @@ int zocl_destroy_hw_ctx_ioctl(struct drm_device *dev, void *data, struct drm_fil
{
struct drm_zocl_dev *zdev = ZOCL_GET_ZDEV(dev);
struct drm_zocl_destroy_hw_ctx *drm_hw_ctx = (struct drm_zocl_destroy_hw_ctx *)data;
int ret = 0;
int slot_id = -1;
struct kds_client_hw_ctx *kds_hw_ctx = NULL;
struct kds_client *client = filp->driver_priv;
mutex_lock(&client->lock);
kds_hw_ctx = kds_get_hw_ctx_by_id(client, drm_hw_ctx->hw_context);
if (!kds_hw_ctx) {
DRM_ERROR("%s: No valid hw context is open", __func__);
mutex_unlock(&client->lock);
return -EINVAL;
}
slot_id = kds_hw_ctx->slot_idx;
mutex_unlock(&client->lock);
ret = zocl_destroy_hw_ctx(zdev, drm_hw_ctx, filp);
//TODO do it under lock
zdev->slot_mask &= ~(1 << slot_id);
return ret;

return zocl_destroy_hw_ctx(zdev, drm_hw_ctx, filp);
}

/*
Expand Down
10 changes: 10 additions & 0 deletions src/runtime_src/core/edge/drm/zocl/edge/zocl_hwctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ int zocl_create_hw_ctx(struct drm_zocl_dev *zdev, struct drm_zocl_create_hw_ctx
goto error_out;
}
drm_hw_ctx->hw_context = kds_hw_ctx->hw_ctx_idx;
//increase the count for this slot. decrease the count for destroy hw ctx
slot->hwctx_ref_cnt++;

error_out:
mutex_unlock(&client->lock);
Expand All @@ -55,6 +57,7 @@ int zocl_destroy_hw_ctx(struct drm_zocl_dev *zdev, struct drm_zocl_destroy_hw_ct
struct drm_zocl_slot *slot = NULL;
struct kds_client *client = filp->driver_priv;
int ret = 0;
u32 s_id = -1;

if (!client) {
DRM_ERROR("%s: Invalid client", __func__);
Expand All @@ -76,7 +79,14 @@ int zocl_destroy_hw_ctx(struct drm_zocl_dev *zdev, struct drm_zocl_destroy_hw_ct
mutex_unlock(&client->lock);
return -EINVAL;
}

s_id = kds_hw_ctx->slot_idx;
ret = kds_free_hw_ctx(client, kds_hw_ctx);
if (--slot->hwctx_ref_cnt == 0) {
zdev->slot_mask &= ~(1 << s_id);
DRM_DEBUG("Released the slot %d", s_id);
}

mutex_unlock(&client->lock);
return ret;
}
Expand Down
1 change: 1 addition & 0 deletions src/runtime_src/core/edge/drm/zocl/include/zocl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ struct drm_zocl_slot {
struct mutex aie_lock;
struct aie_info *aie_information;
struct zocl_aie *aie;
u32 hwctx_ref_cnt;
};

struct zocl_cu_subdev {
Expand Down

0 comments on commit 9edc3a0

Please sign in to comment.