Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1159811 > unrolled thread

[PATCH v2 1/3] watchdog_core: Add watchdog registration deferral mechanism

Started byJean-Baptiste Theou <jtheou@adeneo-embedded.us>
First post2015-06-06 03:50 +0200
Last post2015-06-06 03:50 +0200
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH v2 1/3] watchdog_core: Add watchdog registration deferral mechanism Jean-Baptiste Theou <jtheou@adeneo-embedded.us> - 2015-06-06 03:50 +0200
    [PATCH v2 2/3] watchdog-kernel-api: Add registration deferral mechanism Jean-Baptiste Theou <jtheou@adeneo-embedded.us> - 2015-06-06 03:50 +0200
    [PATCH v2 3/3] gpio_wdt: Add option for early registration Jean-Baptiste Theou <jtheou@adeneo-embedded.us> - 2015-06-06 03:50 +0200

#1159811 — [PATCH v2 1/3] watchdog_core: Add watchdog registration deferral mechanism

FromJean-Baptiste Theou <jtheou@adeneo-embedded.us>
Date2015-06-06 03:50 +0200
Subject[PATCH v2 1/3] watchdog_core: Add watchdog registration deferral mechanism
Message-ID<pybpg-1Wz-3@gated-at.bofh.it>
Currently, watchdog subsystem require the misc subsystem to
register a watchdog. This may not be the case in case of an
early registration of a watchdog, which can be required when
the watchdog cannot be disabled.

This patch use deferral mechanism to remove this requirement.

Signed-off-by: Jean-Baptiste Theou <jtheou@adeneo-embedded.us>
---
 drivers/watchdog/watchdog_core.c | 92 ++++++++++++++++++++++++++++++++++++++--
 include/linux/watchdog.h         |  3 ++
 2 files changed, 91 insertions(+), 4 deletions(-)

diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index cec9b55..edf6294 100644
--- a/drivers/watchdog/watchdog_core.c
+++ b/drivers/watchdog/watchdog_core.c
@@ -43,6 +43,41 @@
 static DEFINE_IDA(watchdog_ida);
 static struct class *watchdog_class;
 
