From 850784ba0d884220caef5c4144b53164e25e84a6 Mon Sep 17 00:00:00 2001 From: rradjabi Date: Thu, 13 Sep 2018 11:25:01 -0700 Subject: [PATCH 01/13] * separate connectivity cleanup from xocl_cleanup_mem(). --- .../driver/xclng/drm/xocl/userpf/xocl_drm.c | 19 +++++++++++-------- .../driver/xclng/drm/xocl/userpf/xocl_drm.h | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.c b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.c index ddbddc6af4b..547d34730fc 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.c +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.c @@ -437,6 +437,7 @@ 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); @@ -504,14 +505,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; @@ -531,6 +524,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; diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.h b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.h index fa2449313fc..a208985130f 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.h +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.h @@ -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) From 2739a085fdc9d5949376a23e6bdfcab3714e2463 Mon Sep 17 00:00:00 2001 From: rradjabi Date: Thu, 13 Sep 2018 13:38:44 -0700 Subject: [PATCH 02/13] * data retention enabled but needs testing on F1. --- .../driver/xclng/drm/xocl/userpf/xocl_ioctl.c | 66 ++++++++++++++----- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c index 1ae6ffc9951..8505d685a4a 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c @@ -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"); @@ -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); @@ -539,7 +535,45 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) err = -EFAULT; goto done; } + + + /* 1, read MEM_TOPOLOGY */ + /* Populating MEM_TOPOLOGY sections */ + size = xocl_read_sect(MEM_TOPOLOGY, new_toplogy.topology, axlf, buf); + if (size <= 0) { + if (size != 0) + goto done; + } else if (sizeof_sect(new_toplogy.topology, m_mem_data) != size) { + err = -EINVAL; + goto done; + } + /* 2, compare MEM_TOPOLOGY */ + if (xdev->topology != NULL) { + if (!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"); + } + } + + /* 3, cleanup */ + //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); + + /* 4, copy MEM_TOPOLOGY from new_toplogy if !preserve_mem */ + if (!preserve_mem) { + xdev->topology = new_topology; + new_topology = NULL; + } + /* 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); @@ -571,19 +605,15 @@ 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) - 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; + + + + if (!preserve_mem) { + 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; From 28efc16840785b55fd1efc9a71b627d0ba050659 Mon Sep 17 00:00:00 2001 From: Cloud User Date: Thu, 13 Sep 2018 23:03:24 +0000 Subject: [PATCH 03/13] Changes to build xocl --- src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c index 8505d685a4a..d6bb00ad080 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c @@ -448,7 +448,7 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) size_t num_of_sections; size_t size; int preserve_mem = 0; - struct mem_topology new_topology; + struct mem_topology *new_topology; userpf_info(xdev, "READ_AXLF IOCTL\n"); @@ -539,11 +539,11 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) /* 1, read MEM_TOPOLOGY */ /* Populating MEM_TOPOLOGY sections */ - size = xocl_read_sect(MEM_TOPOLOGY, new_toplogy.topology, axlf, buf); + size = xocl_read_sect(MEM_TOPOLOGY, &new_topology, axlf, buf); if (size <= 0) { if (size != 0) goto done; - } else if (sizeof_sect(new_toplogy.topology, m_mem_data) != size) { + } else if (sizeof_sect(new_topology, m_mem_data) != size) { err = -EINVAL; goto done; } @@ -571,7 +571,6 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) /* 4, copy MEM_TOPOLOGY from new_toplogy if !preserve_mem */ if (!preserve_mem) { xdev->topology = new_topology; - new_topology = NULL; } /* Populating IP_LAYOUT sections */ From 1289c7b07061ec17962d8ac1f1661da2833c0be1 Mon Sep 17 00:00:00 2001 From: Ryan Radjabi <32471108+rradjabi@users.noreply.github.com> Date: Wed, 19 Sep 2018 17:04:11 -0700 Subject: [PATCH 04/13] Load with data retention enabled. --- .../driver/xclng/xrt/user_aws/shim.cpp | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp b/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp index 1dc52ee2e7f..72733b5e375 100755 --- a/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp +++ b/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp @@ -166,22 +166,29 @@ namespace awsbwhal { if( int retVal = xclGetXclBinIdFromSysfs( xclbin_id_from_sysfs ) != 0 ) 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) ); + if ( (xclbin_id_from_sysfs == 0) || (axlfbuffer->m_uniqueId != xclbin_id_from_sysfs) || checkA ndSkipReload(afi_id, &orig_info) ) { + // 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) { + std::cout << "fpga_mgmt_load_local_image_with_options() failed, error: " << retVal << std::endl; + return -EINVAL; } + retVal = sleepUntilLoaded( std::string(afi_id) ); if (!retVal) { drm_xocl_axlf axlf_obj = { reinterpret_cast(const_cast(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); From b51e46f8ab11a99a5c660c5ab107448f61111c88 Mon Sep 17 00:00:00 2001 From: Amr Monawir Date: Mon, 24 Sep 2018 20:22:12 +0100 Subject: [PATCH 05/13] support for backward compatibility Added backward compatibility to shim.cpp --- src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp b/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp index 72733b5e375..96cf1af1760 100755 --- a/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp +++ b/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp @@ -166,7 +166,7 @@ namespace awsbwhal { if( int retVal = xclGetXclBinIdFromSysfs( xclbin_id_from_sysfs ) != 0 ) return retVal; - if ( (xclbin_id_from_sysfs == 0) || (axlfbuffer->m_uniqueId != xclbin_id_from_sysfs) || checkA ndSkipReload(afi_id, &orig_info) ) { + if ( (xclbin_id_from_sysfs == 0) || (axlfbuffer->m_uniqueId != xclbin_id_from_sysfs) || checkAndSkipReload(afi_id, &orig_info) ) { // force data retention option union fpga_mgmt_load_local_image_options opt; fpga_mgmt_init_load_local_image_options(&opt); @@ -174,9 +174,17 @@ namespace awsbwhal { 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 << "fpga_mgmt_load_local_image_with_options() failed, error: " << retVal << std::endl; - return -EINVAL; + std::cout << "Failed to load AFI, error: " << retVal << std::endl; + return -retVal; } retVal = sleepUntilLoaded( std::string(afi_id) ); if (!retVal) { From 746364f62e82d8c9cdcfef269a2bfbf13ee0b389 Mon Sep 17 00:00:00 2001 From: Ryan Radjabi <32471108+rradjabi@users.noreply.github.com> Date: Tue, 2 Oct 2018 11:38:13 -0700 Subject: [PATCH 06/13] Whitespace changes spaces -> tabs --- .../driver/xclng/drm/xocl/userpf/xocl_drm.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.c b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.c index 547d34730fc..231dba21eaa 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.c +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_drm.c @@ -437,10 +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); - + 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); @@ -526,12 +524,12 @@ void xocl_cleanup_mem(struct xocl_dev *xdev) 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; + 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) From 119753faef76c1e0b7d933ba88a724a39d359881 Mon Sep 17 00:00:00 2001 From: Ryan Radjabi <32471108+rradjabi@users.noreply.github.com> Date: Tue, 2 Oct 2018 11:44:23 -0700 Subject: [PATCH 07/13] Whitespace changes --- .../driver/xclng/drm/xocl/userpf/xocl_ioctl.c | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c index d6bb00ad080..fcd231f588a 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c @@ -447,8 +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; + int preserve_mem = 0; + struct mem_topology *new_topology; userpf_info(xdev, "READ_AXLF IOCTL\n"); @@ -535,10 +535,8 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) err = -EFAULT; goto done; } - - /* 1, read MEM_TOPOLOGY */ - /* Populating MEM_TOPOLOGY sections */ + /* Populating MEM_TOPOLOGY sections. */ size = xocl_read_sect(MEM_TOPOLOGY, &new_topology, axlf, buf); if (size <= 0) { if (size != 0) @@ -548,31 +546,30 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) goto done; } - /* 2, compare MEM_TOPOLOGY */ - if (xdev->topology != NULL) { - if (!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"); - } - } - - /* 3, cleanup */ - //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); - - /* 4, copy MEM_TOPOLOGY from new_toplogy if !preserve_mem */ - if (!preserve_mem) { - xdev->topology = new_topology; - } - + /* Compare MEM_TOPOLOGY previous vs new. */ + if (xdev->topology != NULL) { + if (!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; + } + /* 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); From f9a852d4db443079e97251b306751de1a15719ce Mon Sep 17 00:00:00 2001 From: Ryan Radjabi <32471108+rradjabi@users.noreply.github.com> Date: Tue, 2 Oct 2018 11:47:15 -0700 Subject: [PATCH 08/13] Whitespace changes to shim.cpp --- src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp b/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp index 96cf1af1760..b1dd2091cb3 100755 --- a/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp +++ b/src/runtime_src/driver/xclng/xrt/user_aws/shim.cpp @@ -174,13 +174,13 @@ namespace awsbwhal { 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) { + 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); - } + 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; @@ -194,7 +194,7 @@ namespace awsbwhal { std::cout << "IOCTL DRM_IOCTL_XOCL_READ_AXLF Failed: " << retVal << std::endl; } else { std::cout << "AFI load complete." << std::endl; - } + } } } return retVal; From e8a1ac5c182b162b45af08dbd43784d58a416917 Mon Sep 17 00:00:00 2001 From: Ryan Radjabi <32471108+rradjabi@users.noreply.github.com> Date: Tue, 2 Oct 2018 11:49:30 -0700 Subject: [PATCH 09/13] Whitespace in xocl_ioctl.c --- .../driver/xclng/drm/xocl/userpf/xocl_ioctl.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c index fcd231f588a..3046147806f 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c @@ -601,15 +601,11 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) goto done; } - - - - - if (!preserve_mem) { - err = xocl_init_mm(xdev); - if (err) - goto done; - } + if (!preserve_mem) { + 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; From a8df983be7936240548419c238c6f9e2f08e4079 Mon Sep 17 00:00:00 2001 From: rradjabi Date: Fri, 5 Oct 2018 12:24:08 -0700 Subject: [PATCH 10/13] adds logic for memcmp\nrefs rradjabi/XRT#5 --- src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c index 3046147806f..70d14e2aedd 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c @@ -548,9 +548,11 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) /* Compare MEM_TOPOLOGY previous vs new. */ if (xdev->topology != NULL) { - if (!memcmp(new_topology, xdev->topology, size)) { + // m_mem_data can be of different length but we would not compare them if topology match fails + if (!memcmp(new_topology, xdev->topology, size) && + (sizeof_sect(new_topology, m_mem_data) == sizeof_sect(xdev->topology, m_mem_data))) { printk(KERN_INFO "XOCL: MEM_TOPOLOGY match, preserve mem_topology.\n"); - preserve_mem =1; + preserve_mem = 1; } else { printk(KERN_INFO "XOCL: MEM_TOPOLOGY mismatch, do not preserve mem_topology.\n"); } From a6cac4a2070235de82159114cd524c81050aea56 Mon Sep 17 00:00:00 2001 From: rradjabi Date: Fri, 5 Oct 2018 12:26:28 -0700 Subject: [PATCH 11/13] free new_topology when preserving memory\nrefs rradjabi/XRT#4 --- src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c index 70d14e2aedd..30a8e491691 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c @@ -568,9 +568,10 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) xocl_cleanup_connectivity(xdev); /* Copy MEM_TOPOLOGY from new_toplogy if not preserving memory. */ - if (!preserve_mem) { + 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 */ From b60c91502e9aea75b56162178edab12748848ce5 Mon Sep 17 00:00:00 2001 From: rradjabi Date: Fri, 5 Oct 2018 12:32:35 -0700 Subject: [PATCH 12/13] check for aws device before setting preserve_mem=1\nrefs rradjabi/XRT#6 --- src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c index 30a8e491691..698f9fec15b 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c @@ -546,8 +546,8 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) goto done; } - /* Compare MEM_TOPOLOGY previous vs new. */ - if (xdev->topology != NULL) { + /* 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)) { // m_mem_data can be of different length but we would not compare them if topology match fails if (!memcmp(new_topology, xdev->topology, size) && (sizeof_sect(new_topology, m_mem_data) == sizeof_sect(xdev->topology, m_mem_data))) { From b2998d9be5fb75956311173222a90c4ed8571a1a Mon Sep 17 00:00:00 2001 From: Ryan Radjabi <32471108+rradjabi@users.noreply.github.com> Date: Fri, 5 Oct 2018 16:10:52 -0700 Subject: [PATCH 13/13] compare mem_topology sizes before memcmp on the contents --- src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c index 698f9fec15b..352ac5c024a 100644 --- a/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c +++ b/src/runtime_src/driver/xclng/drm/xocl/userpf/xocl_ioctl.c @@ -548,9 +548,8 @@ xocl_read_axlf_helper(struct xocl_dev *xdev, struct drm_xocl_axlf *axlf_ptr) /* 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)) { - // m_mem_data can be of different length but we would not compare them if topology match fails - if (!memcmp(new_topology, xdev->topology, size) && - (sizeof_sect(new_topology, m_mem_data) == sizeof_sect(xdev->topology, m_mem_data))) { + 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 {