From nobody Sat Nov 15 15:41:07 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1595405570; cv=none; d=zohomail.com; s=zohoarc; b=I7pktza3ff5CfJUE9P1Lo1uOUB3IwCHPslCQboUR04yP0PauOBwCghkPEysosb+6Q8Vy1cAVveVwxN2ECH2HAdSilcVkflOpdKnz1ohg9NAZvc1yJY30K5R6qhzhWtykxtTNB97608HT4Vv6oXKfQ6m3zHgXJTwRgzw0QYK4cMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595405570; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=6V99W02GkGEOvLFoscScAIr4QxNunPjRflinPUoa3Qo=; b=irKKZews1eEmBIBeCweP+zFtibEmCYpE7C3nTvQ0WvvkVC27BsQXgqwWQoG7fkjlGGFpXA0hIdO9N44bxaV9hhAsmJaPX7BDYXs9U2/520NH1YB7CJBAdEGnODv3rRe6gI5gMIsJ/lpz/3zi7j/df4IUDu8JaGHmiJ3bzzHcIhc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15954055700311006.6245697072433; Wed, 22 Jul 2020 01:12:50 -0700 (PDT) Received: from localhost ([::1]:45210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jy9rs-0000cY-Q6 for importer@patchew.org; Wed, 22 Jul 2020 04:12:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jy9qt-0007it-GB for qemu-devel@nongnu.org; Wed, 22 Jul 2020 04:11:47 -0400 Received: from relay.sw.ru ([185.231.240.75]:54956 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jy9qq-0004p7-ML for qemu-devel@nongnu.org; Wed, 22 Jul 2020 04:11:46 -0400 Received: from [10.94.4.71] (helo=dptest2.qa.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jy9ql-0002yK-PU; Wed, 22 Jul 2020 11:11:39 +0300 From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v0 1/4] bitops: add some atomic versions of bitmap operations Date: Wed, 22 Jul 2020 11:11:30 +0300 Message-Id: <20200722081133.29926-2-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20200722081133.29926-1-dplotnikov@virtuozzo.com> References: <20200722081133.29926-1-dplotnikov@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=dplotnikov@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/22 04:11:41 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_BL_SPAMCOP_NET=1.347, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: quintela@redhat.com, dgilbert@redhat.com, peterx@redhat.com, armbru@redhat.com, den@openvz.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 1. test bit 2. test and set bit Signed-off-by: Denis Plotnikov Reviewed-by: Peter Xu --- include/qemu/bitops.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index f55ce8b320..63218afa5a 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -95,6 +95,21 @@ static inline int test_and_set_bit(long nr, unsigned lon= g *addr) return (old & mask) !=3D 0; } =20 +/** + * test_and_set_bit_atomic - Set a bit atomically and return its old value + * @nr: Bit to set + * @addr: Address to count from + */ +static inline int test_and_set_bit_atomic(long nr, unsigned long *addr) +{ + unsigned long mask =3D BIT_MASK(nr); + unsigned long *p =3D addr + BIT_WORD(nr); + unsigned long old; + + old =3D atomic_fetch_or(p, mask); + return (old & mask) !=3D 0; +} + /** * test_and_clear_bit - Clear a bit and return its old value * @nr: Bit to clear @@ -135,6 +150,16 @@ static inline int test_bit(long nr, const unsigned lon= g *addr) return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); } =20 +/** + * test_bit_atomic - Determine whether a bit is set atomicallly + * @nr: bit number to test + * @addr: Address to start counting from + */ +static inline int test_bit_atomic(long nr, const unsigned long *addr) +{ + long valid_nr =3D nr & (BITS_PER_LONG - 1); + return 1UL & (atomic_read(&addr[BIT_WORD(nr)]) >> valid_nr); +} /** * find_last_bit - find the last set bit in a memory region * @addr: The address to start the search at --=20 2.17.0