Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp185382ybh; Mon, 20 Jul 2020 13:52:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwukm131gGW23y8rsn8z7+BuHoIAmGTpmnuAHbnZ+2IKQTG8t65Zinj4H6P9lEex7d7Q6Cw X-Received: by 2002:a17:906:33ca:: with SMTP id w10mr23467079eja.171.1595278336432; Mon, 20 Jul 2020 13:52:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595278336; cv=none; d=google.com; s=arc-20160816; b=byfehXFVFga5XPKdFi6sEfXK50UsZOH1uvx0Q07+HSMRCnTK5cKL0wG9OnWiQ2Ly5M Z5iLRyXoZI6dnanOkgURaPowqYgJkdYACkvSoDYVlDeQUpxnYhFHobOJmVLinVec7fJx ybonrgxnOB2tLoaSupDonTAQw6wqjAYIHH+lN5HLccZHcArvjjkcrWUz7J9JAGJVXu// 79XOfkPQg3SpgVaeujviBiYD0smQC3pey7rikhIc802SV+1ShiBA70z0SqYSPLMwnOsO QETZkO4j+L6kVZMh1z4clGydDw08M4zW2GPhTGefauMUrw6gkBgsxfLit1r7L9Z2i3G7 GxEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=qr1G39+WcPcTQOpLfSr1R0TatiitMUIoDWHFssxm+t4=; b=whMQPIOS9eE3gMIX1Z94HvEHvdKb6PkTpzLOQgZekObACBIY23vfE9S6dZW9VGt9oY uaaiswcT6ZelE3tbW3zz5ur+UGfUHlJr7stHPmLzyYFg/3N+IwpQY2G5jvOB9LsofyTU Cg+7s6ZDwGi7AZ+7AhmX4q7Fuy8hve/23G6Fqp6R+9qPWQfZZbT3zGd3OdlUzJlFHB7i 86BZiUKkWJly7WDed3ech580SA2mMmspW+GqMZTGJj2stpqpxf8SjvItW5girrWBYXDV t9qVDHKu55JukD0FfLISvOerlnhYXBu9snJbDdhakaWfjBu0uCIXZ5avWzg4UAcQSus7 IXPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YgwGYfJw; 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 z27si12122593ejl.277.2020.07.20.13.51.53; Mon, 20 Jul 2020 13:52: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=YgwGYfJw; 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 S1729496AbgGTUuU (ORCPT + 99 others); Mon, 20 Jul 2020 16:50:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728911AbgGTUuT (ORCPT ); Mon, 20 Jul 2020 16:50:19 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23FFEC061794 for ; Mon, 20 Jul 2020 13:50:19 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id i62so22971429ybc.15 for ; Mon, 20 Jul 2020 13:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=qr1G39+WcPcTQOpLfSr1R0TatiitMUIoDWHFssxm+t4=; b=YgwGYfJw5QnjQG+P8j+jVB7gQFIOZnbK8YHAu11ZYD/FZ6CqrSEMkNNUqTeSFq1VVx 4/MEgX9IlYzfwWgYEl6zNYcQ08vZnKPrrpiMq9b7dNis44znxS1GMw2W4TvzBko2P/Sw TDNo5AtYSIcVNq+tY3zjDWzk8D+LT6jQeFSlXr+5tX8NS0jHCoo8XWt5I2H/Pee6l5gr Ufv/c+T/lX8sSOBHZVgIJElgKwqnVIgW802oz6Dzqy6P1guROykHWO6aiEKCOZlHWSMM uvkNtoCB/axhnqaLze0jRfOzkcEN9KufoIyUyZCJvaoc3QLjz7W3nW7VQd1S9pEj8V9Z V85w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qr1G39+WcPcTQOpLfSr1R0TatiitMUIoDWHFssxm+t4=; b=TlbPNzxLY0jmz8ytPNwUDmHOpxEaNc9WWV1FqbPKqsyXFO48e+jHHAhmcaxxyXh7Hv lNJ7DQW10J8s4tA5ieXXBlLzmPcUC/Y09kF/ACLUJRirdDwyV71YbXbSou97T7QHXS/o /N2YAeUNcrix87nj7j88PuN7xBKaBMsw4EtuwIeIx4SA3GsQmfPeYHiHdsq+wEWEYZix pXt5WUpMnkzfkqOJsXfpcIcvg+HQGfnjvkqsdLTVc6jAmUN9Ujx98U5tnBHWngLBXuyC GHX068UD2c1auUqqstXRxD5B4nS5uRsLk/cBrtE37gQLsTghSo2GI1sFQRIobmA5g8Tg ZhXg== X-Gm-Message-State: AOAM532T8HcevvCzYK9ymRf5q1X2/ujZcJdJdfqrxeSoMRLjEWvrnwwn wzrVDba2CtSacz1bC7rJkorkgZSX0QVopLzRMic= X-Received: by 2002:a05:6902:6b2:: with SMTP id j18mr36704610ybt.178.1595278218312; Mon, 20 Jul 2020 13:50:18 -0700 (PDT) Date: Mon, 20 Jul 2020 13:49:20 -0700 In-Reply-To: <20200720204925.3654302-1-ndesaulniers@google.com> Message-Id: <20200720204925.3654302-7-ndesaulniers@google.com> Mime-Version: 1.0 References: <20200720204925.3654302-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH v3 06/11] x86/percpu: Clean up percpu_add_return_op() From: Nick Desaulniers To: Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Dennis Zhou , Tejun Heo , Christoph Lameter , x86@kernel.org, "H. Peter Anvin" , Al Viro , Andrew Morton , Peter Zijlstra , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Brian Gerst , Nick Desaulniers , Linus Torvalds 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 From: Brian Gerst 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. Tested-by: Nick Desaulniers Reviewed-by: Nick Desaulniers Acked-by: Linus Torvalds Acked-by: Peter Zijlstra (Intel) Signed-off-by: Brian Gerst Signed-off-by: Nick Desaulniers --- arch/x86/include/asm/percpu.h | 51 +++++++++++------------------------ 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 9bb5440d98d3..0776a11e7e11 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -199,34 +199,15 @@ do { \ /* * Add return operation */ -#define percpu_add_return_op(qual, var, val) \ +#define percpu_add_return_op(size, qual, _var, _val) \ ({ \ - typeof(var) paro_ret__ = val; \ - switch (sizeof(var)) { \ - case 1: \ - asm qual ("xaddb %0, "__percpu_arg(1) \ - : "+q" (paro_ret__), "+m" (var) \ - : : "memory"); \ - break; \ - case 2: \ - asm qual ("xaddw %0, "__percpu_arg(1) \ - : "+r" (paro_ret__), "+m" (var) \ - : : "memory"); \ - break; \ - case 4: \ - asm qual ("xaddl %0, "__percpu_arg(1) \ - : "+r" (paro_ret__), "+m" (var) \ - : : "memory"); \ - break; \ - case 8: \ - asm qual ("xaddq %0, "__percpu_arg(1) \ - : "+r" (paro_ret__), "+m" (var) \ - : : "memory"); \ - break; \ - default: __bad_percpu_size(); \ - } \ - paro_ret__ += val; \ - paro_ret__; \ + __pcpu_type_##size paro_tmp__ = __pcpu_cast_##size(_val); \ + asm qual (__pcpu_op2_##size("xadd", "%[tmp]", \ + __percpu_arg([var])) \ + : [tmp] __pcpu_reg_##size("+", paro_tmp__), \ + [var] "+m" (_var) \ + : : "memory"); \ + (typeof(_var))(unsigned long) (paro_tmp__ + _val); \ }) /* @@ -377,16 +358,16 @@ do { \ #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 raw_cpu_add_return_1(pcp, val) percpu_add_return_op(, pcp, val) -#define raw_cpu_add_return_2(pcp, val) percpu_add_return_op(, pcp, val) -#define raw_cpu_add_return_4(pcp, val) percpu_add_return_op(, pcp, val) +#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) +#define raw_cpu_add_return_4(pcp, val) percpu_add_return_op(4, , pcp, val) #define raw_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, nval) #define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, nval) #define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, nval) -#define this_cpu_add_return_1(pcp, val) percpu_add_return_op(volatile, pcp, val) -#define this_cpu_add_return_2(pcp, val) percpu_add_return_op(volatile, pcp, val) -#define this_cpu_add_return_4(pcp, val) percpu_add_return_op(volatile, pcp, val) +#define this_cpu_add_return_1(pcp, val) percpu_add_return_op(1, volatile, pcp, val) +#define this_cpu_add_return_2(pcp, val) percpu_add_return_op(2, volatile, pcp, val) +#define this_cpu_add_return_4(pcp, val) percpu_add_return_op(4, volatile, pcp, val) #define this_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(volatile, pcp, oval, nval) #define this_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(volatile, pcp, oval, nval) #define this_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(volatile, pcp, oval, nval) @@ -418,7 +399,7 @@ do { \ #define raw_cpu_add_8(pcp, val) percpu_add_op(8, , (pcp), val) #define raw_cpu_and_8(pcp, val) percpu_to_op(8, , "and", (pcp), val) #define raw_cpu_or_8(pcp, val) percpu_to_op(8, , "or", (pcp), val) -#define raw_cpu_add_return_8(pcp, val) percpu_add_return_op(, pcp, val) +#define raw_cpu_add_return_8(pcp, val) percpu_add_return_op(8, , pcp, val) #define raw_cpu_xchg_8(pcp, nval) raw_percpu_xchg_op(pcp, nval) #define raw_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, nval) @@ -427,7 +408,7 @@ do { \ #define this_cpu_add_8(pcp, val) percpu_add_op(8, volatile, (pcp), val) #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(volatile, 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_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(volatile, pcp, oval, nval) -- 2.28.0.rc0.105.gf9edc3c819-goog