Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp83766rwj; Thu, 22 Dec 2022 05:19:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXtS/2fMf0F89nStd0Vb9LaakLKcf7yC/9YZexpPcpS81KhURx7d46LqImh1dDLCQMDda3OX X-Received: by 2002:a17:907:c28f:b0:7c1:eb:b2a7 with SMTP id tk15-20020a170907c28f00b007c100ebb2a7mr8374631ejc.13.1671715164047; Thu, 22 Dec 2022 05:19:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671715164; cv=none; d=google.com; s=arc-20160816; b=wjZH1x5R26e1u7AlNSa7bi8VAFmHoXT7YNyaUAvvmeGwioEZD56rutEQ4xTj6iHEOx reFvHBjsLgxlDeDCONTgnPBc4J7USeYcNj1WA72dGpj//b63MM+sk702/CZ7MlsXr4l3 V4+jK82BMCRwPQ7b3982oscJch1pFksmkJkrBi2sIw8tBv1XQAZqZ/l94BF3/vBhbEyF hnoT7XkU9LQ2QO2YHOmfYOMGymmatsvsXZrrLfLDXQW1fvvDlXNYmGwtOBD6RDHPGUZB hBA/gGsSC8iFD7pzjmD6b9Y2CJfXX2lgwQAyGGGeUYLlUmbDMR9JjgBO2zt2NFSLby86 x2ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=+7uCqitK+q5Gl8xTt9Jn6BQP/Gzj2rHpUyl7jrSeXLY=; b=XMN28Dtp41bZWFtLS9tiI+V+d52Co9MtP29sSfPzw5VyaO/FTVNvAzz6VnSIvvpui9 u7zPD2syhoS74d8+F4RrZAahUCNcllQ6+B1SCKl95z6YCzkqMslkmqdR9zC2+PvHryXP ZDEHw0YQ/hM0abpRKTUVLUPt1swr9j5Ty1B4QnwdGvLcRFId2UVU0KmFh9utJPa4C4A5 MQFRHQ+xK/TfbjUBUR680iDQDl27vc46BoOxV2sPkzCMyqkkpjJWjvc5Z/p3hjlVSDvg PiN99BSp16ia6UrQ03JB7KJ1lar0pDB1OqqcAUafdYXUrLEftRplpaPfqBjhRPG/+1dU DGEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=U7Ti5gM7; 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 ji19-20020a170907981300b007b7f39942c1si465526ejc.632.2022.12.22.05.19.08; Thu, 22 Dec 2022 05:19: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; dkim=pass header.i=@intel.com header.s=Intel header.b=U7Ti5gM7; 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 S235274AbiLVMrz (ORCPT + 67 others); Thu, 22 Dec 2022 07:47:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230134AbiLVMrx (ORCPT ); Thu, 22 Dec 2022 07:47:53 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41D9E22B; Thu, 22 Dec 2022 04:47:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671713272; x=1703249272; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=UPM8RDFaM30ZmFrIb8CKMZ1JANhWUp662jbH45qLr6M=; b=U7Ti5gM7uX2hSBxzWafGGZSDBcDqjumI2csrgPUV3Gmaxw1BNaf3z8Ro FF6neieM8V/SA6HrQxhmet6cGsg8V1Pn4Ot+4KX3fglxDxDH1pnW3PVoK 9YZRCSIZn28az1kCO6XUr5BdCTW0FvwIqD4SViceQ6X0gdg6zF7f5QLxR /Bo00h41XDF2crkrb9MNAQZgCN8wXjmgNq51blBh7KNfBIdJYH2/+Rvm3 /zv4/jpzOePRSdt+y2oFm4ceGTgMmphSDzSce147uOX4vF6brBHpliEaY BbIViYm6PVSbzGpAKVyuCm0/IWoVcd4nQbwgISsWEK4Ox8GcXvIGwMOIB A==; X-IronPort-AV: E=McAfee;i="6500,9779,10568"; a="322031547" X-IronPort-AV: E=Sophos;i="5.96,265,1665471600"; d="scan'208";a="322031547" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2022 04:47:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10568"; a="897213732" X-IronPort-AV: E=Sophos;i="5.96,265,1665471600"; d="scan'208";a="897213732" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga006.fm.intel.com with ESMTP; 22 Dec 2022 04:47:45 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1p8Kz8-00Duf4-1e; Thu, 22 Dec 2022 14:47:42 +0200 Date: Thu, 22 Dec 2022 14:47:42 +0200 From: Andy Shevchenko To: Andrzej Hajda Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Arnd Bergmann , Rodrigo Vivi , Andrew Morton , Peter Zijlstra , Boqun Feng , Mark Rutland Subject: Re: [PATCH 18/19] linux/include: add non-atomic version of xchg Message-ID: References: <20221222114635.1251934-1-andrzej.hajda@intel.com> <20221222114635.1251934-19-andrzej.hajda@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221222114635.1251934-19-andrzej.hajda@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo 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, Dec 22, 2022 at 12:46:34PM +0100, 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. FWIW, Reviewed-by: Andy Shevchenko > Signed-off-by: Andrzej Hajda > --- > include/linux/non-atomic/xchg.h | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > create mode 100644 include/linux/non-atomic/xchg.h > > diff --git a/include/linux/non-atomic/xchg.h b/include/linux/non-atomic/xchg.h > new file mode 100644 > index 00000000000000..f7fa5dd746f37d > --- /dev/null > +++ b/include/linux/non-atomic/xchg.h > @@ -0,0 +1,19 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _LINUX_NON_ATOMIC_XCHG_H > +#define _LINUX_NON_ATOMIC_XCHG_H > + > +/** > + * __xchg - 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 __xchg(ptr, val) ({ \ > + __auto_type __ptr = ptr; \ > + __auto_type __t = *__ptr; \ > + *__ptr = (val); \ > + __t; \ > +}) > + > +#endif > -- > 2.34.1 > -- With Best Regards, Andy Shevchenko