Skip to content

Commit d95a9ef

Browse files
committed
Fix spl_thread_create not setting thread priority
1 parent 1b5a18c commit d95a9ef

File tree

3 files changed

+79
-12
lines changed

3 files changed

+79
-12
lines changed

include/os/windows/spl/sys/sysmacros.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ extern unsigned int num_ecores;
8181
* swap priority is at 92. Most ZFS priorities should probably
8282
* stay below this, but kmem_reap needs to be higher.
8383
*/
84-
#define minclsyspri 81 /* BASEPRI_KERNEL */
85-
#define defclsyspri 81 /* BASEPRI_KERNEL */
86-
#define maxclsyspri 89
84+
#define minclsyspri 8 /* BASEPRI_KERNEL */
85+
#define defclsyspri 8 /* BASEPRI_KERNEL */
86+
#define maxclsyspri 12
8787

8888
#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
8989
#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)

module/os/windows/spl/spl-thread.c

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,78 @@
3939

4040
uint64_t zfs_threads = 0;
4141

42-
kthread_t *
42+
43+
kthread_t*
44+
spl_thread_create(
45+
caddr_t stk,
46+
size_t stksize,
47+
void (*proc)(void*),
48+
void* arg,
49+
size_t len,
50+
int state,
51+
#ifdef SPL_DEBUG_THREAD
52+
char* filename,
53+
int line,
54+
#endif
55+
pri_t pri)
56+
{
57+
NTSTATUS status;
58+
HANDLE hThread = NULL;
59+
PETHREAD eThread = NULL;
60+
61+
#ifdef SPL_DEBUG_THREAD
62+
dprintf("Start thread pri %d\n", pri);
63+
#endif
64+
65+
status = PsCreateSystemThread(
66+
&hThread,
67+
THREAD_ALL_ACCESS,
68+
NULL,
69+
NULL,
70+
NULL,
71+
proc,
72+
arg);
73+
74+
if (!NT_SUCCESS(status))
75+
return NULL;
76+
77+
/* Convert HANDLE ETHREAD */
78+
status = ObReferenceObjectByHandle(
79+
hThread,
80+
THREAD_ALL_ACCESS,
81+
*PsThreadType,
82+
KernelMode,
83+
(PVOID*)&eThread,
84+
NULL);
85+
86+
/* We no longer need the handle */
87+
ZwClose(hThread);
88+
89+
if (!NT_SUCCESS(status))
90+
return NULL;
91+
92+
/* Clamp priority to safe Windows range */
93+
KPRIORITY newPri = (KPRIORITY)pri;
94+
95+
if (newPri > maxclsyspri)
96+
newPri = maxclsyspri;
97+
98+
if (newPri < minclsyspri)
99+
newPri = minclsyspri;
100+
101+
/* Set absolute priority */
102+
KeSetPriorityThread((PKTHREAD)eThread, newPri);
103+
104+
#ifdef SPL_DEBUG_THREAD
105+
dprintf("Thread created with priority %d\n", newPri);
106+
#endif
107+
108+
atomic_inc_64(&zfs_threads);
109+
110+
return (kthread_t*)eThread;
111+
}
112+
113+
/*kthread_t*
43114
spl_thread_create(
44115
caddr_t stk,
45116
size_t stksize,
@@ -72,12 +143,7 @@ spl_thread_create(
72143
if (result != STATUS_SUCCESS)
73144
return (NULL);
74145
75-
/*
76-
* Improve the priority when asked to do so
77-
* Thread priorities range from 0 to 31, where 0 is the lowest
78-
* priority and 31 is the highest
79-
*/
80-
146+
81147
if (pri > minclsyspri) {
82148
// thread_precedence_policy_data_t policy;
83149
// policy.importance = pri - minclsyspri;
@@ -102,7 +168,7 @@ spl_thread_create(
102168
ObDereferenceObject(eThread);
103169
ZwClose(thread);
104170
return ((kthread_t *)eThread);
105-
}
171+
}*/
106172

107173
kthread_t *
108174
spl_current_thread(void)

module/zfs/txg.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ txg_sync_start(dsl_pool_t *dp)
213213
* 32-bit x86. This is due in part to nested pools and
214214
* scrub_visitbp() recursion.
215215
*/
216+
216217
tx->tx_sync_thread = thread_create(NULL, 0, txg_sync_thread,
217-
dp, 0, &p0, TS_RUN, defclsyspri);
218+
dp, 0, &p0, TS_RUN, maxclsyspri);
218219

219220
mutex_exit(&tx->tx_sync_lock);
220221
}

0 commit comments

Comments
 (0)