From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23E07C25B7A for ; Wed, 15 May 2024 08:15:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D7E6F10E198; Wed, 15 May 2024 08:15:33 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="bKMiYQP7"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id 600C710E5A5 for ; Wed, 15 May 2024 08:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715760912; x=1747296912; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=k31yW6S0w/VUi4DmWjK9oRnHidtXfvc2Vbj6wOt18RM=; b=bKMiYQP7RLwmcZMXS6Y+BgyS14RKL5NGeGIZQ59Nyag02M7Bst9EuV8J b3zAqeMd1lP9fYaDWrHIc0EPLsU28CD58M7PkIBvtFtnMvGSwkQsSaKWX LJwSYxJZ2V7PWOo7xhvz+Uyg2wIJnBEHGKxQX/CdTTAe8rFgcGCQknmCs P0ErcF7qp+TxBbjfQUigklTql9vtiOZRoCyZiuGeOZMS7CjiHAuFyGccA MFR+JyXkPRBiRvMETl2RivwRijy+qawTC+NUnZVWCixc5zY7vihHyTnov hxMAqzYy2Ki1Z1bpF/zHghuisk+VXqAnou07LGM1rUluRe7m1GDdGOL3b w==; X-CSE-ConnectionGUID: 1srQ2OkLQOWeVDuAeK9rxQ== X-CSE-MsgGUID: z15chGWWSd69kn2+hC01Tg== X-IronPort-AV: E=McAfee;i="6600,9927,11073"; a="23193317" X-IronPort-AV: E=Sophos;i="6.08,161,1712646000"; d="scan'208";a="23193317" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2024 01:15:12 -0700 X-CSE-ConnectionGUID: NYmDkkFASr+2/mlhq8coOg== X-CSE-MsgGUID: G2GmtmudQLmfaECppL6cFw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,161,1712646000"; d="scan'208";a="30977477" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fedora..) ([10.245.246.147]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2024 01:15:11 -0700 From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= To: intel-xe@lists.freedesktop.org Subject: [CI 14/21] drm/exec: drm_exec_trylock() Date: Wed, 15 May 2024 10:14:42 +0200 Message-ID: <20240515081449.46646-15-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240515081449.46646-1-thomas.hellstrom@linux.intel.com> References: <20240515081449.46646-1-thomas.hellstrom@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" Signed-off-by: Thomas Hellström --- drivers/gpu/drm/drm_exec.c | 38 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_exec.h | 1 + 2 files changed, 39 insertions(+) diff --git a/drivers/gpu/drm/drm_exec.c b/drivers/gpu/drm/drm_exec.c index 2a28cbccaec7..ec8c245e33d1 100644 --- a/drivers/gpu/drm/drm_exec.c +++ b/drivers/gpu/drm/drm_exec.c @@ -207,6 +207,44 @@ int drm_exec_handle_contended(struct drm_exec *exec) } EXPORT_SYMBOL(drm_exec_handle_contended); +/** + * drm_exec_lock_obj - lock a GEM object for use + * @exec: the drm_exec object with the state + * @obj: the GEM object to lock + * + * Lock a GEM object for use and grab a reference to it. + * + * Returns: -EDEADLK if a contention is detected, -EALREADY when object is + * already locked (can be suppressed by setting the DRM_EXEC_IGNORE_DUPLICATES + * flag), -ENOMEM when memory allocation failed and zero for success. + */ +int drm_exec_trylock_obj(struct drm_exec *exec, struct drm_gem_object *obj) +{ + int ret; + + might_alloc(GFP_KERNEL); + + if (exec->prelocked == obj) { + drm_gem_object_put(exec->prelocked); + exec->prelocked = NULL; + return 0; + } + + if (!dma_resv_trylock_ctx(obj->resv, &exec->ticket)) { + if (dma_resv_locking_ctx(obj->resv) == &exec->ticket) + return (exec->flags & DRM_EXEC_IGNORE_DUPLICATES) ? 0 : -EALREADY; + else + return -EBUSY; + } + + ret = drm_exec_obj_locked(exec, obj); + if (ret) + dma_resv_unlock(obj->resv); + + return ret; +} +EXPORT_SYMBOL(drm_exec_trylock_obj); + /** * drm_exec_lock_obj - lock a GEM object for use * @exec: the drm_exec object with the state diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h index a3490794ef35..a37c851a178b 100644 --- a/include/drm/drm_exec.h +++ b/include/drm/drm_exec.h @@ -148,6 +148,7 @@ void drm_exec_init(struct drm_exec *exec, u32 flags, unsigned nr); void drm_exec_fini(struct drm_exec *exec); bool drm_exec_cleanup(struct drm_exec *exec); int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj); +int drm_exec_trylock_obj(struct drm_exec *exec, struct drm_gem_object *obj); void drm_exec_unlock_obj(struct drm_exec *exec, struct drm_gem_object *obj); int drm_exec_prepare_obj(struct drm_exec *exec, struct drm_gem_object *obj, unsigned int num_fences); -- 2.44.0