summaryrefslogtreecommitdiffstats
path: root/kernel/Documentation/watchdog/src
diff options
context:
space:
mode:
authorYunhong Jiang <yunhong.jiang@intel.com>2015-08-04 12:17:53 -0700
committerYunhong Jiang <yunhong.jiang@intel.com>2015-08-04 15:44:42 -0700
commit9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (patch)
tree1c9cafbcd35f783a87880a10f85d1a060db1a563 /kernel/Documentation/watchdog/src
parent98260f3884f4a202f9ca5eabed40b1354c489b29 (diff)
Add the rt linux 4.1.3-rt3 as base
Import the rt linux 4.1.3-rt3 as OPNFV kvm base. It's from git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git linux-4.1.y-rt and the base is: commit 0917f823c59692d751951bf5ea699a2d1e2f26a2 Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Sat Jul 25 12:13:34 2015 +0200 Prepare v4.1.3-rt3 Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> We lose all the git history this way and it's not good. We should apply another opnfv project repo in future. Change-Id: I87543d81c9df70d99c5001fbdf646b202c19f423 Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Diffstat (limited to 'kernel/Documentation/watchdog/src')
-rw-r--r--kernel/Documentation/watchdog/src/.gitignore2
-rw-r--r--kernel/Documentation/watchdog/src/Makefile5
-rw-r--r--kernel/Documentation/watchdog/src/watchdog-simple.c24
-rw-r--r--kernel/Documentation/watchdog/src/watchdog-test.c86
4 files changed, 117 insertions, 0 deletions
diff --git a/kernel/Documentation/watchdog/src/.gitignore b/kernel/Documentation/watchdog/src/.gitignore
new file mode 100644
index 000000000..ac90997db
--- /dev/null
+++ b/kernel/Documentation/watchdog/src/.gitignore
@@ -0,0 +1,2 @@
+watchdog-simple
+watchdog-test
diff --git a/kernel/Documentation/watchdog/src/Makefile b/kernel/Documentation/watchdog/src/Makefile
new file mode 100644
index 000000000..4a892c304
--- /dev/null
+++ b/kernel/Documentation/watchdog/src/Makefile
@@ -0,0 +1,5 @@
+# List of programs to build
+hostprogs-y := watchdog-simple watchdog-test
+
+# Tell kbuild to always build the programs
+always := $(hostprogs-y)
diff --git a/kernel/Documentation/watchdog/src/watchdog-simple.c b/kernel/Documentation/watchdog/src/watchdog-simple.c
new file mode 100644
index 000000000..ba45803a2
--- /dev/null
+++ b/kernel/Documentation/watchdog/src/watchdog-simple.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int main(void)
+{
+ int fd = open("/dev/watchdog", O_WRONLY);
+ int ret = 0;
+ if (fd == -1) {
+ perror("watchdog");
+ exit(EXIT_FAILURE);
+ }
+ while (1) {
+ ret = write(fd, "\0", 1);
+ if (ret != 1) {
+ ret = -1;
+ break;
+ }
+ sleep(10);
+ }
+ close(fd);
+ return ret;
+}
diff --git a/kernel/Documentation/watchdog/src/watchdog-test.c b/kernel/Documentation/watchdog/src/watchdog-test.c
new file mode 100644
index 000000000..3da822967
--- /dev/null
+++ b/kernel/Documentation/watchdog/src/watchdog-test.c
@@ -0,0 +1,86 @@
+/*
+ * Watchdog Driver Test Program
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <linux/types.h>
+#include <linux/watchdog.h>
+
+int fd;
+
+/*
+ * This function simply sends an IOCTL to the driver, which in turn ticks
+ * the PC Watchdog card to reset its internal timer so it doesn't trigger
+ * a computer reset.
+ */
+static void keep_alive(void)
+{
+ int dummy;
+
+ ioctl(fd, WDIOC_KEEPALIVE, &dummy);
+}
+
+/*
+ * The main program. Run the program with "-d" to disable the card,
+ * or "-e" to enable the card.
+ */
+
+static void term(int sig)
+{
+ close(fd);
+ fprintf(stderr, "Stopping watchdog ticks...\n");
+ exit(0);
+}
+
+int main(int argc, char *argv[])
+{
+ int flags;
+
+ fd = open("/dev/watchdog", O_WRONLY);
+
+ if (fd == -1) {
+ fprintf(stderr, "Watchdog device not enabled.\n");
+ fflush(stderr);
+ exit(-1);
+ }
+
+ if (argc > 1) {
+ if (!strncasecmp(argv[1], "-d", 2)) {
+ flags = WDIOS_DISABLECARD;
+ ioctl(fd, WDIOC_SETOPTIONS, &flags);
+ fprintf(stderr, "Watchdog card disabled.\n");
+ fflush(stderr);
+ goto end;
+ } else if (!strncasecmp(argv[1], "-e", 2)) {
+ flags = WDIOS_ENABLECARD;
+ ioctl(fd, WDIOC_SETOPTIONS, &flags);
+ fprintf(stderr, "Watchdog card enabled.\n");
+ fflush(stderr);
+ goto end;
+ } else {
+ fprintf(stderr, "-d to disable, -e to enable.\n");
+ fprintf(stderr, "run by itself to tick the card.\n");
+ fflush(stderr);
+ goto end;
+ }
+ } else {
+ fprintf(stderr, "Watchdog Ticking Away!\n");
+ fflush(stderr);
+ }
+
+ signal(SIGINT, term);
+
+ while(1) {
+ keep_alive();
+ sleep(1);
+ }
+end:
+ close(fd);
+ return 0;
+}