HelenOS sources
This source file includes following definitions.
- cpu_mask_size
- cpu_mask_count
- cpu_mask_active
- cpu_mask_all
- cpu_mask_none
- cpu_mask_set
- cpu_mask_reset
- cpu_mask_is_set
- cpu_mask_is_none
#include <assert.h>
#include <cpu/cpu_mask.h>
#include <cpu.h>
#include <config.h>
static const size_t word_size = sizeof(unsigned int);
static const size_t word_bit_cnt = 8 * sizeof(unsigned int);
size_t cpu_mask_size(void)
{
size_t word_cnt = (config.cpu_count + word_bit_cnt - 1) / word_bit_cnt;
return word_cnt * word_size;
}
static void cpu_mask_count(cpu_mask_t *cpus, size_t cpu_cnt)
{
assert(NULL != cpus);
assert(cpu_cnt <= config.cpu_count);
for (size_t active_word = 0;
(active_word + 1) * word_bit_cnt <= cpu_cnt;
++active_word) {
cpus->mask[active_word] = -1;
}
size_t remaining_bits = (cpu_cnt % word_bit_cnt);
if (0 < remaining_bits) {
cpus->mask[cpu_cnt / word_bit_cnt] = (1 << remaining_bits) - 1;
}
}
void cpu_mask_active(cpu_mask_t *cpus)
{
cpu_mask_none(cpus);
cpu_mask_count(cpus, config.cpu_active);
}
void cpu_mask_all(cpu_mask_t *cpus)
{
cpu_mask_count(cpus, config.cpu_count);
}
void cpu_mask_none(cpu_mask_t *cpus)
{
assert(cpus);
size_t word_cnt = cpu_mask_size() / word_size;
for (size_t word = 0; word < word_cnt; ++word) {
cpus->mask[word] = 0;
}
}
void cpu_mask_set(cpu_mask_t *cpus, unsigned int cpu_id)
{
size_t word = cpu_id / word_bit_cnt;
size_t word_pos = cpu_id % word_bit_cnt;
cpus->mask[word] |= (1U << word_pos);
}
void cpu_mask_reset(cpu_mask_t *cpus, unsigned int cpu_id)
{
size_t word = cpu_id / word_bit_cnt;
size_t word_pos = cpu_id % word_bit_cnt;
cpus->mask[word] &= ~(1U << word_pos);
}
bool cpu_mask_is_set(cpu_mask_t *cpus, unsigned int cpu_id)
{
size_t word = cpu_id / word_bit_cnt;
size_t word_pos = cpu_id % word_bit_cnt;
return 0 != (cpus->mask[word] & (1U << word_pos));
}
bool cpu_mask_is_none(cpu_mask_t *cpus)
{
size_t word_cnt = cpu_mask_size() / word_size;
for (size_t word = 0; word < word_cnt; ++word) {
if (cpus->mask[word])
return false;
}
return true;
}
HelenOS homepage, sources at GitHub