diff --git a/Makefile.umbrella.tmk b/Makefile.umbrella.tmk index bf611e456..51437f2ed 100644 --- a/Makefile.umbrella.tmk +++ b/Makefile.umbrella.tmk @@ -87,6 +87,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/fifo/pbdma NV_REPOSITORY_COMPONENTS += userspace/units/fifo/pbdma/gv11b NV_REPOSITORY_COMPONENTS += userspace/units/fifo/pbdma/gm20b NV_REPOSITORY_COMPONENTS += userspace/units/fifo/pbdma/gp10b +NV_REPOSITORY_COMPONENTS += userspace/units/fifo/preempt NV_REPOSITORY_COMPONENTS += userspace/units/fifo/runlist NV_REPOSITORY_COMPONENTS += userspace/units/fifo/runlist/gk20a NV_REPOSITORY_COMPONENTS += userspace/units/fifo/runlist/gv11b diff --git a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export index 6d3fe752e..a7c8c2354 100644 --- a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export +++ b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export @@ -534,6 +534,9 @@ nvgpu_posix_io_get_reg_space nvgpu_posix_is_fault_injection_triggered nvgpu_posix_probe nvgpu_posix_register_io +nvgpu_preempt_channel +nvgpu_preempt_get_timeout +nvgpu_preempt_poll_tsg_on_pbdma nvgpu_prepare_poweroff nvgpu_print_current_impl nvgpu_put diff --git a/userspace/Makefile.sources b/userspace/Makefile.sources index f8aff3fc0..7827a971d 100644 --- a/userspace/Makefile.sources +++ b/userspace/Makefile.sources @@ -95,6 +95,7 @@ UNITS := \ $(UNIT_SRC)/fifo/pbdma/gm20b \ $(UNIT_SRC)/fifo/pbdma/gp10b \ $(UNIT_SRC)/fifo/pbdma/gv11b \ + $(UNIT_SRC)/fifo/preempt \ $(UNIT_SRC)/fifo/runlist \ $(UNIT_SRC)/fifo/runlist/gk20a \ $(UNIT_SRC)/fifo/runlist/gv11b \ diff --git a/userspace/SWUTS.h b/userspace/SWUTS.h index d0953734c..c78cd5b9d 100644 --- a/userspace/SWUTS.h +++ b/userspace/SWUTS.h @@ -52,6 +52,7 @@ * - @ref SWUTS-fifo-pbdma-gm20b * - @ref SWUTS-fifo-pbdma-gp10b * - @ref SWUTS-fifo-pbdma-gv11b + * - @ref SWUTS-fifo-preempt * - @ref SWUTS-fifo-runlist * - @ref SWUTS-fifo-runlist-gk20a * - @ref SWUTS-fifo-runlist-gv11b diff --git a/userspace/SWUTS.sources b/userspace/SWUTS.sources index 5a43f1e52..5cf32faa8 100644 --- a/userspace/SWUTS.sources +++ b/userspace/SWUTS.sources @@ -24,6 +24,7 @@ INPUT += ../../../userspace/units/fifo/pbdma/nvgpu-pbdma.h INPUT += ../../../userspace/units/fifo/pbdma/gm20b/nvgpu-pbdma-gm20b.h INPUT += ../../../userspace/units/fifo/pbdma/gp10b/nvgpu-pbdma-gp10b.h INPUT += ../../../userspace/units/fifo/pbdma/gv11b/nvgpu-pbdma-gv11b.h +INPUT += ../../../userspace/units/fifo/preempt/nvgpu-preempt.h INPUT += ../../../userspace/units/fifo/runlist/nvgpu-runlist.h INPUT += ../../../userspace/units/fifo/runlist/gk20a/nvgpu-runlist-gk20a.h INPUT += ../../../userspace/units/fifo/runlist/gv11b/nvgpu-runlist-gv11b.h diff --git a/userspace/required_tests.json b/userspace/required_tests.json index 246ef6fc9..dfd370db9 100644 --- a/userspace/required_tests.json +++ b/userspace/required_tests.json @@ -2356,6 +2356,36 @@ "case": "setup_hw", "unit": "nvgpu_pbdma_gv11b", "test_level": 0 + }, + { + "test": "test_preempt_get_timeout", + "case": "get_timeout", + "unit": "nvgpu_preempt", + "test_level": 0 + }, + { + "test": "test_fifo_init_support", + "case": "init_support", + "unit": "nvgpu_preempt", + "test_level": 0 + }, + { + "test": "test_preempt", + "case": "preempt", + "unit": "nvgpu_preempt", + "test_level": 0 + }, + { + "test": "test_preempt_poll_tsg_on_pbdma", + "case": "preempt_poll", + "unit": "nvgpu_preempt", + "test_level": 0 + }, + { + "test": "test_fifo_remove_support", + "case": "remove_support", + "unit": "nvgpu_preempt", + "test_level": 0 }, { "test": "test_flat", diff --git a/userspace/units/fifo/preempt/Makefile b/userspace/units/fifo/preempt/Makefile new file mode 100644 index 000000000..e81c874a0 --- /dev/null +++ b/userspace/units/fifo/preempt/Makefile @@ -0,0 +1,32 @@ +# Copyright (c) 2018, 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 = nvgpu-preempt.o +MODULE = nvgpu-preempt + +LIB_PATHS += -lnvgpu-fifo +include ../../Makefile.units + +lib$(MODULE).so: fifo + +fifo: + $(MAKE) -C .. \ No newline at end of file diff --git a/userspace/units/fifo/preempt/Makefile.interface.tmk b/userspace/units/fifo/preempt/Makefile.interface.tmk new file mode 100644 index 000000000..385ad22c0 --- /dev/null +++ b/userspace/units/fifo/preempt/Makefile.interface.tmk @@ -0,0 +1,35 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# Copyright (c) 2018-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=nvgpu-preempt + +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/fifo/preempt/Makefile.tmk b/userspace/units/fifo/preempt/Makefile.tmk new file mode 100644 index 000000000..6de8e6d70 --- /dev/null +++ b/userspace/units/fifo/preempt/Makefile.tmk @@ -0,0 +1,40 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# Copyright (c) 2018-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=nvgpu-preempt +NVGPU_UNIT_SRCS = nvgpu-preempt.c + +NVGPU_UNIT_INTERFACE_DIRS := \ + $(NV_COMPONENT_DIR)/.. \ + $(NV_SOURCE)/kernel/nvgpu/drivers/gpu/nvgpu + +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/fifo/preempt/nvgpu-preempt.c b/userspace/units/fifo/preempt/nvgpu-preempt.c new file mode 100644 index 000000000..cd411e2b6 --- /dev/null +++ b/userspace/units/fifo/preempt/nvgpu-preempt.c @@ -0,0 +1,273 @@ +/* + * Copyright (c) 2018-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 +#include +#include +#include +#include +#include + +#include "hal/fifo/runlist_ram_gk20a.h" +#include "hal/fifo/tsg_gk20a.h" +#include "nvgpu/hw/gk20a/hw_ram_gk20a.h" +#include "nvgpu-preempt.h" +#include "nvgpu/hw/gk20a/hw_fifo_gk20a.h" + +#define RL_MAX_TIMESLICE_TIMEOUT ram_rl_entry_timeslice_timeout_v(U32_MAX) +#define RL_MAX_TIMESLICE_SCALE ram_rl_entry_timeslice_scale_v(U32_MAX) + +#include "../nvgpu-fifo.h" + +#ifdef PREEMPT_UNIT_DEBUG +#define unit_verbose unit_info +#else +#define unit_verbose(unit, msg, ...) \ + do { \ + if (0) { \ + unit_info(unit, msg, ##__VA_ARGS__); \ + } \ + } while (0) +#endif + +#define assert(cond) unit_assert(cond, goto done) + +#define MAX_STUB 2 + +struct stub_ctx { + const char *name; + u32 chid; + u32 count; + u32 tsgid; + u32 pbdma_id; +}; + +struct stub_ctx stub[MAX_STUB]; + +struct preempt_unit_ctx { + u32 branches; +}; + +static struct preempt_unit_ctx unit_ctx; + +static void subtest_setup(u32 branches) +{ + u32 i; + + unit_ctx.branches = branches; + + memset(stub, 0, sizeof(stub)); + for (i = 0; i < MAX_STUB; i++) { + stub[i].name = ""; + stub[i].count = 0; + stub[i].chid = NVGPU_INVALID_CHANNEL_ID; + stub[i].tsgid = NVGPU_INVALID_TSG_ID; + } +} + +#define branches_str test_fifo_flags_str +#define pruned test_fifo_subtest_pruned + +#define F_PREEMPT_CHANNEL BIT(0) +#define F_PREEMPT_LAST BIT(1) + +static const char *f_preempt[] = { + "preempt_tsg", + "preempt_channel", +}; + +static int stub_fifo_preempt_channel(struct gk20a *g, struct nvgpu_channel *ch) +{ + stub[0].chid = ch->chid; + return 0; +} + +static int stub_fifo_preempt_tsg(struct gk20a *g, struct nvgpu_tsg *tsg) +{ + stub[0].tsgid = tsg->tsgid; + return 0; +} + +int test_preempt(struct unit_module *m, struct gk20a *g, void *args) +{ + struct gpu_ops gops = g->ops; + struct nvgpu_channel *ch = NULL; + u32 runlist_id = NVGPU_INVALID_RUNLIST_ID; + bool privileged = false; + + u32 branches = 0U; + int ret = UNIT_FAIL; + int err = 0U; + + ch = nvgpu_channel_open_new(g, runlist_id, + privileged, getpid(), getpid()); + assert(ch != NULL); + + g->ops.fifo.preempt_tsg = stub_fifo_preempt_tsg; + g->ops.fifo.preempt_channel = stub_fifo_preempt_channel; + + for (branches = 0U; branches < F_PREEMPT_LAST; + branches++) { + + unit_verbose(m, "%s branches=%u\n", __func__, branches); + subtest_setup(branches); + + ch->tsgid = (branches & F_PREEMPT_CHANNEL) ? + NVGPU_INVALID_TSG_ID : 0; + + err = nvgpu_preempt_channel(g, ch); + assert(err == 0); + + if (branches & F_PREEMPT_CHANNEL) { + assert(stub[0].chid == ch->chid); + } else { + assert(stub[0].tsgid == ch->tsgid); + } + } + + ret = UNIT_SUCCESS; + +done: + if (ret != UNIT_SUCCESS) { + unit_err(m, "%s branches=%s\n", __func__, + branches_str(branches, f_preempt)); + } + + g->ops = gops; + return ret; +} + +#define F_PREEMPT_POLL_PBDMA_NULL BIT(0) +#define F_PREEMPT_POLL_TSG_NULL BIT(1) +#define F_PREEMPT_POLL_PBDMA_BUSY BIT(2) +#define F_PREEMPT_POLL_LAST BIT(3) + +static const char *f_preempt_poll[] = { + "preempt_poll_pbdma_null", + "tsg_null", + "preempt_poll_pbdma_busy", +}; + +static int stub_fifo_preempt_poll_pbdma_busy(struct gk20a *g, u32 tsgid, + u32 pbdma_id) +{ + stub[0].tsgid = tsgid; + stub[0].pbdma_id = pbdma_id; + return -EBUSY; +} + +static int stub_fifo_preempt_poll_pbdma(struct gk20a *g, u32 tsgid, + u32 pbdma_id) +{ + stub[0].tsgid = tsgid; + stub[0].pbdma_id = pbdma_id; + return 0; +} + +int test_preempt_poll_tsg_on_pbdma(struct unit_module *m, struct gk20a *g, + void *args) +{ + struct gpu_ops gops = g->ops; + struct nvgpu_tsg *tsg; + struct nvgpu_fifo *f = &g->fifo; + + u32 branches = 0U; + int ret = UNIT_FAIL; + u32 prune = F_PREEMPT_POLL_PBDMA_NULL | F_PREEMPT_POLL_TSG_NULL; + + tsg = nvgpu_tsg_open(g, getpid()); + assert(tsg != NULL); + tsg->runlist_id = 0; + + for (branches = 0U; branches < F_PREEMPT_POLL_LAST; + branches++) { + + if (pruned(branches, prune)) { + unit_verbose(m, "%s branches=%s (pruned)\n", __func__, + branches_str(branches, f_preempt_poll)); + continue; + } + subtest_setup(branches); + unit_verbose(m, "%s branches=%s\n", __func__, + branches_str(branches, f_preempt_poll)); + + g->ops.fifo.preempt_poll_pbdma = + (branches & F_PREEMPT_POLL_PBDMA_NULL) ? + NULL : ((branches & F_PREEMPT_POLL_PBDMA_BUSY) ? + stub_fifo_preempt_poll_pbdma_busy : + stub_fifo_preempt_poll_pbdma); + + if (branches & F_PREEMPT_POLL_TSG_NULL) { + nvgpu_preempt_poll_tsg_on_pbdma(g, NULL); + } else { + nvgpu_preempt_poll_tsg_on_pbdma(g, tsg); + } + + if (branches & F_PREEMPT_POLL_TSG_NULL) { + assert(stub[0].tsgid == NVGPU_INVALID_TSG_ID); + } else if (!(branches & F_PREEMPT_POLL_PBDMA_NULL)) { + assert(stub[0].tsgid == 0); + assert(stub[0].pbdma_id == + nvgpu_ffs(f->runlist_info[0]->pbdma_bitmask)); + } + } + + ret = UNIT_SUCCESS; +done: + if (ret != UNIT_SUCCESS) { + unit_err(m, "%s branches=%s\n", __func__, + branches_str(branches, f_preempt_poll)); + } + g->ops = gops; + return ret; +} + +int test_preempt_get_timeout(struct unit_module *m, struct gk20a *g, void *args) +{ + u32 timeout; + int ret = UNIT_FAIL; + + timeout = nvgpu_preempt_get_timeout(g); + assert(timeout == 0U); + + ret = UNIT_SUCCESS; +done: + return ret; +} + +struct unit_module_test nvgpu_preempt_tests[] = { + + UNIT_TEST(init_support, test_fifo_init_support, &unit_ctx, 0), + UNIT_TEST(preempt, test_preempt, NULL, 0), + UNIT_TEST(preempt_poll, test_preempt_poll_tsg_on_pbdma, NULL, 0), + UNIT_TEST(get_timeout, test_preempt_get_timeout, NULL, 0), + UNIT_TEST(remove_support, test_fifo_remove_support, &unit_ctx, 0), +}; + +UNIT_MODULE(nvgpu_preempt, nvgpu_preempt_tests, UNIT_PRIO_NVGPU_TEST); diff --git a/userspace/units/fifo/preempt/nvgpu-preempt.h b/userspace/units/fifo/preempt/nvgpu-preempt.h new file mode 100644 index 000000000..21fd17f6e --- /dev/null +++ b/userspace/units/fifo/preempt/nvgpu-preempt.h @@ -0,0 +1,93 @@ +/* + * 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_NVGPU_PREEMPT_H +#define UNIT_NVGPU_PREEMPT_H + +#include + +struct unit_module; +struct gk20a; + +/** @addtogroup SWUTS-fifo-preempt + * @{ + * + * Software Unit Test Specification for fifo/preempt */ + +/** + * Test specification for: test_preempt + * + * Description: Test TSG preempt. + * + * Test Type: Feature based + * + * Targets: nvgpu_preempt_channel + * + * Input: test_fifo_init_support + * + * Steps: + * - Test channel preempt with below cases: + * - Channel bound to TSG: TSG is preempted. + * - Independent channel, not bound to TSG. + * + * Output: Returns PASS if all branches gave expected results. FAIL otherwise. + */ +int test_preempt(struct unit_module *m, struct gk20a *g, void *args); + +/** + * Test specification for: test_preempt_poll_tsg_on_pbdma + * + * Description: Poll and preempt all TSGs serving PBDMA. + * + * Test Type: Feature based + * + * Targets: nvgpu_preempt_poll_tsg_on_pbdma + * + * Input: test_fifo_init_support + * + * Steps: + * - Go through list of TSGs serving PBDMAs and preempt the TSGs. + * + * Output: Returns PASS if all branches gave expected results. FAIL otherwise. + */ +int test_preempt_poll_tsg_on_pbdma(struct unit_module *m, struct gk20a *g, + void *args); + +/** + * Test specification for: test_preempt_get_timeout + * + * Description: Check GPU timeout value + * + * Test Type: Feature based + * + * Targets: nvgpu_preempt_get_timeout + * + * Input: test_fifo_init_support + * + * Steps: + * - GPU timeout value is not set in init. So, check if timeout value is 0. + * + * Output: Returns PASS if all branches gave expected results. FAIL otherwise. + */ +int test_preempt_get_timeout(struct unit_module *m, struct gk20a *g, + void *args); + +#endif /* UNIT_NVGPU_PREEMPT_H */