mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
Merge patch series "lmb: miscellaneous fixes and improvements"
Sughosh Ganu <sughosh.ganu@linaro.org> says: The patch series contains some fixes and improvements in the lmb code, along with addition of corresponding test cases for the changes made. The lmb_reserve() function currently does not check if the requested reservation would overlap with existing reserved regions. While some scenarios are being handled, some corner cases still exist. These are being handled by patch 1, along with adding test cases for these scenarios. Patch 2 is handling the case of reserving a new region of memory, but that region overlaps with an existing region. The current code only handles one particular scenario, but prints a message for the other scenario of an encompassing overlap and returns back. The patch handles the encompassing overlap. Patch 3 is an improvement whereby we allow coalescing a newly reserved region with an existing region. The current code exits this check prematurely. Patch 4 is removing a now superfluous check for overlapping regions with flag other than LMB_NONE. This now gets handled at an earlier point in lmb_reserve(). Patch 5 is clubbing the functionality to check if two regions are adjacent, or overlap, allowing some code re-use. Patch 6 is optimising the lmb_alloc() function by having it call _lmb_alloc_base() directly. Link: https://lore.kernel.org/r/20250303133231.405279-1-sughosh.ganu@linaro.org
This commit is contained in:
114
test/lib/lmb.c
114
test/lib/lmb.c
@@ -471,17 +471,17 @@ static int lib_test_lmb_overlapping_reserve(struct unit_test_state *uts)
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000,
|
||||
0, 0, 0, 0);
|
||||
|
||||
/* allocate overlapping region should return the coalesced count */
|
||||
/* allocate overlapping region */
|
||||
ret = lmb_reserve(0x40011000, 0x10000, LMB_NONE);
|
||||
ut_asserteq(ret, 0);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x11000,
|
||||
0, 0, 0, 0);
|
||||
/* allocate 3nd region */
|
||||
/* allocate 2nd region */
|
||||
ret = lmb_reserve(0x40030000, 0x10000, LMB_NONE);
|
||||
ut_asserteq(ret, 0);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40010000, 0x11000,
|
||||
0x40030000, 0x10000, 0, 0);
|
||||
/* allocate 2nd region , This should coalesced all region into one */
|
||||
/* allocate 3rd region , This should coalesce all regions into one */
|
||||
ret = lmb_reserve(0x40020000, 0x10000, LMB_NONE);
|
||||
ut_assert(ret >= 0);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x30000,
|
||||
@@ -499,6 +499,41 @@ static int lib_test_lmb_overlapping_reserve(struct unit_test_state *uts)
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40000000, 0x40000,
|
||||
0, 0, 0, 0);
|
||||
|
||||
/* try to allocate overlapping region with a different flag, should fail */
|
||||
ret = lmb_reserve(0x40008000, 0x1000, LMB_NOOVERWRITE);
|
||||
ut_asserteq(ret, -EEXIST);
|
||||
|
||||
/* allocate another region at 0x40050000 with a different flag */
|
||||
ret = lmb_reserve(0x40050000, 0x10000, LMB_NOOVERWRITE);
|
||||
ut_asserteq(ret, 0);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x40000,
|
||||
0x40050000, 0x10000, 0, 0);
|
||||
|
||||
/*
|
||||
* try to reserve a region adjacent to region 1 overlapping the 2nd region,
|
||||
* should fail
|
||||
*/
|
||||
ret = lmb_reserve(0x40040000, 0x20000, LMB_NONE);
|
||||
ut_asserteq(ret, -EEXIST);
|
||||
|
||||
/*
|
||||
* try to reserve a region between the two regions, but without an overlap,
|
||||
* should succeed. this added region coalesces with the region 1
|
||||
*/
|
||||
ret = lmb_reserve(0x40040000, 0x10000, LMB_NONE);
|
||||
ut_asserteq(ret, 0);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x50000,
|
||||
0x40050000, 0x10000, 0, 0);
|
||||
|
||||
/*
|
||||
* try to reserve a region which overlaps with both the regions,
|
||||
* should fail as the flags do not match
|
||||
*/
|
||||
ret = lmb_reserve(0x40020000, 0x80000, LMB_NONE);
|
||||
ut_asserteq(ret, -EEXIST);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x50000,
|
||||
0x40050000, 0x10000, 0, 0);
|
||||
|
||||
lmb_pop(&store);
|
||||
|
||||
return 0;
|
||||
@@ -549,6 +584,77 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
|
||||
ret = lmb_free(alloc_addr_a, 0x1000);
|
||||
ut_asserteq(ret, 0);
|
||||
|
||||
/*
|
||||
* Add two regions with different flags, region1 and region2 with
|
||||
* a gap between them.
|
||||
* Try adding another region, adjacent to region 1 and overlapping
|
||||
* region 2. Should fail.
|
||||
*/
|
||||
a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE);
|
||||
ut_asserteq(a, alloc_addr_a);
|
||||
|
||||
b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NOOVERWRITE);
|
||||
ut_asserteq(b, alloc_addr_a + 0x4000);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000,
|
||||
b, 0x1000, 0, 0);
|
||||
|
||||
c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NONE);
|
||||
ut_asserteq(c, 0);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000,
|
||||
b, 0x1000, 0, 0);
|
||||
|
||||
ret = lmb_free(a, 0x1000);
|
||||
ut_asserteq(ret, 0);
|
||||
ret = lmb_free(b, 0x1000);
|
||||
ut_asserteq(ret, 0);
|
||||
|
||||
/*
|
||||
* Add two regions with same flags(LMB_NONE), region1 and region2
|
||||
* with a gap between them.
|
||||
* Try adding another region, adjacent to region 1 and overlapping
|
||||
* region 2. Should succeed. All regions should coalesce into a
|
||||
* single region.
|
||||
*/
|
||||
a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE);
|
||||
ut_asserteq(a, alloc_addr_a);
|
||||
|
||||
b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NONE);
|
||||
ut_asserteq(b, alloc_addr_a + 0x4000);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000,
|
||||
b, 0x1000, 0, 0);
|
||||
|
||||
c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NONE);
|
||||
ut_asserteq(c, alloc_addr_a + 0x1000);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, 0x6000,
|
||||
0, 0, 0, 0);
|
||||
|
||||
ret = lmb_free(a, 0x6000);
|
||||
ut_asserteq(ret, 0);
|
||||
|
||||
/*
|
||||
* Add two regions with same flags(LMB_NOOVERWRITE), region1 and
|
||||
* region2 with a gap between them.
|
||||
* Try adding another region, adjacent to region 1 and overlapping
|
||||
* region 2. Should fail.
|
||||
*/
|
||||
a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
|
||||
ut_asserteq(a, alloc_addr_a);
|
||||
|
||||
b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NOOVERWRITE);
|
||||
ut_asserteq(b, alloc_addr_a + 0x4000);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000,
|
||||
b, 0x1000, 0, 0);
|
||||
|
||||
c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NOOVERWRITE);
|
||||
ut_asserteq(c, 0);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000,
|
||||
b, 0x1000, 0, 0);
|
||||
|
||||
ret = lmb_free(a, 0x1000);
|
||||
ut_asserteq(ret, 0);
|
||||
ret = lmb_free(b, 0x1000);
|
||||
ut_asserteq(ret, 0);
|
||||
|
||||
/* reserve 3 blocks */
|
||||
ret = lmb_reserve(alloc_addr_a, 0x10000, LMB_NONE);
|
||||
ut_asserteq(ret, 0);
|
||||
@@ -760,7 +866,7 @@ static int lib_test_lmb_flags(struct unit_test_state *uts)
|
||||
|
||||
/* reserve again, new flag */
|
||||
ret = lmb_reserve(0x40010000, 0x10000, LMB_NONE);
|
||||
ut_asserteq(ret, -1);
|
||||
ut_asserteq(ret, -EEXIST);
|
||||
ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000,
|
||||
0, 0, 0, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user