Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Add TASKQID_INVALID and TASKQID_INITIAL macros
Browse files Browse the repository at this point in the history
Add the TASKQID_INVALID and TASKQID_INITIAL macros and update the
taskq implementation and test cases to use them.  This is solely
for the purposes of readability and introduces no functional change.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
  • Loading branch information
Ubuntu authored and behlendorf committed Nov 2, 2016
1 parent 1b457bc commit cbba714
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 36 deletions.
6 changes: 6 additions & 0 deletions include/sys/taskq.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
#define TQ_NEW 0x04000000
#define TQ_FRONT 0x08000000

/*
* Reserved taskqid values.
*/
#define TASKQID_INVALID ((taskqid_t)0)
#define TASKQID_INITIAL ((taskqid_t)1)

/*
* spin_lock(lock) and spin_lock_nested(lock,0) are equivalent,
* so TQ_LOCK_DYNAMIC must not evaluate to 0
Expand Down
18 changes: 9 additions & 9 deletions module/spl/spl-taskq.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ task_done(taskq_t *tq, taskq_ent_t *t)
list_del_init(&t->tqent_list);

if (tq->tq_nalloc <= tq->tq_minalloc) {
t->tqent_id = 0;
t->tqent_id = TASKQID_INVALID;
t->tqent_func = NULL;
t->tqent_arg = NULL;
t->tqent_flags = 0;
Expand Down Expand Up @@ -276,7 +276,7 @@ taskq_lowest_id(taskq_t *tq)
if (!list_empty(&tq->tq_active_list)) {
tqt = list_entry(tq->tq_active_list.next, taskq_thread_t,
tqt_active_list);
ASSERT(tqt->tqt_id != 0);
ASSERT(tqt->tqt_id != TASKQID_INVALID);
lowest_id = MIN(lowest_id, tqt->tqt_id);
}

Expand Down Expand Up @@ -548,7 +548,7 @@ taskqid_t
taskq_dispatch(taskq_t *tq, task_func_t func, void *arg, uint_t flags)
{
taskq_ent_t *t;
taskqid_t rc = 0;
taskqid_t rc = TASKQID_INVALID;
unsigned long irqflags;

ASSERT(tq);
Expand Down Expand Up @@ -611,7 +611,7 @@ taskqid_t
taskq_dispatch_delay(taskq_t *tq, task_func_t func, void *arg,
uint_t flags, clock_t expire_time)
{
taskqid_t rc = 0;
taskqid_t rc = TASKQID_INVALID;
taskq_ent_t *t;
unsigned long irqflags;

Expand Down Expand Up @@ -667,7 +667,7 @@ taskq_dispatch_ent(taskq_t *tq, task_func_t func, void *arg, uint_t flags,

/* Taskq being destroyed and all tasks drained */
if (!(tq->tq_flags & TASKQ_ACTIVE)) {
t->tqent_id = 0;
t->tqent_id = TASKQID_INVALID;
goto out;
}

Expand Down Expand Up @@ -941,7 +941,7 @@ taskq_thread(void *args)
taskq_thread_spawn(tq))
seq_tasks = 0;

