From patchwork Wed Oct 25 23:08:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Ceraolo Spurio X-Patchwork-Id: 10027323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0DE9260245 for ; Wed, 25 Oct 2017 23:08:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0145928C7C for ; Wed, 25 Oct 2017 23:08:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9FD528C7D; Wed, 25 Oct 2017 23:08:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9BBDA28C7E for ; Wed, 25 Oct 2017 23:08:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 361AE6E70F; Wed, 25 Oct 2017 23:08:34 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id E761B6E319 for ; Wed, 25 Oct 2017 23:08:23 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2017 16:08:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,433,1503385200"; d="scan'208";a="913793134" Received: from relo-linux-1.fm.intel.com ([10.1.27.112]) by FMSMGA003.fm.intel.com with ESMTP; 25 Oct 2017 16:08:19 -0700 From: Daniele Ceraolo Spurio To: intel-gfx@lists.freedesktop.org Date: Wed, 25 Oct 2017 16:08:04 -0700 Message-Id: <1508972891-35322-2-git-send-email-daniele.ceraolospurio@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508972891-35322-1-git-send-email-daniele.ceraolospurio@intel.com> References: <1508972891-35322-1-git-send-email-daniele.ceraolospurio@intel.com> Subject: [Intel-gfx] [PATCH i-g-t v2 1/8] lib/igt_dummyload: add igt_cork 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-Virus-Scanned: ClamAV using ClamSMTP The "cork" bo (imported bo with attached fence) is used in several tests to stall execution. Moving it to a common place makes the codebase cleaner. Note that the actual test updates is done in follow up patches as it is simpler to do in one go after one more common function is added in the next patch. v2: don't use new/free naming, don't use dynamic alloc (Chris) Signed-off-by: Daniele Ceraolo Spurio Cc: Chris Wilson --- lib/igt_dummyload.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_dummyload.h | 8 ++++++++ 2 files changed, 66 insertions(+) diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c index bb2be55..ea21ffe 100644 --- a/lib/igt_dummyload.c +++ b/lib/igt_dummyload.c @@ -29,11 +29,13 @@ #include #include "igt_core.h" +#include "drmtest.h" #include "igt_dummyload.h" #include "igt_gt.h" #include "intel_chipset.h" #include "intel_reg.h" #include "ioctl_wrappers.h" +#include "igt_vgem.h" /** * SECTION:igt_dummyload @@ -300,3 +302,59 @@ void igt_terminate_spin_batches(void) igt_list_for_each(iter, &spin_list, link) igt_spin_batch_end(iter); } + +/** + * igt_cork_plug: + * @fd: open drm file descriptor + * @cork: structure that will be filled with the state of the cork bo + * + * Imports a vgem bo with a fence attached to it. This bo can be used as a + * dependency during submission to stall execution until the fence is signaled. + * The parameters required to unblock the execution and to cleanup are stored in + * the provided cork structure. + * + * Returns: + * Handle of the imported BO. + */ +uint32_t igt_cork_plug(int fd, struct igt_cork *cork) +{ + struct vgem_bo bo; + int dmabuf; + uint32_t handle; + + igt_assert(cork); + + cork->device = drm_open_driver(DRIVER_VGEM); + + igt_require(vgem_has_fences(cork->device)); + + bo.width = bo.height = 1; + bo.bpp = 4; + vgem_create(cork->device, &bo); + cork->fence = vgem_fence_attach(cork->device, &bo, VGEM_FENCE_WRITE); + + dmabuf = prime_handle_to_fd(cork->device, bo.handle); + handle = prime_fd_to_handle(fd, dmabuf); + close(dmabuf); + + return handle; +} + +/** + * igt_cork_unplug: + * @cork: cork state from igt_cork_plug() + * + * This function unblocks the execution by signaling the fence attached to the + * imported bo and does the necessary post-processing. + * NOTE: the imported bo handle returned by igt_cork_plug is not closed during + * this phase. + */ +void igt_cork_unplug(struct igt_cork *cork) +{ + if (!cork || !cork->device) + return; + + vgem_fence_signal(cork->device, cork->fence); + close(cork->device); + cork->device = 0; +} diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h index 215425f..8869268 100644 --- a/lib/igt_dummyload.h +++ b/lib/igt_dummyload.h @@ -51,4 +51,12 @@ void igt_spin_batch_free(int fd, igt_spin_t *spin); void igt_terminate_spin_batches(void); +struct igt_cork { + int device; + uint32_t fence; +}; + +uint32_t igt_cork_plug(int fd, struct igt_cork *cork); +void igt_cork_unplug(struct igt_cork *cork); + #endif /* __IGT_DUMMYLOAD_H__ */