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=-14.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,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 24690C433DB for ; Wed, 27 Jan 2021 15:28:29 +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 A8785206C2 for ; Wed, 27 Jan 2021 15:28:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8785206C2 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=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0F0106E837; Wed, 27 Jan 2021 15:28:28 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 56F316E837 for ; Wed, 27 Jan 2021 15:28:26 +0000 (UTC) IronPort-SDR: PWHsgsdwnzIIZCfA1FD9Mupe+wajhlChg/hdNzuGLegrmU8+XbXhxdE0whc7g38cJxGIg4semS gZ76iGUT9jKw== X-IronPort-AV: E=McAfee;i="6000,8403,9877"; a="244161221" X-IronPort-AV: E=Sophos;i="5.79,379,1602572400"; d="scan'208";a="244161221" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 07:28:25 -0800 IronPort-SDR: rNmi8YDo7V7dfDB+BriA7FcL02aUp7ublphpHzR1UIwVfaCHgqoMfKHCJu5S3ztKJiPVYLiCbD EJJP7n+EXbnw== X-IronPort-AV: E=Sophos;i="5.79,379,1602572400"; d="scan'208";a="388359174" Received: from aohana-mobl1.ger.corp.intel.com (HELO [10.214.230.73]) ([10.214.230.73]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 07:28:23 -0800 To: Chris Wilson , intel-gfx@lists.freedesktop.org References: <20210125140136.10494-1-chris@chris-wilson.co.uk> <20210125140136.10494-21-chris@chris-wilson.co.uk> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc Message-ID: <3c007546-ac60-0c1f-3763-95d00be592c7@linux.intel.com> Date: Wed, 27 Jan 2021 15:28:20 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20210125140136.10494-21-chris@chris-wilson.co.uk> Content-Language: en-US Subject: Re: [Intel-gfx] [PATCH 21/41] drm/i915: Wrap cmpxchg64 with try_cmpxchg64() helper 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: , Cc: thomas.hellstrom@intel.com Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On 25/01/2021 14:01, Chris Wilson wrote: > Wrap cmpxchg64 with a try_cmpxchg()-esque helper. Hiding the old-value > dance in the helper allows for cleaner code. > > Signed-off-by: Chris Wilson > --- > drivers/gpu/drm/i915/i915_utils.h | 32 +++++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h > index abd4dcd9f79c..95ead6bb1ba6 100644 > --- a/drivers/gpu/drm/i915/i915_utils.h > +++ b/drivers/gpu/drm/i915/i915_utils.h > @@ -461,4 +461,36 @@ static inline bool timer_expired(const struct timer_list *t) > */ > #define IS_ACTIVE(config) ((config) != 0) > > +#ifndef try_cmpxchg64 > +#if IS_ENABLED(CONFIG_64BIT) > +#define try_cmpxchg64(_ptr, _pold, _new) try_cmpxchg(_ptr, _pold, _new) > +#else > +#define try_cmpxchg64(_ptr, _pold, _new) \ > +({ \ > + __typeof__(_ptr) _old = (__typeof__(_ptr))(_pold); \ > + __typeof__(*(_ptr)) __old = *_old; \ > + __typeof__(*(_ptr)) __cur = cmpxchg64(_ptr, __old, _new); \ > + bool success = __cur == __old; \ > + if (unlikely(!success)) \ > + *_old = __cur; \ > + likely(success); \ > +}) > +#endif > +#endif > + > +#ifndef xchg64 > +#if IS_ENABLED(CONFIG_64BIT) > +#define xchg64(_ptr, _new) xchg(_ptr, _new) > +#else > +#define xchg64(_ptr, _new) \ > +({ \ > + __typeof__(_ptr) __ptr = (_ptr); \ > + __typeof__(*(_ptr)) __old = *__ptr; \ > + while (!try_cmpxchg64(__ptr, &__old, (_new))) \ > + ; \ > + __old; \ > +}) > +#endif > +#endif > + > #endif /* !__I915_UTILS_H */ > Reviewed-by: Tvrtko Ursulin Regards, Tvrtko _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx