gpu: nvgpu: unit: Update allocator init() function

Replace individual buddy and bitmap allocator functions with common
nvgpu_alloc_allocator_init() function corresponding the re-arch.

Jira NVGPU-991

Change-Id: I43a8d84cedbba3ea39b11cd266d04343e1f07b14
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2097963
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Vedashree Vidwans
2019-04-15 09:38:35 -07:00
committed by mobile promotions
parent 8d325e9db1
commit b3271f2836
3 changed files with 59 additions and 60 deletions

View File

@@ -70,12 +70,11 @@ nvgpu_alloc_pte
nvgpu_alloc_release_carveout nvgpu_alloc_release_carveout
nvgpu_alloc_reserve_carveout nvgpu_alloc_reserve_carveout
nvgpu_alloc_space nvgpu_alloc_space
nvgpu_allocator_init
nvgpu_aperture_mask nvgpu_aperture_mask
nvgpu_bar1_readl nvgpu_bar1_readl
nvgpu_bar1_writel nvgpu_bar1_writel
nvgpu_bitmap_allocator_init
nvgpu_bsearch nvgpu_bsearch
nvgpu_buddy_allocator_init
nvgpu_dma_alloc nvgpu_dma_alloc
nvgpu_dma_alloc_get_fault_injection nvgpu_dma_alloc_get_fault_injection
nvgpu_dma_alloc_vid_at nvgpu_dma_alloc_vid_at

View File

