Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp857271rwl; Thu, 5 Jan 2023 05:40:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXtz7BPgDr4YmtJUz3Csuy0is2hKaBBYsnzp6HBM8Q0e0IN2TremV0m4VzeFbUP1EWmlEoXF X-Received: by 2002:a05:6a20:d69a:b0:af:9538:ec5c with SMTP id it26-20020a056a20d69a00b000af9538ec5cmr84426145pzb.51.1672926009411; Thu, 05 Jan 2023 05:40:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672926009; cv=none; d=google.com; s=arc-20160816; b=xCLfxfS3j/FE3QnZLQRIvnco+yxMR5r4IErTV53i7BhCrevbvgd8danRTowHI6WhAP jBcR86YRBBWQg5iimeXsaV2jJJi3t8Zb/bIlwr1enaUhe7KkIDogJxV2qawftJ0NToE7 se1GteCUmqa7MYvvTkI8YeJzYGQho/v/6ahx67+wxeRh7xZO0Ywg19QaxovqR8l9D7LM 50kZz2mV4uPalNl/2C8Ndq17y2R8AtgbVcM/bwL9TO6Ph1iJgqIL/v5HNuiwYsvk4/1V tfsrVppfMfJVHUqSoDhNAZJKs+AzthC3LINoSm4V8BCVD4LNw+KKWjm0pdRjvkxtLdyf Ay7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from:dkim-signature; bh=EPk/xgahSlFa9tPGvKMz2wgTEZ3muwMOXqr/mNuLm1c=; b=ut3Z6Vaj4T3siVCElQdqEg9er6IWx4Vzhk9vSkGHQ07XH0V4DrNC6zCRYjwN+IaYPg KJxVmch7JIDqxLleVsNXeiGX0ijqPWZynNGgpt5flLYgEZRMLyp30g33S3TuHAE17VSg ywrvIon0Z32RSax+4XfYHrz/1JIihh03fgp1TsHB70VFxXPzFDUWOJ8BqhTfaRIWD19I i+OzkkcvEjueuis46PAFMyRhvrYdo14dWeiDb7MB/N/bIAsBNcpM4d+3RAvAhnM2E/j0 GnHwIcBYNdqYLVuiCuTjGptuMUbRRlkVIaDRVBu8giiZN93xug1Urm7Mez/77AogDwCT auew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IUnKF7bK; 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 n1-20020a63b441000000b004a2454410c2si11552380pgu.238.2023.01.05.05.40.00; Thu, 05 Jan 2023 05:40:09 -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=IUnKF7bK; 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 S229652AbjAEN3W (ORCPT + 56 others); Thu, 5 Jan 2023 08:29:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234436AbjAEN2n (ORCPT ); Thu, 5 Jan 2023 08:28:43 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C80BF392EB for ; Thu, 5 Jan 2023 05:28:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672925293; x=1704461293; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=NqDsGrNdPAmshIqIoolwpW2s1mJyJWpHdNYgy5IUVFI=; b=IUnKF7bK7A3+PSVxJqhDZVu2JPADYpIkag2c/5dn5555NCTKDqlFFylR D/2qQHx+ANdH//mhkvLmoKKW+kQWWuNCfPg7SWuRSPO5IBnQgTma+2wzi ooaXTcro7PlUjkca+QWVwBQc+8uL4aSjP5v9L0i1JU8uF+Y0IG9+bpDpC jojHGhz8bAhXVVL3oqK9LqbxMGgfNH3oxiSiwW/KafanYNowG/EtS0KSl 3pdNgLum5dnwpOF7N3BbysdaE7jA1Jah1preEGPnlzEBKqEzMDmj60W+z GsLkEabTQ5bvwZO6e7syMgfyf/OaDLOxIs+ba4GnF/qDQxy5e8O1/OKNl A==; X-IronPort-AV: E=McAfee;i="6500,9779,10580"; a="322271812" X-IronPort-AV: E=Sophos;i="5.96,303,1665471600"; d="scan'208";a="322271812" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2023 05:28:13 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10580"; a="686107107" X-IronPort-AV: E=Sophos;i="5.96,303,1665471600"; d="scan'208";a="686107107" Received: from swathish-mobl.ger.corp.intel.com (HELO localhost) ([10.252.10.152]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2023 05:28:10 -0800 From: Jani Nikula To: Daniel Vetter , David Laight 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 Subject: Re: [Intel-gfx] [PATCH 1/5] linux/minmax.h: add non-atomic version of xchg In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20221209154843.4162814-1-andrzej.hajda@intel.com> Date: Thu, 05 Jan 2023 15:28:07 +0200 Message-ID: <875ydlw1p4.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 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? BR, Jani. > > I think swap() is a standard idiom in C, this one here just isn't. > -Daniel -- Jani Nikula, Intel Open Source Graphics Center