From patchwork Sun Mar 12 14:41:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 68358 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp745232wrd; Sun, 12 Mar 2023 07:43:30 -0700 (PDT) X-Google-Smtp-Source: AK7set9SJviCyqzWRO7XmWHMRlHGsRfj0MBSvHYDsQpYykwF1U/Tzf7hyY5g3uxCOvU728lWbEJC X-Received: by 2002:a17:90b:4d0a:b0:23a:87d1:9586 with SMTP id mw10-20020a17090b4d0a00b0023a87d19586mr30375205pjb.23.1678632210202; Sun, 12 Mar 2023 07:43:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678632210; cv=none; d=google.com; s=arc-20160816; b=vPwaVejLsYKbq+mpFQNefj+ndkzj+mxmOU0TynYEHC2vHgbFOL+aSuFGuNk7HjsUXT +o4tV3IC0C3K1RLunLbgs+q/M2/hgmocwnKf+4PFmuPxw06/fgZvIXcp3D7tFAPNJA4U HjiqbRZneLv7wBhVsstOd1sGmzfS/bAwgwPeQXI7WflrqDrH7rMr4e1qDycTrSvunhZ5 FX8fhFLLlDNHzTBZMNW12MkEik6JnrwWZxm78DLM02ta7gITkWauHO6sRSPLL+ePYAuP bGvD1xPjANmfpfIV18KASbzCmJZtohZZGI2nSJhJp+5fgJr/YgXfQt3gDr9bvCfVUEnA TWRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=k3578pmEp378IQxWSc72XQnWqdC6iEAWteZzAqX+ZxU=; b=Yuw7Fe8zYlb4WWxrgFrl3p0Q/6pAdDyLIhzPGaosovQvBMkh8bPfdk1fxQ0Bq2GLgn of2ae9ho9u+uiLb37Bztjuj7F4P36bFbbf7i+uGLW3CWJTuwCX6aHfGhuAjtfr0tT1vh siZ2vIpX3e7tSyx/Nk+aXfBHzIHKx8DGCBXI4TZsBxVrM2hb65aYd44YbEKjuKdUKuYT P7tJDFPGI77lOafBdRU2aNjb5TxyaUCVn1+8001IUzRJrZljxX9EoKYq2MafN6TYudOu p4zFLn/Gn05l0herN0f/zbuyz6uhbxpcgxTivgt3wxXbDLBUupd6PO1gjH0GM+xNSqW3 pP7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="mz/vk25N"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=x+z6JfEe; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a17090a428a00b002192eb3532bsi4206143pjg.116.2023.03.12.07.43.18; Sun, 12 Mar 2023 07:43:30 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b="mz/vk25N"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=x+z6JfEe; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbjCLOlg (ORCPT + 99 others); Sun, 12 Mar 2023 10:41:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbjCLOlU (ORCPT ); Sun, 12 Mar 2023 10:41:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E3604393B; Sun, 12 Mar 2023 07:41:19 -0700 (PDT) Date: Sun, 12 Mar 2023 14:41:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1678632076; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k3578pmEp378IQxWSc72XQnWqdC6iEAWteZzAqX+ZxU=; b=mz/vk25NAYQnhC+MN88gOb60ehNle3T0o8El0GwRDE539kdPF1YC/oG8a12A04zrSNpb0V YH5qQlkZCTfefrGmMY34EJkD0HEaoNxvOFeMWuLLHAuIUDrd4V63KiaRgd5+CZ8O3wTtLd JS28TOPOyLgyB7zdyG2seo+8f/Y2OgnZwkZ939Yvww8j2z9wur+xX+B6pUlD2duHi3SwUV niSfQCuEdtwl/RNODN6W1ayqnqo2BYh8pVU/3blmtR0hvqg0W6wbTSbyKa6ZD+rfpKqGe7 0gr3T8CmqyropewBaEZ+Je17JgIW2wQWNeYW7H6/ZfLlZc3iPAdM8DiJ87UWyg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1678632076; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k3578pmEp378IQxWSc72XQnWqdC6iEAWteZzAqX+ZxU=; b=x+z6JfEe4Hr2t4Ox2SfPQ/409kxN6CbiKnNUtzAL3om/PSIGrWEdZiEMC5RR2TeeWLzg76 QjeX5u5EMiqLcNAA== From: "tip-bot2 for Andrzej Hajda" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] linux/include: add non-atomic version of xchg Cc: Andrzej Hajda , "Peter Zijlstra (Intel)" , Andy Shevchenko , Andi Shyti , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230118154450.73842-2-andrzej.hajda@intel.com> References: <20230118154450.73842-2-andrzej.hajda@intel.com> MIME-Version: 1.0 Message-ID: <167863207565.5837.13979748605991037374.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755375804012581402?= X-GMAIL-MSGID: =?utf-8?q?1760173448462246419?= The following commit has been merged into the locking/core branch of tip: Commit-ID: 6e58fca8f12015d783df9d155bbb969a09a29e64 Gitweb: https://git.kernel.org/tip/6e58fca8f12015d783df9d155bbb969a09a29e64 Author: Andrzej Hajda AuthorDate: Wed, 18 Jan 2023 16:44:45 +01:00 Committer: Peter Zijlstra CommitterDate: Sat, 11 Mar 2023 14:03:58 +01:00 linux/include: add non-atomic version of xchg 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. Signed-off-by: Andrzej Hajda Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Andy Shevchenko Reviewed-by: Andi Shyti Link: https://lore.kernel.org/r/20230118154450.73842-2-andrzej.hajda@intel.com --- 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 0000000..f7fa5dd --- /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