Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932346AbbDVSn6 (ORCPT ); Wed, 22 Apr 2015 14:43:58 -0400 Received: from cantor2.suse.de ([195.135.220.15]:33416 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757619AbbDVSnw (ORCPT ); Wed, 22 Apr 2015 14:43:52 -0400 Message-ID: <1429728220.10273.26.camel@stgolabs.net> Subject: [PATCH] cciss: Optimize scan_thread From: Davidlohr Bueso To: Jens Axboe Cc: Mike Miller , Don Brace , iss_storagedev@hp.com, storagedev@pmcs.com, linux-kernel@vger.kernel.org, dave@stgolabs.net Date: Wed, 22 Apr 2015 11:43:40 -0700 Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.11 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1794 Lines: 60 Two rather small optimizations found while going through driver code: 1) Use the cheaper alternative to set_current_state() as we are sure the task will block right afterward. 2) Checks for list_empty without the scan_mutex. The list_empty function is very much designed to work without locks, obviously as long as the head (scan_q) is reliable. In this case if another thread is doing add_to_scan_list(), we still buckle in the outer loop, so it will be caught upon the next iteration -- and if kthread_should_stop() hits, it does not matter _anyway_ as we'd still need to abort the function regardless of the status of the scan_q. Compile tested only. Signed-off-by: Davidlohr Bueso Cc: Jens Axboe Cc: Mike Miller Cc: Don Brace --- drivers/block/cciss.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index ff20f19..7dd3750 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c @@ -3727,18 +3727,13 @@ static int scan_thread(void *data) struct ctlr_info *h; while (1) { - set_current_state(TASK_INTERRUPTIBLE); + __set_current_state(TASK_INTERRUPTIBLE); schedule(); if (kthread_should_stop()) break; - while (1) { + while (!list_empty(&scan_q)) { mutex_lock(&scan_mutex); - if (list_empty(&scan_q)) { - mutex_unlock(&scan_mutex); - break; - } - h = list_entry(scan_q.next, struct ctlr_info, scan_list); -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/