gpu: nvgpu: unit: fifo: preempt unit test

This unit test covers most of the nvgpu.common.fifo.preempt module lines
and almost all branches.

Jira NVGPU-3698

Change-Id: I3960cd77c88126659e4d990f4d27dc43850f9ae4
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2236730
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Vedashree Vidwans
2019-11-07 13:53:45 -08:00
committed by Alex Waterman
parent c25ccbb130
commit 0285ca6d98
11 changed files with 510 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 \

View File

@@ -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

View File

@@ -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

View File

@@ -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",

View File

@@ -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 ..

View File

@@ -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:

View File

@@ -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:

View File

@@ -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 <stdlib.h>
#include <unistd.h>
#include <unit/io.h>
#include <unit/unit.h>
#include <nvgpu/channel.h>
#include <nvgpu/runlist.h>
#include <nvgpu/preempt.h>
#include <nvgpu/gk20a.h>
#include <nvgpu/posix/posix-fault-injection.h>
#include <nvgpu/posix/dma.h>
#include <nvgpu/io.h>
#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);

View File

@@ -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 <nvgpu/types.h>
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 */