linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Davidlohr Bueso <dave@stgolabs.net>
To: Jens Axboe <axboe@kernel.dk>
Cc: Mike Miller <mike.miller@hp.com>, Don Brace <don.brace@pmcs.com>,
	iss_storagedev@hp.com, storagedev@pmcs.com,
	linux-kernel@vger.kernel.org, dave@stgolabs.net
Subject: [PATCH] cciss: Optimize scan_thread
Date: Wed, 22 Apr 2015 11:43:40 -0700	[thread overview]
Message-ID: <1429728220.10273.26.camel@stgolabs.net> (raw)

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 <dbueso@suse.de>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Mike Miller <mike.miller@hp.com>
Cc: Don Brace <don.brace@pmcs.com>
---
 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




             reply	other threads:[~2015-04-22 18:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-22 18:43 Davidlohr Bueso [this message]
2015-04-23 16:51 ` [PATCH] cciss: Optimize scan_thread Jens Axboe
2015-04-23 17:06   ` Davidlohr Bueso
2015-04-23 17:11     ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1429728220.10273.26.camel@stgolabs.net \
    --to=dave@stgolabs.net \
    --cc=axboe@kernel.dk \
    --cc=don.brace@pmcs.com \
    --cc=iss_storagedev@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mike.miller@hp.com \
    --cc=storagedev@pmcs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).