tqt->tqt_id = 0;
tqt->tqt_id = TASKQID_INVALID;
tqt->tqt_flags = 0;
wake_up_all(&tq->tq_wait_waitq);
} else {
Expand Down Expand Up @@ -975,7 +975,7 @@ taskq_thread_create(taskq_t *tq)
INIT_LIST_HEAD(&tqt->tqt_thread_list);
INIT_LIST_HEAD(&tqt->tqt_active_list);
tqt->tqt_tq = tq;
tqt->tqt_id = 0;
tqt->tqt_id = TASKQID_INVALID;

tqt->tqt_thread = spl_kthread_create(taskq_thread, tqt,
"%s", tq->tq_name);
Expand Down Expand Up @@ -1037,8 +1037,8 @@ taskq_create(const char *name, int nthreads, pri_t pri,
tq->tq_maxalloc = maxalloc;
tq->tq_nalloc = 0;
tq->tq_flags = (flags | TASKQ_ACTIVE);
tq->tq_next_id = 1;
tq->tq_lowest_id = 1;
tq->tq_next_id = TASKQID_INITIAL;
tq->tq_lowest_id = TASKQID_INITIAL;
INIT_LIST_HEAD(&tq->tq_free_list);
INIT_LIST_HEAD(&tq->tq_pend_list);
INIT_LIST_HEAD(&tq->tq_prio_list);
Expand Down
30 changes: 18 additions & 12 deletions module/splat/splat-mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ splat_mutex_test1(struct file *file, void *arg)
{
mutex_priv_t *mp;
taskq_t *tq;
int id, rc = 0;
taskqid_t id;
int rc = 0;

mp = (mutex_priv_t *)kmalloc(sizeof(*mp), GFP_KERNEL);
if (mp == NULL)
Expand All @@ -105,8 +106,8 @@ splat_mutex_test1(struct file *file, void *arg)
* function will indicate this status in the passed private data.
*/
mp->mp_rc = -EINVAL;
id = taskq_dispatch(tq, splat_mutex_test1_func, mp, TQ_SLEEP);
if (id == 0) {
id = taskq_dispatch(tq, splat_mutex_test1_func, mp, TQ_SLEEP);
if (id == TASKQID_INVALID) {
mutex_exit(&mp->mp_mtx);
splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, "%s",
"taskq_dispatch() failed\n");
Expand All @@ -120,8 +121,8 @@ splat_mutex_test1(struct file *file, void *arg)
/* Task function successfully acquired mutex, very bad! */
if (mp->mp_rc != -EBUSY) {
splat_vprint(file, SPLAT_MUTEX_TEST1_NAME,
"mutex_trylock() incorrectly succeeded when "
"the mutex was held, %d/%d\n", id, mp->mp_rc);
"mutex_trylock() incorrectly succeeded when "
"the mutex was held, %d/%d\n", (int)id, mp->mp_rc);
rc = -EINVAL;
goto out;
} else {
Expand All @@ -136,8 +137,8 @@ splat_mutex_test1(struct file *file, void *arg)
* can be verified by checking the private data.
*/
mp->mp_rc = -EINVAL;
id = taskq_dispatch(tq, splat_mutex_test1_func, mp, TQ_SLEEP);
if (id == 0) {
id = taskq_dispatch(tq, splat_mutex_test1_func, mp, TQ_SLEEP);
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, "%s",
"taskq_dispatch() failed\n");
rc = -EINVAL;
Expand All @@ -149,8 +150,8 @@ splat_mutex_test1(struct file *file, void *arg)
/* Task function failed to acquire mutex, very bad! */
if (mp->mp_rc != 0) {
splat_vprint(file, SPLAT_MUTEX_TEST1_NAME,
"mutex_trylock() incorrectly failed when "
"the mutex was not held, %d/%d\n", id, mp->mp_rc);
"mutex_trylock() incorrectly failed when the mutex "
"was not held, %d/%d\n", (int)id, mp->mp_rc);
rc = -EINVAL;
} else {
splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, "%s",
Expand Down Expand Up @@ -188,6 +189,7 @@ splat_mutex_test2(struct file *file, void *arg)
{
mutex_priv_t *mp;
taskq_t *tq;
taskqid_t id;
int i, rc = 0;

mp = (mutex_priv_t *)kmalloc(sizeof(*mp), GFP_KERNEL);
Expand Down Expand Up @@ -218,7 +220,8 @@ splat_mutex_test2(struct file *file, void *arg)
* mutex is implemented right this will never happy, that's a pass.
*/
for (i = 0; i < SPLAT_MUTEX_TEST_COUNT; i++) {
if (!taskq_dispatch(tq, splat_mutex_test2_func, mp, TQ_SLEEP)) {
id = taskq_dispatch(tq, splat_mutex_test2_func, mp, TQ_SLEEP);
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_MUTEX_TEST2_NAME,
"Failed to queue task %d\n", i);
rc = -EINVAL;
Expand Down Expand Up @@ -260,6 +263,7 @@ splat_mutex_test3(struct file *file, void *arg)
{
mutex_priv_t mp;
taskq_t *tq;
taskqid_t id;
int rc = 0;

mp.mp_magic = SPLAT_MUTEX_TEST_MAGIC;
Expand All @@ -283,7 +287,8 @@ splat_mutex_test3(struct file *file, void *arg)
goto out_exit;
}

if (taskq_dispatch(tq, splat_mutex_owned, &mp, TQ_SLEEP) == 0) {
id = taskq_dispatch(tq, splat_mutex_owned, &mp, TQ_SLEEP);
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_MUTEX_TEST3_NAME, "Failed to "
"dispatch function '%s' to taskq\n",
sym2str(splat_mutex_owned));
Expand All @@ -310,7 +315,8 @@ splat_mutex_test3(struct file *file, void *arg)
goto out;
}

if (taskq_dispatch(tq, splat_mutex_owned, &mp, TQ_SLEEP) == 0) {
id = taskq_dispatch(tq, splat_mutex_owned, &mp, TQ_SLEEP);
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_MUTEX_TEST3_NAME, "Failed to "
"dispatch function '%s' to taskq\n",
sym2str(splat_mutex_owned));
Expand Down
5 changes: 3 additions & 2 deletions module/splat/splat-rwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ splat_rwlock_test2(struct file *file, void *arg)
* rwlock is implemented right this will never happy, that's a pass.
*/
for (i = 0; i < tq_count; i++) {
if (!taskq_dispatch(tq,splat_rwlock_test2_func,rwp,TQ_SLEEP)) {
if (taskq_dispatch(tq, splat_rwlock_test2_func, rwp,
TQ_SLEEP) == TASKQID_INVALID) {
splat_vprint(file, SPLAT_RWLOCK_TEST2_NAME,
"Failed to queue task %d\n", i);
rc = -EINVAL;
Expand Down Expand Up @@ -469,7 +470,7 @@ splat_rwlock_test4_type(taskq_t *tq, rw_priv_t *rwp, int expected_rc,
rw_enter(&rwp->rw_rwlock, holder_type);

id = taskq_dispatch(tq, splat_rwlock_test4_func, rwp, TQ_SLEEP);
if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(rwp->rw_file, SPLAT_RWLOCK_TEST4_NAME, "%s",
"taskq_dispatch() failed\n");
rc = -EINVAL;
Expand Down
26 changes: 13 additions & 13 deletions module/splat/splat-taskq.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ splat_taskq_test1_impl(struct file *file, void *arg, boolean_t prealloc)
&tq_arg, TQ_SLEEP);
}

if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST1_NAME,
"Taskq '%s' function '%s' dispatch failed\n",
tq_arg.name, sym2str(splat_taskq_test13_func));
Expand Down Expand Up @@ -296,7 +296,7 @@ splat_taskq_test2_impl(struct file *file, void *arg, boolean_t prealloc) {
tq_args[i], TQ_SLEEP);
}

if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST2_NAME,
"Taskq '%s/%d' function '%s' dispatch "
"failed\n", tq_args[i]->name, tq_args[i]->id,
Expand All @@ -318,7 +318,7 @@ splat_taskq_test2_impl(struct file *file, void *arg, boolean_t prealloc) {
tq_args[i], TQ_SLEEP);
}

if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST2_NAME, "Taskq "
"'%s/%d' function '%s' dispatch failed\n",
tq_args[i]->name, tq_args[i]->id,
Expand Down Expand Up @@ -420,7 +420,7 @@ splat_taskq_test3_impl(struct file *file, void *arg, boolean_t prealloc)
tq_arg, TQ_SLEEP);
}

if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST3_NAME,
"Taskq '%s' function '%s' dispatch failed\n",
tq_arg->name, sym2str(splat_taskq_test13_func));
Expand Down Expand Up @@ -525,7 +525,7 @@ splat_taskq_test4_common(struct file *file, void *arg, int minalloc,
&tq_arg, TQ_SLEEP);
}

