Skip to content

Commit

Permalink
Have taskq_create_synced() wait for threads to be created.
Browse files Browse the repository at this point in the history
  • Loading branch information
datacore-rm committed Feb 28, 2024
1 parent 3160047 commit 61ebd48
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/os/windows/spl/sys/sysmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ extern uint32_t cpu_number(void);
#define is_system_labeled() 0

extern unsigned int max_ncpus;
extern unsigned int boot_ncpus;
extern unsigned int num_ecores;

#ifndef RLIM64_INFINITY
#define RLIM64_INFINITY (~0ULL)
Expand Down Expand Up @@ -132,7 +134,6 @@ extern uint32_t zone_get_hostid(void *zone);
extern void spl_setup(void);
extern void spl_cleanup(void);

#define boot_ncpus max_ncpus
#define SET_ERROR(err) \
(__set_error(__FILE__, __func__, __LINE__, err), err)

Expand Down
5 changes: 3 additions & 2 deletions include/os/windows/spl/sys/taskq.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ struct proc;
#define TASKQ_DC_BATCH 0x0010 /* Taskq uses SDC in batch mode */

#ifdef _WIN32
#define TASKQ_TIMESHARE 0x0020 /* macOS dynamic thread priority */
#define TASKQ_REALLY_DYNAMIC 0x0040 /* don't filter out TASKQ_DYNAMIC */
#define TASKQ_TIMESHARE 0x0020 /* macOS dynamic thread priority */
#define TASKQ_REALLY_DYNAMIC 0x0040 /* don't filter out TASKQ_DYNAMIC */
#define TASKQ_CREATE_SYNCED 0x0080 /* don't deflate ncpus */
#endif
/*
* Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as
Expand Down
19 changes: 17 additions & 2 deletions module/os/windows/spl/spl-taskq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2374,6 +2374,8 @@ taskq_create_common(const char *name, int instance, int nthreads, pri_t pri,
taskq_t *tq = kmem_cache_alloc(taskq_cache, KM_SLEEP);
#ifdef _WIN32
uint_t ncpus = max_ncpus;
if (!(flags & TASKQ_CREATE_SYNCED))
ncpus = boot_ncpus; /* possibly deflated by num_ecores */
#else
uint_t ncpus = ((boot_max_ncpus == -1) ? max_ncpus : boot_max_ncpus);
#endif
Expand Down Expand Up @@ -2834,9 +2836,22 @@ taskq_create_synced(const char *name, int nthreads, pri_t pri,
flags &= ~(TASKQ_DYNAMIC | TASKQ_THREADS_CPU_PCT | TASKQ_DC_BATCH);

tq = taskq_create(name, nthreads, minclsyspri, nthreads, INT_MAX,
flags | TASKQ_PREPOPULATE);
flags | TASKQ_PREPOPULATE | TASKQ_CREATE_SYNCED);

VERIFY(tq != NULL);
VERIFY(tq->tq_nthreads == nthreads);

/* wait until our minalloc (nthreads) threads are created */
mutex_enter(&tq->tq_lock);
for (int i = 1; tq->tq_nthreads != nthreads; i++) {
dprintf("SPL: %s:%d: waiting for tq_nthreads (%d)"
" to be nthreads (%d), (target = %d, pass %d)\n",
__func__, __LINE__,
tq->tq_nthreads, tq->tq_nthreads_target, nthreads, i);
cv_wait(&tq->tq_wait_cv, &tq->tq_lock);
}
mutex_exit(&tq->tq_lock);

VERIFY3U(tq->tq_nthreads, ==, nthreads);

/* spawn all syncthreads */
for (int i = 0; i < nthreads; i++) {
Expand Down
7 changes: 7 additions & 0 deletions module/os/windows/spl/spl-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
static utsname_t utsname_static = { { 0 } };

unsigned int max_ncpus = 0;
unsigned int boot_ncpus = 0;
uint64_t total_memory = 0;
uint64_t real_total_memory = 0;

Expand Down Expand Up @@ -480,6 +481,12 @@ spl_start(PUNICODE_STRING RegistryPath)
max_ncpus = KeQueryActiveProcessorCountEx(ALL_PROCESSOR_GROUPS);
if (!max_ncpus) max_ncpus = 1;
dprintf("SPL: total ncpu %d\n", max_ncpus);
#if defined(__arm64__)
num_ecores = (max_ncpus > 4) ? 4 : 0; // Apple has 4 eCores, fixme
boot_ncpus = MAX(1, (int)max_ncpus - (int)num_ecores);
#else
boot_ncpus = max_ncpus;
#endif

// Not sure how to get physical RAM size in a Windows Driver
// So until then, pull some numbers out of the aether. Next
Expand Down

0 comments on commit 61ebd48

Please sign in to comment.