Skip to contentSkip to conversation

Watchdog device class

RFC In review Rudolf Marek 6 participants 15 messages Apr 17, 2006 – Sep 14, 2006 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

RFC 1/1 Watchdog device class

Hello all,

I wanted to create a watchdog driver for I2C W83792D chip and I realized that there is no clean way how to connect the existing I2C device driver with the watchdog ops. As the consequence of this I created new watchdog device class.

This class supports all common infrastructure such as char device handling, sysfs exports and even the infrastructure for too fast watchdogs (the self ping feature). The class is based on the RTC class which is fairly similar in some aspects.

The char device of watchdog class is compatible with existing watchdog API, so no need to change the user applications. There is just one exception and this is temperature handling. I belive it should be implemented not via IOCTL but using the HWMON class. (100% compatibility can be restored with the ioctl class op)

I have defined this class ops so far:

struct watchdog_class_ops {
	int (*enable)(struct device *);
	int (*disable)(struct device *);
	int (*ping)(struct device *);
	int (*set_timeout)(struct device *, int sec);
	int (*notify_reboot)(struct notifier_block *this, unsigned long code,
	        void *unused);
};

Each instance of the class has some predefined variables for common stuff:

	int expect_close;
	int timeout;
	int nowayout;
	unsigned long status;
	unsigned long boot_status;
	/* this may be removed in the future */
	struct watchdog_info legacy_info;

For further details please ask or consult the source code.

I have attached the some code that demonstrates the class usage in softdog driver and for i2c based driver (w93792d). This code is not yet to be included, because I dont know if the class interface has all features you might think of.

So far the software watchdog works for me and also the w83792d driver, both needs more testing to be sure everything works as expected.

In a meanwhile I would like to hear the comments on the class design and interface design. This is my first kernel class so I expect that something might not be correct ;)

I know about this issues:

* I'm not sure if I'm locking the stuff correctly, please take a look
into this.
* Some lines of code exceeds the 80 collumns, codingstyle is not yet
perfect
* I created new directory for the class in drivers/watchdog, the Kconfig is only for testing, not yet full featured - help is missing, watchdog.h is local only
* The W83792D driver is to be placed in the hwmon directory in final, but it is requested for now to be in the watchdog directory.
* the w83792d driver needs improvement in the register banks handling, and watchdog integration.
* some stuff in nowayout feature is missing for w83792d (the module can be unloaded)

Please CC me, I'm not subscribed yet.

Thanks,
Regards
Rudolf

drivers/Kconfig +2 -0
diff -Naur a/drivers/Kconfig watchdog/drivers/Kconfig
@@ -74,4 +74,6 @@
 
 source "drivers/rtc/Kconfig"
 
+source "drivers/watchdog/Kconfig"
+
 endmenu
drivers/Makefile +1 -0
diff -Naur a/drivers/Makefile watchdog/drivers/Makefile
@@ -58,6 +58,7 @@
 obj-$(CONFIG_I2C)		+= i2c/
 obj-$(CONFIG_W1)		+= w1/
 obj-$(CONFIG_HWMON)		+= hwmon/
+obj-$(CONFIG_HWMON)             += watchdog/
 obj-$(CONFIG_PHONE)		+= telephony/
 obj-$(CONFIG_MD)		+= md/
 obj-$(CONFIG_BT)		+= bluetooth/
drivers/watchdog/class.c +174 -0

174 lines not on this page · raw message

drivers/watchdog/Kconfig +55 -0

55 lines not on this page · raw message

drivers/watchdog/Makefile +13 -0
diff -Naur a/drivers/watchdog/Makefile watchdog/drivers/watchdog/Makefile
@@ -0,0 +1,13 @@
+#
+# Makefile for Watchdog class/drivers.
+#
+
+obj-$(CONFIG_WATCHDOG_CLASS)		+= watchdog-core.o
+watchdog-core-y			:= class.o
+
+obj-$(CONFIG_WATCHDOG_INTF_DEV) += watchdog-dev.o
+obj-$(CONFIG_WATCHDOG_INTF_SYSFS) += watchdog-sysfs.o
+
+
+obj-$(CONFIG_WATCHDOG_DRV_SOFTDOG)	+= softdog.o
+obj-$(CONFIG_WATCHDOG_DRV_W8379X)	+= w83792d.o
drivers/watchdog/softdog.c +225 -0

225 lines not on this page · raw message

drivers/watchdog/w83792d.c +89 -3

141 lines not on this page · raw message

drivers/watchdog/watchdog-dev.c +322 -0

322 lines not on this page · raw message

drivers/watchdog/watchdog.h +139 -0

139 lines not on this page · raw message

drivers/watchdog/watchdog-sysfs.c +113 -0

113 lines not on this page · raw message

#1 lore raw
Quoted 5 lines · Rudolf Marek

The char device of watchdog class is compatible with existing watchdog API, so no need to change the user applications. There is just one exception and this is temperature handling. I belive it should be implemented not via IOCTL but using the HWMON class. (100% compatibility can be restored with the ioctl class op)

Then it should be kept.

The watchdog API simply pre-dates the sysfs world, it goes back to the 1.0-1.2 era and has remained very consistent since that time.

If you expose it in sysfs somewhere (which I think is a good idea) then the units should probably also be fixed in the sysfs case to be metric (ie Kelvin or Centigrade float values) [or scaled int]

Quoted 1 line
	int (*set_timeout)(struct device *, int sec);

Pass the usual time structures instead. Seconds is a field so it is free but it means all the signed/unsigned stuff and any future subsecond watchdogs for embedded environments don't break stuff.

Quoted 2 lines
	int (*notify_reboot)(struct notifier_block *this, unsigned long code,
	        void *unused);

Can this not use the power management callbacks from the device model instead

Quoted 2 lines
	/* this may be removed in the future */
	struct watchdog_info legacy_info;

This wants breaking out into sysfs, but again the ioctls are expected and standardised for years now.

People have talked about sorting out a watchdog helper library for years so this is overdue, and doing it with the class model in mind is even better.

Alan

#4 lore raw
In reply to Rudolf Marek
Quoted 4 lines · Rudolf Marek

I wanted to create a watchdog driver for I2C W83792D chip and I realized that there is no clean way how to connect the existing I2C device driver with the watchdog ops. As the consequence of this I created new watchdog device class.

Good, I've missed this before as well, but did have the patience to do something about it.

Wim used to have an experimental tree with a similar idea. Did you look at that before you started this? Is that tree still maintained?

drivers/watchdog/watchdog-dev.c line 25

Quoted 8 lines
drivers/watchdog/watchdog-dev.c +8 -0
+#include <linux/module.h>
+#include "watchdog.h"
+
+static struct class *watchdog_dev_class;
+static dev_t watchdog_devt;
+
+#define WATCHDOG_DEV_MAX 8 /* 8 watchdogs should be enough for everyone... */
+

What's the point in having more than one watchdog active? If you want more than one, why hardcode a specific limit?

Quoted 17 lines
drivers/watchdog/watchdog-dev.c +17 -0
+static int watchdog_dev_add_device(struct class_device *class_dev,
+                               struct class_interface *class_intf)
+{
+       int err = 0;
+       struct watchdog_device *watchdog = to_watchdog_device(class_dev);
+
+       if (watchdog->id >= WATCHDOG_DEV_MAX) {
+               dev_err(class_dev->dev, "too many watchdogs\n");
+               return -EINVAL;
+       }
+
+       mutex_init(&watchdog->char_lock);
+
+       cdev_init(&watchdog->char_dev, &watchdog_dev_fops);
+       watchdog->char_dev.owner = watchdog->owner;
+
+       if (cdev_add(&watchdog->char_dev, MKDEV(MAJOR(watchdog_devt), watchdog->id), 1)) {

drivers/watchdog/watchdog-dev.c line 237

Quoted 10 lines
drivers/watchdog/watchdog-dev.c +10 -0
+               cdev_del(&watchdog->char_dev);
+               dev_err(class_dev->dev,
+                       "failed to add char device %d:%d\n",
+                       MAJOR(watchdog_devt), watchdog->id);
+               return -ENODEV;
+       }
+
+       watchdog->watchdog_dev = class_device_create(watchdog_dev_class, NULL,
+                                               MKDEV(MAJOR(watchdog_devt), watchdog->id),
+                                               class_dev->dev, "watchdog%d", watchdog->id);

Existing user space typically depends on the watchdog device being called /dev/watchdog, which breaks if your devices are called watchdog%d. I can see two ways out of this:

1. add a udev rule that creates /dev/watchdog as an alias for /dev/watchdog0.
2. add a misc device /dev/watchdog that works as a multiplexer for all others, similar to the idea of /dev/input/mice as a multiplexer for /dev/input/mouse%d.

drivers/watchdog/watchdog.h line 88

Quoted 8 lines
drivers/watchdog/watchdog.h +8 -0
+#define WATCHDOG_DEVICE_NAME_SIZE 20
+
+struct watchdog_device {
+       struct class_device class_dev;
+       struct module *owner;
+
+       int id;
+       char name[WATCHDOG_DEVICE_NAME_SIZE];

Can this be the embedded name in class_device?

drivers/watchdog/watchdog.h line 93

Quoted 5 lines
drivers/watchdog/watchdog.h +5 -0
+
+       struct watchdog_class_ops *ops;
+       struct mutex ops_lock;
+
+       struct class_device *watchdog_dev; 

Having two classes (watchdog_class and watchdog_dev_class) as well as two class_devices (class_dev and watchdog_dev) per device seems wrong. What is the reason for splitting these?

drivers/watchdog/watchdog.h line 123

Quoted 13 lines
drivers/watchdog/watchdog.h +13 -0
+/* watchdog_device_register_simple, will register device into watchdog class
+   just with default timeout from kernel configuration.
+   
+   watchdog_device_register_selfping, will register the watchdog device same 
+   way as above function, but the device will be pinged every selfping interval
+   (useful for watchdog with damm fast timeouts)
+*/
+
+#define watchdog_device_register_simple(name, dev, ops)  \
+           _watchdog_device_register(name, dev, ops, THIS_MODULE, CONFIG_WATCHDOG_DEFAULT_TIMEOUT, 0)
+
+#define watchdog_device_register_selfping(name, dev, ops, selfping)  \
+           _watchdog_device_register(name, dev, ops, THIS_MODULE, CONFIG_WATCHDOG_DEFAULT_TIMEOUT, selfping)

All callers of this seem to have constant arguments (except dev), so you could easily put name, owner, timeout and selfping into the ops structure. Maybe the structure could use a different name then.

drivers/watchdog/watchdog-sysfs.c line 25

Quoted 5 lines
drivers/watchdog/watchdog-sysfs.c +5 -0
+static ssize_t watchdog_sysfs_show_name(struct class_device *dev, char *buf)
+{
+       return sprintf(buf, "%s\n", to_watchdog_device(dev)->name);
+}
+static CLASS_DEVICE_ATTR(name, S_IRUGO, watchdog_sysfs_show_name, NULL);

Why do you need a name attribute? Should the name of the class_device itself not be enough as an identifier?

drivers/watchdog/watchdog-sysfs.c line 113

Quoted 7 lines
drivers/watchdog/watchdog-sysfs.c +7 -0
+
+module_init(watchdog_sysfs_init);
+module_exit(watchdog_sysfs_exit);
+
+MODULE_AUTHOR("Rudolf Marek <[email protected]>");
+MODULE_DESCRIPTION("Watchdog class sysfs interface");
+MODULE_LICENSE("GPL");

What's the point in making the sysfs stuff an extra module? I guess it would be a lot simpler to just always add the files. We might want to make the dev interface optional, but then again it is what all applications to date are using, so you may just as well have a single base module and no infrastructure for multiple interfaces at all.

	Arnd <><
#2 lore raw
In reply to Alan Cox

Hello Alan,

Quoted 8 lines
Quoted 5 lines

The char device of watchdog class is compatible with existing watchdog API, so no need to change the user applications. There is just one exception and this is temperature handling. I belive it should be implemented not via IOCTL but using the HWMON class. (100% compatibility can be restored with the ioctl class op)

Then it should be kept.

Ok I think best would be to create ops->ioctl callback for not so common ioctls (like the temp one) and let the driver to deal with them.

Quoted 6 lines

The watchdog API simply pre-dates the sysfs world, it goes back to the 1.0-1.2 era and has remained very consistent since that time.

If you expose it in sysfs somewhere (which I think is a good idea) then the units should probably also be fixed in the sysfs case to be metric (ie Kelvin or Centigrade float values) [or scaled int]

Yep I have this in mind. But not yet the topic of the day. So far I have:

name - this is not need perhaps it can be found in another place in sysfs timeout - timeout value in sec - convert it to ms perhaps?
ping - "ping" file, to replace the /dev/watchdog writes
boot_status - the boot status - meaning same as IOCTL has, generaly the reset reason status - current status - same as ioctl equivalent

And optional firmware_ver to reflect the IOCTL equvalent.

This is needed to be discussed with Wim first. I hope he will speak up ;)

As for the temps/fans I belive the driver should register in hwmon class and use hwmon class sysfs iterface and then just create sort of relation between the sysfs files/classes, so the watchdog app can find the temps.

Quoted 6 lines
Quoted 1 line
	int (*set_timeout)(struct device *, int sec);

Pass the usual time structures instead. Seconds is a field so it is free but it means all the signed/unsigned stuff and any future subsecond watchdogs for embedded environments don't break stuff.

Good idea, I will change it. Thanks.

Quoted 4 lines
Quoted 2 lines
	int (*notify_reboot)(struct notifier_block *this, unsigned long code,
	        void *unused);

Can this not use the power management callbacks from the device model instead

Ah I knew about the suspend/resume and it seems there is also a shutdown one.

Quoted 9 lines
Quoted 2 lines
	/* this may be removed in the future */
	struct watchdog_info legacy_info;

This wants breaking out into sysfs, but again the ioctls are expected and standardised for years now.

People have talked about sorting out a watchdog helper library for years so this is overdue, and doing it with the class model in mind is even better.

I was quite amazed when I saw same code copied 40x in one directory ;)

Thanks for the comments,
Regards
Rudolf

#5 lore raw
In reply to Arnd Bergmann

Hello Arnd,

Quoted 2 lines

Wim used to have an experimental tree with a similar idea. Did you look at that before you started this? Is that tree still maintained?

No I did not, I thought if the class exist it is already there ... Instead I have taken the RTC class which was fairly similar to the watchdog needs and changed it to a watchdog one. I think this may answer some of your questions ;)

Now we have something that works and might be used as the base for the watchdog class. Many thanks for your comments.

Quoted 10 lines

drivers/watchdog/watchdog-dev.c line 24

Quoted 7 lines
drivers/watchdog/watchdog-dev.c +7 -0
+#include <linux/module.h>
+#include "watchdog.h"
+
+static struct class *watchdog_dev_class;
+static dev_t watchdog_devt;
+
+#define WATCHDOG_DEV_MAX 8 /* 8 watchdogs should be enough for everyone... */

What's the point in having more than one watchdog active? If you want more than one, why hardcode a specific limit?

I thought there might be such future need, nowdays it used to test the stuff.

If nobody here wants it I have no problem to change the class just to allow one active watchdog.

Quoted 8 lines

Existing user space typically depends on the watchdog device being called /dev/watchdog, which breaks if your devices are called watchdog%d. I can see two ways out of this:

1. add a udev rule that creates /dev/watchdog as an alias for /dev/watchdog0.
2. add a misc device /dev/watchdog that works as a multiplexer for all others, similar to the idea of /dev/input/mice as a multiplexer for /dev/input/mouse%d.

True, this depends if someone wants this multi watchdog stuff.

Quoted 10 lines

drivers/watchdog/watchdog.h line 88

Quoted 8 lines
drivers/watchdog/watchdog.h +8 -0
+#define WATCHDOG_DEVICE_NAME_SIZE 20
+
+struct watchdog_device {
+       struct class_device class_dev;
+       struct module *owner;
+
+       int id;
+       char name[WATCHDOG_DEVICE_NAME_SIZE];

Can this be the embedded name in class_device?

I copied this from the RTC, and because it is already in kernel I assumed it is OK to have it this way.

Quoted 10 lines

drivers/watchdog/watchdog.h line 93

Quoted 5 lines
drivers/watchdog/watchdog.h +5 -0
+
+       struct watchdog_class_ops *ops;
+       struct mutex ops_lock;
+
+       struct class_device *watchdog_dev; 

Having two classes (watchdog_class and watchdog_dev_class) as well as two class_devices (class_dev and watchdog_dev) per device seems wrong. What is the reason for splitting these?

Again, this was taken from the RTC subsystem and I left the modularity of the stuff. But for the watchdog case it might go without the additional class. As for the watchdog_dev it depends how tight we want to integrate it into the class.

Quoted 10 lines
Quoted 10 lines
drivers/watchdog/watchdog.h +10 -0
+/* watchdog_device_register_simple, will register device into watchdog class
+   just with default timeout from kernel configuration.
+   
+   watchdog_device_register_selfping, will register the watchdog device same 
+   way as above function, but the device will be pinged every selfping interval
+   (useful for watchdog with damm fast timeouts)
+*/
+
+#define watchdog_device_register_simple(name, dev, ops)  \
+           _watchdog_device_register(name, dev, ops, THIS_MODULE, CONFIG_WATCHDOG_DEFAULT_TIMEOUT, 0)
Quoted 8 lines

drivers/watchdog/watchdog.h line 123

Quoted 3 lines
drivers/watchdog/watchdog.h +3 -0
+
+#define watchdog_device_register_selfping(name, dev, ops, selfping)  \
+           _watchdog_device_register(name, dev, ops, THIS_MODULE, CONFIG_WATCHDOG_DEFAULT_TIMEOUT, selfping)

All callers of this seem to have constant arguments (except dev), so you could easily put name, owner, timeout and selfping into the ops structure. Maybe the structure could use a different name then.

Hmm even to think the name is a bit problem, because the in it will be used for two different things, for the ops and as the data container.

Quoted 9 lines

drivers/watchdog/watchdog-sysfs.c line 25

Quoted 5 lines
drivers/watchdog/watchdog-sysfs.c +5 -0
+static ssize_t watchdog_sysfs_show_name(struct class_device *dev, char *buf)
+{
+       return sprintf(buf, "%s\n", to_watchdog_device(dev)->name);
+}
+static CLASS_DEVICE_ATTR(name, S_IRUGO, watchdog_sysfs_show_name, NULL);

Why do you need a name attribute? Should the name of the class_device itself not be enough as an identifier?

True, RTC has it this way too so I thought there must be some reason...

Quoted 5 lines

What's the point in making the sysfs stuff an extra module? I guess it would be a lot simpler to just always add the files. We might want to make the dev interface optional, but then again it is what all applications to date are using, so you may just as well have a single base module and no infrastructure for multiple interfaces at all.

Well the sysfs seemed still bit a future for watchdog and embedded devices might want to save some space. I even did not know that sysfs interface will be on the topic so quickly. So this was the reason I left it as it was in RTC...

Thanks,
Regards
Rudolf

PS: please CC me.

#7 lore raw
In reply to Rudolf Marek

Hi Rudolf,

Quoted 18 lines

I wanted to create a watchdog driver for I2C W83792D chip and I realized that there is no clean way how to connect the existing I2C device driver with the watchdog ops. As the consequence of this I created new watchdog device class.

This class supports all common infrastructure such as char device handling, sysfs exports and even the infrastructure for too fast watchdogs (the self ping feature). The class is based on the RTC class which is fairly similar in some aspects.

The char device of watchdog class is compatible with existing watchdog API, so no need to change the user applications. There is just one exception and this is temperature handling. I belive it should be implemented not via IOCTL but using the HWMON class. (100% compatibility can be restored with the ioctl class op)

I have defined this class ops so far:

Quoted 7 lines
struct watchdog_class_ops {
	int (*enable)(struct device *);
	int (*disable)(struct device *);
	int (*ping)(struct device *);
	int (*set_timeout)(struct device *, int sec);
	int (*notify_reboot)(struct notifier_block *this, unsigned long code,
	        void *unused);

I was doing some stuff for the ICH6 & ICH7 I/O chipsets first and was then planning to resume working on my generic watchdog code again. (It used to be stored in a bitkeeper tree, but I didn't convert it to a git tree yet). I'll make sure that the code get's stored in the linux-2.6-watchdog-experimental git tree in the coming days.

But basically this is what we need for watchdog devices:
---------------------------------------------------------------------------
struct watchdog_ops;
struct watchdog_device;

struct watchdog_ops {
/* mandatory routines */
int (*start)(struct watchdog_device *); /* operation = start watchdog */
int (*stop)(struct watchdog_device *); /* operation = stop watchdog */
int (*keepalive)(struct watchdog_device *); /* operation = send keepalive ping */
/* optional routines */
int (*set_heartbeat)(struct watchdog_device *,int); /* operation = set watchdog's heartbeat */
int (*get_status)(struct watchdog_device *,int *); /* operation = get the watchdog's status */
int (*get_temperature)(struct watchdog_device *, int *); /* operation = get the temperature in °F */
int (*get_timervalue)(struct watchdog_device *, int *); /* operation = get the current timer value */
int (*sys_restart)(struct watchdog_device *); /* operation = force a system_restart for rebooting */
};

struct watchdog_device {
unsigned char name[32]; /* The watchdog's 'identity' */
unsigned long options; /* The supported capabilities/options */
unsigned long firmware; /* The watchdog's Firmware version */
int heartbeat; /* The watchdog's heartbeat */
int nowayout; /* The nowayout setting for this watchdog */
int bootstatus; /* The watchdog's bootstatus */
int temppanic; /* wether or not to panic on temperature trip's */
struct watchdog_ops *watchdog_ops; /* link to watchdog_ops */

/* watchdog status state machine */
enum { WATCHDOG_UNINITIALIZED=0,
WATCHDOG_INITIALIZED,
WATCHDOG_STARTED,
WATCHDOG_STOPPED,
WATCHDOG_UNREGISTERED,
} watchdog_state;

struct semaphore sem; /* locks this structure */

/* From here on everything is device dependent */
void *private;
};

/* drivers/watchdog/watchdog.c */
extern struct watchdog_device *alloc_watchdogdev(void); extern int free_watchdogdev(struct watchdog_device *dev); extern int register_watchdogdevice(struct watchdog_device *dev); extern int unregister_watchdogdevice(struct watchdog_device *dev);
---------------------------------------------------------------------------

you don't need an operation for the notify_reboot. This is only necessary to make sure that you either stop the watchdog or force it to reboot (because the hardware isn't capable of rebooting itself. See the cobalt server)). The notify reboot is not a watchdog operation, it's for making sure that when you shutdown/reboot everything runs smoothly.

Greetings,
Wim.

#3 lore raw
In reply to Rudolf Marek
Quoted 1 line · Rudolf Marek

timeout - timeout value in sec - convert it to ms perhaps?

Probably

Quoted 1 line

ping - "ping" file, to replace the /dev/watchdog writes

Well you need to keep /dev/watchdog but yes

Quoted 3 lines

As for the temps/fans I belive the driver should register in hwmon class and use hwmon class sysfs iterface and then just create sort of relation between the sysfs files/classes, so the watchdog app can find the temps.

I think that is appropriate. The temperature and watchdog association is mostly historical because in the past thats where temp sensors lived, nowdays they are everywhere.

Alan

#8 lore raw
In reply to Wim Van Sebroeck

Hi Wim,

Quoted 5 lines

I was doing some stuff for the ICH6 & ICH7 I/O chipsets first and was then planning to resume working on my generic watchdog code again. (It used to be stored in a bitkeeper tree, but I didn't convert it to a git tree yet). I'll make sure that the code get's stored in the linux-2.6-watchdog-experimental git tree in the coming days.

Aha good. I will check it later.

Quoted 1 line
	int	(*get_timervalue)(struct watchdog_device *, int *);

Good one.

Quoted 1 line

int (*sys_restart)(struct watchdog_device *); /* operation = force a

system_restart for rebooting */

Aha as for the cobalt stuff?

Quoted 2 lines

int (*get_status)(struct watchdog_device *,int *); /* operation = get the watchdog's status */
int (*get_temperature)(struct watchdog_device *, int *); /* operation = get the temperature in °F */

I had those there too but I eliminated them. I used following methods:
For the status stuff I did a variable boot_status and status. I have a handler for this in the common IOCTL handling code.

I have no such thing for the temp IOCTL but the new "ioctl" operation could be created to catch it.
(and get called when no standard ioctl in watchdog-dev is used)

As for sysfs, I would like to have the temps handled with the hwmon class and have some sort of "symlink" from the watchdog directory to corresponding hwmon directory. The status stuff might be handled via standard format sysfs file.

Quoted 7 lines

struct watchdog_device {
unsigned char name[32]; /* The watchdog's 'identity' */
unsigned long options; /* The supported capabilities/options */
unsigned long firmware; /* The watchdog's Firmware version */
int heartbeat; /* The watchdog's heartbeat */
int nowayout; /* The nowayout setting for this watchdog */
int bootstatus; /* The watchdog's bootstatus */

got the unsigned long to have more space...

Quoted 10 lines

int temppanic; /* wether or not to panic on temperature trip's */
struct watchdog_ops *watchdog_ops; /* link to watchdog_ops */

/* watchdog status state machine */
enum { WATCHDOG_UNINITIALIZED=0,
WATCHDOG_INITIALIZED,
WATCHDOG_STARTED,
WATCHDOG_STOPPED,
WATCHDOG_UNREGISTERED,
} watchdog_state;

I dont have the state machine but something like this is implemented in the dev device handling.

Additionaly I have the self ping stuff in the class too.

Quoted 2 lines
	/* From here on everything is device dependent */
	void	*private;

In the w83792d I used different approach, because the device is not only a watchog, the struct watchdog_device was a part of the common device structure, and for single purpose devices this *private makes sense. But I think there some per device private data pointer somewhere.

Quoted 3 lines

you don't need an operation for the notify_reboot. This is only necessary to make sure that you either stop the watchdog or force it to reboot (because the hardware isn't capable of rebooting itself. See the cobalt server)).

Alan already did a hint about the device driver callback that may handle this.

Now it seems we have two different approaches and a code, so which one will wim ? ;) If you want to talk to me you may find me on #linux-sensors on freenode.net.

Also I would like to know your ideas about the sysfs file structure for watchdogs and also If you like to have more watchdogs active in the system or just one.

Thanks,
Regards
Rudolf

PS: CC me please.

#6 lore raw
In reply to Rudolf Marek
Quoted 8 lines · Rudolf Marek
Quoted 2 lines

What's the point in having more than one watchdog active? If you want more than one, why hardcode a specific limit?

I thought there might be such future need, nowdays it used to test the stuff.

If nobody here wants it I have no problem to change the class just to allow one active watchdog.

Actually, I have a case right now. For us, a watchdog with minute granularity is just too long, but that is the only hardware watchdog available. So, we use softdog for finer granularity and the additional crappy hardware watchdog just to catch cases that softdog doesn't. I just wanted to pass along an example where more than one watchdog is needed for your consideration.

Signature · 1 line
Mark Rustad, [email protected]
#13 lore raw
In reply to Rudolf Marek
Quoted 10 lines · Rudolf Marek

The char device of watchdog class is compatible with existing watchdog API,
so no need to change the user applications. There is just one exception and this is temperature handling. I belive it should be implemented not via IOCTL but using the HWMON class. (100% compatibility can be restored with the ioctl class op)

I have defined this class ops so far:

Quoted 8 lines
struct watchdog_class_ops {
    int (*enable)(struct device *);
    int (*disable)(struct device *);
    int (*ping)(struct device *);
    int (*set_timeout)(struct device *, int sec);
    int (*notify_reboot)(struct notifier_block *this, unsigned long code,
            void *unused);
};

