Skip to contentSkip to conversation

watchdog: Sysfs status read support

PATCH Superseded Pratyush Anand 2 participants 6 messages Sep 7, 2015 – Nov 16, 2015

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#2 lore raw

PATCH v4 2/2 watchdog: Read device status through sysfs attributes

In reply to Pratyush Anand

This patch adds following attributes to watchdog device's sysfs interface to read its different status.

* state - reads whether device is active or not
* identity - reads Watchdog device's identity string.
* timeout - reads current timeout.
* timeleft - reads timeleft before watchdog generates a reset
* bootstatus - reads status of the watchdog device at boot
* status - reads watchdog device's internal status bits
* nowayout - reads whether nowayout feature was set or not

Testing with iTCO_wdt:

 # cd /sys/class/watchdog/watchdog1/
 # ls
bootstatus  dev  device  identity  nowayout  power  state
subsystem  timeleft  timeout  uevent
 # cat identity
iTCO_wdt
 # cat timeout
30
 # cat state
inactive
 # echo > /dev/watchdog1
 # cat timeleft
26
 # cat state
active
 # cat bootstatus
0
 # cat nowayout
0
---
 Documentation/ABI/testing/sysfs-class-watchdog |  51 ++++++++++++
 drivers/watchdog/watchdog_core.c               |   2 +-
 drivers/watchdog/watchdog_dev.c                | 110 +++++++++++++++++++++++++
 3 files changed, 162 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog
