Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp858902rwl; Thu, 5 Jan 2023 05:41:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXsqGlvJuD2af4ro7pI9JAW5i+7Kv6pTsSRL/l5hIT2btYJTht48Mue3NIRaPWx7g1wbVfw6 X-Received: by 2002:a17:90b:3714:b0:225:f47d:b49f with SMTP id mg20-20020a17090b371400b00225f47db49fmr41233387pjb.39.1672926095586; Thu, 05 Jan 2023 05:41:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672926095; cv=none; d=google.com; s=arc-20160816; b=opBXbalKKVWJnGkeejZ+8E549kuiHVsG7PLewCkjinetdu7UZDVZrVOdz62a5OwLFY iSen/DoLo5Iv9gT2CP/tFy3+R8Um5Y6ddJIJnHs6pp0Vi0kbEU9VmMQbwYypCVvt9JHs a48XCc/Cs6pNv8AY5wPkEMUkQODe2qsalYHmbUZTgpGLv+q5R6ahmgZGbjOgKLKVhmrp qaW7Xs6Tq+ZKuFkmoQuepeus2GNc4wCCR5OJ0FwxbWOnuI0NfzA+r9O7bN4hDmjWa7/5 Pt+qwoQ21X5AimYTjGfaY/4Fp+ao/nhnRXQjxC4MfSvKWxCOfZRupkTB8vbrLIQT9NDz MrqQ== 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=fClLL59Dm4vVY8rRiag8YTuoK7tgrWHXPYqRVO+LTv4=; b=dA8oOC7ZYdBOaMLXPFgOnEmfVL5uGxu8wp15pQBZ4fsn0cloe3rZjqvBYaLJ4GmkAC JPjjiOfcU+a3tB1xMjdBVz/KjSLM4ePZgDQNBpdR6zyRHovQ4qZuB9xkSTMICRyFlvNe 1maRbXlcMq7Z1P8ZfZKkBApxIbuFk0gKlXeu0OGxHyMPmFW40XOlEUvNwYrf5cJRwiPf wQSBiJYtH2jZgOLJeMJyetH74Nt48JegYFzsrFLfD9oUwcf4YVAS66Mesi4jO4RgKcDH 0W21X5RBso7IzTgizUVfPrvZ8DFh+l+sAwTOJ3bJy8Kd/E9rGmbPIJWGCtKIDbROqUqz PWKA== 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 na13-20020a17090b4c0d00b002262ce26628si2115391pjb.184.2023.01.05.05.41.28; Thu, 05 Jan 2023 05:41:35 -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 S231616AbjAENek convert rfc822-to-8bit (ORCPT + 56 others); Thu, 5 Jan 2023 08:34:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230306AbjAENei (ORCPT ); Thu, 5 Jan 2023 08:34:38 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06FF52F79C for ; Thu, 5 Jan 2023 05:34:36 -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-76-LkZmLSiwP3mo41Bkd9-7GA-1; Thu, 05 Jan 2023 13:34:34 +0000 X-MC-Unique: LkZmLSiwP3mo41Bkd9-7GA-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 5 Jan 2023 13:34:33 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.044; Thu, 5 Jan 2023 13:34:33 +0000 From: David Laight To: '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 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/+tl8P8Ka5qAX6ggCX6JSGAAADCAA== Date: Thu, 5 Jan 2023 13:34:33 +0000 Message-ID: <733cd0037bd14a269b54d701e1b80323@AcuMS.aculab.com> References: <20221209154843.4162814-1-andrzej.hajda@intel.com> <875ydlw1p4.fsf@intel.com> In-Reply-To: <875ydlw1p4.fsf@intel.com> 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: 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. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)