From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C0EF2F21 for ; Thu, 22 Dec 2022 12:47:52 +0000 (UTC) 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="322031554" X-IronPort-AV: E=Sophos;i="5.96,265,1665471600"; d="scan'208";a="322031554" 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> Precedence: bulk X-Mailing-List: loongarch@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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 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 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6FA4AC4332F for ; Thu, 22 Dec 2022 12:48:52 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Nd99G5zNTz3bWF for ; Thu, 22 Dec 2022 23:48:50 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=HwtA9Sb0; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.intel.com (client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=andriy.shevchenko@linux.intel.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=HwtA9Sb0; dkim-atps=neutral Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Nd98F3bPvz30RT for ; Thu, 22 Dec 2022 23:47:55 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671713277; x=1703249277; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=UPM8RDFaM30ZmFrIb8CKMZ1JANhWUp662jbH45qLr6M=; b=HwtA9Sb0YmYexIIvfZrVLOPaC9tv8SAlwOAy1EWvD2spPC7GTqOtwKgT /j671UHExTBQ3NCbZdGEA+JY2+kTPy1ZyFkK4NlM40/KF4grf2aB1PWWO w84SWAssgQlPE2N+DHDNV/8fqERpJJmPAmR2MjVsc6vfLZU53CFH+3hix kAsfzDlZy2r9hgI8xCImCP6hVehMXPVokTebPZcYbh8S7Sr5s0NdlgQLQ Ei37k8ksnEpda11PFh0lew7i+u1GB4WLbYZGJwnIc9ApSLc1pxiQCnFz1 FuzsHBH/RBgJy5g0nHvBrQBfpKxhVCQ2PY6md4TiUnrrW3ikdiIjhNfMM A==; X-IronPort-AV: E=McAfee;i="6500,9779,10568"; a="322031551" X-IronPort-AV: E=Sophos;i="5.96,265,1665471600"; d="scan'208";a="322031551" 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: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List 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: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40A4BC4332F for ; Thu, 22 Dec 2022 12:48:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8E09510E11C; Thu, 22 Dec 2022 12:47:55 +0000 (UTC) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1F01710E0C6; Thu, 22 Dec 2022 12:47:51 +0000 (UTC) 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="322031545" X-IronPort-AV: E=Sophos;i="5.96,265,1665471600"; d="scan'208";a="322031545" 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 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 Subject: Re: [Intel-gfx] [PATCH 18/19] linux/include: add non-atomic version of xchg X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development 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: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D67CC4332F for ; Thu, 22 Dec 2022 13:51:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZfAv67ulTfuMJyEffJG+SIoE3FNV+RC9sMO9wXraJyM=; b=1vXtm6iKiMrfet dHiBSYtASIsgULkHNTJWLoqivj3BFQOnwzIG3GGVGNrbBLnq7wsRVtv3mf09glJUL1BfkufAEBFAM /bDczcFzxPV+TUTypBN+DLG6hAnS4vcl0pBxTMTNer4Uf02BcMh8+wZipT1WYOMNTYvUp6QGDB0Kt MNhzpO+zfTmwYV38z6tbw32syIUlAUhTU5NW0wpFzTrbjVrBMrF0ZxUYGIV45IZXTlmaILbKuCB+N GqdupZyP7V8lHhg3frtPdVs2XCFORQND/phDtgswe/EhvPG440UOXCDhYfLhTQK9qIe8/h2QZly1T DTw5DYf5Blfb5TM3BaoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8LxA-00Cb8R-WE; Thu, 22 Dec 2022 13:49:46 +0000 Received: from mga03.intel.com ([134.134.136.65]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8KzM-00C2Bm-Q1; Thu, 22 Dec 2022 12:47:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671713276; x=1703249276; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=UPM8RDFaM30ZmFrIb8CKMZ1JANhWUp662jbH45qLr6M=; b=K2etaX872S+4MUR9/eIj4wJsmme9tOOLNeERDeBxFXkNeqawDUM/WuSn usZwU+wyzttHHtW5gO4j1iOXRXmLzGYc3o3sDnHXDtRLL5h4QtCFOgRko gBs4ZO3/yH6Dq2ict8r+HkIx/n5EDCuxIt7OUdE0ehzYxiN1hClBz5XWv WzlynD5sEqa8QwqVtWgN+9IyI6G6RL4TJK9U/nGNTLxTgsUljl5cdFGPI OBfOfX/qbmzFnNzhEbygBpCC7jubYjKiv3IG1kPk+QZmOsxfXioXYwD7g KWZa4R/5MAMpRmndig3VsyHq0xdbH6DEcKhH8dDjcMOzTx1djO4NgW2hV w==; X-IronPort-AV: E=McAfee;i="6500,9779,10568"; a="322031546" X-IronPort-AV: E=Sophos;i="5.96,265,1665471600"; d="scan'208";a="322031546" 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-Disposition: inline In-Reply-To: <20221222114635.1251934-19-andrzej.hajda@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221222_044756_970198_A5956BCB X-CRM114-Status: GOOD ( 18.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F390BC4332F for ; Thu, 22 Dec 2022 13:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QdzhyNxLMVIPp8rLzA1zW4DrBFRap0+DdSHZgCFiMHE=; b=GX7h1HTfUb1iEm 7jo1XDKIje4wJK6Ukj+zc1Gol88DuqgSw+USnkFS0N++Ji3vYG1clpzbVYnt6oNnqjwfMQQ+/VoaZ A4NOy94aE1XEfSo1zS4JXJf4sim8CQh3+MraO9PzJ0erhLTKAvvw+YTWs5HSp4uAJEeSVPsYdEc74 uB2yLJHMCg+EG5bLLrL10hPx/GWoCz01VoOhBbl5NjjYqDCdepta+tc8t2q9g48eMmGB8ijTIfe6r j8sKs4KJfjTxVc3b7sJM9fuQxuw8ZeTDNj7kRo5bsrvRdQaj+RO1c1uKLTUoUjy7t0bSd7gakIS0L Ilx+K4lv5B2UYDsEAJDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8LzH-00CcUx-U8; Thu, 22 Dec 2022 13:51:56 +0000 Received: from mga03.intel.com ([134.134.136.65]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8KzM-00C2Bm-Q1; Thu, 22 Dec 2022 12:47:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671713276; x=1703249276; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=UPM8RDFaM30ZmFrIb8CKMZ1JANhWUp662jbH45qLr6M=; b=K2etaX872S+4MUR9/eIj4wJsmme9tOOLNeERDeBxFXkNeqawDUM/WuSn usZwU+wyzttHHtW5gO4j1iOXRXmLzGYc3o3sDnHXDtRLL5h4QtCFOgRko gBs4ZO3/yH6Dq2ict8r+HkIx/n5EDCuxIt7OUdE0ehzYxiN1hClBz5XWv WzlynD5sEqa8QwqVtWgN+9IyI6G6RL4TJK9U/nGNTLxTgsUljl5cdFGPI OBfOfX/qbmzFnNzhEbygBpCC7jubYjKiv3IG1kPk+QZmOsxfXioXYwD7g KWZa4R/5MAMpRmndig3VsyHq0xdbH6DEcKhH8dDjcMOzTx1djO4NgW2hV w==; X-IronPort-AV: E=McAfee;i="6500,9779,10568"; a="322031546" X-IronPort-AV: E=Sophos;i="5.96,265,1665471600"; d="scan'208";a="322031546" 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-Disposition: inline In-Reply-To: <20221222114635.1251934-19-andrzej.hajda@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221222_044756_970198_A5956BCB X-CRM114-Status: GOOD ( 18.97 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A147FC4332F for ; Thu, 22 Dec 2022 13:51:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YxNEQNQxn7O+IVJffwEgNrpI2Nj5PV5k+QGnMCaZOrU=; b=cho/doro99Z/2/ U3Ll4rcZQFGzvlcWGZY/xuKY+/nXcGxvsTP5GEooVSaNsS+fF8bSsBvkY1DsSDHHO/0FCTBhKMKIf XZcnbeL9wf36euP127AayWqFCbzewzOfKdzXAhKTlEh4HOrBHTMGv7VCbguF6MHvLQz3CmF0OioBn 5VDlk6xYjefxLYOlHHAS1E1VWpjqAia/m1ioAGtW4UmZqNGMO1pgTVGgF7TFN1n4aqNWXvI5rTUCA DRxRaisxbhSDWtV9KoAdY3gXcJfkzEcNpuEuWiJ5o5JsEV9j1goDJHrZd0U5kDsq++iM99AiWoDl3 GU+8B/8L/7RNjNH0aSCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8LzF-00CcTt-SI; Thu, 22 Dec 2022 13:51:53 +0000 Received: from mga03.intel.com ([134.134.136.65]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8KzM-00C2Bm-Q1; Thu, 22 Dec 2022 12:47:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671713276; x=1703249276; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=UPM8RDFaM30ZmFrIb8CKMZ1JANhWUp662jbH45qLr6M=; b=K2etaX872S+4MUR9/eIj4wJsmme9tOOLNeERDeBxFXkNeqawDUM/WuSn usZwU+wyzttHHtW5gO4j1iOXRXmLzGYc3o3sDnHXDtRLL5h4QtCFOgRko gBs4ZO3/yH6Dq2ict8r+HkIx/n5EDCuxIt7OUdE0ehzYxiN1hClBz5XWv WzlynD5sEqa8QwqVtWgN+9IyI6G6RL4TJK9U/nGNTLxTgsUljl5cdFGPI OBfOfX/qbmzFnNzhEbygBpCC7jubYjKiv3IG1kPk+QZmOsxfXioXYwD7g KWZa4R/5MAMpRmndig3VsyHq0xdbH6DEcKhH8dDjcMOzTx1djO4NgW2hV w==; X-IronPort-AV: E=McAfee;i="6500,9779,10568"; a="322031546" X-IronPort-AV: E=Sophos;i="5.96,265,1665471600"; d="scan'208";a="322031546" 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-Disposition: inline In-Reply-To: <20221222114635.1251934-19-andrzej.hajda@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221222_044756_970198_A5956BCB X-CRM114-Status: GOOD ( 18.97 ) X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+linux-snps-arc=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Shevchenko Date: Thu, 22 Dec 2022 12:47:42 +0000 Subject: Re: [PATCH 18/19] linux/include: add non-atomic version of xchg Message-Id: List-Id: References: <20221222114635.1251934-1-andrzej.hajda@intel.com> <20221222114635.1251934-19-andrzej.hajda@intel.com> In-Reply-To: <20221222114635.1251934-19-andrzej.hajda@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Shevchenko Subject: Re: [PATCH 18/19] linux/include: add non-atomic version of xchg Date: Thu, 22 Dec 2022 14:47:42 +0200 Message-ID: References: <20221222114635.1251934-1-andrzej.hajda@intel.com> <20221222114635.1251934-19-andrzej.hajda@intel.com> Mime-Version: 1.0 Return-path: 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==; Content-Disposition: inline In-Reply-To: <20221222114635.1251934-19-andrzej.hajda@intel.com> List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 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