From patchwork Mon Sep 22 20:55:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: j.uzycki@elproma.com.pl X-Patchwork-Id: 4950411 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6AC789F2BB for ; Mon, 22 Sep 2014 20:56:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6400F2014A for ; Mon, 22 Sep 2014 20:56:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6BE65200FF for ; Mon, 22 Sep 2014 20:56:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XWAcu-0001TO-Qm; Mon, 22 Sep 2014 20:54:28 +0000 Received: from v032797.home.net.pl ([89.161.177.31]) by bombadil.infradead.org with smtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XWAcG-0001BK-GU for linux-arm-kernel@lists.infradead.org; Mon, 22 Sep 2014 20:53:50 +0000 Received: from ip-78-133-172-40.ibd.gtsenergis.pl [78.133.172.40] (HELO ip165.elproma.lan) by elproma.home.pl [89.161.177.31] with SMTP (IdeaSmtpServer v0.80) id 2472a6360355b3c0; Mon, 22 Sep 2014 22:53:18 +0200 From: Janusz Uzycki To: Guenter Roeck Subject: [PATCH 1/6] watchdog: watchdog_dev: WATCHDOG_KEEP_ON feature Date: Mon, 22 Sep 2014 22:55:45 +0200 Message-Id: <1411419350-1297-1-git-send-email-j.uzycki@elproma.com.pl> X-Mailer: git-send-email 1.7.11.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140922_135348_745990_A05F3DEC X-CRM114-Status: GOOD ( 15.52 ) X-Spam-Score: 0.0 (/) Cc: Wim Van Sebroeck , Janusz Uzycki , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some applications require to start watchdog before userspace software. This patch enables such feature. Only the flag is necessary to enable it. Moreover kernel's ping is re-enabled when userspace software closed watchdog using the magic character. The features improves kernel's reliability if hardware watchdog is available. Signed-off-by: Janusz Uzycki --- drivers/watchdog/watchdog_dev.c | 58 ++++++++++++++++++++++++++- include/linux/watchdog.h | 5 +++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 6aaefba..51a65f6 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -41,6 +41,7 @@ #include /* For handling misc devices */ #include /* For __init/__exit/... */ #include /* For copy_to_user/put_user/... */ +#include /* for ping timer */ #include "watchdog_core.h" @@ -277,6 +278,27 @@ out_ioctl: return err; } +/* 'keep on' feature */ +static void watchdog_ping_timer_cb(unsigned long data) +{ + struct watchdog_device *wdd = (struct watchdog_device *)data; + watchdog_ping(wdd); + /* call next ping half the timeout value */ + mod_timer(&wdd->ping_timer, + jiffies + msecs_to_jiffies(wdd->timeout * 500)); +} + +static void watchdog_keepon_start(struct watchdog_device *wdd) +{ + watchdog_start(wdd); + watchdog_ping_timer_cb((unsigned long)wdd); +} + +static void watchdog_keepon_stop(struct watchdog_device *wdd) +{ + del_timer_sync(&wdd->ping_timer); +} + /* * watchdog_write: writes to the watchdog. * @file: file from VFS @@ -430,6 +452,9 @@ static int watchdog_open(struct inode *inode, struct file *file) if (!try_module_get(wdd->ops->owner)) goto out; + if (test_bit(WDOG_KEEP_ON, &wdd->status)) + watchdog_keepon_stop(wdd); + err = watchdog_start(wdd); if (err < 0) goto out_mod; @@ -472,8 +497,13 @@ static int watchdog_release(struct inode *inode, struct file *file) if (!test_bit(WDOG_ACTIVE, &wdd->status)) err = 0; else if (test_and_clear_bit(WDOG_ALLOW_RELEASE, &wdd->status) || - !(wdd->info->options & WDIOF_MAGICCLOSE)) - err = watchdog_stop(wdd); + !(wdd->info->options & WDIOF_MAGICCLOSE)) { + if (test_bit(WDOG_KEEP_ON, &wdd->status)) { + watchdog_keepon_start(wdd); + err = 0; + } else + err = watchdog_stop(wdd); + } /* If the watchdog was not stopped, send a keepalive ping */ if (err < 0) { @@ -524,6 +554,14 @@ int watchdog_dev_register(struct watchdog_device *watchdog) { int err, devno; + if (test_bit(WDOG_KEEP_ON, &watchdog->status)) { + if (!try_module_get(watchdog->ops->owner)) + return -ENODEV; + setup_timer(&watchdog->ping_timer, watchdog_ping_timer_cb, + (unsigned long)watchdog); + watchdog_keepon_start(watchdog); + } + if (watchdog->id == 0) { old_wdd = watchdog; watchdog_miscdev.parent = watchdog->parent; @@ -535,6 +573,11 @@ int watchdog_dev_register(struct watchdog_device *watchdog) pr_err("%s: a legacy watchdog module is probably present.\n", watchdog->info->identity); old_wdd = NULL; + if (test_bit(WDOG_KEEP_ON, &watchdog->status)) { + watchdog_keepon_stop(watchdog); + watchdog_stop(watchdog); + module_put(watchdog->ops->owner); + } return err; } } @@ -553,6 +596,11 @@ int watchdog_dev_register(struct watchdog_device *watchdog) misc_deregister(&watchdog_miscdev); old_wdd = NULL; } + if (test_bit(WDOG_KEEP_ON, &watchdog->status)) { + watchdog_keepon_stop(watchdog); + watchdog_stop(watchdog); + module_put(watchdog->ops->owner); + } } return err; } @@ -575,6 +623,12 @@ int watchdog_dev_unregister(struct watchdog_device *watchdog) misc_deregister(&watchdog_miscdev); old_wdd = NULL; } + + if (test_bit(WDOG_KEEP_ON, &watchdog->status)) { + watchdog_keepon_stop(watchdog); + watchdog_stop(watchdog); + module_put(watchdog->ops->owner); + } return 0; } diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h index 2a3038e..650e0d5 100644 --- a/include/linux/watchdog.h +++ b/include/linux/watchdog.h @@ -12,6 +12,7 @@ #include #include #include +#include /* for ping timer */ #include struct watchdog_ops; @@ -95,6 +96,8 @@ 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 */ +#define WDOG_KEEP_ON 5 /* Is 'keep on' feature set? */ + struct timer_list ping_timer; /* timer to keep on hardware ping */ }; #ifdef CONFIG_WATCHDOG_NOWAYOUT @@ -104,6 +107,8 @@ struct watchdog_device { #define WATCHDOG_NOWAYOUT 0 #define WATCHDOG_NOWAYOUT_INIT_STATUS 0 #endif +/* other proposal: WATCHDOG_ALWAYS_ACTIVE */ +#define WATCHDOG_KEEP_ON (1 << WDOG_KEEP_ON) /* Use the following function to check whether or not the watchdog is active */ static inline bool watchdog_active(struct watchdog_device *wdd)