Use a 64-bit bitmap rather than a 32-bit bitmap.
This commit is contained in:
parent
764dcba75a
commit
6108ff1608
|
@ -19,18 +19,18 @@ BitMap::BitMap() = default;
|
||||||
|
|
||||||
BitMap::BitMap(size_t size_bits) { Resize(size_bits); }
|
BitMap::BitMap(size_t size_bits) { Resize(size_bits); }
|
||||||
|
|
||||||
BitMap::BitMap(uint32_t* data, size_t size_bits) {
|
BitMap::BitMap(uint64_t* data, size_t size_bits) {
|
||||||
assert_true(size_bits % 32 == 0);
|
assert_true(size_bits % kDataSizeBits == 0);
|
||||||
|
|
||||||
data_.resize(size_bits / 32);
|
data_.resize(size_bits / kDataSizeBits);
|
||||||
std::memcpy(data_.data(), data, size_bits / 32);
|
std::memcpy(data_.data(), data, size_bits / kDataSizeBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BitMap::Acquire() {
|
size_t BitMap::Acquire() {
|
||||||
for (size_t i = 0; i < data_.size(); i++) {
|
for (size_t i = 0; i < data_.size(); i++) {
|
||||||
uint32_t entry = 0;
|
uint64_t entry = 0;
|
||||||
uint32_t new_entry = 0;
|
uint64_t new_entry = 0;
|
||||||
int acquired_idx = -1;
|
int64_t acquired_idx = -1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
entry = data_[i];
|
entry = data_[i];
|
||||||
|
@ -42,7 +42,7 @@ size_t BitMap::Acquire() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entry has a free bit. Acquire it.
|
// 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;
|
new_entry = entry & ~bit;
|
||||||
assert_not_zero(entry & bit);
|
assert_not_zero(entry & bit);
|
||||||
|
|
||||||
|
@ -62,10 +62,10 @@ void BitMap::Release(size_t index) {
|
||||||
auto slot = index / kDataSizeBits;
|
auto slot = index / kDataSizeBits;
|
||||||
index -= slot * kDataSizeBits;
|
index -= slot * kDataSizeBits;
|
||||||
|
|
||||||
uint32_t bit = 1 << (kDataSizeBits - index - 1);
|
uint64_t bit = 1ull << (kDataSizeBits - index - 1);
|
||||||
|
|
||||||
uint32_t entry = 0;
|
uint64_t entry = 0;
|
||||||
uint32_t new_entry = 0;
|
uint64_t new_entry = 0;
|
||||||
do {
|
do {
|
||||||
entry = data_[slot];
|
entry = data_[slot];
|
||||||
assert_zero(entry & bit);
|
assert_zero(entry & bit);
|
||||||
|
@ -76,8 +76,8 @@ void BitMap::Release(size_t index) {
|
||||||
|
|
||||||
void BitMap::Resize(size_t new_size_bits) {
|
void BitMap::Resize(size_t new_size_bits) {
|
||||||
auto old_size = data_.size();
|
auto old_size = data_.size();
|
||||||
assert_true(new_size_bits % 32 == 0);
|
assert_true(new_size_bits % kDataSizeBits == 0);
|
||||||
data_.resize(new_size_bits / 32);
|
data_.resize(new_size_bits / kDataSizeBits);
|
||||||
|
|
||||||
// Initialize new entries.
|
// Initialize new entries.
|
||||||
if (data_.size() > old_size) {
|
if (data_.size() > old_size) {
|
||||||
|
|
|
@ -20,13 +20,13 @@ class BitMap {
|
||||||
public:
|
public:
|
||||||
BitMap();
|
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);
|
BitMap(size_t size_bits);
|
||||||
|
|
||||||
// Data does not have to be aligned to a 4-byte boundary, but it is
|
// Data does not have to be aligned to a 4-byte boundary, but it is
|
||||||
// preferable.
|
// preferable.
|
||||||
// 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(uint32_t* data, size_t size_bits);
|
BitMap(uint64_t* data, size_t size_bits);
|
||||||
|
|
||||||
// (threadsafe) Acquires an entry and returns its index. Returns -1 if there
|
// (threadsafe) Acquires an entry and returns its index. Returns -1 if there
|
||||||
// are no more free entries.
|
// are no more free entries.
|
||||||
|
@ -35,19 +35,19 @@ class BitMap {
|
||||||
// (threadsafe) Releases an entry by an index.
|
// (threadsafe) Releases an entry by an index.
|
||||||
void Release(size_t 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);
|
void Resize(size_t new_size_bits);
|
||||||
|
|
||||||
// Sets all entries to free.
|
// Sets all entries to free.
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
const std::vector<uint32_t> data() const { return data_; }
|
const std::vector<uint64_t> data() const { return data_; }
|
||||||
std::vector<uint32_t>& data() { return data_; }
|
std::vector<uint64_t>& data() { return data_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const static uint32_t kDataSize = 4;
|
const static size_t kDataSize = 8;
|
||||||
const static uint32_t kDataSizeBits = kDataSize * 8;
|
const static size_t kDataSizeBits = kDataSize * 8;
|
||||||
std::vector<uint32_t> data_;
|
std::vector<uint64_t> data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace xe
|
} // namespace xe
|
||||||
|
|
|
@ -652,7 +652,7 @@ bool KernelState::Save(ByteStream* stream) {
|
||||||
auto tls_bitmap = tls_bitmap_.data();
|
auto tls_bitmap = tls_bitmap_.data();
|
||||||
stream->Write(uint32_t(tls_bitmap.size()));
|
stream->Write(uint32_t(tls_bitmap.size()));
|
||||||
for (size_t i = 0; i < tls_bitmap.size(); i++) {
|
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
|
// 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());
|
stream->Write<uint32_t>(object->type());
|
||||||
if (!object->Save(stream)) {
|
if (!object->Save(stream)) {
|
||||||
XELOGD("Did not save object of type %d", object->type());
|
XELOGD("Did not save object of type %d", object->type());
|
||||||
|
assert_always();
|
||||||
|
|
||||||
// Revert backwards and overwrite if a save failed.
|
// Revert backwards and overwrite if a save failed.
|
||||||
stream->set_offset(prev_offset);
|
stream->set_offset(prev_offset);
|
||||||
|
@ -724,7 +725,7 @@ bool KernelState::Restore(ByteStream* stream) {
|
||||||
auto& tls_bitmap = tls_bitmap_.data();
|
auto& tls_bitmap = tls_bitmap_.data();
|
||||||
tls_bitmap.resize(num_bitmap_entries);
|
tls_bitmap.resize(num_bitmap_entries);
|
||||||
for (uint32_t i = 0; i < num_bitmap_entries; i++) {
|
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>();
|
uint32_t num_threads = stream->Read<uint32_t>();
|
||||||
|
|
Loading…
Reference in New Issue