From patchwork Tue May 29 18:07:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137198 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp4363460lji; Tue, 29 May 2018 11:08:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrcm6BxjzEE3GoMys+FSDmdmTzI35s6NPQ1kwaiQlagj9FPqgWZAJKh74dPfwuqOykrLfSG X-Received: by 2002:a17:902:7209:: with SMTP id ba9-v6mr18972747plb.119.1527617286372; Tue, 29 May 2018 11:08:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527617286; cv=none; d=google.com; s=arc-20160816; b=yvF7qctQzJtoG6Bbp1Lm726xK0ltLMWr0efiV/lUNHq6RywNjVlQbXogKvVRFsdQVc Gv+Yo8yPVkBp3Uv3GS+4PLuY28iQt6UcRCI409Ug2XPcuQDjZWUHpZg4EY/6ppWUF3yT 7rRRktVinAHS2aMnPie1sxSx/+Nn0P8kcqsXRl4Geb1Rqf1UOJXolc7SqMkC2LqzcLUd AZZ3A2sTKZ/PSjOi55O71j0xQGNvC/8l2BTMu/NR6otGEwlNTWBucRufELC1MWT0VOG8 7Y3W3rdBXmepaxYo6bey8X81JSoSsQnOM8g89nFfcBmLLOBiEu5bi8xYC/3m4aYfWSwp JeIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=dlZjiEI/pPVe6hIdHiFe5+yZLu44xb823Zwf5HYqlDE=; b=f0FbGfRgiLgjFEwhKIRJSYRFtU39mar1TtJr3e9BmHdWKieIgYVdV4sM26Ks2KTGXd ACKD3PlDpOCCsyeu3mF9mRIgDoKH/hZAGNGAFjA5aMNSHB49ZmQemjTIRsjXrgLjguGW nmgmHq1dNYeBBMskE2+S3QMCbsC7PMQzGTbF0V89GLgO44lvBEWeIw8AD1Y9nYUQpCZF RpPYM9cul6GZg6hDRherScsp2REEVB6yymT9raTnWW+KmpgjeJFsPzT6P5C44a++M18H 8kLXgE0TcZ9zLK/ZLthf3sKW5wTxM7PhepCkBWj/cAWHBsY60ctvU4t6AAU/QwqVgAmN OOwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b19-v6si32700472pfh.358.2018.05.29.11.08.06; Tue, 29 May 2018 11:08:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965784AbeE2SIE (ORCPT + 30 others); Tue, 29 May 2018 14:08:04 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:45852 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936850AbeE2SH7 (ORCPT ); Tue, 29 May 2018 14:07:59 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C45531435; Tue, 29 May 2018 11:07:58 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B2C023F557; Tue, 29 May 2018 11:07:56 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org, boqun.feng@gmail.com, peterz@infradead.org, will.deacon@arm.com Cc: Mark Rutland , arnd@arndb.de, aryabinin@virtuozzo.com, dvyukov@google.com, glider@google.com, gregkh@linuxfoundation.org, jslaby@suse.com, parri.andrea@gmail.com Subject: [PATCH 0/7] atomics: generate atomic headers Date: Tue, 29 May 2018 19:07:39 +0100 Message-Id: <20180529180746.29684-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series scripts the generation of the various atomic headers, to ensure that the various atomic APIs remain consistent, reducing the risk of human error, and simplifying future rework. The series is based on my atomic API cleanup patches [1,2], and can be found on my atomics/generated branch [3] on kernel.org. The first three patches are preparatory rework, with patch four introducing the infrastructure. The final three patches migrate to generated headers. The scripts themselves are mostly POSIX sh (modulo local), without bashisms, and work in dash and bash. Per Linus request that it is possible to use git grep to inspect the atomic headers [3], the headers are committed (and not generated by kbuild). Since we now expand the fallback definitions inline, each *should* be easier to find with grep. Each header also has a comment at the top with a path to the script used to generate it. While the diff stat looks like a huge addition, the scripting comes in at ~800 lines in total, including the fallback definitions, so we're removing ~1000 lines of hand-written code. At the same time, we fill in gaps in the atomic_long API, and the instrumented atomic wrappers. Longer-term, I think things could be simplified if we were to rework the headers such that we have: * arch/*/include/asm/atomic.h providing arch_atomic_*(). * include/linux/atomic-raw.h building raw_atomic_*() atop of the arch_atomic_*() definitions, filling in gaps in the API. Having separate arch_ and raw_ namespaces would simplify the ifdeffery. * include/linux/atomic.h building atomic_*() atop of the raw_atomic_*() definitions, complete with any instrumentation. Instrumenting at this level would lower the instrumentation overhead, and would not require any ifdeffery as the whole raw_atomic_*() API would be available. ... I've avoided this for the time being due to the necessary churn in arch code. Thanks, Mark. [1] https://lkml.kernel.org/r/20180529154346.3168-1-mark.rutland@arm.com [2] git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git atomics/api-cleanup [3] git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git atomics/generated [4] https://lkml.kernel.org/r/CA+55aFxjU0op8QLLu0n-RjHBs7gQsLvD8jcyedgw6jeZFN7B+Q@mail.gmail.com Mark Rutland (7): atomics/tty: add missing atomic_long_t * cast atomics/treewide: rework ordering barriers atomics: separate basic {cmp,}xchg() atomics: add common header generation files atomics: switch to generated fallbacks atomics: switch to generated atomic-long atomics: switch to generated instrumentation MAINTAINERS | 1 + arch/alpha/include/asm/atomic.h | 8 +- arch/powerpc/include/asm/atomic.h | 17 +- arch/riscv/include/asm/atomic.h | 17 +- drivers/tty/tty_ldsem.c | 2 +- include/asm-generic/atomic-instrumented-atomic.h | 1629 ++++++++++++++++ include/asm-generic/atomic-instrumented.h | 394 +--- include/asm-generic/atomic-long.h | 1150 +++++++++-- include/linux/atomic-fallback.h | 2223 ++++++++++++++++++++++ include/linux/atomic.h | 1244 +----------- scripts/atomic/atomic-tbl.sh | 186 ++ scripts/atomic/atomics.tbl | 41 + scripts/atomic/fallbacks/acquire | 9 + scripts/atomic/fallbacks/add_negative | 16 + scripts/atomic/fallbacks/add_unless | 16 + scripts/atomic/fallbacks/andnot | 7 + scripts/atomic/fallbacks/dec | 7 + scripts/atomic/fallbacks/dec_and_test | 15 + scripts/atomic/fallbacks/dec_if_positive | 15 + scripts/atomic/fallbacks/dec_unless_positive | 14 + scripts/atomic/fallbacks/fence | 11 + scripts/atomic/fallbacks/fetch_add_unless | 23 + scripts/atomic/fallbacks/inc | 7 + scripts/atomic/fallbacks/inc_and_test | 15 + scripts/atomic/fallbacks/inc_not_zero | 14 + scripts/atomic/fallbacks/inc_unless_negative | 14 + scripts/atomic/fallbacks/read_acquire | 7 + scripts/atomic/fallbacks/release | 8 + scripts/atomic/fallbacks/set_release | 7 + scripts/atomic/fallbacks/sub_and_test | 16 + scripts/atomic/fallbacks/try_cmpxchg | 11 + scripts/atomic/gen-atomic-fallback.sh | 144 ++ scripts/atomic/gen-atomic-instrumented.sh | 122 ++ scripts/atomic/gen-atomic-long.sh | 98 + 34 files changed, 5671 insertions(+), 1837 deletions(-) create mode 100644 include/asm-generic/atomic-instrumented-atomic.h create mode 100644 include/linux/atomic-fallback.h create mode 100755 scripts/atomic/atomic-tbl.sh create mode 100644 scripts/atomic/atomics.tbl create mode 100644 scripts/atomic/fallbacks/acquire create mode 100644 scripts/atomic/fallbacks/add_negative create mode 100644 scripts/atomic/fallbacks/add_unless create mode 100644 scripts/atomic/fallbacks/andnot create mode 100644 scripts/atomic/fallbacks/dec create mode 100644 scripts/atomic/fallbacks/dec_and_test create mode 100644 scripts/atomic/fallbacks/dec_if_positive create mode 100644 scripts/atomic/fallbacks/dec_unless_positive create mode 100644 scripts/atomic/fallbacks/fence create mode 100644 scripts/atomic/fallbacks/fetch_add_unless create mode 100644 scripts/atomic/fallbacks/inc create mode 100644 scripts/atomic/fallbacks/inc_and_test create mode 100644 scripts/atomic/fallbacks/inc_not_zero create mode 100644 scripts/atomic/fallbacks/inc_unless_negative create mode 100644 scripts/atomic/fallbacks/read_acquire create mode 100644 scripts/atomic/fallbacks/release create mode 100644 scripts/atomic/fallbacks/set_release create mode 100644 scripts/atomic/fallbacks/sub_and_test create mode 100644 scripts/atomic/fallbacks/try_cmpxchg create mode 100755 scripts/atomic/gen-atomic-fallback.sh create mode 100755 scripts/atomic/gen-atomic-instrumented.sh create mode 100755 scripts/atomic/gen-atomic-long.sh -- 2.11.0