Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp961829rwl; Thu, 5 Jan 2023 07:01:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXt7Jl/kUF9xiryLLjIaqxCI/Z4XIrWDH/pOtjd0ANTKy8bcGHPBfHnqY5BRPGDNpvmuzuAc X-Received: by 2002:a17:906:2801:b0:7c1:639:6b46 with SMTP id r1-20020a170906280100b007c106396b46mr40640406ejc.9.1672930884960; Thu, 05 Jan 2023 07:01:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672930884; cv=none; d=google.com; s=arc-20160816; b=VWIaBEqbsi2Uo2tPbQZ/fRJXWAErdWVxebrnysCVmWSc73ORwhfbqWHVciI0UOtx7w y9D6aET4CpTkicFVM6lMOrVIbPZY0ct05Duijzwne5F/U+XeRXLDvjfd2bRialUWLTpo O/sEz+xIT5l1qTr1W5H1JxXIJrGEHX+z9eRGT1fTTyOn29351DEnRavAYuGilfcStn2C jOXn9qUkIC6SICKyhegfeCD3mZF1jo0iTDjfa0dMYD0eDs9Va5SnxNQBK5lN5BCgQjFX OwaL1pRFwdBLcXOM+QlAflpLTBP+JNWFPnsDvYkXhdVxb0Tfd3PEi4p7HA7mwm2DZIcN GFbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=DtGt11HhgsZ45qNu61jMq21+Y6CaEWkW48MPYr22gEQ=; b=qAUt2IP/P+YGUSETNNgKjkVPt/aAdu21oEqnRa9Zi+MtQ9Q0EEyVsP3Wkx0lowWPdE MTRsDpfQuc39BqKGmC0/XK2+TarRoZPh8D3kz0oF5qu+azo04+Qcqb49H/kFPVMFqdXv a5S66KeIFeEMIQ+GtlfdOuEFrfimRRJsYjOhaIkkrYqv1fmK7HmDro8/5wjzxRZHC+em a4TpfhTzPAcVm2Nb98LgFOu1yw/qmdDHzqlCJgfHXEQu/6iJ0VZB2NxsT43O2rvkyYyb cTEueYCtpXqpUc9OgP7mRlsAyDlICmxEKiy8NxxkXvmS7UUG2NX2KDqaPo2E0dtA24dA hvUw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js4-20020a17090797c400b007acdb4016e0si33621672ejc.224.2023.01.05.07.00.56; Thu, 05 Jan 2023 07:01:24 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233384AbjAEOlw convert rfc822-to-8bit (ORCPT + 57 others); Thu, 5 Jan 2023 09:41:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233552AbjAEOlt (ORCPT ); Thu, 5 Jan 2023 09:41:49 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 702E42678 for ; Thu, 5 Jan 2023 06:41:47 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-267-TONGIBv5N4Gn3vUIarjFdA-1; Thu, 05 Jan 2023 14:41:44 +0000 X-MC-Unique: TONGIBv5N4Gn3vUIarjFdA-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 5 Jan 2023 14:41:43 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.044; Thu, 5 Jan 2023 14:41:43 +0000 From: David Laight To: 'Daniel Vetter' CC: 'Jani Nikula' , 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 Thread-Topic: [Intel-gfx] [PATCH 1/5] linux/minmax.h: add non-atomic version of xchg Thread-Index: AQHZC+X/n2yHksRnF0Csd/+tl8P8Ka5qAX6ggCX6JSGAAADCAIAAC3eAgAAFAzA= Date: Thu, 5 Jan 2023 14:41:43 +0000 Message-ID: <6617dfb150f94cbb9654a585843e3287@AcuMS.aculab.com> References: <20221209154843.4162814-1-andrzej.hajda@intel.com> <875ydlw1p4.fsf@intel.com> <733cd0037bd14a269b54d701e1b80323@AcuMS.aculab.com> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,PDS_BAD_THREAD_QP_64, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 From: Daniel Vetter > Sent: 05 January 2023 14:13 ... > > > 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. > > Yeah this is my point for fetch_and_zero or any of the other proposals. > We're essentially replacing these two lines: > > var = some->pointer->chase; > some->pointer->chase = NULL; > > with a macro. C is verbose, and sometimes painfully so, Try ADA or VHDL :-) > if the pointer > chase is really to onerous then I think that should be refactored with a > meaningfully locally name variable, not fancy macros wrapped around to > golf a few characters away. Provided 'var' is a local the compiler is pretty likely to only do the 'pointer chase' once. You can also do: var = NULL; swap(some->pointer->chase, var); and get pretty much the same object code. > But what about swap() you ask? That one needs a temp variable, and it does > make sense to hide that in a ({}) block in a macro. Sometimes, but not enough for the 'missed opportunity for swap()' message. > But for the above two > lines I really don't see a point outside of obfuscated C contexts. Indeed. Isn't the suggested __xchg() in one of the 'reserved for implementation' namespaces - so shouldn't be a function that might be expected to be actually used. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)