diff --git a/Makefile.umbrella.tmk b/Makefile.umbrella.tmk index 22c586248..dfe9328f2 100644 --- a/Makefile.umbrella.tmk +++ b/Makefile.umbrella.tmk @@ -39,6 +39,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/posix/env NV_REPOSITORY_COMPONENTS += userspace/units/posix/mockio NV_REPOSITORY_COMPONENTS += userspace/units/posix/fault-injection NV_REPOSITORY_COMPONENTS += userspace/units/posix/bug +NV_REPOSITORY_COMPONENTS += userspace/units/posix/os_sched NV_REPOSITORY_COMPONENTS += userspace/units/posix/sizes NV_REPOSITORY_COMPONENTS += userspace/units/init NV_REPOSITORY_COMPONENTS += userspace/units/posix/thread diff --git a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export index 18a3eff2c..9c48920b3 100644 --- a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export +++ b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export @@ -127,6 +127,8 @@ nvgpu_cg_slcg_ce2_load_enable nvgpu_cg_init_gr_load_gating_prod nvgpu_cg_elcg_enable_no_wait nvgpu_cg_elcg_disable_no_wait +nvgpu_current_pid +nvgpu_current_tid nvgpu_gr_alloc nvgpu_gr_free nvgpu_gr_init @@ -343,6 +345,7 @@ nvgpu_posix_is_fault_injection_triggered nvgpu_posix_probe nvgpu_posix_register_io nvgpu_prepare_poweroff +nvgpu_print_current_impl nvgpu_put nvgpu_raw_spinlock_acquire nvgpu_raw_spinlock_init diff --git a/userspace/Makefile.sources b/userspace/Makefile.sources index 4376e598d..a0732520d 100644 --- a/userspace/Makefile.sources +++ b/userspace/Makefile.sources @@ -47,6 +47,7 @@ UNITS := \ $(UNIT_SRC)/posix/mockio \ $(UNIT_SRC)/posix/fault-injection \ $(UNIT_SRC)/posix/bug \ + $(UNIT_SRC)/posix/os_sched \ $(UNIT_SRC)/posix/sizes \ $(UNIT_SRC)/posix/thread \ $(UNIT_SRC)/posix/cond \ diff --git a/userspace/units/posix/os_sched/Makefile b/userspace/units/posix/os_sched/Makefile new file mode 100644 index 000000000..2efd1d19a --- /dev/null +++ b/userspace/units/posix/os_sched/Makefile @@ -0,0 +1,26 @@ +# 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. + +.SUFFIXES: + +OBJS = posix-ossched.o +MODULE = posix-ossched + +include ../../Makefile.units diff --git a/userspace/units/posix/os_sched/Makefile.interface.tmk b/userspace/units/posix/os_sched/Makefile.interface.tmk new file mode 100644 index 000000000..7731e1f18 --- /dev/null +++ b/userspace/units/posix/os_sched/Makefile.interface.tmk @@ -0,0 +1,35 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# 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. +# +# tmake for SW Mobile component makefile +# +############################################################################### + +NVGPU_UNIT_NAME=posix-ossched + +include $(NV_COMPONENT_DIR)/../../Makefile.units.common.interface.tmk + +# Local Variables: +# indent-tabs-mode: t +# tab-width: 8 +# End: +# vi: set tabstop=8 noexpandtab: diff --git a/userspace/units/posix/os_sched/Makefile.tmk b/userspace/units/posix/os_sched/Makefile.tmk new file mode 100644 index 000000000..7a9ce3dbd --- /dev/null +++ b/userspace/units/posix/os_sched/Makefile.tmk @@ -0,0 +1,39 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# 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. +# +# tmake for SW Mobile component makefile +# +############################################################################### + +NVGPU_UNIT_NAME=posix-ossched + +ifneq ($(NV_BUILD_CONFIGURATION_OS_IS_QNX),1) +NVGPU_UNIT_SHARED_LIBRARIES += pthread +endif + +include $(NV_COMPONENT_DIR)/../../Makefile.units.common.tmk + +# Local Variables: +# indent-tabs-mode: t +# tab-width: 8 +# End: +# vi: set tabstop=8 noexpandtab: diff --git a/userspace/units/posix/os_sched/posix-ossched.c b/userspace/units/posix/os_sched/posix-ossched.c new file mode 100644 index 000000000..14208f6de --- /dev/null +++ b/userspace/units/posix/os_sched/posix-ossched.c @@ -0,0 +1,81 @@ +/* + * 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. + */ + +#include +#include +#include + +#include +#include + +#include "posix-ossched.h" + +int test_current_pid(struct unit_module *m, + struct gk20a *g, void *args) +{ + int pid; + int nvgpu_pid; + + pid = (int) getpid(); + nvgpu_pid = nvgpu_current_pid(g); + + if (nvgpu_pid != pid) { + unit_return_fail(m, "PID mismatch %d %d\n", pid, nvgpu_pid); + } + + return UNIT_SUCCESS; +} + +int test_current_tid(struct unit_module *m, + struct gk20a *g, void *args) +{ + int tid; + int nvgpu_tid; + + tid = (int) pthread_self(); + nvgpu_tid = nvgpu_current_tid(g); + + if (nvgpu_tid != tid) { + unit_return_fail(m, "TID mismatch %d %d\n", tid, nvgpu_tid); + } + + return UNIT_SUCCESS; +} + +int test_print_current(struct unit_module *m, + struct gk20a *g, void *args) +{ + nvgpu_print_current(g, NULL, NVGPU_INFO); + nvgpu_print_current(g, NULL, NVGPU_DEBUG); + nvgpu_print_current(g, NULL, NVGPU_WARNING); + nvgpu_print_current(g, NULL, NVGPU_ERROR); + nvgpu_print_current(g, NULL, 10); + + return UNIT_SUCCESS; +} +struct unit_module_test posix_ossched_tests[] = { + UNIT_TEST(current_pid, test_current_pid, NULL, 0), + UNIT_TEST(current_tid, test_current_tid, NULL, 0), + UNIT_TEST(print_current, test_print_current, NULL, 0), +}; + +UNIT_MODULE(posix_ossched, posix_ossched_tests, UNIT_PRIO_POSIX_TEST); diff --git a/userspace/units/posix/os_sched/posix-ossched.h b/userspace/units/posix/os_sched/posix-ossched.h new file mode 100644 index 000000000..617a07111 --- /dev/null +++ b/userspace/units/posix/os_sched/posix-ossched.h @@ -0,0 +1,103 @@ +/* + * 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. + */ + +/** + * @addtogroup SWUTS-posix-ossched + * @{ + * + * Software Unit Test Specification for posix-ossched + */ + +#ifndef __UNIT_POSIX_OSSCHED_H__ +#define __UNIT_POSIX_OSSCHED_H__ + +#include + +/** + * Test specification for test_current_pid + * + * Description: Test the PID of the current process. + * + * Test Type: Feature based. + * + * Inputs: + * + * Steps: + * 1) Get the PID of the current process using standard lib call. + * 2) Get the PID of the current process using NVGPU API. + * 3) Compare the PIDs obtained in step 1 and 2. + * 4) Return Fail if the PIDs dont match. + * + * Output: + * Return PASS if the PIDs fetched using standard library call and NVGPU API + * matches; otherwise, the test returns FAIL. + */ +int test_current_pid(struct unit_module *m, + struct gk20a *g, void *args); + +/** + * Test specification for test_current_tid + * + * Description: Test the TID of the current thread. + * + * Test Type: Feature based. + * + * Inputs: + * + * Steps: + * 1) Get the TID of the current thread using standard lib call. + * 2) Get the TID of the current thread using NVGPU API. + * 3) Compare the TIDs obtained in step 1 and 2. + * 4) Return Fail if the TIDs dont match. + * + * Output: + * Return PASS if the TIDs fetched using standard library call and NVGPU API + * matches; otherwise, the test returns FAIL. + */ +int test_current_tid(struct unit_module *m, + struct gk20a *g, void *args); + +/** + * Test specification for test_print_current + * + * Description: Print the current thread name. + * + * Test Type: Feature based. + * + * Inputs: + * + * Steps: + * 1) Print the current thread name with log type NVGPU_INFO + * 2) Print the current thread name with log type NVGPU_DEBUG + * 3) Print the current thread name with log type NVGPU_WARNING + * 4) Print the current thread name with log type NVGPU_ERROR + * 5) Print the current thread name with invalid log type which should result + * in the function using default log type. + * + * Output: + * The test returns PASS if all the print calls gets executed without any + * crash/hang. Since the function does not return any value, the only case + * in which the test can fail is due to an internal hang or crash. + */ +int test_print_current(struct unit_module *m, + struct gk20a *g, void *args); +#endif /* __UNIT_POSIX_OSSCHED_H__ */