From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.librecores.org (lists.librecores.org [88.198.125.70]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB705C10F1D for ; Thu, 22 Dec 2022 12:47:56 +0000 (UTC) Received: from [172.31.1.100] (localhost.localdomain [127.0.0.1]) by mail.librecores.org (Postfix) with ESMTP id 8CEBD25C15; Thu, 22 Dec 2022 13:47:55 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mail.librecores.org (Postfix) with ESMTPS id 3827825BFE for ; Thu, 22 Dec 2022 13:47:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671713274; x=1703249274; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=UPM8RDFaM30ZmFrIb8CKMZ1JANhWUp662jbH45qLr6M=; b=CJrefC1nTVyLiuNEMgvtGEqSN8He8lV9VA4K3Kdn203KZgelY5TNuqGC hT3wYxKrAKujkwhYOM0vJjVp7Xt7Yt9n76UgjKigc7d5miwMi3l6GxaWZ SiVDTo1gLTvJ0XqWDwWJMvtvitpWV2+ICeb3DBt9Dy0vMCs9Alhsn1u9W UaIzomewW6wNpF8+y/L70tHmPb8ilQ85CUyOxXxv7rUMyR12Nod0EH2x5 lF5ilD9umE+/wYzfraZaG/w8IFdAPU83WD7qqVKmxaz7sqUHzsGpnIqCz P5czRJHZMIks6kH/am+CWOxak5hTch2NAaF1MgZvUH3fTvvZbAPczE+ae g==; X-IronPort-AV: E=McAfee;i="6500,9779,10568"; a="322031556" X-IronPort-AV: E=Sophos;i="5.96,265,1665471600"; d="scan'208";a="322031556" 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 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-BeenThere: openrisc@lists.librecores.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Discussion around the OpenRISC processor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , linux-ia64@vger.kernel.org, linux-sh@vger.kernel.org, Peter Zijlstra , dri-devel@lists.freedesktop.org, linux-mips@vger.kernel.org, sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-snps-arc@lists.infradead.org, Boqun Feng , linux-xtensa@linux-xtensa.org, Arnd Bergmann , intel-gfx@lists.freedesktop.org, linux-m68k@lists.linux-m68k.org, openrisc@lists.librecores.org, loongarch@lists.linux.dev, Rodrigo Vivi , linux-arm-kernel@lists.infradead.org, linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: openrisc-bounces@lists.librecores.org Sender: "OpenRISC" 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