Add TASKQID_INVALID and TASKQID_INITIAL macros

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>
This commit is contained in:
Ubuntu 2016-10-28 21:23:30 +00:00 committed by Brian Behlendorf
parent 1b457bcbe5
commit cbba714667
5 changed files with 49 additions and 36 deletions

View File

@ -56,6 +56,12 @@
#define TQ_NEW 0x04000000 #define TQ_NEW 0x04000000
#define TQ_FRONT 0x08000000 #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, * spin_lock(lock) and spin_lock_nested(lock,0) are equivalent,
* so TQ_LOCK_DYNAMIC must not evaluate to 0 * so TQ_LOCK_DYNAMIC must not evaluate to 0

View File

@ -190,7 +190,7 @@ task_done(taskq_t *tq, taskq_ent_t *t)
list_del_init(&t->tqent_list); list_del_init(&t->tqent_list);
if (tq->tq_nalloc <= tq->tq_minalloc) { if (tq->tq_nalloc <= tq->tq_minalloc) {
t->tqent_id = 0; t->tqent_id = TASKQID_INVALID;
t->tqent_func = NULL; t->tqent_func = NULL;
t->tqent_arg = NULL; t->tqent_arg = NULL;
t->tqent_flags = 0; t->tqent_flags = 0;
@ -276,7 +276,7 @@ taskq_lowest_id(taskq_t *tq)
if (!list_empty(&tq->tq_active_list)) { if (!list_empty(&tq->tq_active_list)) {
tqt = list_entry(tq->tq_active_list.next, taskq_thread_t, tqt = list_entry(tq->tq_active_list.next, taskq_thread_t,
tqt_active_list); tqt_active_list);
ASSERT(tqt->tqt_id != 0); ASSERT(tqt->tqt_id != TASKQID_INVALID);
lowest_id = MIN(lowest_id, tqt->tqt_id); lowest_id = MIN(lowest_id, tqt->tqt_id);
} }
@ -548,7 +548,7 @@ taskqid_t
taskq_dispatch(taskq_t *tq, task_func_t func, void *arg, uint_t flags) taskq_dispatch(taskq_t *tq, task_func_t func, void *arg, uint_t flags)
{ {
taskq_ent_t *t; taskq_ent_t *t;
taskqid_t rc = 0; taskqid_t rc = TASKQID_INVALID;
unsigned long irqflags; unsigned long irqflags;
ASSERT(tq); ASSERT(tq);
@ -611,7 +611,7 @@ taskqid_t
taskq_dispatch_delay(taskq_t *tq, task_func_t func, void *arg, taskq_dispatch_delay(taskq_t *tq, task_func_t func, void *arg,
uint_t flags, clock_t expire_time) uint_t flags, clock_t expire_time)
{ {
taskqid_t rc = 0; taskqid_t rc = TASKQID_INVALID;
taskq_ent_t *t; taskq_ent_t *t;
unsigned long irqflags; unsigned long irqflags;
@ -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 */ /* Taskq being destroyed and all tasks drained */
if (!(tq->tq_flags & TASKQ_ACTIVE)) { if (!(tq->tq_flags & TASKQ_ACTIVE)) {
t->tqent_id = 0; t->tqent_id = TASKQID_INVALID;
goto out; goto out;
} }
@ -941,7 +941,7 @@ taskq_thread(void *args)
taskq_thread_spawn(tq)) taskq_thread_spawn(tq))
seq_tasks = 0; seq_tasks = 0;
tqt->tqt_id = 0; tqt->tqt_id = TASKQID_INVALID;
tqt->tqt_flags = 0; tqt->tqt_flags = 0;
wake_up_all(&tq->tq_wait_waitq); wake_up_all(&tq->tq_wait_waitq);
} else { } else {
@ -975,7 +975,7 @@ taskq_thread_create(taskq_t *tq)
INIT_LIST_HEAD(&tqt->tqt_thread_list); INIT_LIST_HEAD(&tqt->tqt_thread_list);
INIT_LIST_HEAD(&tqt->tqt_active_list); INIT_LIST_HEAD(&tqt->tqt_active_list);
tqt->tqt_tq = tq; tqt->tqt_tq = tq;
tqt->tqt_id = 0; tqt->tqt_id = TASKQID_INVALID;
tqt->tqt_thread = spl_kthread_create(taskq_thread, tqt, tqt->tqt_thread = spl_kthread_create(taskq_thread, tqt,
"%s", tq->tq_name); "%s", tq->tq_name);
@ -1037,8 +1037,8 @@ taskq_create(const char *name, int nthreads, pri_t pri,
tq->tq_maxalloc = maxalloc; tq->tq_maxalloc = maxalloc;
tq->tq_nalloc = 0; tq->tq_nalloc = 0;
tq->tq_flags = (flags | TASKQ_ACTIVE); tq->tq_flags = (flags | TASKQ_ACTIVE);
tq->tq_next_id = 1; tq->tq_next_id = TASKQID_INITIAL;
tq->tq_lowest_id = 1; tq->tq_lowest_id = TASKQID_INITIAL;
INIT_LIST_HEAD(&tq->tq_free_list); INIT_LIST_HEAD(&tq->tq_free_list);
INIT_LIST_HEAD(&tq->tq_pend_list); INIT_LIST_HEAD(&tq->tq_pend_list);
INIT_LIST_HEAD(&tq->tq_prio_list); INIT_LIST_HEAD(&tq->tq_prio_list);

View File

@ -81,7 +81,8 @@ splat_mutex_test1(struct file *file, void *arg)
{ {
mutex_priv_t *mp; mutex_priv_t *mp;
taskq_t *tq; taskq_t *tq;
int id, rc = 0; taskqid_t id;
int rc = 0;
mp = (mutex_priv_t *)kmalloc(sizeof(*mp), GFP_KERNEL); mp = (mutex_priv_t *)kmalloc(sizeof(*mp), GFP_KERNEL);
if (mp == NULL) if (mp == NULL)
@ -105,8 +106,8 @@ splat_mutex_test1(struct file *file, void *arg)
* function will indicate this status in the passed private data. * function will indicate this status in the passed private data.
*/ */
mp->mp_rc = -EINVAL; mp->mp_rc = -EINVAL;
id = taskq_dispatch(tq, splat_mutex_test1_func, mp, TQ_SLEEP); id = taskq_dispatch(tq, splat_mutex_test1_func, mp, TQ_SLEEP);
if (id == 0) { if (id == TASKQID_INVALID) {
mutex_exit(&mp->mp_mtx); mutex_exit(&mp->mp_mtx);
splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, "%s", splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, "%s",
"taskq_dispatch() failed\n"); "taskq_dispatch() failed\n");
@ -120,8 +121,8 @@ splat_mutex_test1(struct file *file, void *arg)
/* Task function successfully acquired mutex, very bad! */ /* Task function successfully acquired mutex, very bad! */
if (mp->mp_rc != -EBUSY) { if (mp->mp_rc != -EBUSY) {
splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, splat_vprint(file, SPLAT_MUTEX_TEST1_NAME,
"mutex_trylock() incorrectly succeeded when " "mutex_trylock() incorrectly succeeded when "
"the mutex was held, %d/%d\n", id, mp->mp_rc); "the mutex was held, %d/%d\n", (int)id, mp->mp_rc);
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
} else { } else {
@ -136,8 +137,8 @@ splat_mutex_test1(struct file *file, void *arg)
* can be verified by checking the private data. * can be verified by checking the private data.
*/ */
mp->mp_rc = -EINVAL; mp->mp_rc = -EINVAL;
id = taskq_dispatch(tq, splat_mutex_test1_func, mp, TQ_SLEEP); id = taskq_dispatch(tq, splat_mutex_test1_func, mp, TQ_SLEEP);
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, "%s", splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, "%s",
"taskq_dispatch() failed\n"); "taskq_dispatch() failed\n");
rc = -EINVAL; rc = -EINVAL;
@ -149,8 +150,8 @@ splat_mutex_test1(struct file *file, void *arg)
/* Task function failed to acquire mutex, very bad! */ /* Task function failed to acquire mutex, very bad! */
if (mp->mp_rc != 0) { if (mp->mp_rc != 0) {
splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, splat_vprint(file, SPLAT_MUTEX_TEST1_NAME,
"mutex_trylock() incorrectly failed when " "mutex_trylock() incorrectly failed when the mutex "
"the mutex was not held, %d/%d\n", id, mp->mp_rc); "was not held, %d/%d\n", (int)id, mp->mp_rc);
rc = -EINVAL; rc = -EINVAL;
} else { } else {
splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, "%s", splat_vprint(file, SPLAT_MUTEX_TEST1_NAME, "%s",
@ -188,6 +189,7 @@ splat_mutex_test2(struct file *file, void *arg)
{ {
mutex_priv_t *mp; mutex_priv_t *mp;
taskq_t *tq; taskq_t *tq;
taskqid_t id;
int i, rc = 0; int i, rc = 0;
mp = (mutex_priv_t *)kmalloc(sizeof(*mp), GFP_KERNEL); mp = (mutex_priv_t *)kmalloc(sizeof(*mp), GFP_KERNEL);
@ -218,7 +220,8 @@ splat_mutex_test2(struct file *file, void *arg)
* mutex is implemented right this will never happy, that's a pass. * mutex is implemented right this will never happy, that's a pass.
*/ */
for (i = 0; i < SPLAT_MUTEX_TEST_COUNT; i++) { 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, splat_vprint(file, SPLAT_MUTEX_TEST2_NAME,
"Failed to queue task %d\n", i); "Failed to queue task %d\n", i);
rc = -EINVAL; rc = -EINVAL;
@ -260,6 +263,7 @@ splat_mutex_test3(struct file *file, void *arg)
{ {
mutex_priv_t mp; mutex_priv_t mp;
taskq_t *tq; taskq_t *tq;
taskqid_t id;
int rc = 0; int rc = 0;
mp.mp_magic = SPLAT_MUTEX_TEST_MAGIC; mp.mp_magic = SPLAT_MUTEX_TEST_MAGIC;
@ -283,7 +287,8 @@ splat_mutex_test3(struct file *file, void *arg)
goto out_exit; 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 " splat_vprint(file, SPLAT_MUTEX_TEST3_NAME, "Failed to "
"dispatch function '%s' to taskq\n", "dispatch function '%s' to taskq\n",
sym2str(splat_mutex_owned)); sym2str(splat_mutex_owned));
@ -310,7 +315,8 @@ splat_mutex_test3(struct file *file, void *arg)
goto out; 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 " splat_vprint(file, SPLAT_MUTEX_TEST3_NAME, "Failed to "
"dispatch function '%s' to taskq\n", "dispatch function '%s' to taskq\n",
sym2str(splat_mutex_owned)); sym2str(splat_mutex_owned));

View File

@ -348,7 +348,8 @@ splat_rwlock_test2(struct file *file, void *arg)
* rwlock is implemented right this will never happy, that's a pass. * rwlock is implemented right this will never happy, that's a pass.
*/ */
for (i = 0; i < tq_count; i++) { 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, splat_vprint(file, SPLAT_RWLOCK_TEST2_NAME,
"Failed to queue task %d\n", i); "Failed to queue task %d\n", i);
rc = -EINVAL; rc = -EINVAL;
@ -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); rw_enter(&rwp->rw_rwlock, holder_type);
id = taskq_dispatch(tq, splat_rwlock_test4_func, rwp, TQ_SLEEP); 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", splat_vprint(rwp->rw_file, SPLAT_RWLOCK_TEST4_NAME, "%s",
"taskq_dispatch() failed\n"); "taskq_dispatch() failed\n");
rc = -EINVAL; rc = -EINVAL;

View File

@ -160,7 +160,7 @@ splat_taskq_test1_impl(struct file *file, void *arg, boolean_t prealloc)
&tq_arg, TQ_SLEEP); &tq_arg, TQ_SLEEP);
} }
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST1_NAME, splat_vprint(file, SPLAT_TASKQ_TEST1_NAME,
"Taskq '%s' function '%s' dispatch failed\n", "Taskq '%s' function '%s' dispatch failed\n",
tq_arg.name, sym2str(splat_taskq_test13_func)); tq_arg.name, sym2str(splat_taskq_test13_func));
@ -296,7 +296,7 @@ splat_taskq_test2_impl(struct file *file, void *arg, boolean_t prealloc) {
tq_args[i], TQ_SLEEP); tq_args[i], TQ_SLEEP);
} }
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST2_NAME, splat_vprint(file, SPLAT_TASKQ_TEST2_NAME,
"Taskq '%s/%d' function '%s' dispatch " "Taskq '%s/%d' function '%s' dispatch "
"failed\n", tq_args[i]->name, tq_args[i]->id, "failed\n", tq_args[i]->name, tq_args[i]->id,
@ -318,7 +318,7 @@ splat_taskq_test2_impl(struct file *file, void *arg, boolean_t prealloc) {
tq_args[i], TQ_SLEEP); tq_args[i], TQ_SLEEP);
} }
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST2_NAME, "Taskq " splat_vprint(file, SPLAT_TASKQ_TEST2_NAME, "Taskq "
"'%s/%d' function '%s' dispatch failed\n", "'%s/%d' function '%s' dispatch failed\n",
tq_args[i]->name, tq_args[i]->id, tq_args[i]->name, tq_args[i]->id,
@ -420,7 +420,7 @@ splat_taskq_test3_impl(struct file *file, void *arg, boolean_t prealloc)
tq_arg, TQ_SLEEP); tq_arg, TQ_SLEEP);
} }
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST3_NAME, splat_vprint(file, SPLAT_TASKQ_TEST3_NAME,
"Taskq '%s' function '%s' dispatch failed\n", "Taskq '%s' function '%s' dispatch failed\n",
tq_arg->name, sym2str(splat_taskq_test13_func)); tq_arg->name, sym2str(splat_taskq_test13_func));
@ -525,7 +525,7 @@ splat_taskq_test4_common(struct file *file, void *arg, int minalloc,
&tq_arg, TQ_SLEEP); &tq_arg, TQ_SLEEP);
} }
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST4_NAME, splat_vprint(file, SPLAT_TASKQ_TEST4_NAME,
"Taskq '%s' function '%s' dispatch " "Taskq '%s' function '%s' dispatch "
"%d failed\n", tq_arg.name, "%d failed\n", tq_arg.name,
@ -741,7 +741,7 @@ splat_taskq_test5_impl(struct file *file, void *arg, boolean_t prealloc)
&tq_id[i], TQ_SLEEP); &tq_id[i], TQ_SLEEP);
} }
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST5_NAME, splat_vprint(file, SPLAT_TASKQ_TEST5_NAME,
"Taskq '%s' function '%s' dispatch failed\n", "Taskq '%s' function '%s' dispatch failed\n",
tq_arg.name, sym2str(splat_taskq_test5_func)); tq_arg.name, sym2str(splat_taskq_test5_func));
@ -905,7 +905,7 @@ splat_taskq_test6_impl(struct file *file, void *arg, boolean_t prealloc)
&tq_id[i], tflags); &tq_id[i], tflags);
} }
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST6_NAME, splat_vprint(file, SPLAT_TASKQ_TEST6_NAME,
"Taskq '%s' function '%s' dispatch failed\n", "Taskq '%s' function '%s' dispatch failed\n",
tq_arg.name, sym2str(splat_taskq_test6_func)); tq_arg.name, sym2str(splat_taskq_test6_func));
@ -983,7 +983,7 @@ splat_taskq_test7_func(void *arg)
tq_arg, TQ_SLEEP); tq_arg, TQ_SLEEP);
} }
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(tq_arg->file, SPLAT_TASKQ_TEST7_NAME, splat_vprint(tq_arg->file, SPLAT_TASKQ_TEST7_NAME,
"Taskq '%s' function '%s' dispatch failed " "Taskq '%s' function '%s' dispatch failed "
"(depth = %u)\n", tq_arg->name, "(depth = %u)\n", tq_arg->name,
@ -1121,7 +1121,7 @@ splat_taskq_throughput(struct file *file, void *arg, const char *name,
&tq_arg, TQ_SLEEP, tqes[i]); &tq_arg, TQ_SLEEP, tqes[i]);
id = tqes[i]->tqent_id; id = tqes[i]->tqent_id;
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(file, name, "Taskq '%s' function '%s' " splat_vprint(file, name, "Taskq '%s' function '%s' "
"dispatch %d failed\n", tq_arg.name, "dispatch %d failed\n", tq_arg.name,
sym2str(splat_taskq_throughput_func), i); sym2str(splat_taskq_throughput_func), i);
@ -1235,7 +1235,7 @@ splat_taskq_test9(struct file *file, void *arg)
id = taskq_dispatch_delay(tq, splat_taskq_test9_func, id = taskq_dispatch_delay(tq, splat_taskq_test9_func,
tq_arg, TQ_SLEEP, ddi_get_lbolt() + rnd); tq_arg, TQ_SLEEP, ddi_get_lbolt() + rnd);
if (id == 0) { if (id == TASKQID_INVALID) {
splat_vprint(file, SPLAT_TASKQ_TEST9_NAME, splat_vprint(file, SPLAT_TASKQ_TEST9_NAME,
"Taskq '%s' delay dispatch failed\n", "Taskq '%s' delay dispatch failed\n",
SPLAT_TASKQ_TEST9_NAME); SPLAT_TASKQ_TEST9_NAME);
@ -1344,7 +1344,7 @@ splat_taskq_test10(struct file *file, void *arg)
tq_arg, TQ_SLEEP, ddi_get_lbolt() + rnd); 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, splat_vprint(file, SPLAT_TASKQ_TEST10_NAME,
"Taskq '%s' dispatch failed\n", "Taskq '%s' dispatch failed\n",
SPLAT_TASKQ_TEST10_NAME); SPLAT_TASKQ_TEST10_NAME);
@ -1473,8 +1473,8 @@ splat_taskq_test11(struct file *file, void *arg)
dynamic.tv_sec, dynamic.tv_nsec); dynamic.tv_sec, dynamic.tv_nsec);
/* A 10x increase in runtime is used to indicate a core problem. */ /* A 10x increase in runtime is used to indicate a core problem. */
if ((dynamic.tv_sec * NANOSEC + dynamic.tv_nsec) > if (((int64_t)dynamic.tv_sec * NANOSEC + (int64_t)dynamic.tv_nsec) >
((normal.tv_sec * NANOSEC + normal.tv_nsec) * 10)) (((int64_t)normal.tv_sec * NANOSEC + (int64_t)normal.tv_nsec) * 10))
error = -ETIME; error = -ETIME;
return (error); return (error);