From patchwork Tue Aug 21 09:09:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 1352961 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by patchwork1.kernel.org (Postfix) with ESMTP id 6385040210 for ; Tue, 21 Aug 2012 09:13:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7L9BF4A013329; Tue, 21 Aug 2012 05:11:15 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7L99tYZ025250 for ; Tue, 21 Aug 2012 05:09:55 -0400 Received: from tawny.mazyland.net (ovpn-116-28.ams2.redhat.com [10.36.116.28]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q7L99j8N031291; Tue, 21 Aug 2012 05:09:50 -0400 From: Mikulas Patocka To: dm-devel@redhat.com Date: Tue, 21 Aug 2012 11:09:16 +0200 Message-Id: <7c25d1f54166e77bf2cb639ebd1a393212017ff5.1345477953.git.mbroz@redhat.com> In-Reply-To: <520994e0c87d38ca6abb8dd60760aef993842a32.1345477953.git.mbroz@redhat.com> References: <520994e0c87d38ca6abb8dd60760aef993842a32.1345477953.git.mbroz@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: Mikulas Patocka Subject: [dm-devel] [PATCH 05/20] dm-crypt: Unify spinlock X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Remove "crypt_thread_spinlock" and use wait queue spinlock "crypt_thread_wait.spinlock" instead. This saves few atomic operations in the encryption thread. Signed-off-by: Mikulas Patocka --- drivers/md/dm-crypt.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index cb0e26f..b251e15 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -130,7 +130,6 @@ struct crypt_config { struct task_struct **crypt_threads; wait_queue_head_t crypt_thread_wait; - spinlock_t crypt_thread_spinlock; struct list_head crypt_thread_list; char *cipher; @@ -680,15 +679,16 @@ static int dmcrypt_thread(void *data) DECLARE_WAITQUEUE(wait, current); - spin_lock(&cc->crypt_thread_spinlock); + spin_lock_irq(&cc->crypt_thread_wait.lock); +continue_locked: if (!list_empty(&cc->crypt_thread_list)) goto pop_from_list; __set_current_state(TASK_INTERRUPTIBLE); - add_wait_queue(&cc->crypt_thread_wait, &wait); + __add_wait_queue(&cc->crypt_thread_wait, &wait); - spin_unlock(&cc->crypt_thread_spinlock); + spin_unlock_irq(&cc->crypt_thread_wait.lock); if (unlikely(kthread_should_stop())) { set_task_state(current, TASK_RUNNING); @@ -699,8 +699,9 @@ static int dmcrypt_thread(void *data) schedule(); set_task_state(current, TASK_RUNNING); - remove_wait_queue(&cc->crypt_thread_wait, &wait); - continue; + spin_lock_irq(&cc->crypt_thread_wait.lock); + __remove_wait_queue(&cc->crypt_thread_wait, &wait); + goto continue_locked; pop_from_list: n_dmreqs = 0; @@ -712,7 +713,8 @@ pop_from_list: dmreqs[n_dmreqs++] = dmreq; } while (n_dmreqs < DMREQ_PULL_BATCH && !list_empty(&cc->crypt_thread_list)); - spin_unlock(&cc->crypt_thread_spinlock); + + spin_unlock_irq(&cc->crypt_thread_wait.lock); i = 0; do { @@ -805,10 +807,10 @@ static struct ablkcipher_request *crypt_alloc_req(struct crypt_config *cc, static void crypt_flush_batch(struct crypt_config *cc, struct list_head *batch) { - spin_lock(&cc->crypt_thread_spinlock); + spin_lock_irq(&cc->crypt_thread_wait.lock); list_splice_tail(batch, &cc->crypt_thread_list); - spin_unlock(&cc->crypt_thread_spinlock); - wake_up_all(&cc->crypt_thread_wait); + wake_up_locked(&cc->crypt_thread_wait); + spin_unlock_irq(&cc->crypt_thread_wait.lock); INIT_LIST_HEAD(batch); } @@ -1750,7 +1752,6 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) cc->crypt_threads_size = i + 1; init_waitqueue_head(&cc->crypt_thread_wait); - spin_lock_init(&cc->crypt_thread_spinlock); INIT_LIST_HEAD(&cc->crypt_thread_list); cc->crypt_threads = kzalloc(cc->crypt_threads_size *