[PATCH] fs/resctrl: Slightly optimize cbm_validate()
From: Christophe JAILLET
Date: Sun Oct 26 2025 - 03:42:17 EST
'first_bit' is known to be 1, so it can be skipped when searching for the
next 0 bit. Doing so mimics bitmap_next_set_region() and can save a few
cycles.
Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
Compile tested only.
For the records, on x86, the diff of the asm code is:
--- fs/resctrl/ctrlmondata.s.old 2025-10-26 08:21:46.928920563 +0100
+++ fs/resctrl/ctrlmondata.s 2025-10-26 08:21:40.864024143 +0100
@@ -1603,11 +1603,12 @@
call _find_first_bit
# ./include/linux/find.h:192: return _find_next_zero_bit(addr, size, offset);
movq %r12, %rsi
- leaq 48(%rsp), %rdi
- movq %rax, %rdx
+# fs/resctrl/ctrlmondata.c:133: zero_bit = find_next_zero_bit(&val, cbm_len, first_bit + 1);
+ leaq 1(%rax), %rdx
# ./include/linux/find.h:214: return _find_first_bit(addr, size);
movq %rax, 8(%rsp)
# ./include/linux/find.h:192: return _find_next_zero_bit(addr, size, offset);
+ leaq 48(%rsp), %rdi
call _find_next_zero_bit
# fs/resctrl/ctrlmondata.c:136: if (!r->cache.arch_has_sparse_bitmasks &&
leaq 28(%rbx), %rdi
---
fs/resctrl/ctrlmondata.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index 0d0ef54fc4de..1ff479a2dbbc 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -130,7 +130,7 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
}
first_bit = find_first_bit(&val, cbm_len);
- zero_bit = find_next_zero_bit(&val, cbm_len, first_bit);
+ zero_bit = find_next_zero_bit(&val, cbm_len, first_bit + 1);
/* Are non-contiguous bitmasks allowed? */
if (!r->cache.arch_has_sparse_bitmasks &&
--
2.51.0