Received: by 10.223.164.202 with SMTP id h10csp679690wrb; Wed, 22 Nov 2017 13:36:27 -0800 (PST) X-Google-Smtp-Source: AGs4zMa3k8LOjL/1WRXBosWtKJftllhV5FhR7cnHRbregpqYZ6BXHbwY+3d29ijAS0eK55pXdToi X-Received: by 10.159.242.4 with SMTP id t4mr22554209plr.411.1511386587231; Wed, 22 Nov 2017 13:36:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511386587; cv=none; d=google.com; s=arc-20160816; b=dYSEI6aGUtYnTcgGe0QKQE1I7fhPb3xoZ3eeJQ7xGPE8z6P0lh+nTKwswtPcl5PqYQ 7lA61217O47R0b6gnbpTBhPgHYnPPEQEP55vToqTpW1VW4Eexj4MV+4rlqdZikNbrLKF Yfbd1B2reb/RA9rIMp/+SCixyxKwgwxC/a2V3inOYhftQMfTu15t/GtIqPK7fgBIwyF5 OjIeKGzLgOjLS1pl0k81O0GbJ3kvrNkfdSgvdUME7B/WE8529B0UC/iOV6BAT5tMsN4O Hztpt5/12Siwusa/woknXxDbU/VZAsSz8M4GSAF1Awdnrm9MNcTtpBpB1uSWfSN6DikF ozlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=u2Gu7CATerb6kfk4t4EoMkfPje3QfmYQdjekQqLAbBA=; b=Vq76zsAQ3mMgqFJXvfp9OKMigFmfC8VyMDfbob9PeuAqBfBmu5VmvGWgTlpqEY49aZ cIccxnpxKPdhPOFVhIrFbYZxR10q4eh2aKxusB0M6trpfuRqF6aUlORof3m7Afkk6Je5 7NLEuXUDv3oVeioE/1LGESNvu4cU/x3z+X+8oHPOK+pTmViEwQPD4R8azMv7Uccy6n2n 6TaXXVxlXppgPSWvHMZiLoarRhf7skuvLovd+9XZ7DAdC3ABkMayAWs6FHWME8vv+wAb yXw4jMT914ZnWYXf4ydXmLVsxSTqM+67RjX/Nk7/qYbm+UdfCx+wUIBJP+pRT6ai8Xyh YS8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ky89yTI6; 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 p14si14741681pli.781.2017.11.22.13.36.15; Wed, 22 Nov 2017 13:36:27 -0800 (PST) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ky89yTI6; 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 S1752421AbdKVVf2 (ORCPT + 77 others); Wed, 22 Nov 2017 16:35:28 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:40896 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751482AbdKVVHr (ORCPT ); Wed, 22 Nov 2017 16:07:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=u2Gu7CATerb6kfk4t4EoMkfPje3QfmYQdjekQqLAbBA=; b=ky89yTI6BgVgKg3tu7AfV81LR 7LRkRtKAiepUc7R/Vr/zOqyhac6/p07IfN+rYUZNexEzKMqP9BYst55xytziJpET8TYuuRF+z/Qqh f3rWBAT4Sg0e1Veeui7uvXol4UHJkTXQjx2XnDvwvRgEzADabi1PXbrnoABjt61Lwh0nOCITn5AiQ ucg8mGEg0BkTYc460D7F35iZD4aA1UQi7FXikj+yZCNXlvMTfbo59b+Pb6ONRDvat/0+3sHfIv8Zj 3Gx7rF7KbhDgfbRwwGgI0pcdMOx9DlDgXOjGOcpjbsON27wEmTPRW5mqftltNlg3UVnn8Gg5FbCge CVuN9K6gA==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eHcFG-0007oi-3O; Wed, 22 Nov 2017 21:07:46 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH 01/62] tools: Make __test_and_clear_bit available Date: Wed, 22 Nov 2017 13:06:38 -0800 Message-Id: <20171122210739.29916-2-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171122210739.29916-1-willy@infradead.org> References: <20171122210739.29916-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox Copy over non-atomic.h and delete the duplicate definitions which had been pasted into atomic.h. Signed-off-by: Matthew Wilcox --- tools/include/asm-generic/bitops.h | 1 + tools/include/asm-generic/bitops/atomic.h | 9 --- tools/include/asm-generic/bitops/non-atomic.h | 109 ++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 tools/include/asm-generic/bitops/non-atomic.h diff --git a/tools/include/asm-generic/bitops.h b/tools/include/asm-generic/bitops.h index 9bce3b56b5e7..5d2ab38965cc 100644 --- a/tools/include/asm-generic/bitops.h +++ b/tools/include/asm-generic/bitops.h @@ -27,5 +27,6 @@ #include #include +#include #endif /* __TOOLS_ASM_GENERIC_BITOPS_H */ diff --git a/tools/include/asm-generic/bitops/atomic.h b/tools/include/asm-generic/bitops/atomic.h index 21c41ccd1266..2f6ea28764a7 100644 --- a/tools/include/asm-generic/bitops/atomic.h +++ b/tools/include/asm-generic/bitops/atomic.h @@ -15,13 +15,4 @@ static inline void clear_bit(int nr, unsigned long *addr) addr[nr / __BITS_PER_LONG] &= ~(1UL << (nr % __BITS_PER_LONG)); } -static __always_inline int test_bit(unsigned int nr, const unsigned long *addr) -{ - return ((1UL << (nr % __BITS_PER_LONG)) & - (((unsigned long *)addr)[nr / __BITS_PER_LONG])) != 0; -} - -#define __set_bit(nr, addr) set_bit(nr, addr) -#define __clear_bit(nr, addr) clear_bit(nr, addr) - #endif /* _TOOLS_LINUX_ASM_GENERIC_BITOPS_ATOMIC_H_ */ diff --git a/tools/include/asm-generic/bitops/non-atomic.h b/tools/include/asm-generic/bitops/non-atomic.h new file mode 100644 index 000000000000..7e10c4b50c5d --- /dev/null +++ b/tools/include/asm-generic/bitops/non-atomic.h @@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ +#define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ + +#include + +/** + * __set_bit - Set a bit in memory + * @nr: the bit to set + * @addr: the address to start counting from + * + * Unlike set_bit(), this function is non-atomic and may be reordered. + * If it's called on the same region of memory simultaneously, the effect + * may be that only one operation succeeds. + */ +static inline void __set_bit(int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p |= mask; +} + +static inline void __clear_bit(int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p &= ~mask; +} + +/** + * __change_bit - Toggle a bit in memory + * @nr: the bit to change + * @addr: the address to start counting from + * + * Unlike change_bit(), this function is non-atomic and may be reordered. + * If it's called on the same region of memory simultaneously, the effect + * may be that only one operation succeeds. + */ +static inline void __change_bit(int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p ^= mask; +} + +/** + * __test_and_set_bit - Set a bit and return its old value + * @nr: Bit to set + * @addr: Address to count from + * + * This operation is non-atomic and can be reordered. + * If two examples of this operation race, one can appear to succeed + * but actually fail. You must protect multiple accesses with a lock. + */ +static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + unsigned long old = *p; + + *p = old | mask; + return (old & mask) != 0; +} + +/** + * __test_and_clear_bit - Clear a bit and return its old value + * @nr: Bit to clear + * @addr: Address to count from + * + * This operation is non-atomic and can be reordered. + * If two examples of this operation race, one can appear to succeed + * but actually fail. You must protect multiple accesses with a lock. + */ +static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + unsigned long old = *p; + + *p = old & ~mask; + return (old & mask) != 0; +} + +/* WARNING: non atomic and it can be reordered! */ +static inline int __test_and_change_bit(int nr, + volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + unsigned long old = *p; + + *p = old ^ mask; + return (old & mask) != 0; +} + +/** + * test_bit - Determine whether a bit is set + * @nr: bit number to test + * @addr: Address to start counting from + */ +static inline int test_bit(int nr, const volatile unsigned long *addr) +{ + return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); +} + +#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */ -- 2.15.0 From 1584808370559893688@xxx Wed Nov 22 22:50:39 +0000 2017 X-GM-THRID: 1584808370559893688 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread