From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D5FC2DB798 for ; Thu, 18 Jun 2026 01:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781747598; cv=none; b=mCfBC0S/pH9WKb0h2Hva7W8d4sy25OAVr2LRjD7vUlcYeOR6gQa4faK8V0SesgRDktgNDkaEGx04LNdhX40ffSe+j3tj/ejacTs5lV9dJZnL1h2ru5aQLc4/MlK5B49MIMUW5l4kQ3lXu6ZLi8vskP+BBcyI3povFlEFkMYMFaA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781747598; c=relaxed/simple; bh=XKgZc6rwNP2TT7F7BUoF8sxmhOz5mlSZ/Ayq5QOWw5Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SWLWhUHEeguxaK4/KaE0wC5CgMowQ0Is7QMt1HQYOKW76yd0pejP5Qbp2Yrp4/onP3Emh5/9QA194FXUuBUtzh+r/qpeFA/gB6YHndSnWDKxuE4xiZ5ee+fgvwQPL+oln5TCYHeC7Iw6XZJXWbCy2A9wKDLJra7uNcomdBwklkM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; dkim=pass (2048-bit key) header.d=unisoc.com header.i=@unisoc.com header.b=afKfHDbb; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=unisoc.com header.i=@unisoc.com header.b="afKfHDbb" Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTPS id 65I1qxRC065502 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 18 Jun 2026 09:52:59 +0800 (+08) (envelope-from Yi.Sun@unisoc.com) Received: from SHDLP.spreadtrum.com (BJMBX02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4ggkC93Bfyz2Mp1GC; Thu, 18 Jun 2026 09:48:21 +0800 (CST) Received: from tj10379pcu.spreadtrum.com (10.5.32.15) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 18 Jun 2026 09:52:56 +0800 From: Yi Sun To: , CC: , <279644543@qq.com>, , , , , , , , , , , , , , , , Subject: [PATCH v5 1/2] lib: bitmap: add tests for bitmap_find_next_zero_area_off() Date: Thu, 18 Jun 2026 09:52:51 +0800 Message-ID: <20260618015252.3601554-2-yi.sun@unisoc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260618015252.3601554-1-yi.sun@unisoc.com> References: <20260618015252.3601554-1-yi.sun@unisoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL:SHSQR01.spreadtrum.com 65I1qxRC065502 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unisoc.com; s=default; t=1781747591; bh=pMHDXGucIks4BebGtt2CHTcCUq5MfVjGcx+gGZkD//o=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=afKfHDbbMZZlLPqGyLKc5gJ+kNxzUJ+NLkzosX8w9OOvah78IAiGRJqdsPsyXaYnH wiSlU80pe666MPAv0jFaX9YDAs6Z4nqsRR9OVmOaXMpcsxeg8fwxVSrHxPyXWniKgA Z/3bVv3I9BKt+GALvMsBMHovOqmWxKBSB000whHu/CGRR2ZZBrDo/lQxOM/xQZ1tUH 1CjuhPdgUolPbDzjItTfPAm+Zw7KgfUW6Nr0eLTMv3RGUh2Dmr6nTuyzYUd6urKWCw 2lLjNGyM940YLCuvZJ20vV9e87UkKhhUD37GsDCEyddp+k1RS8iwOBIskJyg0DWSck bcFaTSvr1ButA== Add functional and performance tests for bitmap_find_next_zero_area_off(). To maintain consistent output format, use "find_next_0_area" instead of "bitmap_find_next_zero_area_off". performance tests partial output: Start testing find_bit() with random-filled bitmap [ 0.191166] find_next_0_area: 1521308 ns, 1326 iterations [ 0.192552] find_next_bit: 1382385 ns, 163724 iterations Start testing find_bit() with sparse bitmap [ 0.196835] find_next_0_area: 4250307 ns, 322497 iterations [ 0.196853] find_next_bit: 15077 ns, 656 iterations Signed-off-by: Yi Sun --- lib/find_bit_benchmark.c | 17 +++++++++++++++++ lib/test_bitmap.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/lib/find_bit_benchmark.c b/lib/find_bit_benchmark.c index 00d9dc61cd46..062a69930d83 100644 --- a/lib/find_bit_benchmark.c +++ b/lib/find_bit_benchmark.c @@ -149,6 +149,21 @@ static int __init test_find_next_and_bit(const void *bitmap, return 0; } +static int __init +test_bitmap_find_next_zero_area_off(unsigned long *bitmap, unsigned long len) +{ + unsigned long i, cnt; + ktime_t time; + + time = ktime_get(); + for (cnt = i = 0; i < BITMAP_LEN; cnt++) + i = bitmap_find_next_zero_area_off(bitmap, BITMAP_LEN, i, 8, 0, 0) + 1; + time = ktime_get() - time; + pr_err("find_next_0_area: %18llu ns, %6ld iterations\n", time, cnt); + + return 0; +} + static int __init find_bit_test(void) { unsigned long nbits = BITMAP_LEN / SPARSE; @@ -158,6 +173,7 @@ static int __init find_bit_test(void) get_random_bytes(bitmap, sizeof(bitmap)); get_random_bytes(bitmap2, sizeof(bitmap2)); + test_bitmap_find_next_zero_area_off(bitmap, BITMAP_LEN); test_find_next_bit(bitmap, BITMAP_LEN); test_find_next_zero_bit(bitmap, BITMAP_LEN); test_find_last_bit(bitmap, BITMAP_LEN); @@ -181,6 +197,7 @@ static int __init find_bit_test(void) __set_bit(get_random_u32_below(BITMAP_LEN), bitmap2); } + test_bitmap_find_next_zero_area_off(bitmap, BITMAP_LEN); test_find_next_bit(bitmap, BITMAP_LEN); test_find_next_zero_bit(bitmap, BITMAP_LEN); test_find_last_bit(bitmap, BITMAP_LEN); diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 69813c10e6c0..12aa2ca37fe1 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -234,6 +234,43 @@ static void __init test_find_nth_bit(void) } } +static void __init +test_bitmap_find_next_zero_area_off(void) +{ + DECLARE_BITMAP(bmap, 192); + + bitmap_set(bmap, 0, 192); + + bitmap_clear(bmap, 0, 8); + __clear_bit(50, bmap); + bitmap_clear(bmap, 60, 18); + __set_bit(69, bmap); + __clear_bit(80, bmap); + bitmap_clear(bmap, 100, 10); + __clear_bit(120, bmap); + bitmap_clear(bmap, 145, 8); + bitmap_clear(bmap, 160, 32); + + expect_eq_uint(0, + bitmap_find_next_zero_area_off(bmap, 192, 0, 8, 0, 0)); + expect_eq_uint(0, + bitmap_find_next_zero_area_off(bmap, 192, 0, 8, 3, 0)); + expect_eq_uint(163, + bitmap_find_next_zero_area_off(bmap, 192, 0, 8, 3, 1)); + expect_eq_uint(60, + bitmap_find_next_zero_area_off(bmap, 192, 1, 8, 0, 0)); + expect_eq_uint(160, + bitmap_find_next_zero_area_off(bmap, 192, 1, 8, 7, 0)); + expect_eq_uint(60, + bitmap_find_next_zero_area_off(bmap, 192, 1, 8, 7, 4)); + expect_eq_uint(100, + bitmap_find_next_zero_area_off(bmap, 192, 0, 10, 0, 0)); + expect_eq_uint(160, + bitmap_find_next_zero_area_off(bmap, 192, 0, 32, 0, 0)); + expect_eq_uint(1, + !!(bitmap_find_next_zero_area_off(bmap, 192, 0, 33, 0, 0) > 192)); +} + static void __init test_fill_set(void) { DECLARE_BITMAP(bmap, 1024); @@ -1559,6 +1596,7 @@ static void __init selftest(void) test_for_each_clear_bitrange_from(); test_for_each_set_clump8(); test_for_each_set_bit_wrap(); + test_bitmap_find_next_zero_area_off(); } KSTM_MODULE_LOADERS(test_bitmap); -- 2.34.1