scst: Move ioctx manipulation code

Move the code for obtaining and releasing an I/O context out of
scst_process_active_cmd() in order to improve source code
readability.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>



git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4254 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Vladislav Bolkhovitin
2012-04-30 19:41:18 +00:00
parent a913a223f9
commit 474dca1fb2

View File

@@ -4098,6 +4098,79 @@ int scst_init_thread(void *arg)
return 0;
}
/**
* scst_ioctx_get() - Associate an I/O context with a thread.
*
* Associate an I/O context with a thread in such a way that all threads in an
* SCST thread pool share the same I/O context. This greatly improves thread
* pool I/O performance with at least the CFQ scheduler.
*
* Note: A more elegant approach would be to allocate the I/O context in
* scst_init_threads() instead of this function. That approach is only possible
* though after exporting alloc_io_context(). A previous discussion of this
* topic can be found here: http://lkml.org/lkml/2008/12/11/282.
*/
static void scst_ioctx_get(struct scst_cmd_threads *p_cmd_threads)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
mutex_lock(&p_cmd_threads->io_context_mutex);
WARN_ON(current->io_context);
if (p_cmd_threads != &scst_main_cmd_threads) {
/*
* For linked IO contexts io_context might be not NULL while
* io_context 0.
*/
if (p_cmd_threads->io_context == NULL) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)
p_cmd_threads->io_context = get_task_io_context(current,
GFP_KERNEL, NUMA_NO_NODE);
#else
p_cmd_threads->io_context = get_io_context(GFP_KERNEL, -1);
#endif
TRACE_MGMT_DBG("Alloced new IO context %p "
"(p_cmd_threads %p)", p_cmd_threads->io_context,
p_cmd_threads);
/*
* Put the extra reference created by get_io_context()
* because we don't need it.
*/
put_io_context(p_cmd_threads->io_context);
} else {
current->io_context =
ioc_task_link(p_cmd_threads->io_context);
TRACE_MGMT_DBG("Linked IO context %p "
"(p_cmd_threads %p)", p_cmd_threads->io_context,
p_cmd_threads);
}
p_cmd_threads->io_context_refcnt++;
}
mutex_unlock(&p_cmd_threads->io_context_mutex);
#endif
smp_wmb();
p_cmd_threads->io_context_ready = true;
return;
}
/**
* scst_ioctx_put() - Free I/O context allocated by scst_ioctx_get().
*/
static void scst_ioctx_put(struct scst_cmd_threads *p_cmd_threads)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
if (p_cmd_threads != &scst_main_cmd_threads) {
mutex_lock(&p_cmd_threads->io_context_mutex);
if (--p_cmd_threads->io_context_refcnt == 0)
p_cmd_threads->io_context = NULL;
mutex_unlock(&p_cmd_threads->io_context_mutex);
}
#endif
return;
}
/**
* scst_process_active_cmd() - process active command
*
@@ -4320,46 +4393,7 @@ int scst_cmd_thread(void *arg)
#endif
current->flags |= PF_NOFREEZE;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
mutex_lock(&p_cmd_threads->io_context_mutex);
WARN_ON(current->io_context);
if (p_cmd_threads != &scst_main_cmd_threads) {
/*
* For linked IO contexts io_context might be not NULL while
* io_context 0.
*/
if (p_cmd_threads->io_context == NULL) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)
p_cmd_threads->io_context = get_task_io_context(current,
GFP_KERNEL, NUMA_NO_NODE);
#else
p_cmd_threads->io_context = get_io_context(GFP_KERNEL, -1);
#endif
TRACE_MGMT_DBG("Alloced new IO context %p "
"(p_cmd_threads %p)",
p_cmd_threads->io_context,
p_cmd_threads);
/*
* Put the extra reference created by get_io_context()
* because we don't need it.
*/
put_io_context(p_cmd_threads->io_context);
} else {
current->io_context = ioc_task_link(p_cmd_threads->io_context);
TRACE_MGMT_DBG("Linked IO context %p "
"(p_cmd_threads %p)", p_cmd_threads->io_context,
p_cmd_threads);
}
p_cmd_threads->io_context_refcnt++;
}
mutex_unlock(&p_cmd_threads->io_context_mutex);
#endif
smp_wmb();
p_cmd_threads->io_context_ready = true;
scst_ioctx_get(p_cmd_threads);
spin_lock_irq(&p_cmd_threads->cmd_list_lock);
while (!kthread_should_stop()) {
@@ -4378,14 +4412,7 @@ int scst_cmd_thread(void *arg)
}
spin_unlock_irq(&p_cmd_threads->cmd_list_lock);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
if (p_cmd_threads != &scst_main_cmd_threads) {
mutex_lock(&p_cmd_threads->io_context_mutex);
if (--p_cmd_threads->io_context_refcnt == 0)
p_cmd_threads->io_context = NULL;
mutex_unlock(&p_cmd_threads->io_context_mutex);
}
#endif
scst_ioctx_put(p_cmd_threads);
PRINT_INFO("Processing thread %s (PID %d) finished", current->comm,
current->pid);