Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1624853ybm; Sat, 30 May 2020 15:14:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz82veygKRdDR+dhzwVpTCnZ6YIMuZw2zRr2Trs5PzwKrcdRcYNxRc2HOMEE8pBfq9Y3rl2 X-Received: by 2002:a05:6402:1bcc:: with SMTP id ch12mr15115343edb.22.1590876842759; Sat, 30 May 2020 15:14:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590876842; cv=none; d=google.com; s=arc-20160816; b=PTA1WuR+xKIWsgk6KaNQWNh8NjLBkUvZ0rbVeWiFQCXAjhjSisHy6oH5GpFxM7+Fwg uMdf9eaS1y8kGmI3OJx1Nqebk1V+Y0jgjUGx4fwnpGaBg4V0aNP0S5aabCP3tTnqilc1 77GjzJpIAM5XyxdqgsU1k9KjZYKHj5yqEippkJj5CfbDQmBsx4KGlkLUyuIykM0Z5wDi s7J8StLxlyxqEGZ51vNzZfo4VcH+NKI+w902Bx04rcTD9Q3X/swKHIf/dXfSCd49yLF5 IYQVPFDlFAGO8S4uPJ5VVRsbkh2+pv+jgQLceoLIbJqxKoTpRQxeHKEGpcUdu+1HRlrk +UXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=91CInpU4Cyy1eJiDeE1wnCFd+k0uw8ETJ1vg5EH3afw=; b=XnOT2KoJHMSmZFJg3cv53DhRlsfO1eFG37kpD7vb1wlU1X+W/NzK2draLeqIwfWApx Dn2K23cHaR+LwGlkH7B1KT+a+4xvjt3YHghl990hJFxYDr6CloriNrm19XiydnAMLlxD NXZajeRmcdLmsa4/BzTR7l/UrFwo1p3FIFYizAqejr5Cytl6N9QlpQsNWBdJJkYAiM1r zaRz+RkCc6BCrorHe0Wo9+7qYTq7lZ9UmfWigFK08TjuObBhNZ9cs4FvK+lhO/g+VwsZ Z5xoRFO4MOqVfvcrhXdbYaDYLoFuKGXpUz3lLzP7OlvkazJYVxO7a043nscKIW8mj/wX 3AZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BqZBYWdn; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u20si7238546eda.569.2020.05.30.15.13.40; Sat, 30 May 2020 15:14:02 -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=@gmail.com header.s=20161025 header.b=BqZBYWdn; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729391AbgE3WLx (ORCPT + 99 others); Sat, 30 May 2020 18:11:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729443AbgE3WLr (ORCPT ); Sat, 30 May 2020 18:11:47 -0400 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB565C08C5CA for ; Sat, 30 May 2020 15:11:46 -0700 (PDT) Received: by mail-il1-x144.google.com with SMTP id t8so5407897ilm.7 for ; Sat, 30 May 2020 15:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=91CInpU4Cyy1eJiDeE1wnCFd+k0uw8ETJ1vg5EH3afw=; b=BqZBYWdn1rw66hGbTh8L4ktSZUDayuf9qbGv9aRyb9lrjUMgJniZNOalOvJuqvUMsj cVduf9zneBKwqat7HznI0vQvSkreOrseWL+ktQdm/zpRRW5RKlr1xLGSg1dCWsfBZBfh n4JO0fQCHDsX/mmFEm0UIk5yn0lg8NDP6MeCNlRAgSgAc8lqXE0GNSHtA3ZcByluusI9 MJ1ugg8UyBAaozI4defS1uifiDZA5Z9gDXoPRiGghSux6n9LxzfO/H4/v9/uacCS5eL4 vev6q50LRKGxNurHeytNKRGdhsxpmkJdsmCWisz6Mo+IrbAJaybG7XP10yPVvTPpKgZC ifSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=91CInpU4Cyy1eJiDeE1wnCFd+k0uw8ETJ1vg5EH3afw=; b=ZsXX4RJTsA0aXr2mDScg7Tde9ASSSY3rvfpnjhRi0JVv48gyp4H+YFn6ssl/bWu4m2 EN3Dsbt8RZlR8QRSDhxjA+CkSB0z17hcbvLtEZwd2USGl5MV2iiLEFhQ0udQcbwWG1Cu BmkLfbeM9THNnvSdyFcQt925B+4QFzHPlDWt4muV+wAcztCjPERGq1xPQjRDp8ExcAfM x7V9O1QQhh3O9KXcVHWWncb5utvBZApvj/lzDvibPZXUE/izDcx9REWqIGR4oUATASIG 43aozLUrMIUSQRSVnLz1XVt14XL59Am9CvjFCSEXa4BLzVv0gRgUTore960Y7fsIWlQo yuYg== X-Gm-Message-State: AOAM532k/sTeKqklZ0Fibj+jp1F2ToqI1Y4PnIZRE2pDUr6B0LFL9kFw CWHmmKAz8l7SDuDPzyeeW0ZuCJ6xrg== X-Received: by 2002:a92:ba14:: with SMTP id o20mr14465831ili.23.1590876706027; Sat, 30 May 2020 15:11:46 -0700 (PDT) Received: from localhost.localdomain (174-084-153-250.res.spectrum.com. [174.84.153.250]) by smtp.gmail.com with ESMTPSA id w78sm2735698ilk.14.2020.05.30.15.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 15:11:45 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Nick Desaulniers , Brian Gerst Subject: [PATCH v2 06/10] x86/percpu: Clean up percpu_add_return_op() Date: Sat, 30 May 2020 18:11:23 -0400 Message-Id: <20200530221127.459704-7-brgerst@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200530221127.459704-1-brgerst@gmail.com> References: <20200530221127.459704-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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.25.4