Received: by 2002:a17:90a:bc8d:0:0:0:0 with SMTP id x13csp1519275pjr; Mon, 18 May 2020 15:18:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJye21+pxyVyMO/YnJ5MkEBUAYfO5oRe+v9FVKjySkhwqzADrVpQN83rYqnmbMuWfbCtgwsr X-Received: by 2002:a50:e607:: with SMTP id y7mr15985286edm.71.1589840296583; Mon, 18 May 2020 15:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589840296; cv=none; d=google.com; s=arc-20160816; b=HHXBE4tEDjSKLpFAmTf9N3q10RGUxoPUtNZPXFXEH4Rfh4kW8WcLW0T2puLOMyeYDb UkFPbP3MeqFEUarJgPzRYNovJv2N4VLMD70Yv5gDYcM/zQwu/5/8PK0IYPaL/BDahIDJ eOaKwqSn+hch4KI9E96nuADGYBES5fJ0qzTgNwSNGJfQOjvqi6I2szgnNT8a4+wo0sAi xJduteW9/rRIVxo1GF3aWNeVzN3+FiE62C/PPYKK+lvc/zWoI8LIvI2sUOBW5IlAn2Il CtY1HB74j6dZGkHXBFgl8yocVr4szPT7lRLBHnUTPE9unQ03Azq2L3SfWTchSdxq3WWw KjUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vkP+UGX470bkhN1JPkQIj9DQ3/sS/6tlpvt6hXlXh0s=; b=R78u4d5/8XhN2KrUwYXquP/TKMEGEPLvsbxdE3qD03wO7CaH8VhyC33OvhPUPL/qGy 6ZhbJNyBC5753NH2ET/ySlHcbIEPelGdW3T0UhNpZk9CqJgzalsqk8XDQZTZaEFv/6rt wChgnNxFPjJpplgqXEPgbCcoPAjtHXOhZ/P3G7FdcY0sRF33R30jToN6kkCBob2yHOyE a9Dq24ns6ehFdWe/eYQU+/kAYUThzK4Xnw9WD9DBLMzPNonNhF8JO8Vy/DNj6t5sInMR +Zz+6XrrgA9b8WuBQu8eCYg7TxWJk71kdwBU6m6/WjKFAAR9r1G60kZ5GqkoT71AsQ4j 9ABg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ObfRZ9Sc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm8si9197652ejc.453.2020.05.18.15.17.53; Mon, 18 May 2020 15:18:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ObfRZ9Sc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728287AbgERWQO (ORCPT + 99 others); Mon, 18 May 2020 18:16:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726386AbgERWQN (ORCPT ); Mon, 18 May 2020 18:16:13 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 786BDC061A0C for ; Mon, 18 May 2020 15:16:13 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id s69so456389pjb.4 for ; Mon, 18 May 2020 15:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vkP+UGX470bkhN1JPkQIj9DQ3/sS/6tlpvt6hXlXh0s=; b=ObfRZ9Sc3E5TFE30lxNGV1WqAKe/y97qTa4d1IlG5NVXN4NJ7Xe+dYdQn9CpONN1pd T33SoElRWHnpXKWSNJXYSoSdu/Iww4MRm/p2CyR6+fRuggGBBNRPy5hPw+Z1IRK6etTc ZhjWdAcnZmo+VHcnl06ssK7iJRqrcko72W2jC374kmjWmKO0x9+m7ic+W5eRn/6nQ5ic Sf/UYsk/+uBYR0vVSik6ysIRWGKvqipyL2A9kk5N7bXh0SJ+cXZSS0OxBvI5MucoMu9n FLiQ9KyAm+zLLL668zsn7hJlTIIAooYINaL1mrMpIrbgT2ElAqSB0351DdYHmNMf3zMH E1JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vkP+UGX470bkhN1JPkQIj9DQ3/sS/6tlpvt6hXlXh0s=; b=DxLfjZ4mnPACufw4GdhrvjUFh9omiPdZG/D3CEoJS949eSSJmLGhN57Jb8EW4FDbb/ TNcghBBTeXH3HQWHmvJtwHkK/B18Db7j8zmddpUG9gr2bdyNVQ5WIRKsJcvh1izBcVlL WiA2Rn/SVpL4W7SRFyE08fdJKwoMYb1FD8KbsmntF5kv6BzD8A5/EHpPIKeyn6NL83BW c6hyBo+TUlLIOKD84ZK4IHpOMTnOwOlvqekDT7OennTTimty4JaNWsJc4kLpGgrF+6W+ 5sv1IFDs3Ox+mtqYZ1M0OlRtJv7Fh7vk44x1gZ2azX4gAUNCRXfrNPm2EXvL5JrLE3rE 3Hvg== X-Gm-Message-State: AOAM530Rj+tXUuVDfDw45qwvLetGHLhdAPB17yUYMk7qe6JIy8NKdXUe CFDondyNAbtXqpzAHv92TKL4pvZ7GmUEjq2aRkLN8w== X-Received: by 2002:a17:90b:19cc:: with SMTP id nm12mr1526627pjb.25.1589840172658; Mon, 18 May 2020 15:16:12 -0700 (PDT) MIME-Version: 1.0 References: <20200517152916.3146539-1-brgerst@gmail.com> <20200517152916.3146539-7-brgerst@gmail.com> In-Reply-To: <20200517152916.3146539-7-brgerst@gmail.com> From: Nick Desaulniers Date: Mon, 18 May 2020 15:15:58 -0700 Message-ID: Subject: Re: [PATCH 6/7] x86/percpu: Clean up percpu_xchg_op() To: Brian Gerst Cc: LKML , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 17, 2020 at 8:29 AM Brian Gerst wrote: > > The core percpu macros already have a switch on the data size, so the switch > in the x86 code is redundant and produces more dead code. > > Also use appropriate types for the width of the instructions. This avoids > errors when compiling with Clang. > > Signed-off-by: Brian Gerst Reviewed-by: Nick Desaulniers > --- > arch/x86/include/asm/percpu.h | 61 +++++++++++------------------------ > 1 file changed, 18 insertions(+), 43 deletions(-) > > diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h > index ac8c391a190e..3c95ab3c99cd 100644 > --- a/arch/x86/include/asm/percpu.h > +++ b/arch/x86/include/asm/percpu.h > @@ -215,46 +215,21 @@ do { \ > * expensive due to the implied lock prefix. The processor cannot prefetch > * cachelines if xchg is used. > */ > -#define percpu_xchg_op(qual, var, nval) \ > +#define percpu_xchg_op(size, qual, _var, _nval) \ > ({ \ > - typeof(var) pxo_ret__; \ > - typeof(var) pxo_new__ = (nval); \ > - switch (sizeof(var)) { \ > - case 1: \ > - asm qual ("\n\tmov "__percpu_arg(1)",%%al" \ > - "\n1:\tcmpxchgb %2, "__percpu_arg(1) \ > - "\n\tjnz 1b" \ > - : "=&a" (pxo_ret__), "+m" (var) \ > - : "q" (pxo_new__) \ > - : "memory"); \ > - break; \ > - case 2: \ > - asm qual ("\n\tmov "__percpu_arg(1)",%%ax" \ > - "\n1:\tcmpxchgw %2, "__percpu_arg(1) \ > - "\n\tjnz 1b" \ > - : "=&a" (pxo_ret__), "+m" (var) \ > - : "r" (pxo_new__) \ > - : "memory"); \ > - break; \ > - case 4: \ > - asm qual ("\n\tmov "__percpu_arg(1)",%%eax" \ > - "\n1:\tcmpxchgl %2, "__percpu_arg(1) \ > - "\n\tjnz 1b" \ > - : "=&a" (pxo_ret__), "+m" (var) \ > - : "r" (pxo_new__) \ > - : "memory"); \ > - break; \ > - case 8: \ > - asm qual ("\n\tmov "__percpu_arg(1)",%%rax" \ > - "\n1:\tcmpxchgq %2, "__percpu_arg(1) \ > - "\n\tjnz 1b" \ > - : "=&a" (pxo_ret__), "+m" (var) \ > - : "r" (pxo_new__) \ > - : "memory"); \ > - break; \ > - default: __bad_percpu_size(); \ > - } \ > - pxo_ret__; \ > + __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" (_var) \ > + : [nval] __pcpu_reg_##size(, pxo_new__) \ > + : "memory"); \ > + (typeof(_var))(unsigned long) pxo_old__; \ > }) > > /* > @@ -354,9 +329,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(volatile, pcp, nval) > -#define this_cpu_xchg_2(pcp, nval) percpu_xchg_op(volatile, pcp, nval) > -#define this_cpu_xchg_4(pcp, nval) percpu_xchg_op(volatile, pcp, nval) > +#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 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) > @@ -409,7 +384,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(volatile, pcp, nval) > +#define this_cpu_xchg_8(pcp, nval) percpu_xchg_op(8, volatile, pcp, nval) > #define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(volatile, pcp, oval, nval) > > /* > -- > 2.25.4 > -- Thanks, ~Nick Desaulniers