Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'bitmap-for-6.10v2' of https://github.com/norov/linux

Pull bitmap updates from Yury Norov:

- topology_span_sane() optimization from Kyle Meyer

- fns() rework from Kuan-Wei Chiu (used in cpumask_local_spread() and
other places)

- headers cleanup from Andy

- add a MAINTAINERS record for bitops API

* tag 'bitmap-for-6.10v2' of https://github.com/norov/linux:
usercopy: Don't use "proxy" headers
bitops: Move aligned_byte_mask() to wordpart.h
MAINTAINERS: add BITOPS API record
bitmap: relax find_nth_bit() limitation on return value
lib: make test_bitops compilable into the kernel image
bitops: Optimize fns() for improved performance
lib/test_bitops: Add benchmark test for fns()
Compiler Attributes: Add __always_used macro
sched/topology: Optimize topology_span_sane()
cpumask: Add for_each_cpu_from()

+88 -27
+14
MAINTAINERS
··· 3725 3725 F: tools/lib/bitmap.c 3726 3726 F: tools/lib/find_bit.c 3727 3727 3728 + BITOPS API 3729 + M: Yury Norov <yury.norov@gmail.com> 3730 + R: Rasmus Villemoes <linux@rasmusvillemoes.dk> 3731 + S: Maintained 3732 + F: arch/*/include/asm/bitops.h 3733 + F: arch/*/include/asm/bitops_32.h 3734 + F: arch/*/include/asm/bitops_64.h 3735 + F: arch/*/lib/bitops.c 3736 + F: include/asm-generic/bitops 3737 + F: include/asm-generic/bitops.h 3738 + F: include/linux/bitops.h 3739 + F: lib/test_bitops.c 3740 + F: tools/*/bitops* 3741 + 3728 3742 BLINKM RGB LED DRIVER 3729 3743 M: Jan-Simon Moeller <jansimon.moeller@gmx.de> 3730 3744 S: Maintained
+3 -16
include/linux/bitops.h
··· 8 8 9 9 #include <uapi/linux/kernel.h> 10 10 11 - /* Set bits in the first 'n' bytes when loaded from memory */ 12 - #ifdef __LITTLE_ENDIAN 13 - # define aligned_byte_mask(n) ((1UL << 8*(n))-1) 14 - #else 15 - # define aligned_byte_mask(n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n))) 16 - #endif 17 - 18 11 #define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE) 19 12 #define BITS_TO_LONGS(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long)) 20 13 #define BITS_TO_U64(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u64)) ··· 250 257 */ 251 258 static inline unsigned int fns(unsigned long word, unsigned int n) 252 259 { 253 - unsigned int bit; 260 + while (word && n--) 261 + word &= word - 1; 254 262 255 - while (word) { 256 - bit = __ffs(word); 257 - if (n-- == 0) 258 - return bit; 259 - __clear_bit(bit, &word); 260 - } 261 - 262 - return BITS_PER_LONG; 263 + return word ? __ffs(word) : BITS_PER_LONG; 263 264 } 264 265 265 266 /**
+13
include/linux/compiler_attributes.h
··· 362 362 #define __used __attribute__((__used__)) 363 363 364 364 /* 365 + * The __used attribute guarantees that the attributed variable will be 366 + * always emitted by a compiler. It doesn't prevent the compiler from 367 + * throwing 'unused' warnings when it can't detect how the variable is 368 + * actually used. It's a compiler implementation details either emit 369 + * the warning in that case or not. 370 + * 371 + * The combination of both 'used' and 'unused' attributes ensures that 372 + * the variable would be emitted, and will not trigger 'unused' warnings. 373 + * The attribute is applicable for functions, static and global variables. 374 + */ 375 + #define __always_used __used __maybe_unused 376 + 377 + /* 365 378 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-warn_005funused_005fresult-function-attribute 366 379 * clang: https://clang.llvm.org/docs/AttributeReference.html#nodiscard-warn-unused-result 367 380 */
+10
include/linux/cpumask.h
··· 386 386 for_each_or_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), small_cpumask_bits) 387 387 388 388 /** 389 + * for_each_cpu_from - iterate over CPUs present in @mask, from @cpu to the end of @mask. 390 + * @cpu: the (optionally unsigned) integer iterator 391 + * @mask: the cpumask pointer 392 + * 393 + * After the loop, cpu is >= nr_cpu_ids. 394 + */ 395 + #define for_each_cpu_from(cpu, mask) \ 396 + for_each_set_bit_from(cpu, cpumask_bits(mask), small_cpumask_bits) 397 + 398 + /** 389 399 * cpumask_any_but - return a "random" in a cpumask, but not this one. 390 400 * @mask: the cpumask to search 391 401 * @cpu: the cpu to ignore.
+1 -1
include/linux/find.h
··· 222 222 * idx = find_first_bit(addr, size); 223 223 * 224 224 * Returns the bit number of the N'th set bit. 225 - * If no such, returns @size. 225 + * If no such, returns >= @size. 226 226 */ 227 227 static inline 228 228 unsigned long find_nth_bit(const unsigned long *addr, unsigned long size, unsigned long n)
+7
include/linux/wordpart.h
··· 39 39 */ 40 40 #define REPEAT_BYTE(x) ((~0ul / 0xff) * (x)) 41 41 42 + /* Set bits in the first 'n' bytes when loaded from memory */ 43 + #ifdef __LITTLE_ENDIAN 44 + # define aligned_byte_mask(n) ((1UL << 8*(n))-1) 45 + #else 46 + # define aligned_byte_mask(n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n))) 47 + #endif 48 + 42 49 #endif // _LINUX_WORDPART_H
+2 -4
kernel/sched/topology.c
··· 2353 2353 static bool topology_span_sane(struct sched_domain_topology_level *tl, 2354 2354 const struct cpumask *cpu_map, int cpu) 2355 2355 { 2356 - int i; 2356 + int i = cpu + 1; 2357 2357 2358 2358 /* NUMA levels are allowed to overlap */ 2359 2359 if (tl->flags & SDTL_OVERLAP) ··· 2365 2365 * breaking the sched_group lists - i.e. a later get_group() pass 2366 2366 * breaks the linking done for an earlier span. 2367 2367 */ 2368 - for_each_cpu(i, cpu_map) { 2369 - if (i == cpu) 2370 - continue; 2368 + for_each_cpu_from(i, cpu_map) { 2371 2369 /* 2372 2370 * We should 'and' all those masks with 'cpu_map' to exactly 2373 2371 * match the topology we're about to build, but that can only
-1
lib/Kconfig.debug
··· 2482 2482 2483 2483 config TEST_BITOPS 2484 2484 tristate "Test module for compilation of bitops operations" 2485 - depends on m 2486 2485 help 2487 2486 This builds the "test_bitops" module that is much like the 2488 2487 TEST_LKM module except that it does a basic exercise of the
+1 -1
lib/find_bit.c
··· 87 87 if (sz % BITS_PER_LONG) \ 88 88 tmp = (FETCH) & BITMAP_LAST_WORD_MASK(sz); \ 89 89 found: \ 90 - sz = min(idx * BITS_PER_LONG + fns(tmp, nr), sz); \ 90 + sz = idx * BITS_PER_LONG + fns(tmp, nr); \ 91 91 out: \ 92 92 sz; \ 93 93 })
+2 -2
lib/test_bitmap.c
··· 244 244 expect_eq_uint(60, find_nth_bit(bmap, 64 * 3, 5)); 245 245 expect_eq_uint(80, find_nth_bit(bmap, 64 * 3, 6)); 246 246 expect_eq_uint(123, find_nth_bit(bmap, 64 * 3, 7)); 247 - expect_eq_uint(64 * 3, find_nth_bit(bmap, 64 * 3, 8)); 247 + expect_eq_uint(0, !!(find_nth_bit(bmap, 64 * 3, 8) < 64 * 3)); 248 248 249 249 expect_eq_uint(10, find_nth_bit(bmap, 64 * 3 - 1, 0)); 250 250 expect_eq_uint(20, find_nth_bit(bmap, 64 * 3 - 1, 1)); ··· 254 254 expect_eq_uint(60, find_nth_bit(bmap, 64 * 3 - 1, 5)); 255 255 expect_eq_uint(80, find_nth_bit(bmap, 64 * 3 - 1, 6)); 256 256 expect_eq_uint(123, find_nth_bit(bmap, 64 * 3 - 1, 7)); 257 - expect_eq_uint(64 * 3 - 1, find_nth_bit(bmap, 64 * 3 - 1, 8)); 257 + expect_eq_uint(0, !!(find_nth_bit(bmap, 64 * 3 - 1, 8) < 64 * 3 - 1)); 258 258 259 259 for_each_set_bit(bit, exp1, EXP1_IN_BITS) { 260 260 b = find_nth_bit(exp1, EXP1_IN_BITS, cnt++);
+28
lib/test_bitops.c
··· 5 5 6 6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 7 7 8 + #include <linux/cleanup.h> 8 9 #include <linux/init.h> 9 10 #include <linux/module.h> 10 11 #include <linux/printk.h> 12 + #include <linux/slab.h> 11 13 12 14 /* a tiny module only meant to test 13 15 * ··· 51 49 {0x8000300000000000, 64}, 52 50 }; 53 51 #endif 52 + 53 + static int __init test_fns(void) 54 + { 55 + static volatile __always_used unsigned long tmp __initdata; 56 + unsigned long *buf __free(kfree) = NULL; 57 + unsigned int i, n; 58 + ktime_t time; 59 + 60 + buf = kmalloc_array(10000, sizeof(unsigned long), GFP_KERNEL); 61 + if (!buf) 62 + return -ENOMEM; 63 + 64 + get_random_bytes(buf, 10000 * sizeof(unsigned long)); 65 + time = ktime_get(); 66 + 67 + for (n = 0; n < BITS_PER_LONG; n++) 68 + for (i = 0; i < 10000; i++) 69 + tmp = fns(buf[i], n); 70 + 71 + time = ktime_get() - time; 72 + pr_err("fns: %18llu ns\n", time); 73 + 74 + return 0; 75 + } 54 76 55 77 static int __init test_bitops_startup(void) 56 78 { ··· 119 93 bit_set = find_first_bit(g_bitmap, BITOPS_LAST); 120 94 if (bit_set != BITOPS_LAST) 121 95 pr_err("ERROR: FOUND SET BIT %d\n", bit_set); 96 + 97 + test_fns(); 122 98 123 99 pr_info("Completed bitops test\n"); 124 100
+7 -2
lib/usercopy.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #include <linux/bitops.h> 2 + #include <linux/compiler.h> 3 + #include <linux/errno.h> 4 + #include <linux/export.h> 3 5 #include <linux/fault-inject-usercopy.h> 4 6 #include <linux/instrumented.h> 5 - #include <linux/uaccess.h> 7 + #include <linux/kernel.h> 6 8 #include <linux/nospec.h> 9 + #include <linux/string.h> 10 + #include <linux/uaccess.h> 11 + #include <linux/wordpart.h> 7 12 8 13 /* out-of-line parts */ 9 14