Skip to content

Commit

Permalink
Merge pull request #466 from rradjabi/aws-2018_2-data-retention
Browse files Browse the repository at this point in the history
AWS 2018.2 Data Retention
  • Loading branch information
sonals authored Oct 16, 2018
2 parents 7c13004 + b2998d9 commit 4f8f73f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 33 deletions.
21 changes: 11 additions & 10 deletions src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,8 @@ int xocl_drm_init(struct xocl_dev *xdev)
void xocl_drm_fini(struct xocl_dev *xdev)
{
xocl_cleanup_mem(xdev);

xocl_cleanup_connectivity(xdev);
drm_put_dev(xdev->ddev);

mutex_destroy(&xdev->ctx_list_lock);
mutex_destroy(&xdev->stat_lock);
mutex_destroy(&xdev->mm_lock);
Expand Down Expand Up @@ -504,14 +503,6 @@ void xocl_cleanup_mem(struct xocl_dev *xdev)
u16 i, ddr;

topology = xdev->topology;

vfree(xdev->layout);
xdev->layout = NULL;
vfree(xdev->debug_layout);
xdev->debug_layout = NULL;
vfree(xdev->connectivity);
xdev->connectivity = NULL;

if (topology == NULL)
return;

Expand All @@ -531,6 +522,16 @@ void xocl_cleanup_mem(struct xocl_dev *xdev)
xdev->topology = NULL;
}

void xocl_cleanup_connectivity(struct xocl_dev *xdev)
{
vfree(xdev->layout);
xdev->layout = NULL;
vfree(xdev->debug_layout);
xdev->debug_layout = NULL;
vfree(xdev->connectivity);
xdev->connectivity = NULL;
}

ssize_t xocl_mm_sysfs_stat(struct xocl_dev *xdev, char *buf, bool raw)
{
int i;
Expand Down
1 change: 1 addition & 0 deletions src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ int xocl_drm_init(struct xocl_dev *xdev);
void xocl_drm_fini(struct xocl_dev *xdev);

void xocl_cleanup_mem(struct xocl_dev *xdev);
void xocl_cleanup_connectivity(struct xocl_dev *xdev);
int xocl_check_topology(struct xocl_dev *xdev);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)
Expand Down
58 changes: 41 additions & 17 deletions src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr)
size_t size_of_header;
size_t num_of_sections;
size_t size;
int preserve_mem = 0;
struct mem_topology *new_topology;

userpf_info(xdev, "READ_AXLF IOCTL\n");

Expand Down Expand Up @@ -509,12 +511,6 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr)
goto done;
}

//Switching the xclbin, make sure none of the buffers are used.
err = xocl_check_topology(xdev);
if(err)
goto done;

xocl_cleanup_mem(xdev);

//Copy from user space and proceed.
size_of_header = sizeof(struct axlf_section_header);
Expand All @@ -540,6 +536,42 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr)
goto done;
}

/* Populating MEM_TOPOLOGY sections. */
size = xocl_read_sect(MEM_TOPOLOGY, &new_topology, axlf, buf);
if (size <= 0) {
if (size != 0)
goto done;
} else if (sizeof_sect(new_topology, m_mem_data) != size) {
err = -EINVAL;
goto done;
}

/* Compare MEM_TOPOLOGY previous vs new. Ignore this and keep disable preserve_mem if not for aws.*/
if (xocl_is_aws(xdev) && (xdev->topology != NULL)) {
if ( (size == sizeof_sect(xdev->topology, m_mem_data)) &&
!memcmp(new_topology, xdev->topology, size) ) {
printk(KERN_INFO "XOCL: MEM_TOPOLOGY match, preserve mem_topology.\n");
preserve_mem = 1;
} else {
printk(KERN_INFO "XOCL: MEM_TOPOLOGY mismatch, do not preserve mem_topology.\n");
}
}

/* Switching the xclbin, make sure none of the buffers are used. */
if (!preserve_mem) {
err = xocl_check_topology(xdev);
if(err)
goto done;
xocl_cleanup_mem(xdev);
}
xocl_cleanup_connectivity(xdev);

/* Copy MEM_TOPOLOGY from new_toplogy if not preserving memory. */
if (!preserve_mem)
xdev->topology = new_topology;
else
vfree(new_topology);

/* Populating IP_LAYOUT sections */
/* zocl_read_sect return size of section when successfully find it */
size = xocl_read_sect(IP_LAYOUT, &xdev->layout, axlf, buf);
Expand Down Expand Up @@ -571,20 +603,12 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr)
goto done;
}

/* Populating MEM_TOPOLOGY sections */
size = xocl_read_sect(MEM_TOPOLOGY, &xdev->topology, axlf, buf);
if (size <= 0) {
if (size != 0)
if (!preserve_mem) {
err = xocl_init_mm(xdev);
if (err)
goto done;
} else if (sizeof_sect(xdev->topology, m_mem_data) != size) {
err = -EINVAL;
goto done;
}

err = xocl_init_mm(xdev);
if (err)
goto done;

//Populate with "this" bitstream, so avoid redownload the next time
xdev->unique_id_last_bitstream = bin_obj.m_uniqueId;
uuid_copy(&xdev->xclbin_id, &bin_obj.m_header.uuid);
Expand Down
27 changes: 21 additions & 6 deletions src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,36 @@ namespace awsbwhal {
return retVal;

if ( (xclbin_id_from_sysfs == 0) || (axlfbuffer->m_uniqueId != xclbin_id_from_sysfs) || checkAndSkipReload(afi_id, &orig_info) ) {
// proceed with download
retVal = fpga_mgmt_load_local_image(mBoardNumber, afi_id);
if (!retVal) {
retVal = sleepUntilLoaded( std::string(afi_id) );
// force data retention option
union fpga_mgmt_load_local_image_options opt;
fpga_mgmt_init_load_local_image_options(&opt);
opt.flags = FPGA_CMD_DRAM_DATA_RETENTION;
opt.afi_id = afi_id;
opt.slot_id = mBoardNumber;
retVal = fpga_mgmt_load_local_image_with_options(&opt);
if (retVal == FPGA_ERR_DRAM_DATA_RETENTION_NOT_POSSIBLE ||
retVal == FPGA_ERR_DRAM_DATA_RETENTION_FAILED ||
retVal == FPGA_ERR_DRAM_DATA_RETENTION_SETUP_FAILED) {
std::cout << "INFO: Could not load AFI for data retention, code: " << retVal
<< " - Loading in classic mode." << std::endl;
retVal = fpga_mgmt_load_local_image(mBoardNumber, afi_id);
}
// check retVal from image load
if (retVal) {
std::cout << "Failed to load AFI, error: " << retVal << std::endl;
return -retVal;
}
retVal = sleepUntilLoaded( std::string(afi_id) );
if (!retVal) {
drm_xocl_axlf axlf_obj = { reinterpret_cast<axlf*>(const_cast<xclBin*>(buffer)) };
retVal = ioctl(mUserHandle, DRM_IOCTL_XOCL_READ_AXLF, &axlf_obj);
if (retVal) {
std::cout << "IOCTL DRM_IOCTL_XOCL_READ_AXLF Failed: " << retVal << std::endl;
} else {
std::cout << "AFI load complete." << std::endl;
std::cout << "AFI load complete." << std::endl;
}
}
}
}
return retVal;
} else {
//char* afi_id = get_afi_from_xclBin(buffer);
Expand Down

0 comments on commit 4f8f73f

Please sign in to comment.