Skip to content

Commit

Permalink
apply xnu thread policies to taskq_d threads too
Browse files Browse the repository at this point in the history
assuming this works, it calls out for DRY refactoring
with the other two flavours, that operate on current_thread().
  • Loading branch information
rottegift committed Apr 11, 2021
1 parent e2f55ec commit 39f93be
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions module/os/macos/spl/spl-taskq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2711,6 +2711,44 @@ taskq_bucket_extend(void *arg)
tqe->tqent_thread = (kthread_t *)0xCEDEC0DE;
thread = thread_create(NULL, 0, (void (*)(void *))taskq_d_thread,
tqe, 0, pp0, TS_RUN, tq->tq_pri);

thread_precedence_policy_data_t prec = { 0 };
prec.importance = tq->tq_pri - 81;
if (tq->tq_DC <= 50)
prec.importance--;
if (tq->tq_flags & TASKQ_DC_BATCH)
prec.importance--;
if (prec.importance < -11)
prec.importance = -11;
else if (prec.importance > -1)
prec.importance = -1;
kern_return_t precret = thread_policy_set(tqe->tqent_thread,
THREAD_PRECEDENCE_POLICY,
(thread_policy_t)&prec,
THREAD_PRECEDENCE_POLICY_COUNT);
if (precret != KERN_SUCCESS) {
printf("SPL: %s:%d: WARNING failed to set thread precedence retval %d"
" (prec now %d)\n",
__func__, __LINE__, precret, prec.importance);
} else {
tq->tq_pri = defclsyspri + prec.importance;
dprintf("SPL: %s:%d: SUCCESS setting thread precedence %x, %s\n", __func__, __LINE__,
prec.importance, tq->tq_name);
}

/* set the TIMESHARE property on all taskq_d threads */
thread_extended_policy_data_t policy = { .timeshare = TRUE };
kern_return_t kret = thread_policy_set(tqe->tqent_thread,
THREAD_EXTENDED_POLICY,
(thread_policy_t)&policy,
THREAD_EXTENDED_POLICY_COUNT);
if (kret != KERN_SUCCESS) {
printf("SPL: %s:%d: WARNING failed to set timeshare policy retval: %d, %s\n",
__func__, __LINE__, kret, tq->tq_name);
} else {
dprintf("SPL: %s:%d: SUCCESS setting timeshare policy, %s\n", __func__, __LINE__,
tq->tq_name);
}
#else

/*
Expand Down

0 comments on commit 39f93be

Please sign in to comment.