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 X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E469C4338F for ; Mon, 16 Aug 2021 13:30:59 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id BE66C6054F for ; Mon, 16 Aug 2021 13:30:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BE66C6054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 11EF689EBD; Mon, 16 Aug 2021 13:30:55 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 14B2189EA6; Mon, 16 Aug 2021 13:30:53 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10077"; a="215588162" X-IronPort-AV: E=Sophos;i="5.84,326,1620716400"; d="scan'208";a="215588162" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2021 06:30:52 -0700 X-IronPort-AV: E=Sophos;i="5.84,326,1620716400"; d="scan'208";a="519655235" Received: from yifeiren-mobl.ccr.corp.intel.com (HELO [10.249.254.101]) ([10.249.254.101]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2021 06:30:51 -0700 Subject: Re: [PATCH] drm/i915: Ditch the i915_gem_ww_ctx loop member To: Matthew Auld Cc: Intel Graphics Development , ML dri-devel , Maarten Lankhorst References: <20210816084855.75586-1-thomas.hellstrom@linux.intel.com> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m?= Message-ID: Date: Mon, 16 Aug 2021 15:30:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On 8/16/21 3:25 PM, Matthew Auld wrote: > On Mon, 16 Aug 2021 at 09:49, Thomas Hellström > wrote: >> It's only used by the for_i915_gem_ww() macro and we can use >> the (typically) on-stack _err variable in its place. >> >> While initially setting the _err variable to -EDEADLK to enter the >> loop, we clear it before actually entering using fetch_and_zero() to >> avoid empty loops or code not setting the _err variable running forever. >> >> Suggested-by: Maarten Lankhorst >> Signed-off-by: Thomas Hellström >> --- >> drivers/gpu/drm/i915/i915_gem_ww.h | 23 ++++++++--------------- >> 1 file changed, 8 insertions(+), 15 deletions(-) >> >> diff --git a/drivers/gpu/drm/i915/i915_gem_ww.h b/drivers/gpu/drm/i915/i915_gem_ww.h >> index f6b1a796667b..98348b1e6182 100644 >> --- a/drivers/gpu/drm/i915/i915_gem_ww.h >> +++ b/drivers/gpu/drm/i915/i915_gem_ww.h >> @@ -7,12 +7,13 @@ >> >> #include >> >> +#include "i915_utils.h" >> + >> struct i915_gem_ww_ctx { >> struct ww_acquire_ctx ctx; >> struct list_head obj_list; >> struct drm_i915_gem_object *contended; >> - unsigned short intr; >> - unsigned short loop; >> + bool intr; >> }; >> >> void i915_gem_ww_ctx_init(struct i915_gem_ww_ctx *ctx, bool intr); >> @@ -23,28 +24,20 @@ void i915_gem_ww_unlock_single(struct drm_i915_gem_object *obj); >> /* Internal functions used by the inlines! Don't use. */ >> static inline int __i915_gem_ww_fini(struct i915_gem_ww_ctx *ww, int err) >> { >> - ww->loop = 0; >> if (err == -EDEADLK) { >> err = i915_gem_ww_ctx_backoff(ww); >> if (!err) >> - ww->loop = 1; >> + err = -EDEADLK; >> } >> >> - if (!ww->loop) >> + if (err != -EDEADLK) >> i915_gem_ww_ctx_fini(ww); >> >> return err; >> } >> >> -static inline void >> -__i915_gem_ww_init(struct i915_gem_ww_ctx *ww, bool intr) >> -{ >> - i915_gem_ww_ctx_init(ww, intr); >> - ww->loop = 1; >> -} >> - >> -#define for_i915_gem_ww(_ww, _err, _intr) \ >> - for (__i915_gem_ww_init(_ww, _intr); (_ww)->loop; \ >> +#define for_i915_gem_ww(_ww, _err, _intr) \ >> + for (i915_gem_ww_ctx_init(_ww, _intr), (_err) = -EDEADLK; \ >> + fetch_and_zero(&_err) == -EDEADLK; \ > Doesn't this now hide "normal" errors, like say get_pages() returning > -ENOSPC or so? Yes, good catch. We should either just clear the -EDEADLK case, or not clear the error at all.. /Thomas 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 X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBD5FC4320A for ; Mon, 16 Aug 2021 13:30:55 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7960761A6E for ; Mon, 16 Aug 2021 13:30:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7960761A6E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 94BD989EA6; Mon, 16 Aug 2021 13:30:54 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 14B2189EA6; Mon, 16 Aug 2021 13:30:53 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10077"; a="215588162" X-IronPort-AV: E=Sophos;i="5.84,326,1620716400"; d="scan'208";a="215588162" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2021 06:30:52 -0700 X-IronPort-AV: E=Sophos;i="5.84,326,1620716400"; d="scan'208";a="519655235" Received: from yifeiren-mobl.ccr.corp.intel.com (HELO [10.249.254.101]) ([10.249.254.101]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2021 06:30:51 -0700 To: Matthew Auld Cc: Intel Graphics Development , ML dri-devel , Maarten Lankhorst References: <20210816084855.75586-1-thomas.hellstrom@linux.intel.com> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m?= Message-ID: Date: Mon, 16 Aug 2021 15:30:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [Intel-gfx] [PATCH] drm/i915: Ditch the i915_gem_ww_ctx loop member X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On 8/16/21 3:25 PM, Matthew Auld wrote: > On Mon, 16 Aug 2021 at 09:49, Thomas Hellström > wrote: >> It's only used by the for_i915_gem_ww() macro and we can use >> the (typically) on-stack _err variable in its place. >> >> While initially setting the _err variable to -EDEADLK to enter the >> loop, we clear it before actually entering using fetch_and_zero() to >> avoid empty loops or code not setting the _err variable running forever. >> >> Suggested-by: Maarten Lankhorst >> Signed-off-by: Thomas Hellström >> --- >> drivers/gpu/drm/i915/i915_gem_ww.h | 23 ++++++++--------------- >> 1 file changed, 8 insertions(+), 15 deletions(-) >> >> diff --git a/drivers/gpu/drm/i915/i915_gem_ww.h b/drivers/gpu/drm/i915/i915_gem_ww.h >> index f6b1a796667b..98348b1e6182 100644 >> --- a/drivers/gpu/drm/i915/i915_gem_ww.h >> +++ b/drivers/gpu/drm/i915/i915_gem_ww.h >> @@ -7,12 +7,13 @@ >> >> #include >> >> +#include "i915_utils.h" >> + >> struct i915_gem_ww_ctx { >> struct ww_acquire_ctx ctx; >> struct list_head obj_list; >> struct drm_i915_gem_object *contended; >> - unsigned short intr; >> - unsigned short loop; >> + bool intr; >> }; >> >> void i915_gem_ww_ctx_init(struct i915_gem_ww_ctx *ctx, bool intr); >> @@ -23,28 +24,20 @@ void i915_gem_ww_unlock_single(struct drm_i915_gem_object *obj); >> /* Internal functions used by the inlines! Don't use. */ >> static inline int __i915_gem_ww_fini(struct i915_gem_ww_ctx *ww, int err) >> { >> - ww->loop = 0; >> if (err == -EDEADLK) { >> err = i915_gem_ww_ctx_backoff(ww); >> if (!err) >> - ww->loop = 1; >> + err = -EDEADLK; >> } >> >> - if (!ww->loop) >> + if (err != -EDEADLK) >> i915_gem_ww_ctx_fini(ww); >> >> return err; >> } >> >> -static inline void >> -__i915_gem_ww_init(struct i915_gem_ww_ctx *ww, bool intr) >> -{ >> - i915_gem_ww_ctx_init(ww, intr); >> - ww->loop = 1; >> -} >> - >> -#define for_i915_gem_ww(_ww, _err, _intr) \ >> - for (__i915_gem_ww_init(_ww, _intr); (_ww)->loop; \ >> +#define for_i915_gem_ww(_ww, _err, _intr) \ >> + for (i915_gem_ww_ctx_init(_ww, _intr), (_err) = -EDEADLK; \ >> + fetch_and_zero(&_err) == -EDEADLK; \ > Doesn't this now hide "normal" errors, like say get_pages() returning > -ENOSPC or so? Yes, good catch. We should either just clear the -EDEADLK case, or not clear the error at all.. /Thomas