From: David Jeffery <djeffery@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
David Jeffery <djeffery@redhat.com>,
Laurence Oberman <loberman@redhat.com>
Subject: [RFC PATCH 2/6] Improve ability to perform async shutdown in parallel
Date: Wed, 7 Feb 2024 13:40:56 -0500 [thread overview]
Message-ID: <20240207184100.18066-3-djeffery@redhat.com> (raw)
In-Reply-To: <20240207184100.18066-1-djeffery@redhat.com>
Expands the async shutdown implementation to allow more cases of parallel
async shutdown. A field is added so that a device under async shutdown can
mark its parent as busy due to the async shutdown. A busy parent on reaching
the head of the shutdown list gets stored and flags its own parent as busy.
Once the async shutdown operations are completed, the stored parents are
returned to the shutdown list and shut down in an order maintaining their
parent-child ordering. Unlike the minimal implementation, this allows more
end nodes of the device tree to be under async shutdown in parallel.
A cap on the number of async shutdown devices is still enforced, though not
required and could be removed if desired.
Signed-off-by: David Jeffery <djeffery@redhat.com>
Tested-by: Laurence Oberman <loberman@redhat.com>
---
drivers/base/base.h | 1 +
drivers/base/core.c | 71 ++++++++++++++++++++++++++++++++-------------
2 files changed, 52 insertions(+), 20 deletions(-)
diff --git a/drivers/base/base.h b/drivers/base/base.h
index eb4c0ace9242..954008bd39e5 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -116,6 +116,7 @@ struct device_private {
char *deferred_probe_reason;
struct device *device;
u8 dead:1;
+ u8 child_shutdown:1;
};
#define to_device_private_parent(obj) \
container_of(obj, struct device_private, knode_parent)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 5bc2282c00cd..e88d418bf0fd 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4720,9 +4720,10 @@ int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)
EXPORT_SYMBOL_GPL(device_change_owner);
-#define MAX_ASYNC_SHUTDOWNS 32
+#define MAX_ASYNC_SHUTDOWNS 256
static int async_shutdown_count;
static LIST_HEAD(async_shutdown_list);
+static LIST_HEAD(async_delayed_list);
/**
* If a device has a child busy with an async shutdown or there are too many
@@ -4730,15 +4731,15 @@ static LIST_HEAD(async_shutdown_list);
*/
static bool may_shutdown_device(struct device *dev)
{
- struct device *tmp;
-
- if (async_shutdown_count >= MAX_ASYNC_SHUTDOWNS)
+ if (dev->p->child_shutdown) {
+ if (list_empty(&async_shutdown_list)) {
+ dev_err(dev, "child_shutdown set but no children? Clearing\n");
+ dev->p->child_shutdown = 0;
+ return true;
+ }
return false;
-
- list_for_each_entry(tmp, &async_shutdown_list, kobj.entry) {
- if (tmp->parent == dev)
- return false;
}
+
return true;
}
@@ -4753,6 +4754,9 @@ static void async_shutdown_start(struct device *dev, void (*callback) (struct de
(*callback)(dev);
list_add_tail(&dev->kobj.entry, &async_shutdown_list);
async_shutdown_count++;
+
+ if (dev->parent)
+ dev->parent->p->child_shutdown = 1;
}
/**
@@ -4760,7 +4764,7 @@ static void async_shutdown_start(struct device *dev, void (*callback) (struct de
*/
static void wait_for_active_async_shutdown(void)
{
- struct device *dev, *parent;
+ struct device *dev, *parent, *tmp;
while (!list_empty(&async_shutdown_list)) {
dev = list_entry(async_shutdown_list.next, struct device,
@@ -4787,15 +4791,29 @@ static void wait_for_active_async_shutdown(void)
dev->driver->async_shutdown_end(dev);
}
device_unlock(dev);
- if (parent)
- device_unlock(parent);
-
+ if (parent) {
+ tmp = parent;
+ do {
+ tmp->p->child_shutdown = 0;
+ device_unlock(tmp);
+
+ tmp = tmp->parent;
+ if (!tmp || !tmp->p->child_shutdown)
+ break;
+ device_lock(tmp);
+ } while (1);
+ }
put_device(dev);
put_device(parent);
}
if (initcall_debug)
printk(KERN_INFO "device shutdown: waited for %d async shutdown callbacks\n", async_shutdown_count);
+
async_shutdown_count = 0;
+ spin_lock(&devices_kset->list_lock);
+ list_splice_tail_init(&async_delayed_list, &devices_kset->list);
+ spin_unlock(&devices_kset->list_lock);
+
}
/**
@@ -4810,7 +4828,7 @@ void device_shutdown(void)
device_block_probing();
cpufreq_suspend();
-
+restart:
spin_lock(&devices_kset->list_lock);
/*
* Walk the devices list backward, shutting down each in turn.
@@ -4832,12 +4850,15 @@ void device_shutdown(void)
get_device(dev);
if (!may_shutdown_device(dev)) {
+ list_move(&dev->kobj.entry, &async_delayed_list);
+ if (parent) {
+ device_lock(parent);
+ parent->p->child_shutdown = 1;
+ device_unlock(parent);
+ }
+
put_device(dev);
put_device(parent);
-
- spin_unlock(&devices_kset->list_lock);
- wait_for_active_async_shutdown();
- spin_lock(&devices_kset->list_lock);
continue;
}
@@ -4863,14 +4884,16 @@ void device_shutdown(void)
dev->class->shutdown_pre(dev);
}
if (dev->bus && dev->bus->async_shutdown_start) {
- async_shutdown_start(dev, dev->bus->async_shutdown_start);
+ async_shutdown_start(dev,
+ dev->bus->async_shutdown_start);
async_busy = true;
} else if (dev->bus && dev->bus->shutdown) {
if (initcall_debug)
dev_info(dev, "shutdown\n");
dev->bus->shutdown(dev);
} else if (dev->driver && dev->driver->async_shutdown_start) {
- async_shutdown_start(dev, dev->driver->async_shutdown_start);
+ async_shutdown_start(dev,
+ dev->driver->async_shutdown_start);
async_busy = true;
} else if (dev->driver && dev->driver->shutdown) {
if (initcall_debug)
@@ -4891,14 +4914,22 @@ void device_shutdown(void)
put_device(parent);
}
+ if (async_shutdown_count == MAX_ASYNC_SHUTDOWNS)
+ wait_for_active_async_shutdown();
+
spin_lock(&devices_kset->list_lock);
}
spin_unlock(&devices_kset->list_lock);
/*
- * Wait for any async shutdown still running.
+ * Wait for any async shutdown still running, then restart the loop
+ * if the list is no longer empty from delayed entries returning to
+ * the list.
*/
if (!list_empty(&async_shutdown_list))
wait_for_active_async_shutdown();
+
+ if(!list_empty(&devices_kset->list))
+ goto restart;
}
/*
--
2.43.0
next prev parent reply other threads:[~2024-02-07 18:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 18:40 [RFC PATCH 0/6] async device shutdown support David Jeffery
2024-02-07 18:40 ` [RFC PATCH 1/6] minimal async shutdown infrastructure David Jeffery
2024-02-14 3:42 ` Saravana Kannan
2024-02-14 20:55 ` David Jeffery
2024-02-07 18:40 ` David Jeffery [this message]
2024-02-07 18:40 ` [RFC PATCH 3/6] pci bus async shutdown support David Jeffery
2024-02-07 18:40 ` [RFC PATCH 4/6] pci nvme " David Jeffery
2024-02-07 18:40 ` [RFC PATCH 5/6] scsi mid layer support for async command submit David Jeffery
2024-02-07 18:41 ` [RFC PATCH 6/6] sd: async cache flush on shutdown David Jeffery
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=20240207184100.18066-3-djeffery@redhat.com \
--to=djeffery@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=loberman@redhat.com \
--cc=rafael@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®