FreeBSD: Create taskq threads in appropriate proc

Stepping stone toward re-enabling spa_thread on FreeBSD.

Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #10715
This commit is contained in:
Ryan Moeller 2020-08-17 14:01:19 -04:00 committed by GitHub
parent fc34dfba8e
commit 3c3d7c8a57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 19 deletions

View File

@ -61,13 +61,14 @@ typedef struct thread kthread_t;
typedef struct thread *kthread_id_t; typedef struct thread *kthread_id_t;
typedef struct proc proc_t; typedef struct proc proc_t;
extern struct proc *zfsproc; extern proc_t *system_proc;
static __inline kthread_t * static __inline kthread_t *
do_thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg, do_thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg,
size_t len, proc_t *pp, int state, pri_t pri, const char *name) size_t len, proc_t *pp, int state, pri_t pri, const char *name)
{ {
kthread_t *td = NULL; kthread_t *td = NULL;
proc_t **ppp;
int error; int error;
/* /*
@ -77,8 +78,12 @@ do_thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg,
ASSERT(len == 0); ASSERT(len == 0);
ASSERT(state == TS_RUN); ASSERT(state == TS_RUN);
error = kproc_kthread_add(proc, arg, &zfsproc, &td, if (pp == &p0)
RFSTOPPED, stksize / PAGE_SIZE, "zfskern", "%s", name); ppp = &system_proc;
else
ppp = &pp;
error = kproc_kthread_add(proc, arg, ppp, &td, RFSTOPPED,
stksize / PAGE_SIZE, "zfskern", "%s", name);
if (error == 0) { if (error == 0) {
thread_lock(td); thread_lock(td);
sched_prio(td, pri); sched_prio(td, pri);

View File

@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <sys/malloc.h> #include <sys/malloc.h>
#include <sys/kmem.h> #include <sys/kmem.h>
#include <sys/list.h> #include <sys/list.h>
#include <sys/proc.h>
#include <sys/sbuf.h> #include <sys/sbuf.h>
#include <sys/nvpair.h> #include <sys/nvpair.h>
#include <sys/sunddi.h> #include <sys/sunddi.h>
@ -256,6 +257,6 @@ sysevent_worker(void *arg __unused)
void void
ddi_sysevent_init(void) ddi_sysevent_init(void)
{ {
kproc_kthread_add(sysevent_worker, NULL, &zfsproc, NULL, 0, 0, kproc_kthread_add(sysevent_worker, NULL, &system_proc, NULL, 0, 0,
"zfskern", "sysevent"); "zfskern", "sysevent");
} }

View File

@ -44,6 +44,11 @@ __FBSDID("$FreeBSD$");
#include <vm/uma.h> #include <vm/uma.h>
#if __FreeBSD_version < 1201522
#define taskqueue_start_threads_in_proc(tqp, count, pri, proc, name, ...) \
taskqueue_start_threads(tqp, count, pri, name, __VA_ARGS__)
#endif
static uint_t taskq_tsd; static uint_t taskq_tsd;
static uma_zone_t taskq_zone; static uma_zone_t taskq_zone;
@ -51,6 +56,8 @@ taskq_t *system_taskq = NULL;
taskq_t *system_delay_taskq = NULL; taskq_t *system_delay_taskq = NULL;
taskq_t *dynamic_taskq = NULL; taskq_t *dynamic_taskq = NULL;
proc_t *system_proc;
extern int uma_align_cache; extern int uma_align_cache;
static MALLOC_DEFINE(M_TASKQ, "taskq", "taskq structures"); static MALLOC_DEFINE(M_TASKQ, "taskq", "taskq structures");
@ -166,8 +173,8 @@ taskq_tsd_set(void *context)
} }
static taskq_t * static taskq_t *
taskq_create_with_init(const char *name, int nthreads, pri_t pri, taskq_create_impl(const char *name, int nthreads, pri_t pri,
int minalloc __unused, int maxalloc __unused, uint_t flags) proc_t *proc __maybe_unused, uint_t flags)
{ {
taskq_t *tq; taskq_t *tq;
@ -181,8 +188,8 @@ taskq_create_with_init(const char *name, int nthreads, pri_t pri,
taskq_tsd_set, tq); taskq_tsd_set, tq);
taskqueue_set_callback(tq->tq_queue, TASKQUEUE_CALLBACK_TYPE_SHUTDOWN, taskqueue_set_callback(tq->tq_queue, TASKQUEUE_CALLBACK_TYPE_SHUTDOWN,
taskq_tsd_set, NULL); taskq_tsd_set, NULL);
(void) taskqueue_start_threads(&tq->tq_queue, nthreads, pri, (void) taskqueue_start_threads_in_proc(&tq->tq_queue, nthreads, pri,
"%s", name); proc, "%s", name);
return ((taskq_t *)tq); return ((taskq_t *)tq);
} }
@ -191,18 +198,14 @@ taskq_t *
taskq_create(const char *name, int nthreads, pri_t pri, int minalloc __unused, taskq_create(const char *name, int nthreads, pri_t pri, int minalloc __unused,
int maxalloc __unused, uint_t flags) int maxalloc __unused, uint_t flags)
{ {
return (taskq_create_impl(name, nthreads, pri, system_proc, flags));
return (taskq_create_with_init(name, nthreads, pri, minalloc, maxalloc,
flags));
} }
taskq_t * taskq_t *
taskq_create_proc(const char *name, int nthreads, pri_t pri, int minalloc, taskq_create_proc(const char *name, int nthreads, pri_t pri,
int maxalloc, proc_t *proc __unused, uint_t flags) int minalloc __unused, int maxalloc __unused, proc_t *proc, uint_t flags)
{ {
return (taskq_create_impl(name, nthreads, pri, proc, flags));
return (taskq_create_with_init(name, nthreads, pri, minalloc, maxalloc,
flags));
} }
void void

View File

@ -60,6 +60,7 @@
#include <sys/conf.h> #include <sys/conf.h>
#include <sys/cmn_err.h> #include <sys/cmn_err.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/proc.h>
#include <sys/zap.h> #include <sys/zap.h>
#include <sys/spa.h> #include <sys/spa.h>
#include <sys/spa_impl.h> #include <sys/spa_impl.h>
@ -135,8 +136,6 @@ struct zvol_state_os {
} _zso_state; } _zso_state;
}; };
struct proc *zfsproc;
static uint32_t zvol_minors; static uint32_t zvol_minors;
SYSCTL_DECL(_vfs_zfs); SYSCTL_DECL(_vfs_zfs);
@ -385,7 +384,7 @@ zvol_geom_run(zvol_state_t *zv)
g_error_provider(pp, 0); g_error_provider(pp, 0);
kproc_kthread_add(zvol_geom_worker, zv, &zfsproc, NULL, 0, 0, kproc_kthread_add(zvol_geom_worker, zv, &system_proc, NULL, 0, 0,
"zfskern", "zvol %s", pp->name + sizeof (ZVOL_DRIVER)); "zfskern", "zvol %s", pp->name + sizeof (ZVOL_DRIVER));
} }