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 BFC13C4332F for ; Tue, 13 Dec 2022 09:29:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 07C7789048; Tue, 13 Dec 2022 09:29:02 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0214289048; Tue, 13 Dec 2022 09:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670923739; x=1702459739; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=Bp30MA4PgsFJjTtXWD8JVLEk7r0vjtZzmIyP/wIb+WM=; b=fYdooy3DrHXlj0GjjL4p6zYNg9vhX1ibcYITs1vgkriccvG9zEmqSkdq mdXSO0hWtpNqqhAnDmtM7WDYT4kvYILHoOA781hIa+M0V7x9TQ4hXRgBu AEzQ7tPA/KntV+yxZfxR8mDvcfA4JN00IP4vxgBdkDTnGyXOsOpc9uGCQ q5uY56b3KtXEVpqGzIc2duSdkyKvW76LgPzd9RoyQdn2MhxT8mHBpZPrE Xsai0xiTmaSpMo0OVJwpkEPgu6nM1E1CvYnS229z06yp2wtUHfbGvNTEn xurN/W2OGwpAuWlKLr+mVvMGZxEO9PvDjJyiR8joeJ+WPdK6BBsSqy9jz A==; X-IronPort-AV: E=McAfee;i="6500,9779,10559"; a="345147832" X-IronPort-AV: E=Sophos;i="5.96,241,1665471600"; d="scan'208";a="345147832" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2022 01:28:58 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10559"; a="679238977" X-IronPort-AV: E=Sophos;i="5.96,241,1665471600"; d="scan'208";a="679238977" Received: from ahajda-mobl.ger.corp.intel.com (HELO [10.213.28.83]) ([10.213.28.83]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2022 01:28:56 -0800 Message-ID: <53e7e660-9ee0-1177-b34a-365c1397ec3b@intel.com> Date: Tue, 13 Dec 2022 10:28:53 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.5.1 Content-Language: en-US To: Arnd Bergmann , linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org References: <20221209154843.4162814-1-andrzej.hajda@intel.com> From: Andrzej Hajda Organization: Intel Technology Poland sp. z o.o. - ul. Slowackiego 173, 80-298 Gdansk - KRS 101882 - NIP 957-07-52-316 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Intel-gfx] [PATCH 1/5] linux/minmax.h: add non-atomic version of xchg 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: Andrew Morton , Andy Shevchenko , Rodrigo Vivi Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On 09.12.2022 18:16, Arnd Bergmann wrote: > On Fri, Dec 9, 2022, at 16:48, Andrzej Hajda wrote: >> The pattern of setting variable with new value and returning old >> one is very common in kernel. Usually atomicity of the operation >> is not required, so xchg seems to be suboptimal and confusing in >> such cases. Since name xchg is already in use and __xchg is used >> in architecture code, proposition is to name the macro exchange. >> >> Signed-off-by: Andrzej Hajda > > While I generally don't like type invariant calling conventions > of xchg() and cmpxchg(), having a new function that has a similar > name without being able to tell which one is which from the > name seems more confusing. > > Since __xchg() is only used on 11 architectures as an internal Quite big number for 'only' :) > name for the backing of arch_xchg() or arch_xchg_relaxed(), > maybe we can instead rename those to __arch_xchg() and use the > __xchg() name for the new non-atomic version? I will try, but even compile test will be some challenge, need to find cross-compilers for these archs. Btw exchange is not totally new name, for example C++ uses it [1]. [1]: https://en.cppreference.com/w/cpp/utility/exchange Regards Andrzej > >> +/** >> + * exchange - set variable pointed by @ptr to @val, return old value >> + * @ptr: pointer to affected variable >> + * @val: value to be written >> + * >> + * This is non-atomic variant of xchg. >> + */ >> +#define exchange(ptr, val) ({ \ >> + typeof(ptr) __ptr = ptr; \ >> + typeof(*__ptr) __t = *__ptr; \ > > I think you can better express this using __auto_type than typeof(), > it is now provided by all supported compilers now. > > Arnd