Module Name: src
Committed By: christos
Date: Fri Jan 25 18:33:59 UTC 2019
Modified Files:
src/distrib/sets/lists/tests: mi module.mi
src/tests/kernel: Makefile
src/tests/modules: Makefile
Added Files:
src/tests/modules/threadpool_tester: Makefile threadpool_tester.c
Removed Files:
src/tests/kernel: t_threadpool.sh
Log Message:
PR/53908: Alex Raschi: Test that require modules belong in modules; move the
threadpool test from kernel to modules.
To generate a diff of this commit:
cvs rdiff -u -r1.803 -r1.804 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.14 -r1.15 src/distrib/sets/lists/tests/module.mi
cvs rdiff -u -r1.55 -r1.56 src/tests/kernel/Makefile
cvs rdiff -u -r1.2 -r0 src/tests/kernel/t_threadpool.sh
cvs rdiff -u -r1.13 -r1.14 src/tests/modules/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/modules/threadpool_tester/Makefile \
src/tests/modules/threadpool_tester/threadpool_tester.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.803 src/distrib/sets/lists/tests/mi:1.804
--- src/distrib/sets/lists/tests/mi:1.803 Wed Jan 16 21:49:11 2019
+++ src/distrib/sets/lists/tests/mi Fri Jan 25 13:33:58 2019
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.803 2019/01/17 02:49:11 knakahara Exp $
+# $NetBSD: mi,v 1.804 2019/01/25 18:33:58 christos Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -2205,7 +2205,6 @@
./usr/tests/kernel/t_subr_prf tests-kernel-tests compattestfile,atf
./usr/tests/kernel/t_sysctl tests-kernel-tests compattestfile,atf
./usr/tests/kernel/t_sysv tests-kernel-tests compattestfile,atf
-./usr/tests/kernel/t_threadpool tests-kernel-tests compattestfile,atf
./usr/tests/kernel/t_time tests-obsolete obsolete
./usr/tests/kernel/t_timeleft tests-kernel-tests compattestfile,atf
./usr/tests/kernel/t_trapsignal tests-kernel-tests compattestfile,atf
Index: src/distrib/sets/lists/tests/module.mi
diff -u src/distrib/sets/lists/tests/module.mi:1.14 src/distrib/sets/lists/tests/module.mi:1.15
--- src/distrib/sets/lists/tests/module.mi:1.14 Mon Dec 24 11:58:54 2018
+++ src/distrib/sets/lists/tests/module.mi Fri Jan 25 13:33:58 2019
@@ -1,9 +1,10 @@
-# $NetBSD: module.mi,v 1.14 2018/12/24 16:58:54 thorpej Exp $
+# $NetBSD: module.mi,v 1.15 2019/01/25 18:33:58 christos Exp $
#
# These are only made for ports doing modules.
#
-./usr/tests/kernel/threadpool_tester tests-kernel-tests compattestfile,atf
-./usr/tests/kernel/threadpool_tester/threadpool_tester.kmod tests-kernel-tests compattestfile,atf
+./usr/tests/kernel/t_threadpool tests-obsolete obsolete
+./usr/tests/kernel/threadpool_tester tests-obsolete obsolete
+./usr/tests/kernel/threadpool_tester/threadpool_tester.kmod tests-obsolete obsolete
./usr/tests/modules/Atffile tests-sys-tests atf,rump
./usr/tests/modules/Kyuafile tests-sys-tests atf,rump,kyua
./usr/tests/modules/k_helper tests-sys-tests atf,rump
@@ -19,3 +20,6 @@
./usr/tests/modules/t_klua_pr_52864 tests-sys-tests atf,rump
./usr/tests/modules/t_modctl tests-sys-tests atf,rump
./usr/tests/modules/t_modload tests-sys-tests atf,rump
+./usr/tests/modules/t_threadpool tests-sys-tests atf,compattestfile
+./usr/tests/modules/threadpool_tester tests-sys-tests atf,compattestfile
+./usr/tests/modules/threadpool_tester/threadpool_tester.kmod tests-sys-tests atf,compattestfile
Index: src/tests/kernel/Makefile
diff -u src/tests/kernel/Makefile:1.55 src/tests/kernel/Makefile:1.56
--- src/tests/kernel/Makefile:1.55 Mon Dec 24 11:58:54 2018
+++ src/tests/kernel/Makefile Fri Jan 25 13:33:58 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.55 2018/12/24 16:58:54 thorpej Exp $
+# $NetBSD: Makefile,v 1.56 2019/01/25 18:33:58 christos Exp $
NOMAN= # defined
@@ -25,9 +25,6 @@ TESTS_SH+= t_trapsignal
TESTS_SH+= t_interp
TESTS_SH+= t_procpath
-SUBDIR+= threadpool_tester
-TESTS_SH+= t_threadpool
-
BINDIR= ${TESTSDIR}
PROGS= h_ps_strings1
PROGS+= h_ps_strings2
Index: src/tests/modules/Makefile
diff -u src/tests/modules/Makefile:1.13 src/tests/modules/Makefile:1.14
--- src/tests/modules/Makefile:1.13 Mon Jan 8 09:17:15 2018
+++ src/tests/modules/Makefile Fri Jan 25 13:33:59 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.13 2018/01/08 14:17:15 martin Exp $
+# $NetBSD: Makefile,v 1.14 2019/01/25 18:33:59 christos Exp $
.include <bsd.own.mk>
@@ -18,10 +18,12 @@ LDADD+= -lrumpfs_kernfs -lrumpvfs -lrum
TESTS_SH= t_abi_uvm
TESTS_SH+= t_modload
TESTS_SH+= t_klua_pr_52864
+TESTS_SH+= t_threadpool
SUBDIR= k_helper
SUBDIR+= k_helper2
SUBDIR+= k_helper3
SUBDIR+= k_uvm
+SUBDIR+= threadpool_tester
.include <bsd.test.mk>
Added files:
Index: src/tests/modules/threadpool_tester/Makefile
diff -u /dev/null src/tests/modules/threadpool_tester/Makefile:1.1
--- /dev/null Fri Jan 25 13:33:59 2019
+++ src/tests/modules/threadpool_tester/Makefile Fri Jan 25 13:33:59 2019
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1 2019/01/25 18:33:59 christos Exp $
+
+.include <bsd.own.mk>
+
+KMOD= threadpool_tester
+KMODULEDIR= ${DESTDIR}/${TESTSBASE}/modules/${KMOD}
+
+SRCS= threadpool_tester.c
+
+ATFFILE= no
+NOMAN= # defined
+
+.include <bsd.test.mk>
+.include <bsd.kmodule.mk>
Index: src/tests/modules/threadpool_tester/threadpool_tester.c
diff -u /dev/null src/tests/modules/threadpool_tester/threadpool_tester.c:1.1
--- /dev/null Fri Jan 25 13:33:59 2019
+++ src/tests/modules/threadpool_tester/threadpool_tester.c Fri Jan 25 13:33:59 2019
@@ -0,0 +1,502 @@
+/* $NetBSD: threadpool_tester.c,v 1.1 2019/01/25 18:33:59 christos Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: threadpool_tester.c,v 1.1 2019/01/25 18:33:59 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/sysctl.h>
+#include <sys/threadpool.h>
+
+MODULE(MODULE_CLASS_MISC, threadpool_tester, NULL);
+
+#ifdef THREADPOOL_VERBOSE
+#define TP_LOG(x) printf x
+#else
+#define TP_LOG(x) /* nothing */
+#endif /* THREADPOOL_VERBOSE */
+
+static struct tester_context {
+ kmutex_t ctx_mutex;
+ struct sysctllog *ctx_sysctllog;
+ struct threadpool *ctx_unbound[PRI_COUNT + 1];
+ struct threadpool_percpu *ctx_percpu[PRI_COUNT + 1];
+ unsigned int ctx_value;
+ struct threadpool_job ctx_job;
+} tester_ctx;
+
+#define pri_to_idx(pri) ((pri) == PRI_NONE ? PRI_COUNT : (pri))
+
+static bool
+pri_is_valid(pri_t pri)
+{
+ return (pri == PRI_NONE || (pri >= PRI_USER && pri < PRI_COUNT));
+}
+
+static int
+threadpool_tester_get_unbound(SYSCTLFN_ARGS)
+{
+ struct tester_context *ctx;
+ struct threadpool *pool, *opool = NULL;
+ struct sysctlnode node;
+ int error, val;
+
+ node = *rnode;
+ ctx = node.sysctl_data;
+
+ val = -1;
+ node.sysctl_data = &val;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ if (! pri_is_valid(val))
+ return EINVAL;
+
+ error = threadpool_get(&pool, val);
+ if (error) {
+ TP_LOG(("%s: threadpool_get(..., %d) failed -> %d\n",
+ __func__, val, error));
+ return error;
+ }
+
+ mutex_enter(&ctx->ctx_mutex);
+ if (ctx->ctx_unbound[pri_to_idx(val)] == NULL)
+ ctx->ctx_unbound[pri_to_idx(val)] = pool;
+ else
+ opool = ctx->ctx_unbound[pri_to_idx(val)];
+ mutex_exit(&ctx->ctx_mutex);
+
+ if (opool != NULL) {
+ /* Should have gotten reference to existing pool. */
+ TP_LOG(("%s: found existing unbound pool for pri %d (%s)\n",
+ __func__, val, opool == pool ? "match" : "NO MATCH"));
+ KASSERT(opool == pool);
+ threadpool_put(pool, val);
+ error = EEXIST;
+ } else {
+ TP_LOG(("%s: created unbound pool for pri %d\n",
+ __func__, val));
+ }
+
+ return error;
+}
+
+static int
+threadpool_tester_put_unbound(SYSCTLFN_ARGS)
+{
+ struct tester_context *ctx;
+ struct threadpool *pool;
+ struct sysctlnode node;
+ int error, val;
+
+ node = *rnode;
+ ctx = node.sysctl_data;
+
+ val = -1;
+ node.sysctl_data = &val;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ if (! pri_is_valid(val))
+ return EINVAL;
+
+ mutex_enter(&ctx->ctx_mutex);
+ /* We only ever maintain a single reference. */
+ pool = ctx->ctx_unbound[pri_to_idx(val)];
+ ctx->ctx_unbound[pri_to_idx(val)] = NULL;
+ mutex_exit(&ctx->ctx_mutex);
+
+ if (pool == NULL) {
+ TP_LOG(("%s: no unbound pool for pri %d\n",
+ __func__, val));
+ return ENODEV;
+ }
+
+ threadpool_put(pool, val);
+ TP_LOG(("%s: released unbound pool for pri %d\n",
+ __func__, val));
+
+ return 0;
+}
+
+static int
+threadpool_tester_run_unbound(SYSCTLFN_ARGS)
+{
+ struct tester_context *ctx;
+ struct threadpool *pool;
+ struct sysctlnode node;
+ int error, val;
+
+ node = *rnode;
+ ctx = node.sysctl_data;
+
+ val = -1;
+ node.sysctl_data = &val;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ if (! pri_is_valid(val))
+ return EINVAL;
+
+ mutex_enter(&ctx->ctx_mutex);
+ pool = ctx->ctx_unbound[pri_to_idx(val)];
+ if (pool == NULL) {
+ TP_LOG(("%s: no unbound pool for pri %d\n",
+ __func__, val));
+ mutex_exit(&ctx->ctx_mutex);
+ return ENODEV;
+ }
+
+ threadpool_schedule_job(pool, &ctx->ctx_job);
+ TP_LOG(("%s: scheduled job on unbound pool for pri %d\n",
+ __func__, val));
+ mutex_exit(&ctx->ctx_mutex);
+
+ return 0;
+}
+
+static int
+threadpool_tester_get_percpu(SYSCTLFN_ARGS)
+{
+ struct tester_context *ctx;
+ struct threadpool_percpu *pcpu, *opcpu = NULL;
+ struct sysctlnode node;
+ int error, val;
+
+ node = *rnode;
+ ctx = node.sysctl_data;
+
+ val = -1;
+ node.sysctl_data = &val;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ if (! pri_is_valid(val))
+ return EINVAL;
+
+ error = threadpool_percpu_get(&pcpu, val);
+ if (error) {
+ TP_LOG(("%s: threadpool_percpu_get(..., %d) failed -> %d\n",
+ __func__, val, error));
+ return error;
+ }
+
+ mutex_enter(&ctx->ctx_mutex);
+ if (ctx->ctx_percpu[pri_to_idx(val)] == NULL)
+ ctx->ctx_percpu[pri_to_idx(val)] = pcpu;
+ else
+ opcpu = ctx->ctx_percpu[pri_to_idx(val)];
+ mutex_exit(&ctx->ctx_mutex);
+
+ if (opcpu != NULL) {
+ /* Should have gotten reference to existing pool. */
+ TP_LOG(("%s: found existing unbound pool for pri %d (%s)\n",
+ __func__, val, opcpu == pcpu ? "match" : "NO MATCH"));
+ KASSERT(opcpu == pcpu);
+ threadpool_percpu_put(pcpu, val);
+ error = EEXIST;
+ } else {
+ TP_LOG(("%s: created percpu pool for pri %d\n",
+ __func__, val));
+ }
+
+ return error;
+}
+
+static int
+threadpool_tester_put_percpu(SYSCTLFN_ARGS)
+{
+ struct tester_context *ctx;
+ struct threadpool_percpu *pcpu;
+ struct sysctlnode node;
+ int error, val;
+
+ node = *rnode;
+ ctx = node.sysctl_data;
+
+ val = -1;
+ node.sysctl_data = &val;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ if (! pri_is_valid(val))
+ return EINVAL;
+
+ mutex_enter(&ctx->ctx_mutex);
+ /* We only ever maintain a single reference. */
+ pcpu = ctx->ctx_percpu[pri_to_idx(val)];
+ ctx->ctx_percpu[pri_to_idx(val)] = NULL;
+ mutex_exit(&ctx->ctx_mutex);
+
+ if (pcpu == NULL) {
+ TP_LOG(("%s: no percpu pool for pri %d\n",
+ __func__, val));
+ return ENODEV;
+ }
+
+ threadpool_percpu_put(pcpu, val);
+ TP_LOG(("%s: released percpu pool for pri %d\n",
+ __func__, val));
+
+ return 0;
+}
+
+static int
+threadpool_tester_run_percpu(SYSCTLFN_ARGS)
+{
+ struct tester_context *ctx;
+ struct threadpool_percpu *pcpu;
+ struct threadpool *pool;
+ struct sysctlnode node;
+ int error, val;
+
+ node = *rnode;
+ ctx = node.sysctl_data;
+
+ val = -1;
+ node.sysctl_data = &val;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ if (! pri_is_valid(val))
+ return EINVAL;
+
+ mutex_enter(&ctx->ctx_mutex);
+ pcpu = ctx->ctx_percpu[pri_to_idx(val)];
+ if (pcpu == NULL) {
+ TP_LOG(("%s: no percpu pool for pri %d\n",
+ __func__, val));
+ mutex_exit(&ctx->ctx_mutex);
+ return ENODEV;
+ }
+
+ pool = threadpool_percpu_ref(pcpu);
+ KASSERT(pool != NULL);
+
+ threadpool_schedule_job(pool, &ctx->ctx_job);
+ TP_LOG(("%s: scheduled job on percpu pool for pri %d\n",
+ __func__, val));
+ mutex_exit(&ctx->ctx_mutex);
+
+ return 0;
+}
+
+static int
+threadpool_tester_test_value(SYSCTLFN_ARGS)
+{
+ struct tester_context *ctx;
+ struct sysctlnode node;
+ unsigned int val;
+ int error;
+
+ node = *rnode;
+ ctx = node.sysctl_data;
+
+ mutex_enter(&ctx->ctx_mutex);
+ val = ctx->ctx_value;
+ node.sysctl_data = &val;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL) {
+ mutex_exit(&ctx->ctx_mutex);
+ return error;
+ }
+ ctx->ctx_value = val;
+ mutex_exit(&ctx->ctx_mutex);
+
+ return 0;
+}
+
+static void
+threadpool_tester_job(struct threadpool_job *job)
+{
+ struct tester_context *ctx =
+ container_of(job, struct tester_context, ctx_job);
+ unsigned int oval, nval;
+
+ TP_LOG(("%s: job = %p, ctx = %p\n", __func__, job, ctx));
+
+ mutex_enter(&ctx->ctx_mutex);
+ oval = ctx->ctx_value;
+ nval = oval + 1; /* always reference oval and nval */
+ ctx->ctx_value = nval;
+ mutex_exit(&ctx->ctx_mutex);
+
+ TP_LOG(("%s: %u -> %u\n", __func__, oval, nval));
+ (void) kpause("tptestjob", false, hz, NULL);
+
+ mutex_enter(&ctx->ctx_mutex);
+ threadpool_job_done(job);
+ mutex_exit(&ctx->ctx_mutex);
+}
+
+#define RETURN_ERROR if (error) goto return_error
+
+static int
+threadpool_tester_init(void)
+{
+ struct sysctllog **log = &tester_ctx.ctx_sysctllog;
+ const struct sysctlnode *rnode, *cnode;
+ int error;
+
+ mutex_init(&tester_ctx.ctx_mutex, MUTEX_DEFAULT, IPL_NONE);
+ threadpool_job_init(&tester_ctx.ctx_job, threadpool_tester_job,
+ &tester_ctx.ctx_mutex, "tptest");
+
+ error = sysctl_createv(log, 0, NULL, &rnode, CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "threadpool_tester",
+ SYSCTL_DESCR("threadpool testing interface"),
+ NULL, 0, NULL, 0, CTL_KERN, CTL_CREATE, CTL_EOL);
+ RETURN_ERROR;
+
+ error = sysctl_createv(log, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "get_unbound",
+ SYSCTL_DESCR("get unbound pool of specified priority"),
+ threadpool_tester_get_unbound, 0,
+ (void *)&tester_ctx, 0, CTL_CREATE, CTL_EOL);
+ RETURN_ERROR;
+
+ error = sysctl_createv(log, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "put_unbound",
+ SYSCTL_DESCR("put unbound pool of specified priority"),
+ threadpool_tester_put_unbound, 0,
+ (void *)&tester_ctx, 0, CTL_CREATE, CTL_EOL);
+ RETURN_ERROR;
+
+ error = sysctl_createv(log, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "run_unbound",
+ SYSCTL_DESCR("run on unbound pool of specified priority"),
+ threadpool_tester_run_unbound, 0,
+ (void *)&tester_ctx, 0, CTL_CREATE, CTL_EOL);
+ RETURN_ERROR;
+
+ error = sysctl_createv(log, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "get_percpu",
+ SYSCTL_DESCR("get percpu pool of specified priority"),
+ threadpool_tester_get_percpu, 0,
+ (void *)&tester_ctx, 0, CTL_CREATE, CTL_EOL);
+ RETURN_ERROR;
+
+ error = sysctl_createv(log, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "put_percpu",
+ SYSCTL_DESCR("put percpu pool of specified priority"),
+ threadpool_tester_put_percpu, 0,
+ (void *)&tester_ctx, 0, CTL_CREATE, CTL_EOL);
+ RETURN_ERROR;
+
+ error = sysctl_createv(log, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "run_percpu",
+ SYSCTL_DESCR("run on percpu pool of specified priority"),
+ threadpool_tester_run_percpu, 0,
+ (void *)&tester_ctx, 0, CTL_CREATE, CTL_EOL);
+ RETURN_ERROR;
+
+ error = sysctl_createv(log, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "test_value",
+ SYSCTL_DESCR("test value that jobs increment"),
+ threadpool_tester_test_value, 0,
+ (void *)&tester_ctx, 0, CTL_CREATE, CTL_EOL);
+ RETURN_ERROR;
+
+ return 0;
+
+ return_error:
+ sysctl_teardown(log);
+ return error;
+}
+
+static int
+threadpool_tester_fini(void)
+{
+ pri_t pri;
+
+ mutex_enter(&tester_ctx.ctx_mutex);
+ for (pri = PRI_NONE/*-1*/; pri < PRI_COUNT; pri++) {
+ struct threadpool *pool =
+ tester_ctx.ctx_unbound[pri_to_idx(pri)];
+ struct threadpool_percpu *pcpu =
+ tester_ctx.ctx_percpu[pri_to_idx(pri)];
+
+ /*
+ * threadpool_cancel_job() may be called on a pool
+ * other than what the job is scheduled on. This is
+ * safe; see comment in threadpool_cancel_job_async().
+ */
+
+ if (pool != NULL) {
+ threadpool_cancel_job(pool, &tester_ctx.ctx_job);
+ threadpool_put(pool, pri);
+ tester_ctx.ctx_unbound[pri_to_idx(pri)] = NULL;
+ }
+ if (pcpu != NULL) {
+ pool = threadpool_percpu_ref(pcpu);
+ threadpool_cancel_job(pool, &tester_ctx.ctx_job);
+ threadpool_percpu_put(pcpu, pri);
+ tester_ctx.ctx_percpu[pri_to_idx(pri)] = NULL;
+ }
+ }
+ mutex_exit(&tester_ctx.ctx_mutex);
+ threadpool_job_destroy(&tester_ctx.ctx_job);
+ mutex_destroy(&tester_ctx.ctx_mutex);
+
+ sysctl_teardown(&tester_ctx.ctx_sysctllog);
+
+ return 0;
+}
+
+static int
+threadpool_tester_modcmd(modcmd_t cmd, void *arg __unused)
+{
+ int error;
+
+ switch (cmd) {
+ case MODULE_CMD_INIT:
+ error = threadpool_tester_init();
+ break;
+
+ case MODULE_CMD_FINI:
+ error = threadpool_tester_fini();
+ break;
+
+ case MODULE_CMD_STAT:
+ default:
+ error = ENOTTY;
+ }
+
+ return error;
+}