+/*
+ * Deferred Registration infrastructure.
+ *
+ * Sometimes watchdog drivers need to be loaded as soon as possible,
+ * for example when it's impossible to disable it. To do so,
+ * raising the initcall level of the watchdog driver is a solution.
+ * But in such case, the miscdev is maybe not ready (subsys_initcall), and
+ * watchdog core need miscdev to be populate.
+ *
+ * The deferred registration infrastructure offer a way for the watchdog
+ * subsystem to register a watchdog properly, even before miscdev is ready
+ *
+ * This is based on driver probe deferral mechanism.
+ */
+
+static DEFINE_MUTEX(watchdog_deferred_registration_mutex);
+static LIST_HEAD(watchdog_deferred_registration_pending_list);
+static bool watchdog_deferred_registration_done;
+
+static int watchdog_deferred_registration_add(struct watchdog_device *wdd)
+{
+	dev_dbg(wdd->dev, "Added to deferred list\n");
+	list_add(&wdd->deferred_registration,
+		 &watchdog_deferred_registration_pending_list);
+	return 0;
+}
+
+static void watchdog_deferred_registration_del(struct watchdog_device *wdd)
+{
+	if (!list_empty(&wdd->deferred_registration)) {
+		dev_dbg(wdd->dev, "Removed from deferred list\n");
+		list_del_init(&wdd->deferred_registration);
+	}
+}
+
 static void watchdog_check_min_max_timeout(struct watchdog_device *wdd)
 {
 	/*
@@ -99,7 +134,7 @@ int watchdog_init_timeout(struct watchdog_device *wdd,
 EXPORT_SYMBOL_GPL(watchdog_init_timeout);
 
 /**
- * watchdog_register_device() - register a watchdog device
+ * __watchdog_register_device() - register a watchdog device
  * @wdd: watchdog device
  *
  * Register a watchdog device with the kernel so that the
@@ -108,7 +143,7 @@ EXPORT_SYMBOL_GPL(watchdog_init_timeout);
  * A zero is returned on success and a negative errno code for
  * failure.
  */
-int watchdog_register_device(struct watchdog_device *wdd)
+int __watchdog_register_device(struct watchdog_device *wdd)
 {
 	int ret, id, devno;
 
@@ -164,16 +199,35 @@ int watchdog_register_device(struct watchdog_device *wdd)
 
 	return 0;
 }
+
+/*
+ * watchdog_register_device use either the deferred approach,
+ * or directly register the watchdog, depending on the current
+ * initcall level.
+ */
+
+int watchdog_register_device(struct watchdog_device *wdd)
+{
+	int ret;
+
+	mutex_lock(&watchdog_deferred_registration_mutex);
+	if (watchdog_deferred_registration_done)
+		ret = __watchdog_register_device(wdd);
+	else
+		ret = watchdog_deferred_registration_add(wdd);
+	mutex_unlock(&watchdog_deferred_registration_mutex);
+	return ret;
+}
 EXPORT_SYMBOL_GPL(watchdog_register_device);
 
 /**
- * watchdog_unregister_device() - unregister a watchdog device
+ * __watchdog_unregister_device() - unregister a watchdog device
  * @wdd: watchdog device to unregister
  *
  * Unregister a watchdog device that was previously successfully
  * registered with watchdog_register_device().
  */
-void watchdog_unregister_device(struct watchdog_device *wdd)
+void __watchdog_unregister_device(struct watchdog_device *wdd)
 {
 	int ret;
 	int devno;
@@ -189,8 +243,37 @@ void watchdog_unregister_device(struct watchdog_device *wdd)
 	ida_simple_remove(&watchdog_ida, wdd->id);
 	wdd->dev = NULL;
 }
+
+void watchdog_unregister_device(struct watchdog_device *wdd)
+{
+	mutex_lock(&watchdog_deferred_registration_mutex);
+	if (watchdog_deferred_registration_done)
+		__watchdog_unregister_device(wdd);
+	else
+		watchdog_deferred_registration_del(wdd);
+	mutex_unlock(&watchdog_deferred_registration_mutex);
+}
+
 EXPORT_SYMBOL_GPL(watchdog_unregister_device);
 
+/**
+ * watchdog_deferred_registration_initcall() - Register queued watchdog
+ */
+static int watchdog_deferred_registration_initcall(void)
+{
+	mutex_lock(&watchdog_deferred_registration_mutex);
+	watchdog_deferred_registration_done = true;
+	while (!list_empty(&watchdog_deferred_registration_pending_list)) {
+		struct watchdog_device *wdd = list_first_entry(&watchdog_deferred_registration_pending_list,
+							       struct watchdog_device, deferred_registration);
+		list_del_init(&wdd->deferred_registration);
+		__watchdog_register_device(wdd);
+	}
+	mutex_unlock(&watchdog_deferred_registration_mutex);
+	return 0;
+}
+late_initcall(watchdog_deferred_registration_initcall);
+
 static int __init watchdog_init(void)
 {
 	int err;
@@ -222,5 +305,6 @@ module_exit(watchdog_exit);
 
 MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
 MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
+MODULE_AUTHOR("Jean-Baptiste Theou <jbtheou@gmail.com>");
 MODULE_DESCRIPTION("WatchDog Timer Driver Core");
 MODULE_LICENSE("GPL");
diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h
index a746bf5..fcc190e 100644
--- a/include/linux/watchdog.h
+++ b/include/linux/watchdog.h
@@ -65,6 +65,8 @@ struct watchdog_ops {
  * @driver-data:Pointer to the drivers private data.
  * @lock:	Lock for watchdog core internal use only.
  * @status:	Field that contains the devices internal status bits.
+ * @deferred_registration: entry in deferred_registration_list which is used to
+ *			   register early initialized watchdog.
  *
  * The watchdog_device structure contains all information about a
  * watchdog timer device.
@@ -95,6 +97,7 @@ struct watchdog_device {
 #define WDOG_ALLOW_RELEASE	2	/* Did we receive the magic char ? */
 #define WDOG_NO_WAY_OUT		3	/* Is 'nowayout' feature set ? */
 #define WDOG_UNREGISTERED	4	/* Has the device been unregistered */
+	struct list_head deferred_registration;
 };
 
 #define WATCHDOG_NOWAYOUT		IS_BUILTIN(CONFIG_WATCHDOG_NOWAYOUT)
-- 
2.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1159813 — [PATCH v2 2/3] watchdog-kernel-api: Add registration deferral mechanism

FromJean-Baptiste Theou <jtheou@adeneo-embedded.us>
Date2015-06-06 03:50 +0200
Subject[PATCH v2 2/3] watchdog-kernel-api: Add registration deferral mechanism
Message-ID<pybpg-1Wz-5@gated-at.bofh.it>
In reply to#1159811
Add registration deferral mechanism capability information

Signed-off-by: Jean-Baptiste Theou <jtheou@adeneo-embedded.us>
---
 Documentation/watchdog/watchdog-kernel-api.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/watchdog/watchdog-kernel-api.txt b/Documentation/watchdog/watchdog-kernel-api.txt
index a0438f3..11c988b 100644
--- a/Documentation/watchdog/watchdog-kernel-api.txt
+++ b/Documentation/watchdog/watchdog-kernel-api.txt
@@ -36,6 +36,10 @@ The watchdog_unregister_device routine deregisters a registered watchdog timer
 device. The parameter of this routine is the pointer to the registered
 watchdog_device structure.
 
+The watchdog subsystem contain an registration deferral mechanism,
+which allow you to register an watchdog as early as you wish during
+the boot process, in the situation of a built-in module.
+
 The watchdog device structure looks like this:
 
 struct watchdog_device {
-- 
2.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1159814 — [PATCH v2 3/3] gpio_wdt: Add option for early registration

FromJean-Baptiste Theou <jtheou@adeneo-embedded.us>
Date2015-06-06 03:50 +0200
Subject[PATCH v2 3/3] gpio_wdt: Add option for early registration
Message-ID<pybpg-1Wz-7@gated-at.bofh.it>
In reply to#1159811
In some situation, mainly when it's not possible to disable a
watchdog, you may want the watchdog driver to be started as soon
as possible.

Adding GPIO_WATCHDOG_ARCH_INITCALL to raise initcall from
module_init to arch_initcall. This is only for a built-in
module.

This patch require watchdog registration deferral mechanism

Signed-off-by: Jean-Baptiste Theou <jtheou@adeneo-embedded.us>
---
 drivers/watchdog/Kconfig    | 14 ++++++++++++++
 drivers/watchdog/gpio_wdt.c | 13 +++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index e5e7c55..a9655a9 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1,3 +1,4 @@
+
 #
 # Watchdog device configuration
 #
@@ -114,6 +115,19 @@ config MENF21BMC_WATCHDOG
 	  This driver can also be built as a module. If so the module
 	  will be called menf21bmc_wdt.
 
+config GPIO_WATCHDOG_ARCH_INITCALL
+	bool "Register the watchdog as early as possible"
+	depends on GPIO_WATCHDOG
+	help
+	  This option make sense only on a built-in situation.
+
+	  In some situation, the default initcall level (module_init)
+	  in not early enough on the boot process to avoid the watchdog
+	  to be trigger.
+	  If you say yes here, the initcall level would be raise to
+	  arch_initcall.
+	  "If in doubt, leave it out" - say N.
+
 config WM831X_WATCHDOG
 	tristate "WM831x watchdog"
 	depends on MFD_WM831X
diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c
index cbc313d..07a39cd 100644
--- a/drivers/watchdog/gpio_wdt.c
+++ b/drivers/watchdog/gpio_wdt.c
@@ -267,8 +267,21 @@ static struct platform_driver gpio_wdt_driver = {
 	.probe	= gpio_wdt_probe,
 	.remove	= gpio_wdt_remove,
 };
+#ifndef GPIO_WATCHDOG_ARCH_INITCALL
 module_platform_driver(gpio_wdt_driver);
+#else
+static int __init gpio_wdt_init(void)
+{
+	return platform_driver_register(&gpio_wdt_driver);
+}
+arch_initcall(gpio_wdt_init);
 
+static void __exit gpio_wdt_exit(void)
+{
+	platform_driver_unregister(&gpio_wdt_driver);
+}
+module_exit(gpio_wdt_exit);
+#endif
 MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
 MODULE_DESCRIPTION("GPIO Watchdog");
 MODULE_LICENSE("GPL");
-- 
2.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web