cpumask.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef CPUMASK_H
  2. #define CPUMASK_H
  3. #define NR_CPUS 4096
  4. #include <stdlib.h>
  5. #include "bit_array.h"
  6. #include "hexio.h"
  7. typedef struct {
  8. BIT_ARRAY* bits;
  9. } cpumask_t;
  10. extern cpumask_t _unused_cpumask_arg_;
  11. #define cpus_init(dst) ((dst).bits = bit_array_create(NR_CPUS))
  12. #define cpus_free(dst) bit_array_free((dst).bits)
  13. #define cpus_copy(dst, src) bit_array_copy_all((dst).bits, (src).bits)
  14. #define cpu_set(cpu, dst) bit_array_set_bit((dst).bits, cpu)
  15. #define cpu_clear(cpu, dst) bit_array_clear_bit((dst).bits, cpu)
  16. #define cpus_setall(dst) bit_array_set_all((dst).bits)
  17. #define cpus_clear(dst) bit_array_clear_all((dst).bits)
  18. #define cpu_isset(cpu, cpumask) bit_array_get_bit((cpumask).bits, cpu)
  19. #define cpus_and(dst, src1, src2) bit_array_and((dst).bits, (src1).bits, (src2).bits)
  20. #define cpus_or(dst, src1, src2) bit_array_or((dst).bits, (src1).bits, (src2).bits)
  21. #define cpus_xor(dst, src1, src2) bit_array_xor((dst).bits, (src1).bits, (src2).bits)
  22. #define cpus_complement(dst, src) bit_array_not((dst).bits, (src).bits)
  23. #define cpus_equal(src1, src2) (bit_array_cmp((src1).bits, (src2).bits) == 0)
  24. #define cpus_empty(src) (bit_array_num_bits_set((src).bits) == 0)
  25. #define cpus_full(src) (bit_array_num_bits_cleared((src).bits) == 0)
  26. #define cpus_weight(cpumask) bit_array_num_bits_set((cpumask).bits)\
  27. #define cpus_shift_right(dst, n) bit_array_shift_right((dst).bits, n, 0)
  28. #define cpus_shift_left(dst, n) bit_array_shift_left((dst).bits, n, 0)
  29. static inline int __first_cpu(const cpumask_t srcp)
  30. {
  31. bit_index_t res = bit_array_length(srcp.bits);
  32. bit_array_find_first_set_bit(srcp.bits, &res);
  33. return res;
  34. }
  35. #define first_cpu(src) __first_cpu((src))
  36. int __next_cpu(int n, const cpumask_t *srcp);
  37. #define next_cpu(n, src) __next_cpu((n), (src))
  38. #define cpumask_scnprintf(buf, len, src) bitmask_scnprintf((buf), (len), (src).bits)
  39. #define cpumask_parse_user(ubuf, ulen, dst) bitmask_parse_user((ubuf), (ulen), (dst).bits)
  40. #endif /* CPUMASK_H */