kern_clock.c (a89ec05e3eddc4235386e1246b638b3d4d8815f5) kern_clock.c (4103b7652d1c438d04b360d0c81bae619b1b8259)
1/*-
2 * Copyright (c) 1982, 1986, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 76 unchanged lines hidden (view full) ---

85SYSINIT(clocks, SI_SUB_CLOCKS, SI_ORDER_FIRST, initclocks, NULL)
86
87/* Some of these don't belong here, but it's easiest to concentrate them. */
88long cp_time[CPUSTATES];
89
90SYSCTL_OPAQUE(_kern, OID_AUTO, cp_time, CTLFLAG_RD, &cp_time, sizeof(cp_time),
91 "LU", "CPU time statistics");
92
1/*-
2 * Copyright (c) 1982, 1986, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 76 unchanged lines hidden (view full) ---

85SYSINIT(clocks, SI_SUB_CLOCKS, SI_ORDER_FIRST, initclocks, NULL)
86
87/* Some of these don't belong here, but it's easiest to concentrate them. */
88long cp_time[CPUSTATES];
89
90SYSCTL_OPAQUE(_kern, OID_AUTO, cp_time, CTLFLAG_RD, &cp_time, sizeof(cp_time),
91 "LU", "CPU time statistics");
92
93#ifdef WATCHDOG
94static int sysctl_watchdog_reset(SYSCTL_HANDLER_ARGS);
95static void watchdog_fire(void);
93#ifdef SW_WATCHDOG
94#include <sys/watchdog.h>
96
95
96static int watchdog_ticks;
97static int watchdog_enabled;
97static int watchdog_enabled;
98static unsigned int watchdog_ticks;
99static int watchdog_timeout = 20;
98static void watchdog_fire(void);
99static void watchdog_config(void *, u_int, int *);
100#endif /* SW_WATCHDOG */
100
101
101SYSCTL_NODE(_debug, OID_AUTO, watchdog, CTLFLAG_RW, 0, "System watchdog");
102SYSCTL_INT(_debug_watchdog, OID_AUTO, enabled, CTLFLAG_RW, &watchdog_enabled,
103 0, "Enable the watchdog");
104SYSCTL_INT(_debug_watchdog, OID_AUTO, timeout, CTLFLAG_RW, &watchdog_timeout,
105 0, "Timeout for watchdog checkins");
106
107#endif /* WATCHDOG */
108
109/*
110 * Clock handling routines.
111 *
112 * This code is written to operate with two timers that run independently of
113 * each other.
114 *
115 * The main timer, running hz times per second, is used to trigger interval
116 * timers, timeouts and rescheduling as needed.

--- 45 unchanged lines hidden (view full) ---

162
163 /*
164 * Compute profhz/stathz, and fix profhz if needed.
165 */
166 i = stathz ? stathz : hz;
167 if (profhz == 0)
168 profhz = i;
169 psratio = profhz / i;
102/*
103 * Clock handling routines.
104 *
105 * This code is written to operate with two timers that run independently of
106 * each other.
107 *
108 * The main timer, running hz times per second, is used to trigger interval
109 * timers, timeouts and rescheduling as needed.

--- 45 unchanged lines hidden (view full) ---

155
156 /*
157 * Compute profhz/stathz, and fix profhz if needed.
158 */
159 i = stathz ? stathz : hz;
160 if (profhz == 0)
161 profhz = i;
162 psratio = profhz / i;
163#ifdef SW_WATCHDOG
164 EVENTHANDLER_REGISTER(watchdog_list, watchdog_config, NULL, 0);
165#endif
170}
171
172/*
173 * Each time the real-time timer fires, this function is called on all CPUs.
174 * Note that hardclock() calls hardclock_process() for the boot CPU, so only
175 * the other CPUs in the system need to call this function.
176 */
177void

--- 68 unchanged lines hidden (view full) ---

246
247 /*
248 * swi_sched acquires sched_lock, so we don't want to call it with
249 * callout_lock held; incorrect locking order.
250 */
251 if (need_softclock)
252 swi_sched(softclock_ih, 0);
253
166}
167
168/*
169 * Each time the real-time timer fires, this function is called on all CPUs.
170 * Note that hardclock() calls hardclock_process() for the boot CPU, so only
171 * the other CPUs in the system need to call this function.
172 */
173void

