From patchwork Mon Mar 2 23:42:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jeff.mcgee@intel.com X-Patchwork-Id: 5918141 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 55F42BF440 for ; Mon, 2 Mar 2015 23:21:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6D51A201CD for ; Mon, 2 Mar 2015 23:21:53 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id B0B1F20222 for ; Mon, 2 Mar 2015 23:21:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F11206E4F8; Mon, 2 Mar 2015 15:21:45 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 9B2C36E348; Mon, 2 Mar 2015 15:21:44 -0800 (PST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 02 Mar 2015 15:19:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,678,1418112000"; d="scan'208";a="535118824" Received: from jeffdesk.fm.intel.com ([10.19.123.159]) by orsmga003.jf.intel.com with ESMTP; 02 Mar 2015 15:21:46 -0800 From: jeff.mcgee@intel.com To: beignet@lists.freedesktop.org Date: Mon, 2 Mar 2015 15:42:38 -0800 Message-Id: <1425339759-19027-1-git-send-email-jeff.mcgee@intel.com> X-Mailer: git-send-email 2.3.0 Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [Intel-gfx] [PATCH 1/2] Add driver callback for updating device info X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff McGee We need to update some fields of the device's cl_device_id struct at runtime using driver-specific methods. It is best to group all such updates into a single driver callback to avoid opening/initing and deiniting/closing the device multiple times. Signed-off-by: Jeff McGee Reviewed-by: Zhigang Gong --- src/cl_device_id.c | 20 ++------------------ src/cl_driver.h | 4 ++++ src/cl_driver_defs.c | 1 + src/intel/intel_driver.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/cl_device_id.c b/src/cl_device_id.c index 4e01c9f..fefcef3 100644 --- a/src/cl_device_id.c +++ b/src/cl_device_id.c @@ -506,24 +506,8 @@ skl_gt4_break: ret->profile_sz = strlen(ret->profile) + 1; } -#ifdef HAS_USERPTR - cl_driver dummy = cl_driver_new(NULL); - cl_buffer_mgr bufmgr = cl_driver_get_bufmgr(dummy); - - const size_t sz = 4096; - void* host_ptr = cl_aligned_malloc(sz, 4096);; - if (host_ptr != NULL) { - cl_buffer bo = cl_buffer_alloc_userptr(bufmgr, "CL memory object", host_ptr, sz, 0); - if (bo == NULL) - ret->host_unified_memory = CL_FALSE; - else - cl_buffer_unreference(bo); - cl_free(host_ptr); - } - else - ret->host_unified_memory = CL_FALSE; - cl_driver_delete(dummy); -#endif + /* Apply any driver-dependent updates to the device info */ + cl_driver_update_device_info(ret); struct sysinfo info; if (sysinfo(&info) == 0) { diff --git a/src/cl_driver.h b/src/cl_driver.h index 16f8bba..3f54a27 100644 --- a/src/cl_driver.h +++ b/src/cl_driver.h @@ -376,6 +376,10 @@ extern cl_buffer_get_tiling_align_cb *cl_buffer_get_tiling_align; typedef int (cl_driver_get_device_id_cb)(void); extern cl_driver_get_device_id_cb *cl_driver_get_device_id; +/* Update the device info */ +typedef void (cl_driver_update_device_info_cb)(cl_device_id device); +extern cl_driver_update_device_info_cb *cl_driver_update_device_info; + /************************************************************************** * cl_khr_gl_sharing. **************************************************************************/ diff --git a/src/cl_driver_defs.c b/src/cl_driver_defs.c index 2b68539..9a47210 100644 --- a/src/cl_driver_defs.c +++ b/src/cl_driver_defs.c @@ -26,6 +26,7 @@ LOCAL cl_driver_delete_cb *cl_driver_delete = NULL; LOCAL cl_driver_get_bufmgr_cb *cl_driver_get_bufmgr = NULL; LOCAL cl_driver_get_ver_cb *cl_driver_get_ver = NULL; LOCAL cl_driver_get_device_id_cb *cl_driver_get_device_id = NULL; +LOCAL cl_driver_update_device_info_cb *cl_driver_update_device_info = NULL; /* Buffer */ LOCAL cl_buffer_alloc_cb *cl_buffer_alloc = NULL; diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c index ff0cf27..d61988c 100644 --- a/src/intel/intel_driver.c +++ b/src/intel/intel_driver.c @@ -754,6 +754,41 @@ static int intel_buffer_set_tiling(cl_buffer bo, return ret; } +static void +intel_update_device_info(cl_device_id device) +{ +#ifdef HAS_USERPTR + intel_driver_t *driver; + const size_t sz = 4096; + void *host_ptr; + + driver = intel_driver_new(); + assert(driver != NULL); + if (intel_driver_open(driver, NULL) != CL_SUCCESS) { + intel_driver_delete(driver); + return; + } + + host_ptr = cl_aligned_malloc(sz, 4096); + if (host_ptr != NULL) { + cl_buffer bo = intel_buffer_alloc_userptr((cl_buffer_mgr)driver->bufmgr, + "CL memory object", host_ptr, sz, 0); + if (bo == NULL) + device->host_unified_memory = CL_FALSE; + else + drm_intel_bo_unreference((drm_intel_bo*)bo); + cl_free(host_ptr); + } + else + device->host_unified_memory = CL_FALSE; + + intel_driver_context_destroy(driver); + intel_driver_close(driver); + intel_driver_terminate(driver); + intel_driver_delete(driver); +#endif +} + LOCAL void intel_setup_callbacks(void) { @@ -762,6 +797,7 @@ intel_setup_callbacks(void) cl_driver_get_ver = (cl_driver_get_ver_cb *) intel_driver_get_ver; cl_driver_get_bufmgr = (cl_driver_get_bufmgr_cb *) intel_driver_get_bufmgr; cl_driver_get_device_id = (cl_driver_get_device_id_cb *) intel_get_device_id; + cl_driver_update_device_info = (cl_driver_update_device_info_cb *) intel_update_device_info; cl_buffer_alloc = (cl_buffer_alloc_cb *) drm_intel_bo_alloc; cl_buffer_alloc_userptr = (cl_buffer_alloc_userptr_cb*) intel_buffer_alloc_userptr; cl_buffer_set_tiling = (cl_buffer_set_tiling_cb *) intel_buffer_set_tiling;