Documentation/ABI/testing/sysfs-class-watchdog new file +51 -0
new file mode 100644
index 000000000000..736046b33040
@@ -0,0 +1,51 @@
+What:		/sys/class/watchdog/watchdogn/bootstatus
+Date:		August 2015
+Contact:	Wim Van Sebroeck <[email protected]>
+Description:
+		It is a read only file. It contains status of the watchdog
+		device at boot. It is equivalent to WDIOC_GETBOOTSTATUS of
+		ioctl interface.
+
+What:		/sys/class/watchdog/watchdogn/identity
+Date:		August 2015
+Contact:	Wim Van Sebroeck <[email protected]>
+Description:
+		It is a read only file. It contains identity string of
+		watchdog device.
+
+What:		/sys/class/watchdog/watchdogn/nowayout
+Date:		August 2015
+Contact:	Wim Van Sebroeck <[email protected]>
+Description:
+		It is a read only file. While reading, it gives '1' if that
+		device supports nowayout feature else, it gives '0'.
+
+What:		/sys/class/watchdog/watchdogn/state
+Date:		August 2015
+Contact:	Wim Van Sebroeck <[email protected]>
+Description:
+		It is a read only file. It gives active/inactive status of
+		watchdog device.
+
+What:		/sys/class/watchdog/watchdogn/status
+Date:		August 2015
+Contact:	Wim Van Sebroeck <[email protected]>
+Description:
+		It is a read only file. It contains watchdog device's
+		internal status bits. It is equivalent to WDIOC_GETSTATUS
+		of ioctl interface.
+
+What:		/sys/class/watchdog/watchdogn/timeleft
+Date:		August 2015
+Contact:	Wim Van Sebroeck <[email protected]>
+Description:
+		It is a read only file. It contains value of time left for
+		reset generation. It is equivalent to WDIOC_GETTIMELEFT of
+		ioctl interface.
+
+What:		/sys/class/watchdog/watchdogn/timeout
+Date:		August 2015
+Contact:	Wim Van Sebroeck <[email protected]>
+Description:
+		It is a read only file. It is read to know about current
+		value of timeout programmed.
drivers/watchdog/watchdog_core.c +1 -1
index 47d38c5c3f9a..62666f021762 100644
@@ -183,7 +183,7 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
 
 	devno = wdd->cdev.dev;
 	wdd->dev = device_create(watchdog_class, wdd->parent, devno,
-					NULL, "watchdog%d", wdd->id);
+					wdd, "watchdog%d", wdd->id);
 	if (IS_ERR(wdd->dev)) {
 		watchdog_dev_unregister(wdd);
 		ida_simple_remove(&watchdog_ida, id);
drivers/watchdog/watchdog_dev.c +110 -0

122 lines not on this page · raw message

Signature · 1 line
2.5.0
#0 lore raw

v4 cover watchdog: Sysfs status read support

These patches provide support to read different watchdog device status through sysfs interface.

Changes since V3:
* Added Reviewed by tag
* Corrected a checkpatch warning

Changes since V2:
* Used static struct class watchdog_class in stead of pointer. It helped in keep using device_create().
* Above logic was moved to a separate patch.
* Changed subject line of other patch to look more relevant

Changes since V1(RFC):
* Removed keepalive and start ABI
* timeout is read only now
* state returns text
* only supported ABI visible
* ABI contact changed to MAINTAINER
* unnecessary mutex removed
* aligned continuation with '('
* unnecessary initialization of status (= 0) corrected
* unnecessary else removed
* used __ATTRIBUTE_GROUPS
* removed watchdog_device_create and added functionality in
* watchdog_dev_register.
* optimized nowayout_show
* Now no -EOPNOTSUPP return for timeout read in case of wdd->timeout = 0.

Pratyush Anand (2):
watchdog: Use static struct class watchdog_class in stead of pointer
watchdog: Read device status through sysfs attributes

 Documentation/ABI/testing/sysfs-class-watchdog |  51 ++++++++++
 drivers/watchdog/watchdog_core.c               |  17 +---
 drivers/watchdog/watchdog_core.h               |   2 +-
 drivers/watchdog/watchdog_dev.c                | 136 ++++++++++++++++++++++++-
 4 files changed, 187 insertions(+), 19 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog
Signature · 1 line
2.5.0
#1 lore raw

PATCH v4 1/2 watchdog: Use static struct class watchdog_class in stead of pointer

We need few sysfs attributes to know different status of a watchdog device. To do that, we need to associate .dev_groups with watchdog_class. So convert it from pointer to static.
Putting this static struct in watchdog_dev.c, so that static device attributes defined in that file can be attached to it.

---
 drivers/watchdog/watchdog_core.c | 15 ++-------------
 drivers/watchdog/watchdog_core.h |  2 +-
 drivers/watchdog/watchdog_dev.c  | 26 ++++++++++++++++++++++----
 3 files changed, 25 insertions(+), 18 deletions(-)
drivers/watchdog/watchdog_core.c +2 -13
index 1a8059455413..47d38c5c3f9a 100644
@@ -274,19 +274,9 @@ static int __init watchdog_deferred_registration(void)
 
 static int __init watchdog_init(void)
 {
-	int err;
-
-	watchdog_class = class_create(THIS_MODULE, "watchdog");
-	if (IS_ERR(watchdog_class)) {
-		pr_err("couldn't create class\n");
+	watchdog_class = watchdog_dev_init();
+	if (IS_ERR(watchdog_class))
 		return PTR_ERR(watchdog_class);
-	}
-
-	err = watchdog_dev_init();
-	if (err < 0) {
-		class_destroy(watchdog_class);
-		return err;
-	}
 
 	watchdog_deferred_registration();
 	return 0;
@@ -295,7 +285,6 @@ static int __init watchdog_init(void)
 static void __exit watchdog_exit(void)
 {
 	watchdog_dev_exit();
-	class_destroy(watchdog_class);
 	ida_destroy(&watchdog_ida);
 }
 
drivers/watchdog/watchdog_core.h +1 -1
index 6c951418fca7..1c8d6b0e68c7 100644
@@ -33,5 +33,5 @@
  */
 extern int watchdog_dev_register(struct watchdog_device *);
 extern int watchdog_dev_unregister(struct watchdog_device *);
-extern int __init watchdog_dev_init(void);
+extern struct class * __init watchdog_dev_init(void);
 extern void __exit watchdog_dev_exit(void);
drivers/watchdog/watchdog_dev.c +22 -4
index 6aaefbad303e..986282d44b90 100644
@@ -578,18 +578,35 @@ int watchdog_dev_unregister(struct watchdog_device *watchdog)
 	return 0;
 }
 
+static struct class watchdog_class = {
+	.name =		"watchdog",
+	.owner =	THIS_MODULE,
+};
+
 /*
  *	watchdog_dev_init: init dev part of watchdog core
  *
  *	Allocate a range of chardev nodes to use for watchdog devices
  */
 
-int __init watchdog_dev_init(void)
+struct class * __init watchdog_dev_init(void)
 {
-	int err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog");
-	if (err < 0)
+	int err;
+
+	err = class_register(&watchdog_class);
+	if (err < 0) {
+		pr_err("couldn't register class\n");
+		return ERR_PTR(err);
+	}
+
+	err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog");
+	if (err < 0) {
 		pr_err("watchdog: unable to allocate char dev region\n");
-	return err;
+		class_unregister(&watchdog_class);
+		return ERR_PTR(err);
+	}
+
+	return &watchdog_class;
 }
 
 /*
@@ -601,4 +618,5 @@ int __init watchdog_dev_init(void)
 void __exit watchdog_dev_exit(void)
 {
 	unregister_chrdev_region(watchdog_devt, MAX_DOGS);
+	class_unregister(&watchdog_class);
 }
Signature · 1 line
2.5.0
#3 lore raw
In reply to Pratyush Anand

Hi Wim,

I did not see it in v4.3-rc3 Fixes.
This has already been reviewed by Guenter.
Please let me know if I need to do anything more around it.

~Pratyush

Quoted 42 lines · Pratyush Anand

These patches provide support to read different watchdog device status through sysfs interface.

Changes since V3:
* Added Reviewed by tag
* Corrected a checkpatch warning

Changes since V2:
* Used static struct class watchdog_class in stead of pointer. It helped in keep using device_create().
* Above logic was moved to a separate patch.
* Changed subject line of other patch to look more relevant

Changes since V1(RFC):
* Removed keepalive and start ABI
* timeout is read only now
* state returns text
* only supported ABI visible
* ABI contact changed to MAINTAINER
* unnecessary mutex removed
* aligned continuation with '('
* unnecessary initialization of status (= 0) corrected
* unnecessary else removed
* used __ATTRIBUTE_GROUPS
* removed watchdog_device_create and added functionality in
* watchdog_dev_register.
* optimized nowayout_show
* Now no -EOPNOTSUPP return for timeout read in case of wdd->timeout = 0.

Pratyush Anand (2):
watchdog: Use static struct class watchdog_class in stead of pointer
watchdog: Read device status through sysfs attributes

 Documentation/ABI/testing/sysfs-class-watchdog |  51 ++++++++++
 drivers/watchdog/watchdog_core.c               |  17 +---
 drivers/watchdog/watchdog_core.h               |   2 +-
 drivers/watchdog/watchdog_dev.c                | 136 ++++++++++++++++++++++++-
 4 files changed, 187 insertions(+), 19 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog
Signature · 1 line
2.5.0
maintainer
#4 lore raw
Quoted 6 lines · Pratyush Anand

Hi Wim,

I did not see it in v4.3-rc3 Fixes.
This has already been reviewed by Guenter.
Please let me know if I need to do anything more around it.

It is too late for 4.3, so I guess it will have to wait for 4.4.

Guenter

Quoted 46 lines

~Pratyush

Quoted 42 lines · Pratyush Anand

These patches provide support to read different watchdog device status through sysfs interface.

Changes since V3:
* Added Reviewed by tag
* Corrected a checkpatch warning

Changes since V2:
* Used static struct class watchdog_class in stead of pointer. It helped in keep using device_create().
* Above logic was moved to a separate patch.
* Changed subject line of other patch to look more relevant

Changes since V1(RFC):
* Removed keepalive and start ABI
* timeout is read only now
* state returns text
* only supported ABI visible
* ABI contact changed to MAINTAINER
* unnecessary mutex removed
* aligned continuation with '('
* unnecessary initialization of status (= 0) corrected
* unnecessary else removed
* used __ATTRIBUTE_GROUPS
* removed watchdog_device_create and added functionality in
* watchdog_dev_register.
* optimized nowayout_show
* Now no -EOPNOTSUPP return for timeout read in case of wdd->timeout = 0.

Pratyush Anand (2):
watchdog: Use static struct class watchdog_class in stead of pointer
watchdog: Read device status through sysfs attributes

  Documentation/ABI/testing/sysfs-class-watchdog |  51 ++++++++++
  drivers/watchdog/watchdog_core.c               |  17 +---
  drivers/watchdog/watchdog_core.h               |   2 +-
  drivers/watchdog/watchdog_dev.c                | 136 ++++++++++++++++++++++++-
  4 files changed, 187 insertions(+), 19 deletions(-)

create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog

--
2.5.0

#5 lore raw

Hi Wim,

Quoted 8 lines · Guenter Roeck
Quoted 6 lines · Pratyush Anand

Hi Wim,

I did not see it in v4.3-rc3 Fixes.
This has already been reviewed by Guenter.
Please let me know if I need to do anything more around it.

It is too late for 4.3, so I guess it will have to wait for 4.4.

I do not see it in git://www.linux-watchdog.org/linux-watchdog : master

Please pick it, so that it is not missed in 4.4

~Pratyush