Some watchdog devices have the ability to say "I'm about to reboot you, do you want to do something about it?". The IPMI watchdog calls this a pretimeout, but I have seen this concept on at least two other watchdog devices. This can be delivered via an NMI or SMI and can be used to inform the OS ahead of time that it's going to reboot the system. This is useful because you can panic, do a coredump, or perform other useful operations instead of just rebooting.

Do you think this interface belongs in the structure?

-Corey

#9 lore raw
In reply to Rudolf Marek

Hi Rudolf,

Quoted 1 line

Aha good. I will check it later.

You can have a check now. I uploaded some code. Need to retest it, but it has been working on my v2.6.5 test machine.

Quoted 2 lines
Quoted 1 line
	int	(*get_timervalue)(struct watchdog_device *, int *);

Good one.

We should add this indeed. it's usefull for testing drivers also :-)

Quoted 4 lines
Quoted 1 line

int (*sys_restart)(struct watchdog_device *); /* operation = force a

system_restart for rebooting */

Aha as for the cobalt stuff?

Yes and no: cobalt needs it in it's notifier reboot part which is not part of the generic watchdog device. But I think the option should be available if you go sysfs.

Quoted 6 lines
Quoted 2 lines

int (*get_status)(struct watchdog_device *,int *); /* operation = get the watchdog's status */
int (*get_temperature)(struct watchdog_device *, int *); /* operation = get the temperature in °F */

I had those there too but I eliminated them. I used following methods:
For the status stuff I did a variable boot_status and status. I have a handler for this in the common IOCTL handling code.

Don't agree here: boot_status is a copy of the status at boot. the status itself can change during normal operation. and thus get_status must return the "devices status" at that moment.

Quoted 3 lines

I have no such thing for the temp IOCTL but the new "ioctl" operation could be created to catch it.
(and get called when no standard ioctl in watchdog-dev is used)

I think we want to review the temperature stuff in the kernel in general.

Quoted 3 lines

As for sysfs, I would like to have the temps handled with the hwmon class and have some sort of "symlink" from the watchdog directory to corresponding hwmon directory. The status stuff might be handled via standard format sysfs file.

And I like the idea to look at it as a hwmon.

Quoted 7 lines
Quoted 2 lines
	/* From here on everything is device dependent */
	void	*private;

In the w83792d I used different approach, because the device is not only a watchog, the struct watchdog_device was a part of the common device structure, and for single purpose devices this *private makes sense. But I think there some per device private data pointer somewhere.

I still have to look at your driver in detail, but my first thought would be that the private part here would be a link to this common device structure. (see what I did with the example softdog implementation in the experimental tree).

Quoted 2 lines

Now it seems we have two different approaches and a code, so which one will wim ? ;) If you want to talk to me you may find me on #linux-sensors on freenode.net.

