misc.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef BTRFS_MISC_H
  3. #define BTRFS_MISC_H
  4. #include <linux/sched.h>
  5. #include <linux/wait.h>
  6. #include <asm/div64.h>
  7. #define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len))
  8. static inline void cond_wake_up(struct wait_queue_head *wq)
  9. {
  10. /*
  11. * This implies a full smp_mb barrier, see comments for
  12. * waitqueue_active why.
  13. */
  14. if (wq_has_sleeper(wq))
  15. wake_up(wq);
  16. }
  17. static inline void cond_wake_up_nomb(struct wait_queue_head *wq)
  18. {
  19. /*
  20. * Special case for conditional wakeup where the barrier required for
  21. * waitqueue_active is implied by some of the preceding code. Eg. one
  22. * of such atomic operations (atomic_dec_and_return, ...), or a
  23. * unlock/lock sequence, etc.
  24. */
  25. if (waitqueue_active(wq))
  26. wake_up(wq);
  27. }
  28. static inline u64 div_factor(u64 num, int factor)
  29. {
  30. if (factor == 10)
  31. return num;
  32. num *= factor;
  33. return div_u64(num, 10);
  34. }
  35. static inline u64 div_factor_fine(u64 num, int factor)
  36. {
  37. if (factor == 100)
  38. return num;
  39. num *= factor;
  40. return div_u64(num, 100);
  41. }
  42. #endif