Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1449924lqt; Wed, 20 Mar 2024 04:39:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUZ0dUL6Sr4yx79cbEJ45JMYFOOHsDf8dsqOkD0fAMjTBU1MblZ942/XWrwnE70OhQgYnBsBat4Sp8K/C/j750Ly27ztuffoz6GUilVvA== X-Google-Smtp-Source: AGHT+IEhgjXYrNRZLvFtST0XbXGAiAikbrHokCKle3uqLYVHlJs4IzWcIEcIjLn9h2O5VVRkGBaA X-Received: by 2002:a05:6a00:3c8a:b0:6e7:933:9ecf with SMTP id lm10-20020a056a003c8a00b006e709339ecfmr8153511pfb.16.1710934776666; Wed, 20 Mar 2024 04:39:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710934776; cv=pass; d=google.com; s=arc-20160816; b=N6eI7P5sZWgQ54R8cVqIOV8fRy2K8mr+/BXBJCvk6PpAbWq+qR21snXe+fcdfbECvb /EqZodP7wPiBCvHnlcDgQqf+XVXj9LfFgyr8eG3tOSbDSFnyMsgPTWpTkgwnP8rNjY+O hlysvQ8pmvgMb9YxCPWcIfOgzhkoxM2qAEVeM5v0+OEw8mhBjtZ84O+I2DFRqsyawMJj XgWDzWUBiU3evtCUfyEprj8GNhLSjc5WgNu8DRjcgTxihFl1G6IkWQpJpbqHffK9bNIJ DN5KWtlF8zPAgQEO/yjvbOw6MW2I+QO7IKb1X4ceZfAe1uBS1fwuz7fyDpul+bB+rNGc iqzQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=FmKrlwo6K+OzVjE/c/n5/6AUV9qxvSPCEYbMNQmUmjc=; fh=txHNRbpqmVIABc77gKnpqKAdyWBzMQZ8kaw0A46wZfY=; b=EkCTo/dvl+UroNWDtR2RledbfpuQC7wuptlfKE+CFUOZFsQevNZNi3rJHzFACahISv 0B83qfAOsTbLFdL6cHffeifl0uLRZ9nXQ81pKoLj3XEpda8Ukx4MTI+eQfVnmsO73z+Y YFnY6EQlmme1LMTOhOms2WUIjPO5fHutVVBx3pubV7cJJEE2M5rAquVpk1WD1AmhTKo4 kX6mqPl90VlzWxNu2Bxnw4WeYaCWE/kxcNRiSR6J7XXB5EBz12J6OUq/YSd/dvOmSISA abHc++EZB4EUyv676EbrFYHxAMoX4ZJk5sQ/luC5XmYyVvB6zTHSyVInEKpvTvB/7Bew QnwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EHLSjC1N; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=LqQqa1kk; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-108869-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108869-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g10-20020a63110a000000b005d24ebc7f36si12093833pgl.406.2024.03.20.04.39.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 04:39:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108869-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EHLSjC1N; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=LqQqa1kk; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-108869-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108869-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4B573285A7E for ; Wed, 20 Mar 2024 11:39:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0168B3F9FA; Wed, 20 Mar 2024 11:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EHLSjC1N"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LqQqa1kk" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 7C60B3CF6A; Wed, 20 Mar 2024 11:39:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934764; cv=none; b=ZUpVgESa8qOTIJSXYmLWBloBFfI+4LQo01lqyrWiD5P2a3IpJXObR4nhUl6cuJ/3hM+v0O1RaAk+BatMbOqbIWbi1BNMjjQFyJVODUnz6cdD4Bw4RyPB+peXksK76RFHjKHwnN8/HQvMYSeNQIAp915CuQZcko7tRyVRUJvCAs8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934764; c=relaxed/simple; bh=jIgEtsF7ZyIMIxyuNTCdT3L6w4xlOz2tkLW4F+UoDQ8=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=XuI+gQeSnNhRszwhNagRBx/wivVqHawv6qb9wfvPZJmBGR15m06bYaiGToyNczRRpGmQfsuTZ72YEormKcWN+8z6AddS/XZRPQ0ukMukBZUFvZkUt1cz7SEiOch8AJ4s9XS5Q/W96UKypLriryOEDfm5dP7GVjACJPnSOrA+Myw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=EHLSjC1N; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LqQqa1kk; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 20 Mar 2024 11:39:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1710934760; 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=FmKrlwo6K+OzVjE/c/n5/6AUV9qxvSPCEYbMNQmUmjc=; b=EHLSjC1N4lQLGsZpGhj0B9/PqrzCRvNa4nkJcI/SoudX1sZKQcIROKzoEDm0q+6LzNiKek HW2GbjGP6IEWrxVGFccj/ldDw9nYrIxz8XAM04E3h/UmNbqT7ngpb8TqzNOJP+ElbaGt1p oQ8l1PK1dlaQX8RrPIu1W2Tu7l+EUh0s6KCfRgUCx0zGbcN5G3P2XVFbtLLY8lwb/4FdHm amWfJD7oo5nsKzxrERtUNb6VMnRLc5MvarD7/HHUOF11iax6jqTc8GZ4cg/CFdkcUmne1a 8vwlA2l4s73L3sGwnpgooziYGEPOc6lz7EeBgAcrrmEajLJPeQhKQlzpOiQHpA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1710934760; 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=FmKrlwo6K+OzVjE/c/n5/6AUV9qxvSPCEYbMNQmUmjc=; b=LqQqa1kkbysomm45bM68zN9aDz4QomY50M5IlCRpE6fwCRhfnOGUfVr0eL4wY6Dez0U6nm 2FGFtwSo1HMeDJBw== From: "tip-bot2 for Uros Bizjak" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/percpu] x86/percpu: Convert this_percpu_xchg_op() from asm() to C code, to generate better code Cc: Uros Bizjak , Ingo Molnar , "H. Peter Anvin" , Linus Torvalds , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240320083127.493250-1-ubizjak@gmail.com> References: <20240320083127.493250-1-ubizjak@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171093476000.10875.14076471223590027773.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/percpu branch of tip: Commit-ID: 0539084639f3835c8d0b798e6659ec14a266b4f1 Gitweb: https://git.kernel.org/tip/0539084639f3835c8d0b798e6659ec14a266b4f1 Author: Uros Bizjak AuthorDate: Wed, 20 Mar 2024 09:30:40 +01:00 Committer: Ingo Molnar CommitterDate: Wed, 20 Mar 2024 12:29:02 +01:00 x86/percpu: Convert this_percpu_xchg_op() from asm() to C code, to generate better code Rewrite percpu_xchg_op() using generic percpu primitives instead of using asm. The new implementation is similar to local_xchg() and allows the compiler to perform various optimizations: e.g. the compiler is able to create fast path through the loop, according to likely/unlikely annotations in percpu_try_cmpxchg_op(). No functional changes intended. Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Cc: "H. Peter Anvin" Cc: Linus Torvalds Link: https://lore.kernel.org/r/20240320083127.493250-1-ubizjak@gmail.com --- arch/x86/include/asm/percpu.h | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 44958eb..de991e6 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -230,25 +230,15 @@ do { \ }) /* - * xchg is implemented using cmpxchg without a lock prefix. xchg is - * expensive due to the implied lock prefix. The processor cannot prefetch - * cachelines if xchg is used. + * this_cpu_xchg() is implemented using cmpxchg without a lock prefix. + * xchg is expensive due to the implied lock prefix. The processor + * cannot prefetch cachelines if xchg is used. */ -#define percpu_xchg_op(size, qual, _var, _nval) \ +#define this_percpu_xchg_op(_var, _nval) \ ({ \ - __pcpu_type_##size pxo_old__; \ - __pcpu_type_##size pxo_new__ = __pcpu_cast_##size(_nval); \ - asm qual (__pcpu_op2_##size("mov", __percpu_arg([var]), \ - "%[oval]") \ - "\n1:\t" \ - __pcpu_op2_##size("cmpxchg", "%[nval]", \ - __percpu_arg([var])) \ - "\n\tjnz 1b" \ - : [oval] "=&a" (pxo_old__), \ - [var] "+m" (__my_cpu_var(_var)) \ - : [nval] __pcpu_reg_##size(, pxo_new__) \ - : "memory"); \ - (typeof(_var))(unsigned long) pxo_old__; \ + typeof(_var) pxo_old__ = this_cpu_read(_var); \ + do { } while (!this_cpu_try_cmpxchg(_var, &pxo_old__, _nval)); \ + pxo_old__; \ }) /* @@ -534,9 +524,9 @@ do { \ #define this_cpu_or_1(pcp, val) percpu_to_op(1, volatile, "or", (pcp), val) #define this_cpu_or_2(pcp, val) percpu_to_op(2, volatile, "or", (pcp), val) #define this_cpu_or_4(pcp, val) percpu_to_op(4, volatile, "or", (pcp), val) -#define this_cpu_xchg_1(pcp, nval) percpu_xchg_op(1, volatile, pcp, nval) -#define this_cpu_xchg_2(pcp, nval) percpu_xchg_op(2, volatile, pcp, nval) -#define this_cpu_xchg_4(pcp, nval) percpu_xchg_op(4, volatile, pcp, nval) +#define this_cpu_xchg_1(pcp, nval) this_percpu_xchg_op(pcp, nval) +#define this_cpu_xchg_2(pcp, nval) this_percpu_xchg_op(pcp, nval) +#define this_cpu_xchg_4(pcp, nval) this_percpu_xchg_op(pcp, nval) #define raw_cpu_add_return_1(pcp, val) percpu_add_return_op(1, , pcp, val) #define raw_cpu_add_return_2(pcp, val) percpu_add_return_op(2, , pcp, val) @@ -575,7 +565,7 @@ do { \ #define this_cpu_and_8(pcp, val) percpu_to_op(8, volatile, "and", (pcp), val) #define this_cpu_or_8(pcp, val) percpu_to_op(8, volatile, "or", (pcp), val) #define this_cpu_add_return_8(pcp, val) percpu_add_return_op(8, volatile, pcp, val) -#define this_cpu_xchg_8(pcp, nval) percpu_xchg_op(8, volatile, pcp, nval) +#define this_cpu_xchg_8(pcp, nval) this_percpu_xchg_op(pcp, nval) #define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, volatile, pcp, oval, nval) #define this_cpu_try_cmpxchg_8(pcp, ovalp, nval) percpu_try_cmpxchg_op(8, volatile, pcp, ovalp, nval) #endif