It's not about different approaches: we have to find the best thing for watchdog devicesi, so the best thing is to talk about pro's and con's and see what we should do best. (I for instance didn't come to the sysfs part yet of my code (which would be in watchdog_sysfs.c)

Quoted 3 lines

Also I would like to know your ideas about the sysfs file structure for watchdogs and also If you like to have more watchdogs active in the system or just one.

My view:
to start we should keep one /dev/watchdog, but we should create/define a suitable sysfs interface that makes it possible to have multiple watchdog devices running in parallel. We will need this functionality in the future when a system will consist of different processors that all have their own memory and some basic I/O interfacing.
Later on we will then see what we will do with /dev/watchdog.

Greetings,
Wim.

#14 lore raw
In reply to Corey Minyard

Hi Corey,

Quoted 9 lines

Some watchdog devices have the ability to say "I'm about to reboot you, do you want to do something about it?". The IPMI watchdog calls this a pretimeout, but I have seen this concept on at least two other watchdog devices. This can be delivered via an NMI or SMI and can be used to inform the OS ahead of time that it's going to reboot the system. This is useful because you can panic, do a coredump, or perform other useful operations instead of just rebooting.

Do you think this interface belongs in the structure?

It definitely does and that's why I stored your patch from 1-Nov-2005 and added it to my experimental tree just now.

Greetings,
Wim.

#10 lore raw
In reply to Wim Van Sebroeck

Hello Wim,

Quoted 2 lines

You can have a check now. I uploaded some code. Need to retest it, but it has been working on my v2.6.5 test machine.