if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST4_NAME,
"Taskq '%s' function '%s' dispatch "
"%d failed\n", tq_arg.name,
Expand Down Expand Up @@ -741,7 +741,7 @@ splat_taskq_test5_impl(struct file *file, void *arg, boolean_t prealloc)
&tq_id[i], TQ_SLEEP);
}

if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST5_NAME,
"Taskq '%s' function '%s' dispatch failed\n",
tq_arg.name, sym2str(splat_taskq_test5_func));
Expand Down Expand Up @@ -905,7 +905,7 @@ splat_taskq_test6_impl(struct file *file, void *arg, boolean_t prealloc)
&tq_id[i], tflags);
}

if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST6_NAME,
"Taskq '%s' function '%s' dispatch failed\n",
tq_arg.name, sym2str(splat_taskq_test6_func));
Expand Down Expand Up @@ -983,7 +983,7 @@ splat_taskq_test7_func(void *arg)
tq_arg, TQ_SLEEP);
}

if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(tq_arg->file, SPLAT_TASKQ_TEST7_NAME,
"Taskq '%s' function '%s' dispatch failed "
"(depth = %u)\n", tq_arg->name,
Expand Down Expand Up @@ -1121,7 +1121,7 @@ splat_taskq_throughput(struct file *file, void *arg, const char *name,
&tq_arg, TQ_SLEEP, tqes[i]);
id = tqes[i]->tqent_id;

if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(file, name, "Taskq '%s' function '%s' "
"dispatch %d failed\n", tq_arg.name,
sym2str(splat_taskq_throughput_func), i);
Expand Down Expand Up @@ -1235,7 +1235,7 @@ splat_taskq_test9(struct file *file, void *arg)
id = taskq_dispatch_delay(tq, splat_taskq_test9_func,
tq_arg, TQ_SLEEP, ddi_get_lbolt() + rnd);

if (id == 0) {
if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST9_NAME,
"Taskq '%s' delay dispatch failed\n",
SPLAT_TASKQ_TEST9_NAME);
Expand Down Expand Up @@ -1344,7 +1344,7 @@ splat_taskq_test10(struct file *file, void *arg)
tq_arg, TQ_SLEEP, ddi_get_lbolt() + rnd);
}

if (tq_arg->id == 0) {
if (tq_arg->id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST10_NAME,
"Taskq '%s' dispatch failed\n",
SPLAT_TASKQ_TEST10_NAME);
Expand Down Expand Up @@ -1473,8 +1473,8 @@ splat_taskq_test11(struct file *file, void *arg)
dynamic.tv_sec, dynamic.tv_nsec);

/* A 10x increase in runtime is used to indicate a core problem. */
if ((dynamic.tv_sec * NANOSEC + dynamic.tv_nsec) >
((normal.tv_sec * NANOSEC + normal.tv_nsec) * 10))
if (((int64_t)dynamic.tv_sec * NANOSEC + (int64_t)dynamic.tv_nsec) >
(((int64_t)normal.tv_sec * NANOSEC + (int64_t)normal.tv_nsec) * 10))
error = -ETIME;

return (error);
Expand Down

0 comments on commit cbba714

Please sign in to comment.