sched.h 760 B

123456789101112131415161718192021222324252627282930313233
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_GENERIC_BITOPS_SCHED_H_
  3. #define _ASM_GENERIC_BITOPS_SCHED_H_
  4. #include <linux/compiler.h> /* unlikely() */
  5. #include <asm/types.h>
  6. /*
  7. * Every architecture must define this function. It's the fastest
  8. * way of searching a 100-bit bitmap. It's guaranteed that at least
  9. * one of the 100 bits is cleared.
  10. */
  11. static inline int sched_find_first_bit(const unsigned long *b)
  12. {
  13. #if BITS_PER_LONG == 64
  14. if (b[0])
  15. return __ffs(b[0]);
  16. return __ffs(b[1]) + 64;
  17. #elif BITS_PER_LONG == 32
  18. if (b[0])
  19. return __ffs(b[0]);
  20. if (b[1])
  21. return __ffs(b[1]) + 32;
  22. if (b[2])
  23. return __ffs(b[2]) + 64;
  24. return __ffs(b[3]) + 96;
  25. #else
  26. #error BITS_PER_LONG not defined
  27. #endif
  28. }
  29. #endif /* _ASM_GENERIC_BITOPS_SCHED_H_ */