Use a 64-bit bitmap rather than a 32-bit bitmap.

This commit is contained in:
Dr. Chat 2015-12-28 10:52:22 -06:00 committed by Ben Vanik
parent 764dcba75a
commit 6108ff1608
3 changed files with 25 additions and 24 deletions

View File

@ -19,18 +19,18 @@ BitMap::BitMap() = default;
BitMap::BitMap(size_t size_bits) { Resize(size_bits); }
BitMap::BitMap(uint32_t* data, size_t size_bits) {
assert_true(size_bits % 32 == 0);
BitMap::BitMap(uint64_t* data, size_t size_bits) {
assert_true(size_bits % kDataSizeBits == 0);
data_.resize(size_bits / 32);
std::memcpy(data_.data(), data, size_bits / 32);
data_.resize(size_bits / kDataSizeBits);
std::memcpy(data_.data(), data, size_bits / kDataSizeBits);
}
size_t BitMap::Acquire() {
for (size_t i = 0; i < data_.size(); i++) {
uint32_t entry = 0;
uint32_t new_entry = 0;
int acquired_idx = -1;
uint64_t entry = 0;
uint64_t new_entry = 0;
int64_t acquired_idx = -1;
do {
entry = data_[i];
@ -42,7 +42,7 @@ size_t BitMap::Acquire() {
}
// Entry has a free bit. Acquire it.
uint32_t bit = 1 << (kDataSizeBits - index - 1);
uint64_t bit = 1ull << (kDataSizeBits - index - 1);
new_entry = entry & ~bit;
assert_not_zero(entry & bit);
@ -62,10 +62,10 @@ void BitMap::Release(size_t index) {
auto slot = index / kDataSizeBits;
index -= slot * kDataSizeBits;
uint32_t bit = 1 << (kDataSizeBits - index - 1);
uint64_t bit = 1ull << (kDataSizeBits - index - 1);
uint32_t entry = 0;
uint32_t new_entry = 0;
uint64_t entry = 0;
uint64_t new_entry = 0;
do {
entry = data_[slot];
assert_zero(entry & bit);
@ -76,8 +76,8 @@ void BitMap::Release(size_t index) {
void BitMap::Resize(size_t new_size_bits) {
auto old_size = data_.size();
assert_true(new_size_bits % 32 == 0);
data_.resize(new_size_bits / 32);
assert_true(new_size_bits % kDataSizeBits == 0);
data_.resize(new_size_bits / kDataSizeBits);
// Initialize new entries.
if (data_.size() > old_size) {

View File

@ -20,13 +20,13 @@ class BitMap {
public:
BitMap();
// Size is the number of entries, must be a multiple of 32.
// Size is the number of entries, must be a multiple of 64.
BitMap(size_t size_bits);
// Data does not have to be aligned to a 4-byte boundary, but it is
// preferable.
// Size is the number of entries, must be a multiple of 32.
BitMap(uint32_t* data, size_t size_bits);
// Size is the number of entries, must be a multiple of 64.
BitMap(uint64_t* data, size_t size_bits);
// (threadsafe) Acquires an entry and returns its index. Returns -1 if there
// are no more free entries.
@ -35,19 +35,19 @@ class BitMap {
// (threadsafe) Releases an entry by an index.
void Release(size_t index);
// Resize the bitmap. Size is the number of entries, must be a multiple of 32.
// Resize the bitmap. Size is the number of entries, must be a multiple of 64.
void Resize(size_t new_size_bits);
// Sets all entries to free.
void Reset();
const std::vector<uint32_t> data() const { return data_; }
std::vector<uint32_t>& data() { return data_; }
const std::vector<uint64_t> data() const { return data_; }
std::vector<uint64_t>& data() { return data_; }
private:
const static uint32_t kDataSize = 4;
const static uint32_t kDataSizeBits = kDataSize * 8;
std::vector<uint32_t> data_;
const static size_t kDataSize = 8;
const static size_t kDataSizeBits = kDataSize * 8;
std::vector<uint64_t> data_;
};
} // namespace xe

View File

@ -652,7 +652,7 @@ bool KernelState::Save(ByteStream* stream) {
auto tls_bitmap = tls_bitmap_.data();
stream->Write(uint32_t(tls_bitmap.size()));
for (size_t i = 0; i < tls_bitmap.size(); i++) {
stream->Write<uint32_t>(tls_bitmap[i]);
stream->Write<uint64_t>(tls_bitmap[i]);
}
// We save XThreads absolutely first, as they will execute code upon save
@ -699,6 +699,7 @@ bool KernelState::Save(ByteStream* stream) {
stream->Write<uint32_t>(object->type());
if (!object->Save(stream)) {
XELOGD("Did not save object of type %d", object->type());
assert_always();
// Revert backwards and overwrite if a save failed.
stream->set_offset(prev_offset);
@ -724,7 +725,7 @@ bool KernelState::Restore(ByteStream* stream) {
auto& tls_bitmap = tls_bitmap_.data();
tls_bitmap.resize(num_bitmap_entries);
for (uint32_t i = 0; i < num_bitmap_entries; i++) {
tls_bitmap[i] = stream->Read<uint32_t>();
tls_bitmap[i] = stream->Read<uint64_t>();
}
uint32_t num_threads = stream->Read<uint32_t>();