From 64ecb8fb607e64e4b99873e8b74b472fbf1f0add Mon Sep 17 00:00:00 2001 From: Vedashree Vidwans Date: Fri, 6 Sep 2019 09:28:45 -0700 Subject: [PATCH] gpu: nvgpu: unit: SWUTS for mm.allocator.bitmap Add bitmap_allocator.h header that contains SWUTS for the unit. Jira NVGPU-3943 Change-Id: I13bd00f306bf66079556d775b2de83fd50760201 Signed-off-by: Vedashree Vidwans Reviewed-on: https://git-master.nvidia.com/r/2191878 Reviewed-by: mobile promotions Tested-by: mobile promotions --- userspace/SWUTS.h | 1 + userspace/SWUTS.sources | 1 + .../bitmap_allocator/bitmap_allocator.c | 32 +--- .../bitmap_allocator/bitmap_allocator.h | 150 ++++++++++++++++++ 4 files changed, 158 insertions(+), 26 deletions(-) create mode 100644 userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.h diff --git a/userspace/SWUTS.h b/userspace/SWUTS.h index 475acc319..a4b0a3d6b 100644 --- a/userspace/SWUTS.h +++ b/userspace/SWUTS.h @@ -33,6 +33,7 @@ * - @ref SWUTS-enabled * - @ref SWUTS-init * - @ref SWUTS-interface-atomic + * - @ref SWUTS-mm-allocators-bitmap-allocator * - @ref SWUTS-mm-nvgpu-mem * - @ref SWUTS-mm-vm * - @ref SWUTS-fuse diff --git a/userspace/SWUTS.sources b/userspace/SWUTS.sources index c75093110..65aee9d34 100644 --- a/userspace/SWUTS.sources +++ b/userspace/SWUTS.sources @@ -5,5 +5,6 @@ INPUT += ../../../userspace/units/fuse/nvgpu-fuse-gm20b.h INPUT += ../../../userspace/units/fuse/nvgpu-fuse-gp10b.h INPUT += ../../../userspace/units/init/nvgpu-init.h INPUT += ../../../userspace/units/interface/atomic/atomic.h +INPUT += ../../../userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.h INPUT += ../../../userspace/units/mm/nvgpu_mem/nvgpu_mem.h INPUT += ../../../userspace/units/mm/vm/vm.h diff --git a/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.c b/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.c index e5d01f952..8ab93ee15 100644 --- a/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.c +++ b/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.c @@ -30,6 +30,7 @@ #include #include "common/mm/allocators/bitmap_allocator_priv.h" +#include "bitmap_allocator.h" #define BA_DEFAULT_BASE SZ_1K #define BA_DEFAULT_LENGTH (SZ_64K << 1) @@ -41,10 +42,7 @@ static struct nvgpu_allocator *na; -/* - * Test bitmap_allocator with GPU_ALLOC_NO_ALLOC_PAGE enabled - */ -static int test_nvgpu_bitmap_allocator_critical(struct unit_module *m, +int test_nvgpu_bitmap_allocator_critical(struct unit_module *m, struct gk20a *g, void *args) { u64 base = BA_DEFAULT_BASE; @@ -59,10 +57,6 @@ static int test_nvgpu_bitmap_allocator_critical(struct unit_module *m, unit_return_fail(m, "Could not allocate nvgpu_allocator\n"); } - /* - * Initialize bitmap allocator - * This ba will be used in this test. - */ if (nvgpu_allocator_init(g, na, NULL, "test_bitmap", base, length, blk_size, 0ULL, flags, BITMAP_ALLOCATOR) != 0) { nvgpu_kfree(g, na); @@ -118,10 +112,7 @@ fail: } -/* - * Test bitmap_allocator allocs - */ -static int test_nvgpu_bitmap_allocator_alloc(struct unit_module *m, +int test_nvgpu_bitmap_allocator_alloc(struct unit_module *m, struct gk20a *g, void *args) { u64 alloc0, alloc3k, alloc4k, alloc_at64, addr, addr_fail; @@ -238,11 +229,7 @@ static int test_nvgpu_bitmap_allocator_alloc(struct unit_module *m, return UNIT_SUCCESS; } -/* - * Tests bitmap_allocator basic ops - * Bitmap attributes are set corresponding to default init values - */ -static int test_nvgpu_bitmap_allocator_ops(struct unit_module *m, +int test_nvgpu_bitmap_allocator_ops(struct unit_module *m, struct gk20a *g, void *args) { u64 addr; @@ -269,10 +256,7 @@ static int test_nvgpu_bitmap_allocator_ops(struct unit_module *m, return UNIT_SUCCESS; } -/* - * De-initialize bitmap allocator - */ -static int test_nvgpu_bitmap_allocator_destroy(struct unit_module *m, +int test_nvgpu_bitmap_allocator_destroy(struct unit_module *m, struct gk20a *g, void *args) { na->ops->fini(na); @@ -281,11 +265,7 @@ static int test_nvgpu_bitmap_allocator_destroy(struct unit_module *m, return UNIT_SUCCESS; } -/* - * Tests nvgpu_bitmap_allocator_init() - * This test considers multiple conditions to initialize bitmap allocator - */ -static int test_nvgpu_bitmap_allocator_init(struct unit_module *m, +int test_nvgpu_bitmap_allocator_init(struct unit_module *m, struct gk20a *g, void *args) { u64 base = BA_DEFAULT_BASE; diff --git a/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.h b/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.h new file mode 100644 index 000000000..fb67078f4 --- /dev/null +++ b/userspace/units/mm/allocators/bitmap_allocator/bitmap_allocator.h @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef UNIT_BITMAP_ALLOCATOR_H +#define UNIT_BITMAP_ALLOCATOR_H + +struct gk20a; +struct unit_module; + +/** @addtogroup SWUTS-mm-allocators-bitmap-allocator + * @{ + * + * Software Unit Test Specification for mm.allocators.bitmap_allocator + */ + +/** + * Test specification for: test_nvgpu_bitmap_allocator_init + * + * Description: Initialize bitmap allocator. + * + * Test Type: Feature based + * + * Input: None + * + * Steps: + * - Initialize bitmap allocator with following characteristics. + * - 1K memory base address. + * - 128K length of memory. + * - 1K block size. + * - Use this bitmap allocator for rest of the tests. + * + * Output: Returns SUCCESS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_nvgpu_bitmap_allocator_init(struct unit_module *m, + struct gk20a *g, void *args); + +/** + * Test specification for: test_nvgpu_bitmap_allocator_ops + * + * Description: Check bitmap_allocator attribute values using allocator ops. + * + * Test Type: Feature based + * + * Input: test_nvgpu_bitmap_allocator_init + * + * Steps: + * - Check bitmap_allocator attributes using allocator ops. + * - Execute allocator ops to read attibute value. + * - Confirm that value is equal to the default values set during + * initialization. + * + * Output: Returns SUCCESS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_nvgpu_bitmap_allocator_ops(struct unit_module *m, + struct gk20a *g, void *args); + +/** + * Test specification for: test_nvgpu_bitmap_allocator_alloc + * + * Description: Allocate various sizes of memory to test different scenarios. + * + * Test Type: Feature based + * + * Input: test_nvgpu_bitmap_allocator_init + * + * Steps: + * - Allocate 3k memory using allocation functions. + * - Confirm that allocation is successful. + * - Allocate 2M which is more than available memory. + * - Allocation is expected to fail. + * - Allocate 4K, 8K, 16K and 32K memory segments. + * - Confirm all allocations are successful. + * - Allocate various memory segments using fixed allocation functions. + * - Confirm aloocations are successful as expected. + * - Free allocations. + * - Confirm allocations are freed. + * + * Output: Returns SUCCESS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_nvgpu_bitmap_allocator_alloc(struct unit_module *m, + struct gk20a *g, void *args); + +/** + * Test specification for: test_nvgpu_bitmap_allocator_destroy + * + * Description: Free memory used for bitmap allocator. + * + * Test Type: Other (clean up) + * + * Input: test_nvgpu_bitmap_allocator_init + * + * Steps: + * - Free bitmap_allocator allocated for this unit test. + * + * Output: Returns SUCCESS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_nvgpu_bitmap_allocator_destroy(struct unit_module *m, + struct gk20a *g, void *args); + +/** + * Test specification for: test_nvgpu_bitmap_allocator_critical + * + * Description: Test allocator functions for bitmap allocator in latency + * critical path. + * + * Test Type: Feature based + * + * Input: None + * + * Steps: + * - Initialize allocator with following characteristics. + * - 1K memory base address. + * - 128K memory length. + * - 1K block size. + * - GPU_ALLOC_NO_ALLOC_PAGE flag value. + * - Allocate memory segments using allocation functions. + * - Confirm allocations are successful. + * - Free allocated memory segments. + * - Free bitmap allocator used for this test. + * + * Output: Returns SUCCESS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_nvgpu_bitmap_allocator_critical(struct unit_module *m, + struct gk20a *g, void *args); + +#endif /* UNIT_BITMAP_ALLOCATOR_H */