All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@wdc.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bart.vanassche@wdc.com>,
	Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux.com>,
	NeilBrown <neilb@suse.com>
Subject: [PATCH 1/5] percpu-refcount: Introduce percpu_ref_switch_to_atomic_nowait()
Date: Fri,  8 Sep 2017 16:52:22 -0700	[thread overview]
Message-ID: <20170908235226.26622-2-bart.vanassche@wdc.com> (raw)
In-Reply-To: <20170908235226.26622-1-bart.vanassche@wdc.com>

The blk-mq core keeps track of the number of request queue users
through q->q_usage_count. Make it possible to switch this counter
to atomic mode from the context of the block layer power management
code by introducing percpu_ref_switch_to_atomic_nowait().

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: NeilBrown <neilb@suse.com>
---
 include/linux/percpu-refcount.h |  1 +
 lib/percpu-refcount.c           | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index c13dceb87b60..0d4bfbb392d7 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -100,6 +100,7 @@ void percpu_ref_exit(struct percpu_ref *ref);
 void percpu_ref_switch_to_atomic(struct percpu_ref *ref,
 				 percpu_ref_func_t *confirm_switch);
 void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref);
+void percpu_ref_switch_to_atomic_nowait(struct percpu_ref *ref);
 void percpu_ref_switch_to_percpu(struct percpu_ref *ref);
 void percpu_ref_kill_and_confirm(struct percpu_ref *ref,
 				 percpu_ref_func_t *confirm_kill);
diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
index fe03c6d52761..cf9152ff0892 100644
--- a/lib/percpu-refcount.c
+++ b/lib/percpu-refcount.c
@@ -277,6 +277,27 @@ void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref)
 }
 EXPORT_SYMBOL_GPL(percpu_ref_switch_to_atomic_sync);
 
+/**
+ * percpu_ref_switch_to_nowait - switch a percpu_ref to atomic mode
+ * @ref: percpu_ref to switch to atomic mode
+ *
+ * Schedule switching of @ref to atomic mode. All its percpu counts will be
+ * collected to the main atomic counter. @ref will stay in atomic mode across
+ * kill/reinit cycles until percpu_ref_switch_to_percpu() is called.
+ *
+ * This function does not block and can be called from any context.
+ */
+void percpu_ref_switch_to_atomic_nowait(struct percpu_ref *ref)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&percpu_ref_switch_lock, flags);
+	if (!ref->confirm_switch)
+		__percpu_ref_switch_to_atomic(ref, NULL);
+	spin_unlock_irqrestore(&percpu_ref_switch_lock, flags);
+}
+EXPORT_SYMBOL_GPL(percpu_ref_switch_to_atomic_nowait);
+
 /**
  * percpu_ref_switch_to_percpu - switch a percpu_ref to percpu mode
  * @ref: percpu_ref to switch to percpu mode
-- 
2.14.1

  reply	other threads:[~2017-09-08 23:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-08 23:52 [PATCH 0/5] Make SCSI device suspend work reliably Bart Van Assche
2017-09-08 23:52 ` Bart Van Assche [this message]
2017-09-11  8:42   ` [PATCH 1/5] percpu-refcount: Introduce percpu_ref_switch_to_atomic_nowait() Johannes Thumshirn
2017-09-11 16:10     ` Bart Van Assche
2017-09-11 13:13   ` Tejun Heo
2017-09-11 16:09     ` Bart Van Assche
2017-09-11 16:37       ` tj
2017-09-11 16:55         ` Bart Van Assche
2017-09-11 17:20           ` Tejun Heo
2017-09-11 17:29             ` Bart Van Assche
2017-09-08 23:52 ` [PATCH 2/5] scsi: Change the type of the second last argument of scsi_execute() Bart Van Assche
2017-09-08 23:52 ` [PATCH 3/5] block: Introduce REQ_PM and remove RQF_PM Bart Van Assche
2017-09-08 23:52 ` [PATCH 4/5] block: Make SCSI device suspend work reliably Bart Van Assche
2017-09-12  2:29   ` Ming Lei
2017-09-12 15:45     ` Bart Van Assche
2017-09-12 16:10       ` Ming Lei
2017-09-12 16:25   ` Ming Lei
2017-09-08 23:52 ` [PATCH 5/5] blk-mq: Implement power management support Bart Van Assche
2017-09-12  9:14   ` Ming Lei
2017-09-09 10:39 ` [PATCH 0/5] Make SCSI device suspend work reliably Ming Lei
2017-09-11 16:25   ` Bart Van Assche
2017-09-12  2:17     ` Ming Lei

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=20170908235226.26622-2-bart.vanassche@wdc.com \
    --to=bart.vanassche@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=cl@linux.com \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=neilb@suse.com \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.