Good I will check. I have one test machine provided by Asus, Winbond and me :) (I'm using it for lm-sensors stuff) I can give you access if you give me ssh key.

Quoted 3 lines

Don't agree here: boot_status is a copy of the status at boot. the status itself can change during normal operation. and thus get_status must return the "devices status" at that moment.

Ah correct, not always updated via async event, maybe the register is to be polled only.

Quoted 6 lines
Quoted 3 lines

I have no such thing for the temp IOCTL but the new "ioctl" operation could be created to catch it.
(and get called when no standard ioctl in watchdog-dev is used)

I think we want to review the temperature stuff in the kernel in general.

If you mean in watchdog class, the yes. Otherwise no. The hwmon class has well defined interface for a while...

Quoted 3 lines

I still have to look at your driver in detail, but my first thought would be that the private part here would be a link to this common device structure. (see what I did with the example softdog implementation in the experimental tree).

Ok.

Quoted 4 lines

It's not about different approaches: we have to find the best thing for watchdog devicesi, so the best thing is to talk about pro's and con's and see what we should do best. (I for instance didn't come to the sysfs part yet of my code (which would be in watchdog_sysfs.c)

Ok I will look into your code.

Quoted 5 lines
Quoted 3 lines

Also I would like to know your ideas about the sysfs file structure for watchdogs and also If you like to have more watchdogs active in the system or just one.

Quoted 7 lines

My view:
to start we should keep one /dev/watchdog, but we should create/define a suitable sysfs interface that makes it possible to have multiple watchdog devices running in parallel. We will need this functionality in the future when a system will consist of different processors that all have their own memory and some basic I/O interfacing.
Later on we will then see what we will do with /dev/watchdog.

I will let you know when I'm done with the studying of your code. I hope that I will have some time in near fututure, got lot of stuff to do.

Regards
Rudolf

PS: CC me please.

#11 lore raw

Hi Rudolf,

Quoted 6 lines
Quoted 4 lines

It's not about different approaches: we have to find the best thing for watchdog devicesi, so the best thing is to talk about pro's and con's and see what we should do best. (I for instance didn't come to the sysfs part yet of my code (which would be in watchdog_sysfs.c)

Ok I will look into your code.

Please have a look at the experimental code in the linux-2.6-watchdog-experimental git tree
(http://www.kernel.org/git/?p=linux/kernel/git/wim/linux-2.6-watchdog-experimental.git;a=summary).

It's a first draft of the generic code. (it's split into tree main parts: the core code, the /dev/watchdog code and the sysfs code). (Note: I used Greg's new "class" device setup). And it basically uses the following operations and watchdog_device structure:

struct watchdog_ops {
/* mandatory routines */
int (*start)(struct watchdog_device *); /* operation = start watchdog */
int (*stop)(struct watchdog_device *); /* operation = stop watchdog */
int (*keepalive)(struct watchdog_device *); /* operation = send keepalive ping */
/* optional routines */
int (*set_heartbeat)(struct watchdog_device *,int); /* operation = set watchdog's heartbeat */
int (*get_status)(struct watchdog_device *,int *); /* operation = get the watchdog's status */
int (*get_timeleft)(struct watchdog_device *, int *); /* operation = get the time left before reboot */
int (*sys_restart)(struct watchdog_device *); /* operation = force a system_restart for rebooting */
};

struct watchdog_device {
unsigned char name[32]; /* The watchdog's 'identity' */
unsigned long options; /* The supported capabilities/options */
unsigned long firmware; /* The Watchdog's Firmware version */
int heartbeat; /* The watchdog's heartbeat */
int nowayout; /* The nowayout setting for this watchdog */
int bootstatus; /* The watchdog's bootstatus */
int temppanic; /* wether or not to panic on temperature trip's */
struct watchdog_ops *watchdog_ops; /* link to watchdog_ops */

/* watchdog status (register/unregister) state machine */ enum { WATCHDOG_UNINITIALIZED=0,
WATCHDOG_REGISTERED, /* completed register_watchdogdevice */
WATCHDOG_STARTED, /* watchdog device started */
WATCHDOG_STOPPED, /* watchdog device stopped */
WATCHDOG_UNREGISTERED, /* completed unregister_watchdogdevice */
} watchdog_state;

struct semaphore sem; /* locks this structure */

struct device *cdev; /* Sysfs watchdog class device */

/* From here on everything is device dependent */
void *private;
};

There are still a number of things to be added:
* have a list under register_watchdogdevice so that we can register multiple watchdog devices (Note: only one watchdog device will be linked to /dev/watchdog)
* add pre-timeout stuff
* clean-up sysfs code
* do proper locking
* add documentation
* make docbook ready
* decide how we will handle the old temperature ioctl
...

All comments/suggestions are welcome. Let's see/discuss what's missing, what we should do different, ...

Greetings,
Wim.

#12 lore raw

Hi Wim,

Sorry for the delay I have been quite busy ...

Quoted 33 lines

It's a first draft of the generic code. (it's split into tree main parts: the core code, the /dev/watchdog code and the sysfs code). (Note: I used Greg's new "class" device setup). And it basically uses the following operations and watchdog_device structure:

struct watchdog_ops {
/* mandatory routines */
int (*start)(struct watchdog_device *); /* operation = start watchdog */
int (*stop)(struct watchdog_device *); /* operation = stop watchdog */
int (*keepalive)(struct watchdog_device *); /* operation = send keepalive ping */
/* optional routines */
int (*set_heartbeat)(struct watchdog_device *,int); /* operation = set watchdog's heartbeat */
int (*get_status)(struct watchdog_device *,int *); /* operation = get the watchdog's status */
int (*get_timeleft)(struct watchdog_device *, int *); /* operation = get the time left before reboot */
int (*sys_restart)(struct watchdog_device *); /* operation = force a system_restart for rebooting */
};

struct watchdog_device {
unsigned char name[32]; /* The watchdog's 'identity' */
unsigned long options; /* The supported capabilities/options */
unsigned long firmware; /* The Watchdog's Firmware version */
int heartbeat; /* The watchdog's heartbeat */
int nowayout; /* The nowayout setting for this watchdog */
int bootstatus; /* The watchdog's bootstatus */
int temppanic; /* wether or not to panic on temperature trip's */
struct watchdog_ops *watchdog_ops; /* link to watchdog_ops */

/* watchdog status (register/unregister) state machine */ enum { WATCHDOG_UNINITIALIZED=0,
WATCHDOG_REGISTERED, /* completed register_watchdogdevice */
WATCHDOG_STARTED, /* watchdog device started */
WATCHDOG_STOPPED, /* watchdog device stopped */
WATCHDOG_UNREGISTERED, /* completed unregister_watchdogdevice */
} watchdog_state;

Quoted 7 lines

struct semaphore sem; /* locks this structure */

struct device *cdev; /* Sysfs watchdog class device */

/* From here on everything is device dependent */
void *private;
};

Looks good to me. I would second Alan's idea about the standard time structure, because for embedded stuff even [s] might be too long.

Quoted 8 lines

There are still a number of things to be added:
* have a list under register_watchdogdevice so that we can register multiple watchdog devices (Note: only one watchdog device will be linked to /dev/watchdog)
* add pre-timeout stuff
* clean-up sysfs code
* do proper locking
* add documentation
* make docbook ready

I would add:
* infrastructure for too fast or too slow hardware watchdogs.

The idea is following: If the watchdog is too fast (1s timeout like some winbonds) there could be in watchdog class a common code that would ping this watchdog often as needed and the real ping from userspace would go to the soft one... So same as it is now, but part of the class core instead of part of each driver.

If the design is done correctly, just a time constants could be switched, so the soft dog is required to be "ping"ed more often then hardware. This would solve the other problem with 1m hw watchdogs, which are way too "slow".

Quoted 1 line

* decide how we will handle the old temperature ioctl

Drop? Or there is one easy way. Let the watchdog core call the "private" ioctl for unknown/temp IOCTL commands - routine ptr would be defined in the structure above or NULL. We can mark this interface obsolete, and later remove that private ioctl routine and the field in the watchdog_device structure...

Have you any clue if this IOCTL is used actually by some util? I googled a bit but without any luck.

As for the temps... Enough should be the registration to hwmon class and creation of few sysfs callbacks. The interface is stable and well defined. Just check the Documentation/hwmon/sysfs-interface. I cannot recall if the userspace app will be able to find out the currect hwmon directory in sysfs from a watchdog one, but I guess there is somehow assured this class hiearchy...

As for the sysfs attributes: I would suggest to use [ms] for time stuff. Rest looks quite straightforward.

I'm willing to help with the implementation, just tell me what you have done already from that list ;)

Sorry for the delay, I hope I will be able to schedule this stuff more often now ;)

Regards
Rudolf