From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [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 541F830F548 for ; Mon, 1 Jun 2026 09:43:25 +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=1780307010; cv=none; b=azAJFNzCBVgwjjhpJgXmycvoSWKm9Que9OEoshIZzI8A8SZJktuXy9P6okfCXn8rsoyNfznHw3zVPys+c5DPk27mLzhFTFDnj3MF24PFsMLz+GqCUXHmNtDglDCKWLKPlgw01iN4W2wrBSlMtnxfUlun5oj255w4wamy7SiZMmQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780307010; c=relaxed/simple; bh=aOjD+xAtFf1HNJKFLbXePwz7XgCPr4i5vO1OHfDTFbw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uet+DBRZDk1H5DH6Zq3Q3TWCTR1I3udPAU7CZ2IIisgxZ8iHmX5rg8qPWANGyjUA5268aLyYXIMPeK0n0Jbdg+J6Kw+i91cqCJJRNl1DcOeEjY89X65OM/wNvcZqGVwR/l+a7hH27UZKOSZVWSheA1w15wAhThUiQ7iKCxvQWoI= 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=RS3Uuifr; 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="RS3Uuifr" Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 6519geaa009036; Mon, 1 Jun 2026 17:42:40 +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 4gTTRf3FX3z2M0bYC; Mon, 1 Jun 2026 17:38:38 +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; Mon, 1 Jun 2026 17:42:39 +0800 From: Yi Sun To: , CC: , , , , , Subject: [PATCH v4 2/2] lib/bitmap: add tests for bitmap_find_next_zero_area_off() Date: Mon, 1 Jun 2026 17:42:34 +0800 Message-ID: <20260601094234.103863-3-yi.sun@unisoc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260601094234.103863-1-yi.sun@unisoc.com> References: <20260601094234.103863-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 6519geaa009036 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unisoc.com; s=default; t=1780306971; bh=4LBJK3yEoknDk91SqRZBxsHP9L4+Wv0bjoSHnW295rU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=RS3UuifrE2ZalrCm6JP1utivwNdm1CuqOR9GWRqUM8GSbaEosaxnJkvxuJ6FeIeyi kC7fhrcxsi3Mc6dp/Pja2oY2P1B+lkp00Ca0AT2UbV9OSY5QtwoMczCLD0WpeQm4jK o8BiYFMvAcP0LW+ZSVwtgMGX/+tsGktkA+EBPGwy+Bxd7dwPriBT4F/iiMIgcGNPiy DPbopdjVO3VZGjhpY1sK80+rsI8vpA5w9wxYPYA00J2OPN71BGY54aLjVPAVzkxC/6 HCfTwIkR8da7Y5Pyd3uapt4hv8nrssHXDs0TRuHUzTW3WRXgi4N7DPlpkmdvYce2Sv E0orFzyYq4Wkw== Add functional and performance tests for bitmap_find_next_zero_area_off(). Signed-off-by: Yi Sun --- lib/find_bit_benchmark.c | 17 +++++++++++++++++ lib/test_bitmap.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib/find_bit_benchmark.c b/lib/find_bit_benchmark.c index 00d9dc61cd46..37fe76ad322e 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("bitmap_find_next_zero_area_off: %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..fad2b19760c2 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -234,6 +234,34 @@ static void __init test_find_nth_bit(void) } } +static void __init +test_bitmap_find_next_zero_area_off(void) +{ + int bmap_len = 64 * 3; + DECLARE_BITMAP(bmap, bmap_len); + + bitmap_set(bmap, 0, bmap_len); + + bitmap_clear(bmap, 0, 8); + __clear_bit(50, bmap); + bitmap_clear(bmap, 60, 10); + __clear_bit(80, bmap); + bitmap_clear(bmap, 100, 10); + __clear_bit(120, bmap); + bitmap_clear(bmap, 160, 32); + + expect_eq_uint(0, + bitmap_find_next_zero_area_off(bmap, bmap_len, 0, 8, 0, 0)); + expect_eq_uint(60, + bitmap_find_next_zero_area_off(bmap, bmap_len, 1, 8, 0, 0)); + expect_eq_uint(60, + bitmap_find_next_zero_area_off(bmap, bmap_len, 0, 10, 0, 0)); + expect_eq_uint(160, + bitmap_find_next_zero_area_off(bmap, bmap_len, 0, 32, 0, 0)); + expect_eq_uint(1, + !!(bitmap_find_next_zero_area_off(bmap, bmap_len, 0, 33, 0, 0) > bmap_len)); +} + static void __init test_fill_set(void) { DECLARE_BITMAP(bmap, 1024); -- 2.34.1