linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qing Huang <qing.huang@oracle.com>
To: linux-kernel@vger.kernel.org
Cc: Qing Huang <qing.huang@oracle.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Grant Likely <grant.likely@linaro.org>,
	Santosh Shilimkar <santosh.shilimkar@oracle.com>
Subject: [PATCH] device probe: add self triggered delayed work request
Date: Fri, 29 Jul 2016 22:39:39 -0700	[thread overview]
Message-ID: <1469857179-23863-1-git-send-email-qing.huang@oracle.com> (raw)

In normal condition, the device probe requests kept in deferred
queue would only be triggered for re-probing when another new device
probe is finished successfully. This change will set up a delayed
trigger work request if the current deferred probe being added is
the only one in the queue. This delayed work request will try to
reactivate any device from the deferred queue for re-probing later.

By doing this, if the last device being probed in system boot process
has a deferred probe error, this particular device will still be able
to be probed again.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: Qing Huang <qing.huang@oracle.com>
---
 drivers/base/dd.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 16688f5..251042d 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -53,6 +53,9 @@ static LIST_HEAD(deferred_probe_pending_list);
 static LIST_HEAD(deferred_probe_active_list);
 static struct workqueue_struct *deferred_wq;
 static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
+static atomic_t deferred_self_trigger_count = ATOMIC_INIT(0);
+#define DEFERRED_SELF_TRIGGER_INTERVAL 30 /* 30 secs */
+#define DEFERRED_SELF_TRIGGER_ATTEMPTS 5  /* 5 times */
 
 /*
  * In some cases, like suspend to RAM or hibernation, It might be reasonable
@@ -115,10 +118,23 @@ static void deferred_probe_work_func(struct work_struct *work)
 	mutex_unlock(&deferred_probe_mutex);
 }
 static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
+void driver_deferred_probe_trigger_wrapper(struct work_struct *work);
+static DECLARE_DELAYED_WORK(deferred_probe_trigger_work,
+			    driver_deferred_probe_trigger_wrapper);
 
 static void driver_deferred_probe_add(struct device *dev)
 {
+	int local_self_trigger_count;
+
 	mutex_lock(&deferred_probe_mutex);
+	local_self_trigger_count = atomic_read(&deferred_self_trigger_count);
+	if (list_empty(&deferred_probe_pending_list) &&
+	    local_self_trigger_count <= DEFERRED_SELF_TRIGGER_ATTEMPTS) {
+		cancel_delayed_work(&deferred_probe_trigger_work);
+		queue_delayed_work(deferred_wq, &deferred_probe_trigger_work,
+				   HZ * DEFERRED_SELF_TRIGGER_INTERVAL);
+	}
+
 	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);
@@ -202,6 +218,15 @@ void device_unblock_probing(void)
 	driver_deferred_probe_trigger();
 }
 
+/*
+ * Wrapper function for delayed trigger work requests
+ */
+void driver_deferred_probe_trigger_wrapper(struct work_struct *work)
+{
+	atomic_inc(&deferred_self_trigger_count);
+	driver_deferred_probe_trigger();
+}
+
 /**
  * deferred_probe_initcall() - Enable probing of deferred devices
  *
-- 
1.7.1

             reply	other threads:[~2016-07-30  5:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-30  5:39 Qing Huang [this message]
2016-08-08 20:44 ` [PATCH] device probe: add self triggered delayed work request Frank Rowand
2016-08-08 21:51   ` Qing Huang
2016-08-09  1:11     ` Frank Rowand
2016-08-09  1:15       ` Santosh Shilimkar
2016-08-09  7:16         ` Frank Rowand
  -- strict thread matches above, loose matches on Subject: below --
2016-08-08 10:42 Shamir Rabinovitch
2016-08-09  0:10 ` Qing Huang
2016-08-09 10:11   ` Shamir Rabinovitch
2016-08-09 20:57     ` Qing Huang

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=1469857179-23863-1-git-send-email-qing.huang@oracle.com \
    --to=qing.huang@oracle.com \
    --cc=grant.likely@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=santosh.shilimkar@oracle.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).