--- 68 unchanged lines hidden (view full) ---

242
243 /*
244 * swi_sched acquires sched_lock, so we don't want to call it with
245 * callout_lock held; incorrect locking order.
246 */
247 if (need_softclock)
248 swi_sched(softclock_ih, 0);
249
254#ifdef WATCHDOG
255 if (watchdog_enabled > 0 &&
256 (int)(ticks - watchdog_ticks) >= (hz * watchdog_timeout))
250#ifdef SW_WATCHDOG
251 if (watchdog_enabled > 0 && --watchdog_ticks <= 0)
257 watchdog_fire();
252 watchdog_fire();
258#endif /* WATCHDOG */
253#endif /* SW_WATCHDOG */
259}
260
261/*
262 * Compute number of ticks in the specified amount of time.
263 */
264int
265tvtohz(tv)
266 struct timeval *tv;

--- 236 unchanged lines hidden (view full) ---

503 clkinfo.stathz = stathz ? stathz : hz;
504 return (sysctl_handle_opaque(oidp, &clkinfo, sizeof clkinfo, req));
505}
506
507SYSCTL_PROC(_kern, KERN_CLOCKRATE, clockrate, CTLTYPE_STRUCT|CTLFLAG_RD,
508 0, 0, sysctl_kern_clockrate, "S,clockinfo",
509 "Rate and period of various kernel clocks");
510
254}
255
256/*
257 * Compute number of ticks in the specified amount of time.
258 */
259int
260tvtohz(tv)
261 struct timeval *tv;

--- 236 unchanged lines hidden (view full) ---

498 clkinfo.stathz = stathz ? stathz : hz;
499 return (sysctl_handle_opaque(oidp, &clkinfo, sizeof clkinfo, req));
500}
501
502SYSCTL_PROC(_kern, KERN_CLOCKRATE, clockrate, CTLTYPE_STRUCT|CTLFLAG_RD,
503 0, 0, sysctl_kern_clockrate, "S,clockinfo",
504 "Rate and period of various kernel clocks");
505
511#ifdef WATCHDOG
512/*
513 * Reset the watchdog timer to ticks, thus preventing the watchdog
514 * from firing for another watchdog timeout period.
515 */
516static int
517sysctl_watchdog_reset(SYSCTL_HANDLER_ARGS)
506#ifdef SW_WATCHDOG
507
508static void
509watchdog_config(void *unused __unused, u_int cmd, int *err)
518{
510{
519 int ret;
511 u_int u;
520
512
521 ret = 0;
522 watchdog_ticks = ticks;
523 return sysctl_handle_int(oidp, &ret, 0, req);
513 if (cmd) {
514 u = cmd & WD_INTERVAL;
515 if (u < WD_TO_1SEC)
516 return;
517 watchdog_ticks = (1 << (u - WD_TO_1SEC)) * hz;
518 watchdog_enabled = 1;
519 *err = 0;
520 } else {
521 watchdog_enabled = 0;
522 }
524}
525
523}
524
526SYSCTL_PROC(_debug_watchdog, OID_AUTO, reset, CTLFLAG_RW, 0, 0,
527 sysctl_watchdog_reset, "I", "Reset the watchdog");
528
529/*
530 * Handle a watchdog timeout by dumping interrupt information and
531 * then either dropping to DDB or panicing.
532 */
533static void
534watchdog_fire(void)
535{
536 int nintr;

--- 18 unchanged lines hidden (view full) ---

555#ifdef DDB
556 db_print_backtrace();
557 Debugger("watchdog timeout");
558#else /* !DDB */
559 panic("watchdog timeout");
560#endif /* DDB */
561}
562
525/*
526 * Handle a watchdog timeout by dumping interrupt information and
527 * then either dropping to DDB or panicing.
528 */
529static void
530watchdog_fire(void)
531{
532 int nintr;

--- 18 unchanged lines hidden (view full) ---

551#ifdef DDB
552 db_print_backtrace();
553 Debugger("watchdog timeout");
554#else /* !DDB */
555 panic("watchdog timeout");
556#endif /* DDB */
557}
558
563#endif /* WATCHDOG */
559#endif /* SW_WATCHDOG */