From patchwork Fri May 4 15:45:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 10380893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CC2AE60353 for ; Fri, 4 May 2018 15:45:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B86BB29434 for ; Fri, 4 May 2018 15:45:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACDA5294D6; Fri, 4 May 2018 15:45:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12E90294D5 for ; Fri, 4 May 2018 15:45:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDF466B0266; Fri, 4 May 2018 11:45:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E90276B0269; Fri, 4 May 2018 11:45:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7F376B026A; Fri, 4 May 2018 11:45:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f72.google.com (mail-wm0-f72.google.com [74.125.82.72]) by kanga.kvack.org (Postfix) with ESMTP id 7E8F46B0266 for ; Fri, 4 May 2018 11:45:53 -0400 (EDT) Received: by mail-wm0-f72.google.com with SMTP id e74so790147wmg.5 for ; Fri, 04 May 2018 08:45:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=1amgYpiUSrabvB6s1jHDDspSbs7ilh6sPu2RaCpNIxU=; b=TbPgb6YPcNtpRfczhz+x2UU5AFZqStAkjRpDjapHwWWetfRdk0blrjom6szeEKTNhn 6lTV81ofiBabM6EaNfV0EhpQVUZTlCn9bdozfsZfFRO4Z2JzIZ7bmpnScSi7AJV/jQ7L MXFXyvsjyrCTWNHP2gs6CfpmYGnlsMgfyP49pEgZcPjob+pEhTgPvwkTXSMPfq8cR98v FBDTu+xVV8dH4Zxwv+5qjFxjVq4hqI8GZRUReDIfLk11Vr9mAzLiiPg2M97hNvdrJ40k uq/xDs0QMx1povW/kBD++3m5/NKaP0kPZwASwrWORDwZzSw0FgSkHLV+f1k9Oyppvl1D 1Icg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de X-Gm-Message-State: ALQs6tCDPzstT1e7qz5hqSRDWCZOAcP93VHab2Mh8mWemX25tN0172Ey 6skFVLlOSLJ+ts/nUb6f2lETGTF0lAXpvYWGCVPINaZo3UuV0NmpqJkzbeglIOJEw93RsUeJn63 2YgWf5S2/G4nYLQMhCubt6rHYx/slRtQkJ12FWDy76lmDRC6FOE5UhnHWkctQcqzXqQ== X-Received: by 2002:adf:aa94:: with SMTP id h20-v6mr21614521wrc.149.1525448753050; Fri, 04 May 2018 08:45:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZopGiqeLeJM0QifekhTUvSZLg32guYMlevrge/RhiWEuRzrs/u5MEY/T3miRZGWl+YO3bCa X-Received: by 2002:adf:aa94:: with SMTP id h20-v6mr21614481wrc.149.1525448752294; Fri, 04 May 2018 08:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525448752; cv=none; d=google.com; s=arc-20160816; b=OPXRnpV9Y2Tph8GtGy6it3QYAJoop+vG/It5XJh5Mso54rkMQSYq6EXfqwz2QLFcWE Fa9apx4j7XOOn7N4Gm7GfKtGN+YH5TM9c3w9kkz4gK9mijEZlMhwSwKNZnI+4MRzlqtT CAHaHN4vbQTwaGL/oAeommq7RF/NhzcA38SGnwWP3jvmDrVfZEPY/lHtKI1DtjepCeS2 b3TSG+F+5pgTPya8VptgGFF+76t32MEWui2NYcyj3iH9cfCZAhQ6O5gF0xF1xKGvmKcM QAiZbHCTgn6wvMLDg5VNUAdZXE9WbwjQ58aEJRclH+hOKnuINmJRZGOmyi8ZmrAvRgrW gbww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=1amgYpiUSrabvB6s1jHDDspSbs7ilh6sPu2RaCpNIxU=; b=A1uwPJrhdG/LnmvznmFXL5fQJ56uw2dxav76qy6nqYMomxKhnZeQqlT1sTawOac1ZK DkAlYZWueQPbwb83wikBZ5icqGcloDN89uGBh/oxpU+grMuZ4XpBWICFtR6QJP0kJOo3 HjZE+7b5I73JtXpRbPuA6s0ajrSMucYEgPHJCZSRa6c4SIPLU64FZmaCc7Oq3vhttCAu b95EY+daDSkuQbJ6Z3QKj8qCJWw86yBlBxZ0gmQoz887yf/zgLhAQ+uXskUO/xCYRv+g WuE87unR+B55yv1QAXMpcQlReGTqatZ1WdLjvQJiG9o+cEhongRQUsrvG3InlIKr26ZK 0s6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de Received: from Galois.linutronix.de (Galois.linutronix.de. [2a01:7a0:2:106d:700::1]) by mx.google.com with ESMTPS id m79si1578218wmh.5.2018.05.04.08.45.52 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 04 May 2018 08:45:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) client-ip=2a01:7a0:2:106d:700::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1fEcu4-0006lh-2j; Fri, 04 May 2018 17:45:48 +0200 From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, Peter Zijlstra , Ingo Molnar , linux-mm@kvack.org, Shaohua Li , linux-raid@vger.kernel.org, Anna-Maria Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 1/5] spinlock: atomic_dec_and_lock: Add an irqsave variant Date: Fri, 4 May 2018 17:45:29 +0200 Message-Id: <20180504154533.8833-2-bigeasy@linutronix.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180504154533.8833-1-bigeasy@linutronix.de> References: <20180504154533.8833-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Anna-Maria Gleixner There are in-tree users of atomic_dec_and_lock() which must acquire the spin lock with interrupts disabled. To workaround the lack of an irqsave variant of atomic_dec_and_lock() they use local_irq_save() at the call site. This causes extra code and creates in some places unneeded long interrupt disabled times. These places need also extra treatment for PREEMPT_RT due to the disconnect of the irq disabling and the lock function. Implement the missing irqsave variant of the function. Signed-off-by: Anna-Maria Gleixner Signed-off-by: Sebastian Andrzej Siewior --- include/linux/spinlock.h | 5 +++++ lib/dec_and_lock.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h index 4894d322d258..803536c992f5 100644 --- a/include/linux/spinlock.h +++ b/include/linux/spinlock.h @@ -409,6 +409,11 @@ extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock); #define atomic_dec_and_lock(atomic, lock) \ __cond_lock(lock, _atomic_dec_and_lock(atomic, lock)) +extern int _atomic_dec_and_lock_irqsave(atomic_t *atomic, spinlock_t *lock, + unsigned long *flags); +#define atomic_dec_and_lock_irqsave(atomic, lock, flags) \ + __cond_lock(lock, _atomic_dec_and_lock_irqsave(atomic, lock, &(flags))) + int alloc_bucket_spinlocks(spinlock_t **locks, unsigned int *lock_mask, size_t max_size, unsigned int cpu_mult, gfp_t gfp); diff --git a/lib/dec_and_lock.c b/lib/dec_and_lock.c index 347fa7ac2e8a..9555b68bb774 100644 --- a/lib/dec_and_lock.c +++ b/lib/dec_and_lock.c @@ -33,3 +33,19 @@ int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock) } EXPORT_SYMBOL(_atomic_dec_and_lock); + +int _atomic_dec_and_lock_irqsave(atomic_t *atomic, spinlock_t *lock, + unsigned long *flags) +{ + /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */ + if (atomic_add_unless(atomic, -1, 1)) + return 0; + + /* Otherwise do it the slow way */ + spin_lock_irqsave(lock, *flags); + if (atomic_dec_and_test(atomic)) + return 1; + spin_unlock_irqrestore(lock, *flags); + return 0; +} +EXPORT_SYMBOL(_atomic_dec_and_lock_irqsave);