@@ -63,8 +63,8 @@ static int test_nvgpu_bitmap_allocator_critical(struct unit_module *m,
* Initialize bitmap allocator * Initialize bitmap allocator
* This ba will be used in this test. * This ba will be used in this test.
*/ */
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", base, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", base, length,
length, blk_size, flags) != 0) { blk_size, 0ULL, flags, BITMAP_ALLOCATOR) != 0) {
nvgpu_kfree(g, na); nvgpu_kfree(g, na);
unit_return_fail(m, "bitmap_allocator init failed\n"); unit_return_fail(m, "bitmap_allocator init failed\n");
} }
@@ -303,8 +303,8 @@ static int test_nvgpu_bitmap_allocator_init(struct unit_module *m,
} }
/* base = 0, length = 0, blk_size = 0 */ /* base = 0, length = 0, blk_size = 0 */
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", 0ULL, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", 0ULL, 0ULL, 0ULL,
0ULL, 0ULL, flags) == 0) { 0ULL, flags, BITMAP_ALLOCATOR) == 0) {
na->ops->fini(na); na->ops->fini(na);
unit_return_fail(m, unit_return_fail(m,
"bitmap inited despite blk_size = base = length = 0\n"); "bitmap inited despite blk_size = base = length = 0\n");
@@ -314,32 +314,32 @@ static int test_nvgpu_bitmap_allocator_init(struct unit_module *m,
* blk_size = 0 * blk_size = 0
* Since base and length are not aligned with 0, init fails * Since base and length are not aligned with 0, init fails
*/ */
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", base, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", base, length,
length, 0ULL, flags) == 0) { 0ULL, 0ULL, flags, BITMAP_ALLOCATOR) == 0) {
unit_return_fail(m, "bitmap init failed for blk_size=0\n"); unit_return_fail(m, "bitmap init failed for blk_size=0\n");
} }
/* Odd blk_size */ /* Odd blk_size */
if (!EXPECT_BUG(nvgpu_bitmap_allocator_init(g, na, "test_bitmap", base, if (!EXPECT_BUG(nvgpu_allocator_init(g, na, NULL, "test_bitmap", base,
length, 3ULL, flags))) { length, 3ULL, 0ULL, flags, BITMAP_ALLOCATOR))) {
unit_return_fail(m, "bitmap inited despite odd blk_size\n"); unit_return_fail(m, "bitmap inited despite odd blk_size\n");
} }
/* length unaligned */ /* length unaligned */
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", base, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", base, 0x0010,
0x0010, blk_size, flags) == 0) { blk_size, 0ULL, flags, BITMAP_ALLOCATOR) == 0) {
unit_return_fail(m, "bitmap init despite unaligned length\n"); unit_return_fail(m, "bitmap init despite unaligned length\n");
} }
/* base unaligned */ /* base unaligned */
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", 0x0100, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", 0x0100, length,
length, blk_size, flags) == 0) { blk_size, 0ULL, flags, BITMAP_ALLOCATOR) == 0) {
unit_return_fail(m, "bitmap init despite unaligned base\n"); unit_return_fail(m, "bitmap init despite unaligned base\n");
} }
/* base = 0 */ /* base = 0 */
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", 0ULL, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", 0ULL, length,
length, blk_size, flags) != 0) { blk_size, 0ULL, flags, BITMAP_ALLOCATOR) != 0) {
unit_return_fail(m, "bitmap init failed with base = 0\n"); unit_return_fail(m, "bitmap init failed with base = 0\n");
} else { } else {
ba = na->priv; ba = na->priv;
@@ -353,15 +353,15 @@ static int test_nvgpu_bitmap_allocator_init(struct unit_module *m,
} }
/* length = 0 */ /* length = 0 */
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", 0ULL, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", 0ULL, 0ULL,
0ULL, blk_size, flags) == 0) { blk_size, 0ULL, flags, BITMAP_ALLOCATOR) == 0) {
unit_return_fail(m, "bitmap inited with length = 0\n"); unit_return_fail(m, "bitmap inited with length = 0\n");
} }
/* Fault injection at nvgpu_bitmap_allocator alloc */ /* Fault injection at nvgpu_bitmap_allocator alloc */
nvgpu_posix_enable_fault_injection(kmem_fi, true, 0); nvgpu_posix_enable_fault_injection(kmem_fi, true, 0);
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", base, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", base, length,
length, blk_size, flags) == 0) { blk_size, 0ULL, flags, BITMAP_ALLOCATOR) == 0) {
unit_return_fail(m, "bitmap inited despite " unit_return_fail(m, "bitmap inited despite "
"fault injection at nvgpu_bitmap_allocator alloc\n"); "fault injection at nvgpu_bitmap_allocator alloc\n");
} }
@@ -369,8 +369,8 @@ static int test_nvgpu_bitmap_allocator_init(struct unit_module *m,
/* Fault injection at meta_data_cache create */ /* Fault injection at meta_data_cache create */
nvgpu_posix_enable_fault_injection(kmem_fi, true, 1); nvgpu_posix_enable_fault_injection(kmem_fi, true, 1);
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", base, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", base, length,
length, blk_size, flags) == 0) { blk_size, 0ULL, flags, BITMAP_ALLOCATOR) == 0) {
unit_return_fail(m, "bitmap inited despite " unit_return_fail(m, "bitmap inited despite "
"fault injection at meta_data_cache\n"); "fault injection at meta_data_cache\n");
} }
@@ -378,8 +378,8 @@ static int test_nvgpu_bitmap_allocator_init(struct unit_module *m,
/* Fault injection at bitmap create */ /* Fault injection at bitmap create */
nvgpu_posix_enable_fault_injection(kmem_fi, true, 2); nvgpu_posix_enable_fault_injection(kmem_fi, true, 2);
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", base, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", base, length,
length, blk_size, flags) == 0) { blk_size, 0ULL, flags, BITMAP_ALLOCATOR) == 0) {
unit_return_fail(m, "bitmap inited despite " unit_return_fail(m, "bitmap inited despite "
"fault injection at bitmap create\n"); "fault injection at bitmap create\n");
} }
@@ -389,8 +389,8 @@ static int test_nvgpu_bitmap_allocator_init(struct unit_module *m,
* Initialize bitmap allocator * Initialize bitmap allocator
* This ba will be used for further tests. * This ba will be used for further tests.
*/ */
if (nvgpu_bitmap_allocator_init(g, na, "test_bitmap", base, if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", base, length,
length, blk_size, flags) != 0) { blk_size, 0ULL, flags, BITMAP_ALLOCATOR) != 0) {
unit_return_fail(m, "bitmap_allocator init failed\n"); unit_return_fail(m, "bitmap_allocator init failed\n");
} }

