From 416958ee4b9478c0580159e84517ff03fa297057 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 15 May 2014 01:39:12 +0000 Subject: [PATCH] iscsi-scst: One major number per thread pool Assign one major number per thread pool instead of as many major numbers as there are threads in a thread pool. Do not increment 'major' if thread pool allocation fails. Micro-optimize iscsi_threads_pool_get() by eliminating the assignment to 'fn' and the write via snprintf() into name[]. Signed-off-by: Bart Van Assche git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@5520 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/iscsi.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/iscsi-scst/kernel/iscsi.c b/iscsi-scst/kernel/iscsi.c index bfeb582a1..150d9ea98 100644 --- a/iscsi-scst/kernel/iscsi.c +++ b/iscsi-scst/kernel/iscsi.c @@ -4001,6 +4001,7 @@ int iscsi_threads_pool_get(const cpumask_t *cpu_mask, struct iscsi_thread_pool *p; struct iscsi_thread *t; int i, j, count; + static int major; /* Protected by iscsi_threads_pool_mutex */ TRACE_ENTRY(); @@ -4063,44 +4064,21 @@ int iscsi_threads_pool_get(const cpumask_t *cpu_mask, list_add_tail(&p->thread_pools_list_entry, &iscsi_thread_pools_list); for (j = 0; j < 2; j++) { - int (*fn)(void *); - char name[25]; - static int major; - - if (j == 0) - fn = istrd; - else - fn = istwr; - for (i = 0; i < count; i++) { - if (j == 0) { - major++; - if (cpu_mask == NULL) - snprintf(name, sizeof(name), "iscsird%d", i); - else - snprintf(name, sizeof(name), "iscsird%d_%d", - major, i); - } else { - if (cpu_mask == NULL) - snprintf(name, sizeof(name), "iscsiwr%d", i); - else - snprintf(name, sizeof(name), "iscsiwr%d_%d", - major, i); - } - t = kmalloc(sizeof(*t), GFP_KERNEL); if (t == NULL) { res = -ENOMEM; - PRINT_ERROR("Failed to allocate thread %s " - "(size %zd)", name, sizeof(*t)); + PRINT_ERROR("Failed to allocate thread " + "(size %zd)", sizeof(*t)); goto out_free; } - t->thr = kthread_run(fn, p, name); + t->thr = kthread_run(j ? istwr : istrd, p, + "iscsi%s%d_%d", j ? "wr" : "rd", + major, i); if (IS_ERR(t->thr)) { res = PTR_ERR(t->thr); - PRINT_ERROR("kthread_run() for thread %s failed: %d", - name, res); + PRINT_ERROR("kthread_run() failed: %d", res); kfree(t); goto out_free; } @@ -4108,6 +4086,7 @@ int iscsi_threads_pool_get(const cpumask_t *cpu_mask, } } + major++; res = 0; TRACE_DBG("Created iSCSI thread pool %p", p);