Home | History | Annotate | Line # | Download | only in sysmon
sysmon_wdog.c revision 1.8.2.2
      1  1.8.2.2    skrll /*	$NetBSD: sysmon_wdog.c,v 1.8.2.2 2004/08/03 10:51:29 skrll Exp $	*/
      2      1.1  thorpej 
      3      1.1  thorpej /*-
      4      1.1  thorpej  * Copyright (c) 2000 Zembu Labs, Inc.
      5      1.1  thorpej  * All rights reserved.
      6      1.1  thorpej  *
      7      1.1  thorpej  * Author: Jason R. Thorpe <thorpej (at) zembu.com>
      8      1.1  thorpej  *
      9      1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     10      1.1  thorpej  * modification, are permitted provided that the following conditions
     11      1.1  thorpej  * are met:
     12      1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     13      1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     14      1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     16      1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     17      1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     18      1.1  thorpej  *    must display the following acknowledgement:
     19      1.1  thorpej  *	This product includes software developed by Zembu Labs, Inc.
     20      1.1  thorpej  * 4. Neither the name of Zembu Labs nor the names of its employees may
     21      1.1  thorpej  *    be used to endorse or promote products derived from this software
     22      1.1  thorpej  *    without specific prior written permission.
     23      1.1  thorpej  *
     24      1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY ZEMBU LABS, INC. ``AS IS'' AND ANY EXPRESS
     25      1.1  thorpej  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAR-
     26      1.1  thorpej  * RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
     27      1.1  thorpej  * CLAIMED.  IN NO EVENT SHALL ZEMBU LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
     28      1.1  thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29      1.1  thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30      1.1  thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31      1.1  thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32      1.1  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33      1.1  thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34      1.1  thorpej  */
     35      1.1  thorpej 
     36      1.1  thorpej /*
     37      1.1  thorpej  * Watchdog timer framework for sysmon.  Hardware (and software)
     38      1.1  thorpej  * watchdog timers can register themselves here to provide a
     39      1.1  thorpej  * watchdog function, which provides an abstract interface to the
     40      1.1  thorpej  * user.
     41      1.1  thorpej  */
     42      1.3    lukem 
     43      1.3    lukem #include <sys/cdefs.h>
     44  1.8.2.2    skrll __KERNEL_RCSID(0, "$NetBSD: sysmon_wdog.c,v 1.8.2.2 2004/08/03 10:51:29 skrll Exp $");
     45      1.1  thorpej 
     46      1.1  thorpej #include <sys/param.h>
     47      1.1  thorpej #include <sys/conf.h>
     48      1.1  thorpej #include <sys/errno.h>
     49      1.1  thorpej #include <sys/fcntl.h>
     50      1.1  thorpej #include <sys/lock.h>
     51      1.1  thorpej #include <sys/callout.h>
     52      1.1  thorpej #include <sys/kernel.h>
     53      1.1  thorpej #include <sys/systm.h>
     54      1.1  thorpej #include <sys/proc.h>
     55      1.1  thorpej 
     56      1.1  thorpej #include <dev/sysmon/sysmonvar.h>
     57      1.1  thorpej 
     58      1.1  thorpej LIST_HEAD(, sysmon_wdog) sysmon_wdog_list =
     59      1.1  thorpej     LIST_HEAD_INITIALIZER(&sysmon_wdog_list);
     60      1.1  thorpej int sysmon_wdog_count;
     61      1.1  thorpej struct simplelock sysmon_wdog_list_slock = SIMPLELOCK_INITIALIZER;
     62      1.1  thorpej 
     63      1.1  thorpej struct simplelock sysmon_wdog_slock = SIMPLELOCK_INITIALIZER;
     64      1.1  thorpej struct sysmon_wdog *sysmon_armed_wdog;
     65      1.1  thorpej struct callout sysmon_wdog_callout = CALLOUT_INITIALIZER;
     66      1.1  thorpej void *sysmon_wdog_sdhook;
     67      1.1  thorpej 
     68      1.1  thorpej #define	SYSMON_WDOG_LOCK(s)						\
     69      1.1  thorpej do {									\
     70      1.1  thorpej 	s = splsoftclock();						\
     71      1.1  thorpej 	simple_lock(&sysmon_wdog_slock);				\
     72      1.1  thorpej } while (0)
     73      1.1  thorpej 
     74      1.1  thorpej #define	SYSMON_WDOG_UNLOCK(s)						\
     75      1.1  thorpej do {									\
     76      1.1  thorpej 	simple_unlock(&sysmon_wdog_slock);				\
     77      1.1  thorpej 	splx(s);							\
     78      1.1  thorpej } while (0)
     79      1.1  thorpej 
     80      1.1  thorpej struct sysmon_wdog *sysmon_wdog_find(const char *);
     81      1.1  thorpej void	sysmon_wdog_release(struct sysmon_wdog *);
     82      1.1  thorpej int	sysmon_wdog_setmode(struct sysmon_wdog *, int, u_int);
     83      1.1  thorpej void	sysmon_wdog_ktickle(void *);
     84      1.1  thorpej void	sysmon_wdog_shutdown(void *);
     85      1.1  thorpej 
     86      1.1  thorpej /*
     87      1.1  thorpej  * sysmonopen_wdog:
     88      1.1  thorpej  *
     89      1.1  thorpej  *	Open the system monitor device.
     90      1.1  thorpej  */
     91      1.1  thorpej int
     92  1.8.2.1  darrenr sysmonopen_wdog(dev_t dev, int flag, int mode, struct lwp *l)
     93      1.1  thorpej {
     94      1.1  thorpej 
     95      1.1  thorpej 	simple_lock(&sysmon_wdog_list_slock);
     96      1.1  thorpej 	if (sysmon_wdog_sdhook == NULL) {
     97      1.1  thorpej 		sysmon_wdog_sdhook =
     98      1.1  thorpej 		    shutdownhook_establish(sysmon_wdog_shutdown, NULL);
     99      1.1  thorpej 		if (sysmon_wdog_sdhook == NULL)
    100      1.1  thorpej 			printf("WARNING: unable to register watchdog "
    101      1.1  thorpej 			    "shutdown hook\n");
    102      1.1  thorpej 	}
    103      1.1  thorpej 	simple_unlock(&sysmon_wdog_list_slock);
    104      1.1  thorpej 
    105      1.1  thorpej 	return (0);
    106      1.1  thorpej }
    107      1.1  thorpej 
    108      1.1  thorpej /*
    109      1.1  thorpej  * sysmonclose_wdog:
    110      1.1  thorpej  *
    111      1.1  thorpej  *	Close the system monitor device.
    112      1.1  thorpej  */
    113      1.1  thorpej int
    114  1.8.2.1  darrenr sysmonclose_wdog(dev_t dev, int flag, int mode, struct lwp *l)
    115      1.1  thorpej {
    116      1.1  thorpej 	struct sysmon_wdog *smw;
    117  1.8.2.2    skrll 	int s, error = 0;
    118      1.1  thorpej 
    119      1.1  thorpej 	/*
    120      1.1  thorpej 	 * If this is the last close, and there is a watchdog
    121      1.1  thorpej 	 * running in UTICKLE mode, we need to disable it,
    122      1.1  thorpej 	 * otherwise the system will reset in short order.
    123      1.1  thorpej 	 *
    124      1.1  thorpej 	 * XXX Maybe we should just go into KTICKLE mode?
    125      1.1  thorpej 	 */
    126      1.1  thorpej 	SYSMON_WDOG_LOCK(s);
    127      1.1  thorpej 	if ((smw = sysmon_armed_wdog) != NULL) {
    128  1.8.2.2    skrll 		if (smw->smw_mode == WDOG_MODE_UTICKLE) {
    129      1.1  thorpej 			error = sysmon_wdog_setmode(smw,
    130      1.1  thorpej 			    WDOG_MODE_DISARMED, smw->smw_period);
    131      1.1  thorpej 			if (error) {
    132      1.1  thorpej 				printf("WARNING: UNABLE TO DISARM "
    133      1.1  thorpej 				    "WATCHDOG %s ON CLOSE!\n",
    134      1.1  thorpej 				    smw->smw_name);
    135      1.1  thorpej 				/*
    136      1.1  thorpej 				 * ...we will probably reboot soon.
    137      1.1  thorpej 				 */
    138      1.1  thorpej 			}
    139      1.1  thorpej 		}
    140      1.1  thorpej 	}
    141      1.1  thorpej 	SYSMON_WDOG_UNLOCK(s);
    142      1.1  thorpej 
    143      1.1  thorpej 	return (error);
    144      1.1  thorpej }
    145      1.1  thorpej 
    146      1.1  thorpej /*
    147      1.1  thorpej  * sysmonioctl_wdog:
    148      1.1  thorpej  *
    149      1.1  thorpej  *	Perform a watchdog control request.
    150      1.1  thorpej  */
    151      1.1  thorpej int
    152  1.8.2.1  darrenr sysmonioctl_wdog(dev_t dev, u_long cmd, caddr_t data, int flag, struct lwp *l)
    153      1.1  thorpej {
    154      1.1  thorpej 	struct sysmon_wdog *smw;
    155      1.1  thorpej 	int s, error = 0;
    156      1.1  thorpej 
    157      1.1  thorpej 	switch (cmd) {
    158      1.1  thorpej 	case WDOGIOC_GMODE:
    159      1.1  thorpej 	    {
    160      1.1  thorpej 		struct wdog_mode *wm = (void *) data;
    161      1.1  thorpej 
    162      1.1  thorpej 		wm->wm_name[sizeof(wm->wm_name) - 1] = '\0';
    163      1.1  thorpej 		smw = sysmon_wdog_find(wm->wm_name);
    164      1.1  thorpej 		if (smw == NULL) {
    165      1.1  thorpej 			error = ESRCH;
    166      1.1  thorpej 			break;
    167      1.1  thorpej 		}
    168      1.1  thorpej 
    169      1.1  thorpej 		wm->wm_mode = smw->smw_mode;
    170      1.1  thorpej 		wm->wm_period = smw->smw_period;
    171      1.1  thorpej 		sysmon_wdog_release(smw);
    172      1.1  thorpej 		break;
    173      1.1  thorpej 	    }
    174      1.1  thorpej 
    175      1.1  thorpej 	case WDOGIOC_SMODE:
    176      1.1  thorpej 	    {
    177      1.1  thorpej 		struct wdog_mode *wm = (void *) data;
    178      1.1  thorpej 
    179      1.1  thorpej 		if ((flag & FWRITE) == 0) {
    180      1.1  thorpej 			error = EPERM;
    181      1.1  thorpej 			break;
    182      1.1  thorpej 		}
    183      1.1  thorpej 
    184      1.1  thorpej 		wm->wm_name[sizeof(wm->wm_name) - 1] = '\0';
    185      1.1  thorpej 		smw = sysmon_wdog_find(wm->wm_name);
    186      1.1  thorpej 		if (smw == NULL) {
    187      1.1  thorpej 			error = ESRCH;
    188      1.1  thorpej 			break;
    189      1.1  thorpej 		}
    190      1.1  thorpej 
    191      1.1  thorpej 		if (wm->wm_mode & ~(WDOG_MODE_MASK|WDOG_FEATURE_MASK))
    192      1.1  thorpej 			error = EINVAL;
    193      1.1  thorpej 		else {
    194      1.1  thorpej 			SYSMON_WDOG_LOCK(s);
    195      1.1  thorpej 			error = sysmon_wdog_setmode(smw, wm->wm_mode,
    196      1.1  thorpej 			    wm->wm_period);
    197      1.1  thorpej 			SYSMON_WDOG_UNLOCK(s);
    198      1.1  thorpej 		}
    199      1.1  thorpej 
    200      1.1  thorpej 		sysmon_wdog_release(smw);
    201      1.1  thorpej 		break;
    202      1.1  thorpej 	    }
    203      1.1  thorpej 
    204      1.1  thorpej 	case WDOGIOC_WHICH:
    205      1.1  thorpej 	    {
    206      1.1  thorpej 		struct wdog_mode *wm = (void *) data;
    207      1.1  thorpej 
    208      1.1  thorpej 		SYSMON_WDOG_LOCK(s);
    209      1.1  thorpej 		if ((smw = sysmon_armed_wdog) != NULL) {
    210      1.1  thorpej 			strcpy(wm->wm_name, smw->smw_name);
    211      1.1  thorpej 			wm->wm_mode = smw->smw_mode;
    212      1.1  thorpej 			wm->wm_period = smw->smw_period;
    213      1.1  thorpej 		} else
    214      1.1  thorpej 			error = ESRCH;
    215      1.1  thorpej 		SYSMON_WDOG_UNLOCK(s);
    216      1.1  thorpej 		break;
    217      1.1  thorpej 	    }
    218      1.1  thorpej 
    219      1.1  thorpej 	case WDOGIOC_TICKLE:
    220      1.1  thorpej 		if ((flag & FWRITE) == 0) {
    221      1.1  thorpej 			error = EPERM;
    222      1.1  thorpej 			break;
    223      1.1  thorpej 		}
    224      1.1  thorpej 
    225      1.1  thorpej 		SYSMON_WDOG_LOCK(s);
    226      1.1  thorpej 		if ((smw = sysmon_armed_wdog) != NULL) {
    227      1.1  thorpej 			error = (*smw->smw_tickle)(smw);
    228      1.1  thorpej 			if (error == 0)
    229  1.8.2.1  darrenr 				smw->smw_tickler = l->l_proc->p_pid;
    230      1.1  thorpej 		} else
    231      1.1  thorpej 			error = ESRCH;
    232      1.1  thorpej 		SYSMON_WDOG_UNLOCK(s);
    233      1.1  thorpej 		break;
    234      1.1  thorpej 
    235      1.1  thorpej 	case WDOGIOC_GTICKLER:
    236      1.4   simonb 		if ((smw = sysmon_armed_wdog) != NULL)
    237      1.4   simonb 			*(pid_t *)data = smw->smw_tickler;
    238      1.4   simonb 		else
    239      1.4   simonb 			error = ESRCH;
    240      1.1  thorpej 		break;
    241      1.1  thorpej 
    242      1.1  thorpej 	case WDOGIOC_GWDOGS:
    243      1.1  thorpej 	    {
    244      1.1  thorpej 		struct wdog_conf *wc = (void *) data;
    245      1.1  thorpej 		char *cp;
    246      1.1  thorpej 		int i;
    247      1.1  thorpej 
    248      1.1  thorpej 		simple_lock(&sysmon_wdog_list_slock);
    249      1.1  thorpej 		if (wc->wc_names == NULL)
    250      1.1  thorpej 			wc->wc_count = sysmon_wdog_count;
    251      1.1  thorpej 		else {
    252      1.1  thorpej 			for (i = 0, cp = wc->wc_names,
    253      1.1  thorpej 			       smw = LIST_FIRST(&sysmon_wdog_list);
    254      1.1  thorpej 			     i < sysmon_wdog_count && smw != NULL && error == 0;
    255      1.1  thorpej 			     i++, cp += WDOG_NAMESIZE,
    256      1.1  thorpej 			       smw = LIST_NEXT(smw, smw_list))
    257      1.1  thorpej 				error = copyout(smw->smw_name, cp,
    258      1.1  thorpej 				    strlen(smw->smw_name) + 1);
    259      1.1  thorpej 			wc->wc_count = i;
    260      1.1  thorpej 		}
    261      1.1  thorpej 		simple_unlock(&sysmon_wdog_list_slock);
    262      1.1  thorpej 		break;
    263      1.1  thorpej 	    }
    264      1.1  thorpej 
    265      1.1  thorpej 	default:
    266      1.1  thorpej 		error = ENOTTY;
    267      1.1  thorpej 	}
    268      1.1  thorpej 
    269      1.1  thorpej 	return (error);
    270      1.1  thorpej }
    271      1.1  thorpej 
    272      1.1  thorpej /*
    273      1.1  thorpej  * sysmon_wdog_register:
    274      1.1  thorpej  *
    275      1.1  thorpej  *	Register a watchdog device.
    276      1.1  thorpej  */
    277      1.1  thorpej int
    278      1.1  thorpej sysmon_wdog_register(struct sysmon_wdog *smw)
    279      1.1  thorpej {
    280      1.1  thorpej 	struct sysmon_wdog *lsmw;
    281      1.1  thorpej 	int error = 0;
    282      1.1  thorpej 
    283      1.1  thorpej 	simple_lock(&sysmon_wdog_list_slock);
    284      1.1  thorpej 
    285      1.1  thorpej 	for (lsmw = LIST_FIRST(&sysmon_wdog_list); lsmw != NULL;
    286      1.1  thorpej 	     lsmw = LIST_NEXT(lsmw, smw_list)) {
    287      1.1  thorpej 		if (strcmp(lsmw->smw_name, smw->smw_name) == 0) {
    288      1.1  thorpej 			error = EEXIST;
    289      1.1  thorpej 			goto out;
    290      1.1  thorpej 		}
    291      1.1  thorpej 	}
    292      1.1  thorpej 
    293      1.1  thorpej 	smw->smw_mode = WDOG_MODE_DISARMED;
    294      1.1  thorpej 	smw->smw_tickler = (pid_t) -1;
    295      1.1  thorpej 	smw->smw_refcnt = 0;
    296      1.1  thorpej 	sysmon_wdog_count++;
    297      1.1  thorpej 	LIST_INSERT_HEAD(&sysmon_wdog_list, smw, smw_list);
    298      1.1  thorpej 
    299      1.1  thorpej  out:
    300      1.1  thorpej 	simple_unlock(&sysmon_wdog_list_slock);
    301      1.1  thorpej 	return (error);
    302      1.1  thorpej }
    303      1.1  thorpej 
    304      1.1  thorpej /*
    305      1.1  thorpej  * sysmon_wdog_unregister:
    306      1.1  thorpej  *
    307      1.1  thorpej  *	Unregister a watchdog device.
    308      1.1  thorpej  */
    309      1.1  thorpej void
    310      1.1  thorpej sysmon_wdog_unregister(struct sysmon_wdog *smw)
    311      1.1  thorpej {
    312      1.1  thorpej 
    313      1.1  thorpej 	simple_lock(&sysmon_wdog_list_slock);
    314      1.1  thorpej 	sysmon_wdog_count--;
    315      1.1  thorpej 	LIST_REMOVE(smw, smw_list);
    316      1.1  thorpej 	simple_unlock(&sysmon_wdog_list_slock);
    317      1.1  thorpej }
    318      1.1  thorpej 
    319      1.1  thorpej /*
    320      1.1  thorpej  * sysmon_wdog_find:
    321      1.1  thorpej  *
    322      1.1  thorpej  *	Find a watchdog device.  We increase the reference
    323      1.1  thorpej  *	count on a match.
    324      1.1  thorpej  */
    325      1.1  thorpej struct sysmon_wdog *
    326      1.1  thorpej sysmon_wdog_find(const char *name)
    327      1.1  thorpej {
    328      1.1  thorpej 	struct sysmon_wdog *smw;
    329      1.1  thorpej 
    330      1.1  thorpej 	simple_lock(&sysmon_wdog_list_slock);
    331      1.1  thorpej 
    332      1.1  thorpej 	for (smw = LIST_FIRST(&sysmon_wdog_list); smw != NULL;
    333      1.1  thorpej 	     smw = LIST_NEXT(smw, smw_list)) {
    334      1.1  thorpej 		if (strcmp(smw->smw_name, name) == 0)
    335      1.1  thorpej 			break;
    336      1.1  thorpej 	}
    337      1.1  thorpej 
    338      1.1  thorpej 	if (smw != NULL)
    339      1.1  thorpej 		smw->smw_refcnt++;
    340      1.1  thorpej 
    341      1.1  thorpej 	simple_unlock(&sysmon_wdog_list_slock);
    342      1.1  thorpej 	return (smw);
    343      1.1  thorpej }
    344      1.1  thorpej 
    345      1.1  thorpej /*
    346      1.1  thorpej  * sysmon_wdog_release:
    347      1.1  thorpej  *
    348      1.1  thorpej  *	Release a watchdog device.
    349      1.1  thorpej  */
    350      1.1  thorpej void
    351      1.1  thorpej sysmon_wdog_release(struct sysmon_wdog *smw)
    352      1.1  thorpej {
    353      1.1  thorpej 
    354      1.1  thorpej 	simple_lock(&sysmon_wdog_list_slock);
    355      1.1  thorpej 	KASSERT(smw->smw_refcnt != 0);
    356      1.1  thorpej 	smw->smw_refcnt--;
    357      1.1  thorpej 	simple_unlock(&sysmon_wdog_list_slock);
    358      1.1  thorpej }
    359      1.1  thorpej 
    360      1.1  thorpej /*
    361      1.1  thorpej  * sysmon_wdog_setmode:
    362      1.1  thorpej  *
    363      1.1  thorpej  *	Set the mode of a watchdog device.
    364      1.1  thorpej  */
    365      1.1  thorpej int
    366      1.1  thorpej sysmon_wdog_setmode(struct sysmon_wdog *smw, int mode, u_int period)
    367      1.1  thorpej {
    368      1.1  thorpej 	u_int operiod = smw->smw_period;
    369      1.1  thorpej 	int omode = smw->smw_mode;
    370      1.1  thorpej 	int error = 0;
    371      1.1  thorpej 
    372      1.1  thorpej 	smw->smw_period = period;
    373      1.1  thorpej 	smw->smw_mode = mode;
    374      1.1  thorpej 
    375      1.1  thorpej 	switch (mode & WDOG_MODE_MASK) {
    376      1.1  thorpej 	case WDOG_MODE_DISARMED:
    377      1.1  thorpej 		if (smw != sysmon_armed_wdog) {
    378      1.1  thorpej 			error = EINVAL;
    379      1.1  thorpej 			goto out;
    380      1.1  thorpej 		}
    381      1.1  thorpej 		break;
    382      1.1  thorpej 
    383      1.1  thorpej 	case WDOG_MODE_KTICKLE:
    384      1.1  thorpej 	case WDOG_MODE_UTICKLE:
    385      1.1  thorpej 		if (sysmon_armed_wdog != NULL) {
    386      1.1  thorpej 			error = EBUSY;
    387      1.1  thorpej 			goto out;
    388      1.1  thorpej 		}
    389      1.1  thorpej 		break;
    390      1.1  thorpej 
    391      1.1  thorpej 	default:
    392      1.1  thorpej 		error = EINVAL;
    393      1.1  thorpej 		goto out;
    394      1.1  thorpej 	}
    395      1.1  thorpej 
    396      1.1  thorpej 	error = (*smw->smw_setmode)(smw);
    397      1.1  thorpej 
    398      1.1  thorpej  out:
    399      1.1  thorpej 	if (error) {
    400      1.1  thorpej 		smw->smw_period = operiod;
    401      1.1  thorpej 		smw->smw_mode = omode;
    402      1.1  thorpej 	} else {
    403      1.1  thorpej 		if ((mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
    404      1.2  thorpej 			sysmon_armed_wdog = NULL;
    405      1.1  thorpej 			smw->smw_tickler = (pid_t) -1;
    406      1.1  thorpej 			smw->smw_refcnt--;
    407      1.1  thorpej 			if ((omode & WDOG_MODE_MASK) == WDOG_MODE_KTICKLE)
    408      1.1  thorpej 				callout_stop(&sysmon_wdog_callout);
    409      1.1  thorpej 		} else {
    410      1.1  thorpej 			sysmon_armed_wdog = smw;
    411      1.1  thorpej 			smw->smw_refcnt++;
    412      1.1  thorpej 			if ((mode & WDOG_MODE_MASK) == WDOG_MODE_KTICKLE) {
    413      1.1  thorpej 				callout_reset(&sysmon_wdog_callout,
    414      1.1  thorpej 				    WDOG_PERIOD_TO_TICKS(smw->smw_period) / 2,
    415      1.1  thorpej 				    sysmon_wdog_ktickle, NULL);
    416      1.1  thorpej 			}
    417      1.1  thorpej 		}
    418      1.1  thorpej 	}
    419      1.1  thorpej 	return (error);
    420      1.1  thorpej }
    421      1.1  thorpej 
    422      1.1  thorpej /*
    423      1.1  thorpej  * sysmon_wdog_ktickle:
    424      1.1  thorpej  *
    425      1.1  thorpej  *	Kernel watchdog tickle routine.
    426      1.1  thorpej  */
    427      1.1  thorpej void
    428      1.1  thorpej sysmon_wdog_ktickle(void *arg)
    429      1.1  thorpej {
    430      1.1  thorpej 	struct sysmon_wdog *smw;
    431      1.1  thorpej 	int s;
    432      1.1  thorpej 
    433      1.1  thorpej 	SYSMON_WDOG_LOCK(s);
    434      1.1  thorpej 	if ((smw = sysmon_armed_wdog) != NULL) {
    435      1.1  thorpej 		if ((*smw->smw_tickle)(smw) != 0) {
    436      1.1  thorpej 			printf("WARNING: KERNEL TICKLE OF WATCHDOG %s "
    437      1.1  thorpej 			    "FAILED!\n", smw->smw_name);
    438      1.1  thorpej 			/*
    439      1.1  thorpej 			 * ...we will probably reboot soon.
    440      1.1  thorpej 			 */
    441      1.1  thorpej 		}
    442      1.1  thorpej 		callout_reset(&sysmon_wdog_callout,
    443      1.1  thorpej 		    WDOG_PERIOD_TO_TICKS(smw->smw_period) / 2,
    444      1.1  thorpej 		    sysmon_wdog_ktickle, NULL);
    445      1.1  thorpej 	}
    446      1.1  thorpej 	SYSMON_WDOG_UNLOCK(s);
    447      1.1  thorpej }
    448      1.1  thorpej 
    449      1.1  thorpej /*
    450      1.1  thorpej  * sysmon_wdog_shutdown:
    451      1.1  thorpej  *
    452      1.1  thorpej  *	Perform shutdown-time operations.
    453      1.1  thorpej  */
    454      1.1  thorpej void
    455      1.1  thorpej sysmon_wdog_shutdown(void *arg)
    456      1.1  thorpej {
    457      1.1  thorpej 	struct sysmon_wdog *smw;
    458      1.1  thorpej 
    459      1.1  thorpej 	/*
    460      1.1  thorpej 	 * XXX Locking here?  I don't think it's necessary.
    461      1.1  thorpej 	 */
    462      1.1  thorpej 
    463      1.1  thorpej 	if ((smw = sysmon_armed_wdog) != NULL) {
    464      1.1  thorpej 		if (sysmon_wdog_setmode(smw, WDOG_MODE_DISARMED,
    465      1.1  thorpej 		    smw->smw_period))
    466      1.1  thorpej 			printf("WARNING: FAILED TO SHUTDOWN WATCHDOG %s!\n",
    467      1.1  thorpej 			    smw->smw_name);
    468      1.1  thorpej 	}
    469      1.1  thorpej }
    470