mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: ning.a.zhang@intel.com
To: gregkh@linuxfoundation.org, rafael.j.wysocki@intel.com,
	dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org
Cc: mark.gross@intel.com, Zhang Ning <ning.a.zhang@intel.com>
Subject: [PATCH] driver core: support bus manage deferred probe
Date: Fri, 29 Jun 2018 15:02:26 +0800	[thread overview]
Message-ID: <20180629070226.24506-1-ning.a.zhang@intel.com> (raw)

From: Zhang Ning <ning.a.zhang@intel.com>

deferred probe will be hanlded by deferred_probe_initcall,
starts at late_initcall.

this is too late to handle deferred probe, this will block kernel exec
to userspace, make kernel initial time longer.

if we know when required resources are ready for a list of devices,
related deferred drivers can be probe earlier.

add these kinds of drivers into logical list,
eg, bus_type->deferred_probe_pending_list,
then it can be easily handled by bus driver.

with analysis above:
add manage_deferred to struct bus_type
add deferred_probe_pending_list to struct bus_type

when manage_deferred is true, deferred probe will be
manage by bus.

Signed-off-by: Zhang Ning <ning.a.zhang@intel.com>
---
 drivers/base/bus.c     |  3 ++-
 drivers/base/dd.c      | 24 +++++++++++++++++-------
 include/linux/device.h |  5 +++++
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 8bfd27ec73d6..ca8eaf7565db 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -898,7 +898,8 @@ int bus_register(struct bus_type *bus)
 	retval = bus_add_groups(bus, bus->bus_groups);
 	if (retval)
 		goto bus_groups_fail;
-
+	if (bus->manage_deferred)
+		INIT_LIST_HEAD(&bus->deferred_probe_pending_list);
 	pr_debug("bus: '%s': registered\n", bus->name);
 	return 0;
 
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 1435d7281c66..926e57f8dd2f 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -82,10 +82,8 @@ static void deferred_probe_debug(struct device *dev)
 	       dev_name(dev), duration);
 }
 
-/*
- * deferred_probe_work_func() - Retry probing devices in the active list.
- */
-static void deferred_probe_work_func(struct work_struct *work)
+
+void process_deferred_probe(struct list_head *list)
 {
 	struct device *dev;
 	struct device_private *private;
@@ -102,8 +100,8 @@ static void deferred_probe_work_func(struct work_struct *work)
 	 * from under our feet.
 	 */
 	mutex_lock(&deferred_probe_mutex);
-	while (!list_empty(&deferred_probe_active_list)) {
-		private = list_first_entry(&deferred_probe_active_list,
+	while (!list_empty(list)) {
+		private = list_first_entry(list,
 					typeof(*dev->p), deferred_probe);
 		dev = private->device;
 		list_del_init(&private->deferred_probe);
@@ -136,6 +134,15 @@ static void deferred_probe_work_func(struct work_struct *work)
 	}
 	mutex_unlock(&deferred_probe_mutex);
 }
+
+/*
+ * deferred_probe_work_func() - Retry probing devices in the active list.
+ */
+static void deferred_probe_work_func(struct work_struct *work)
+{
+	process_deferred_probe(&deferred_probe_active_list);
+}
+
 static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
 
 static void driver_deferred_probe_add(struct device *dev)
@@ -143,7 +150,10 @@ static void driver_deferred_probe_add(struct device *dev)
 	mutex_lock(&deferred_probe_mutex);
 	if (list_empty(&dev->p->deferred_probe)) {
 		dev_dbg(dev, "Added to deferred list\n");
-		list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list);
+		if (dev->bus->manage_deferred)
+			list_add_tail(&dev->p->deferred_probe, &dev->bus->deferred_probe_pending_list);
+		else
+			list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list);
 	}
 	mutex_unlock(&deferred_probe_mutex);
 }
diff --git a/include/linux/device.h b/include/linux/device.h
index 055a69dbcd18..2f70f3124d18 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -143,6 +143,9 @@ struct bus_type {
 	struct lock_class_key lock_key;
 
 	bool need_parent_lock;
+
+	bool manage_deferred;
+	struct list_head deferred_probe_pending_list;
 };
 
 extern int __must_check bus_register(struct bus_type *bus);
@@ -151,6 +154,8 @@ extern void bus_unregister(struct bus_type *bus);
 
 extern int __must_check bus_rescan_devices(struct bus_type *bus);
 
+extern void process_deferred_probe(struct list_head *list);
+
 /* iterator helpers for buses */
 struct subsys_dev_iter {
 	struct klist_iter		ki;
-- 
2.17.1


             reply	other threads:[~2018-06-29  7:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-29  7:02 ning.a.zhang [this message]
2018-06-29 10:56 ` kbuild test robot
2018-07-18 17:16 ` Dmitry Torokhov

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=20180629070226.24506-1-ning.a.zhang@intel.com \
    --to=ning.a.zhang@intel.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.gross@intel.com \
    --cc=rafael.j.wysocki@intel.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

all inboxes | Powered by JetHome®