Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp957877rwl; Thu, 5 Jan 2023 06:58:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXvMsizuEpP0DlzR/Vcyb4zLVga59YY5naz+Av9MKEko2ATB5EPfKQsdUrbiBNXXqGj0a3sC X-Received: by 2002:a17:907:7e9f:b0:7c1:7d81:d2a8 with SMTP id qb31-20020a1709077e9f00b007c17d81d2a8mr53164568ejc.3.1672930720546; Thu, 05 Jan 2023 06:58:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672930720; cv=none; d=google.com; s=arc-20160816; b=S8cCV+k60QK3I8oT/bj2hCQRYtzmTOqdeapjJIv2dQ0D2ZthFjtgkpm1jyn1HQf0xM gj6kL0x5qFoDHLbZ0aSQTYFuRQ8awUCtIVk864j8y3C8p4rl55h1kn4jAG5Df4e5VBNq SDJ3rxn42QGQ20vXeduEmmHhULZ2PbGLDQrmrSKHtif6W5MSI1jdQay9EVpcib5U2yYx SGIyAtWpCmUjSEJqNsejH8TNhoDbr/Z9YeiyzDZJDnzpjIFqENzAQHK7WkAW42F2Zm/E oR0mn6CqfrOmBouo3hwYQnyqhwHj0OZy6bjacnY9cDdLjYUAY9dPgkENwcCopefVPgFp fO3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=n5ArsLxL0GZtkgRlTZnaNU6c7iO488ixujwQ2KT/3MY=; b=QHUA9fd3FnNYCUvnuWkAUGAyYGNsBaIKxmtAykXdwnm//zVXAt8D5BfK74zZ999wKX ODlc9Cc6X54Qg1vAKALwDyaG88JFOnqjrWZdlYmqKsSEgtWMMqOlUTcR1x56ELqXnSdl U/EX3M2cb11sVyAz9ucZilu925ZF1yQKJAzjJd+JoMVwzEYaRuz0SvP6pFDIcBqPoIxw KVOAG3YhnpdHvySNUhLEyQcsJa82Y8ACNp47cW4bGIejvOBgQ1YLmIFS/Go1UiRGMIRt fav5o69jH8VovaPQx8BtSIZVWHqFGpx/xXHqCEcdWlSzauikR3fMdfD6Vga4DFSMBUDe kpxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bJmGz2yu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go15-20020a1709070d8f00b00836ecced351si36316116ejc.380.2023.01.05.06.58.27; Thu, 05 Jan 2023 06:58:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bJmGz2yu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233608AbjAEO0o (ORCPT + 55 others); Thu, 5 Jan 2023 09:26:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233520AbjAEO0I (ORCPT ); Thu, 5 Jan 2023 09:26:08 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFF894A964 for ; Thu, 5 Jan 2023 06:26:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672928767; x=1704464767; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=z67iM0jfw8rBDBXuutR2adWOVf2bd9BhkqQyZcE/mpY=; b=bJmGz2yuwoesCJg/qlfR+WaB0Hp24qAjwrrmVH7ARqefSTdmWmO25P98 S9YogtixSUWanBlaOqyElRirgv9IH92DUmkMDoVq7YUaZEGFnBPRffTcG x7nPAi5FznUx/emmoDV2trFYlwnFOOSNP+l/gIQsT7M23ZiPeW8BxS0GO Wg1LQm/RVK5pGMoJFHzuy9lemXk/F3ho3LDJ2Ge5LHx2ZPer0IBpXtftE MzQYpnM+B3BU4lmflHwgFYbvpLW+AzZk1/JSOQlqyQjM/zDXtY5sWq50l WbL8C5cjQ+mZdP+9JI00j9G14SfzIwPPmNqVScjls65+ahpMAu5zR/wZN A==; X-IronPort-AV: E=McAfee;i="6500,9779,10580"; a="305721809" X-IronPort-AV: E=Sophos;i="5.96,303,1665471600"; d="scan'208";a="305721809" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2023 06:13:50 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10580"; a="829564429" X-IronPort-AV: E=Sophos;i="5.96,303,1665471600"; d="scan'208";a="829564429" Received: from ciarapow-mobl1.ger.corp.intel.com (HELO [10.213.208.73]) ([10.213.208.73]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2023 06:13:47 -0800 Message-ID: Date: Thu, 5 Jan 2023 14:13:45 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [Intel-gfx] [PATCH 1/5] linux/minmax.h: add non-atomic version of xchg Content-Language: en-US To: David Laight , 'Jani Nikula' , Daniel Vetter Cc: Arnd Bergmann , "intel-gfx@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , 'Andrzej Hajda' , Rodrigo Vivi , Andrew Morton , Andy Shevchenko References: <20221209154843.4162814-1-andrzej.hajda@intel.com> <875ydlw1p4.fsf@intel.com> <733cd0037bd14a269b54d701e1b80323@AcuMS.aculab.com> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc In-Reply-To: <733cd0037bd14a269b54d701e1b80323@AcuMS.aculab.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, NICE_REPLY_A,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/01/2023 13:34, David Laight wrote: > From: Jani Nikula >> Sent: 05 January 2023 13:28 >> >> On Thu, 05 Jan 2023, Daniel Vetter wrote: >>> On Mon, Dec 12, 2022 at 09:38:12AM +0000, David Laight wrote: >>>> From: Andrzej Hajda >>>>> Sent: 09 December 2022 15:49 >>>>> >>>>> 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. >>>> >>>> Dunno, if it is non-atomic then two separate assignment statements >>>> is decidedly more obvious and needs less brain cells to process. >>>> Otherwise someone will assume 'something clever' is going on >>>> and the operation is atomic. >>> >>> Yes, this also my take. The i915 code that uses this to excess is decidely >>> unreadable imo, and the macro should simply be replaced by open-coded >>> versions. >>> >>> Not moved into shared headers where even more people can play funny games >>> with it. >> >> My stand in i915 has been that the local fetch_and_zero() needs to >> go. Either replaced by a common helper in core kernel headers, or open >> coded, I personally don't care, but the local version can't stay. >> >> My rationale has been that fetch_and_zero() looks atomic and looks like >> it comes from shared headers, but it's neither. It's deceptive. It >> started small and harmless, but things like this just proliferate and >> get copy-pasted all over the place. >> >> So here we are, with Andrzej looking to add the common helper. And the >> same concerns crop up. What should it be called to make it clear that >> it's not atomic? Is that possible? > > old_value = read_write(variable, new_value); > > But two statements are much clearer. In a later thread there was more discussion on this and some new suggestions - exchange(), replace() or even take() sound fine to me. Last one is perhaps most specialized if it implies zeroing, which I at least assume it does. All three are distant enough from atomic connotations of xchg. If that was a concern with __xchg, which I not sure it should be since there is "prior art" in the kernel for atomic vs non-atomic like set_bit and __set_bit. My 2c, regardless of what name, that it is not something which is strictly needed, but a convenient syntactic sugar. (Exploded line counts with sometimes single use local variables are a bit meh.) And I am not really sure that open coding is more readable once the new pattern would be established. In short, if there can be swap there can be $insert_name too I guess. Bonus points if needlessly atomic sites can be converted but identifying them is probably an exercise for a later phase. Regards, Tvrtko P.S. FWIW my preference are either replace() or __xchg().