Rename INVALID_OFFSET to kInvalidOffset.

BUG=dawn:27

Change-Id: Ida590a2b3cf3da17bbedf6ef61d72eaaa443bc4b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11561
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Bryan Bernhart 2019-09-27 15:11:52 +00:00 committed by Commit Bot service account
parent 64f4dd7127
commit 86ac0b93c9
3 changed files with 15 additions and 13 deletions

View File

@ -91,7 +91,7 @@ namespace dawn_native {
break;
}
}
return INVALID_OFFSET; // No free block exists at any level.
return kInvalidOffset; // No free block exists at any level.
}
// Inserts existing free block into the free-list.
@ -141,7 +141,7 @@ namespace dawn_native {
uint64_t BuddyAllocator::Allocate(uint64_t allocationSize, uint64_t alignment) {
if (allocationSize == 0 || allocationSize > mMaxBlockSize) {
return INVALID_OFFSET;
return kInvalidOffset;
}
// Compute the level
@ -152,8 +152,8 @@ namespace dawn_native {
uint64_t currBlockLevel = GetNextFreeAlignedBlock(allocationSizeToLevel, alignment);
// Error when no free blocks exist (allocator is full)
if (currBlockLevel == INVALID_OFFSET) {
return INVALID_OFFSET;
if (currBlockLevel == kInvalidOffset) {
return kInvalidOffset;
}
// Split free blocks level-by-level.

View File

@ -22,9 +22,7 @@
namespace dawn_native {
static constexpr uint64_t INVALID_OFFSET = std::numeric_limits<uint64_t>::max();
// Buddy allocator uses the buddy memory allocation technique to satisify an allocation request.
// Buddy allocator uses the buddy memory allocation technique to satisfy an allocation request.
// Memory is split into halves until just large enough to fit to the request. This
// requires the allocation size to be a power-of-two value. The allocator "allocates" a block by
// returning the starting offset whose size is guaranteed to be greater than or equal to the
@ -47,6 +45,8 @@ namespace dawn_native {
// For testing purposes only.
uint64_t ComputeTotalNumOfFreeBlocksForTesting() const;
static constexpr uint64_t kInvalidOffset = std::numeric_limits<uint64_t>::max();
private:
uint32_t ComputeLevelFromBlockSize(uint64_t blockSize) const;
uint64_t GetNextFreeAlignedBlock(size_t allocationBlockLevel, uint64_t alignment) const;

View File

@ -17,6 +17,8 @@
using namespace dawn_native;
constexpr uint64_t BuddyAllocator::kInvalidOffset;
// Verify the buddy allocator with a basic test.
TEST(BuddyAllocatorTests, SingleBlock) {
// After one 32 byte allocation:
@ -29,17 +31,17 @@ TEST(BuddyAllocatorTests, SingleBlock) {
BuddyAllocator allocator(maxBlockSize);
// Check that we cannot allocate a oversized block.
ASSERT_EQ(allocator.Allocate(maxBlockSize * 2), INVALID_OFFSET);
ASSERT_EQ(allocator.Allocate(maxBlockSize * 2), BuddyAllocator::kInvalidOffset);
// Check that we cannot allocate a zero sized block.
ASSERT_EQ(allocator.Allocate(0u), INVALID_OFFSET);
ASSERT_EQ(allocator.Allocate(0u), BuddyAllocator::kInvalidOffset);
// Allocate the block.
uint64_t blockOffset = allocator.Allocate(maxBlockSize);
ASSERT_EQ(blockOffset, 0u);
// Check that we are full.
ASSERT_EQ(allocator.Allocate(maxBlockSize), INVALID_OFFSET);
ASSERT_EQ(allocator.Allocate(maxBlockSize), BuddyAllocator::kInvalidOffset);
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 0u);
// Deallocate the block.
@ -86,7 +88,7 @@ TEST(BuddyAllocatorTests, SingleSplitBlock) {
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 1u);
// Check that we cannot allocate a block that is oversized.
ASSERT_EQ(allocator.Allocate(maxBlockSize * 2), INVALID_OFFSET);
ASSERT_EQ(allocator.Allocate(maxBlockSize * 2), BuddyAllocator::kInvalidOffset);
// Re-allocate the largest block allowed after merging.
blockOffset = allocator.Allocate(maxBlockSize);
@ -188,7 +190,7 @@ TEST(BuddyAllocatorTests, MultipleSplitBlockIncreasingSize) {
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 0u);
// Check if we're full.
ASSERT_EQ(allocator.Allocate(32), INVALID_OFFSET);
ASSERT_EQ(allocator.Allocate(32), BuddyAllocator::kInvalidOffset);
}
// Verify very small allocations using a larger allocator works correctly.
@ -284,7 +286,7 @@ TEST(BuddyAllocatorTests, SameSizeVariousAlignment) {
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 2u);
// Check that we cannot fit another.
ASSERT_EQ(allocator.Allocate(8, 16), INVALID_OFFSET);
ASSERT_EQ(allocator.Allocate(8, 16), BuddyAllocator::kInvalidOffset);
// Allocate Ac (zero splits and Ab's buddy is now the first free block).
ASSERT_EQ(allocator.Allocate(8, 8), 24u);