View File

@@ -138,8 +138,8 @@ static int test_buddy_allocator_with_big_pages(struct unit_module *m,
* Initialize buddy allocator, base not pde aligned * Initialize buddy allocator, base not pde aligned
* Expect to fail * Expect to fail
*/ */
if (nvgpu_buddy_allocator_init(g, na, vm_big_pages, "test", SZ_1K, if (nvgpu_allocator_init(g, na, vm_big_pages, "test", SZ_1K, size,
size, blk_size, max_order, flags) == 0) { blk_size, max_order, flags, BUDDY_ALLOCATOR) == 0) {
free_vm_env(m, g, vm_big_pages); free_vm_env(m, g, vm_big_pages);
unit_return_fail(m, "ba inited with unaligned pde\n"); unit_return_fail(m, "ba inited with unaligned pde\n");
} }
@@ -148,16 +148,16 @@ static int test_buddy_allocator_with_big_pages(struct unit_module *m,
* Initialize buddy allocator, base = 0 and blk_size not pde aligned * Initialize buddy allocator, base = 0 and blk_size not pde aligned
* Expect to fail * Expect to fail
*/ */
if (nvgpu_buddy_allocator_init(g, na, vm_big_pages, "test", 0ULL, if (nvgpu_allocator_init(g, na, vm_big_pages, "test", 0ULL, size,
size, blk_size, max_order, flags) == 0) { blk_size, max_order, flags, BUDDY_ALLOCATOR) == 0) {
free_vm_env(m, g, vm_big_pages); free_vm_env(m, g, vm_big_pages);
unit_return_fail(m, "ba_big_pages inited " unit_return_fail(m, "ba_big_pages inited "
"despite base=0, blk_size not pde aligned\n"); "despite base=0, blk_size not pde aligned\n");
} }
/* Initialize buddy allocator with big pages for this test */ /* Initialize buddy allocator with big pages for this test */
if (nvgpu_buddy_allocator_init(g, na, vm_big_pages, "test", base, if (nvgpu_allocator_init(g, na, vm_big_pages, "test", base, size,
size, blk_size, max_order, flags) != 0) { blk_size, max_order, flags, BUDDY_ALLOCATOR) != 0) {
free_vm_env(m, g, vm_big_pages); free_vm_env(m, g, vm_big_pages);
unit_return_fail(m, "ba_big_pages init failed\n"); unit_return_fail(m, "ba_big_pages init failed\n");
} }
@@ -286,8 +286,8 @@ static int test_buddy_allocator_with_small_pages(struct unit_module *m,
/* Initialize buddy allocator with big page disabled for this test */ /* Initialize buddy allocator with big page disabled for this test */
if (nvgpu_buddy_allocator_init(g, na, vm_small_pages, "test", base, if (nvgpu_allocator_init(g, na, vm_small_pages, "test", base, size,
size, blk_size, max_order, flags) != 0) { blk_size, max_order, flags, BUDDY_ALLOCATOR) != 0) {
free_vm_env(m, g, vm_small_pages); free_vm_env(m, g, vm_small_pages);
unit_return_fail(m, "ba small pages init failed\n"); unit_return_fail(m, "ba small pages init failed\n");
} }
@@ -438,8 +438,8 @@ static int test_nvgpu_buddy_allocator_alloc(struct unit_module *m,
} }
/* Initialize buddy allocator for this test */ /* Initialize buddy allocator for this test */
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_alloc", base, if (nvgpu_allocator_init(g, na, NULL, "test_alloc", base, size,
size, blk_size, max_order, flags) != 0) { blk_size, max_order, flags, BUDDY_ALLOCATOR) != 0) {
nvgpu_kfree(g, na); nvgpu_kfree(g, na);
unit_return_fail(m, "ba init for alloc failed\n"); unit_return_fail(m, "ba init for alloc failed\n");
} }
@@ -834,27 +834,27 @@ static int test_nvgpu_buddy_allocator_init(struct unit_module *m,
} }
/* blk_size = 0 */ /* blk_size = 0 */
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", base, if (nvgpu_allocator_init(g, na, NULL, "test_ba", base, size, 0ULL,
size, 0ULL, max_order, flags) == 0) { max_order, flags, BUDDY_ALLOCATOR) == 0) {
unit_return_fail(m, "ba inited despite blk_size=0\n"); unit_return_fail(m, "ba inited despite blk_size=0\n");
} }
/* Odd blk_size */ /* Odd blk_size */
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", base, if (nvgpu_allocator_init(g, na, NULL, "test_ba", base, size, 3ULL,
size, 3ULL, max_order, flags) == 0) { max_order, flags, BUDDY_ALLOCATOR) == 0) {
unit_return_fail(m, "ba inited despite odd blk_size value\n"); unit_return_fail(m, "ba inited despite odd blk_size value\n");
} }
/* max_order > (u64)GPU_BALLOC_MAX_ORDER */ /* max_order > (u64)GPU_BALLOC_MAX_ORDER */
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", base, if (nvgpu_allocator_init(g, na, NULL, "test_ba", base, size, blk_size,
size, blk_size, (u64)GPU_BALLOC_MAX_ORDER + 1, flags) == 0) { (u64)GPU_BALLOC_MAX_ORDER + 1, flags, BUDDY_ALLOCATOR) == 0) {
unit_return_fail(m, unit_return_fail(m,
"ba inited despite max_order > GPU_BALLOC_MAX_ORDER\n"); "ba inited despite max_order > GPU_BALLOC_MAX_ORDER\n");
} }
/* size = 0 */ /* size = 0 */
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", base, if (nvgpu_allocator_init(g, na, NULL, "test_ba", base, 0ULL, blk_size,
0ULL, blk_size, max_order, flags) == 0) { max_order, flags, BUDDY_ALLOCATOR) == 0) {
/* If buddy allocator was created, check length */ /* If buddy allocator was created, check length */
ba = buddy_allocator(na); ba = buddy_allocator(na);
if (ba->length == 0ULL) { if (ba->length == 0ULL) {
@@ -865,8 +865,8 @@ static int test_nvgpu_buddy_allocator_init(struct unit_module *m,
} }
/* base = 0 */ /* base = 0 */
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", 0ULL, if (nvgpu_allocator_init(g, na, NULL, "test_ba", 0ULL, size, blk_size,
size, blk_size, max_order, flags) != 0) { max_order, flags, BUDDY_ALLOCATOR) != 0) {
unit_return_fail(m, "ba init with base=0 failed\n"); unit_return_fail(m, "ba init with base=0 failed\n");
} else { } else {
/* If buddy allocator was created, check base */ /* If buddy allocator was created, check base */
@@ -883,24 +883,24 @@ static int test_nvgpu_buddy_allocator_init(struct unit_module *m,
* base = 0x0101 (unaligned), GVA_space is disabled * base = 0x0101 (unaligned), GVA_space is disabled
* adds base as offset * adds base as offset
*/ */
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", 0x0101, if (nvgpu_allocator_init(g, na, NULL, "test_ba", 0x0101, size,
size, blk_size, max_order, flags) != 0) { blk_size, max_order, flags, BUDDY_ALLOCATOR) != 0) {
unit_return_fail(m, "ba init with unaligned base failed\n"); unit_return_fail(m, "ba init with unaligned base failed\n");
} else { } else {
na->ops->fini(na); na->ops->fini(na);
} }
/* ba init - GVA_space enabled, no vm */ /* ba init - GVA_space enabled, no vm */
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", base, if (nvgpu_allocator_init(g, na, NULL, "test_ba", base, size, blk_size,
size, blk_size, max_order, GPU_ALLOC_GVA_SPACE) == 0) { max_order, GPU_ALLOC_GVA_SPACE, BUDDY_ALLOCATOR) == 0) {
unit_return_fail(m, "ba inited " unit_return_fail(m, "ba inited "
"with GPU_ALLOC_GVA_SPACE & vm=NULL\n"); "with GPU_ALLOC_GVA_SPACE & vm=NULL\n");
} }
/* Fault injection at nvgpu_buddy_allocator alloc */ /* Fault injection at nvgpu_buddy_allocator alloc */
nvgpu_posix_enable_fault_injection(kmem_fi, true, 0); nvgpu_posix_enable_fault_injection(kmem_fi, true, 0);
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", base, if (nvgpu_allocator_init(g, na, NULL, "test_ba", base, size, blk_size,
size, blk_size, max_order, flags) == 0) { max_order, flags, BUDDY_ALLOCATOR) == 0) {
unit_return_fail(m, unit_return_fail(m,
"ba inited despite fault injection\n"); "ba inited despite fault injection\n");
} }
@@ -908,8 +908,8 @@ static int test_nvgpu_buddy_allocator_init(struct unit_module *m,
/* Fault injection at buddy_cache create */ /* Fault injection at buddy_cache create */
nvgpu_posix_enable_fault_injection(kmem_fi, true, 1); nvgpu_posix_enable_fault_injection(kmem_fi, true, 1);
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", base, if (nvgpu_allocator_init(g, na, NULL, "test_ba", base, size, blk_size,
size, blk_size, max_order, flags) == 0) { max_order, flags, BUDDY_ALLOCATOR) == 0) {
unit_return_fail(m, unit_return_fail(m,
"ba inited despite fault injection\n"); "ba inited despite fault injection\n");
} }
@@ -917,8 +917,8 @@ static int test_nvgpu_buddy_allocator_init(struct unit_module *m,
/* Fault injection at balloc_new_buddy */ /* Fault injection at balloc_new_buddy */
nvgpu_posix_enable_fault_injection(kmem_fi, true, 5); nvgpu_posix_enable_fault_injection(kmem_fi, true, 5);
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", 0ULL, if (nvgpu_allocator_init(g, na, NULL, "test_ba", 0ULL, size, blk_size,
size, blk_size, max_order, flags) == 0) { max_order, flags, BUDDY_ALLOCATOR) == 0) {
unit_return_fail(m, unit_return_fail(m,
"buddy_allocator inited despite fault injection\n"); "buddy_allocator inited despite fault injection\n");
} }
@@ -929,8 +929,8 @@ static int test_nvgpu_buddy_allocator_init(struct unit_module *m,
* vm un-initialized, * vm un-initialized,
* This doesn't complain as GPU_ALLOC_GVA_SPACE is disabled * This doesn't complain as GPU_ALLOC_GVA_SPACE is disabled
*/ */
if (nvgpu_buddy_allocator_init(g, na, &vm1, "test_ba", base, if (nvgpu_allocator_init(g, na, &vm1, "test_ba", base, 0x40000,
0x40000, blk_size, max_order, flags) != 0) { blk_size, max_order, flags, BUDDY_ALLOCATOR) != 0) {
unit_return_fail(m, "buddy_allocator_init failed\n"); unit_return_fail(m, "buddy_allocator_init failed\n");
} else { } else {
na->ops->fini(na); na->ops->fini(na);
@@ -940,8 +940,8 @@ static int test_nvgpu_buddy_allocator_init(struct unit_module *m,
* Initialize buddy allocator * Initialize buddy allocator
* This ba will be used for further tests. * This ba will be used for further tests.
*/ */
if (nvgpu_buddy_allocator_init(g, na, NULL, "test_ba", base, if (nvgpu_allocator_init(g, na, NULL, "test_ba", base, size, blk_size,
size, blk_size, max_order, flags) != 0) { max_order, flags, BUDDY_ALLOCATOR) != 0) {
unit_return_fail(m, "buddy_allocator_init failed\n"); unit_return_fail(m, "buddy_allocator_init failed\n");
} }