scst: Rework the code for waiting until an I/O context is ready

Introduce a wait event and eliminate the msleep() call that is
used for waiting until an I/O context is ready.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
This commit is contained in:
Bart Van Assche
2015-04-14 10:31:53 +02:00
parent 6317a4a5ee
commit 32cadc07df
5 changed files with 22 additions and 14 deletions

View File

@@ -1965,6 +1965,7 @@ struct scst_cmd_threads {
int io_context_refcnt;
bool io_context_ready;
wait_queue_head_t io_context_wait;
/* io_context_mutex protects io_context and io_context_refcnt. */
struct mutex io_context_mutex;

View File

@@ -4331,13 +4331,7 @@ found:
t->acg_dev->acg->acg_io_grouping_type);
} else {
res = t;
if (!*(volatile bool *)&res->active_cmd_threads->io_context_ready) {
TRACE_DBG("IO context for t %p not yet "
"initialized, waiting...", t);
msleep(100);
goto found;
}
smp_rmb();
scst_wait_ioctx(res->active_cmd_threads);
TRACE_DBG("Going to share IO context %p (res %p, ini %s, "
"dev %s, cmd_threads %p, grouping type %d)",
res->active_cmd_threads->io_context, res,

View File

@@ -1930,12 +1930,7 @@ out_wait:
* Wait for io_context gets initialized to avoid possible races
* for it from the sharing it tgt_devs.
*/
while (!*(volatile bool *)&cmd_threads->io_context_ready) {
TRACE_DBG("Waiting for io_context for cmd_threads %p "
"initialized", cmd_threads);
msleep(50);
}
smp_rmb();
scst_wait_ioctx(cmd_threads);
}
if (res != 0)
@@ -2193,6 +2188,7 @@ void scst_init_threads(struct scst_cmd_threads *cmd_threads)
INIT_LIST_HEAD(&cmd_threads->threads_list);
mutex_init(&cmd_threads->io_context_mutex);
spin_lock_init(&cmd_threads->thr_lock);
init_waitqueue_head(&cmd_threads->io_context_wait);
mutex_lock(&scst_cmd_threads_mutex);
list_add_tail(&cmd_threads->lists_list_entry,

View File

@@ -214,6 +214,8 @@ struct scst_cmd_thread_t {
bool being_stopped;
};
void scst_wait_ioctx(struct scst_cmd_threads *tp);
static inline bool scst_set_io_context(struct scst_cmd *cmd,
struct io_context **old)
{

View File

@@ -4650,6 +4650,20 @@ int scst_init_thread(void *arg)
return 0;
}
/**
* scst_wait_ioctx_timeout() - wait until an I/O context becomes available
* @tp: Thread pool to wait on.
*
* Returns the number of jiffies remaining if the I/O context became available
* in time and zero if the I/O context did not become available in time.
*/
void scst_wait_ioctx(struct scst_cmd_threads *tp)
{
wait_event(tp->io_context_wait,
*(volatile bool *)&tp->io_context_ready);
smp_rmb();
}
/**
* scst_ioctx_get() - Associate an I/O context with a thread.
*
@@ -4717,7 +4731,8 @@ See "http://lkml.org/lkml/2012/7/17/515" for more details.
smp_wmb();
p_cmd_threads->io_context_ready = true;
return;
wake_up_all(&p_cmd_threads->io_context_wait);
}
/**