<s>
A	O
watchdog	B-Application
timer	I-Application
(	O
sometimes	O
called	O
a	O
computer	B-Application
operating	I-Application
properly	I-Application
or	O
COP	O
timer	O
,	O
or	O
simply	O
a	O
watchdog	B-Application
)	O
is	O
an	O
electronic	O
or	O
software	O
timer	O
that	O
is	O
used	O
to	O
detect	O
and	O
recover	O
from	O
computer	O
malfunctions	O
.	O
</s>
<s>
Watchdog	B-Application
timers	I-Application
are	O
widely	O
used	O
in	O
computers	O
to	O
facilitate	O
automatic	O
correction	O
of	O
temporary	O
hardware	O
faults	O
,	O
and	O
to	O
prevent	O
errant	O
or	O
malevolent	O
software	O
from	O
disrupting	O
system	O
operation	O
.	O
</s>
<s>
During	O
normal	O
operation	O
,	O
the	O
computer	O
regularly	O
restarts	O
the	O
watchdog	B-Application
timer	I-Application
to	O
prevent	O
it	O
from	O
elapsing	O
,	O
or	O
"	O
timing	O
out	O
"	O
.	O
</s>
<s>
If	O
,	O
due	O
to	O
a	O
hardware	O
fault	O
or	O
program	O
error	O
,	O
the	O
computer	O
fails	O
to	O
restart	O
the	O
watchdog	B-Application
,	O
the	O
timer	O
will	O
elapse	O
and	O
generate	O
a	O
timeout	O
signal	O
.	O
</s>
<s>
The	O
corrective	O
actions	O
typically	O
include	O
placing	O
the	O
computer	O
and	O
associated	O
hardware	O
in	O
a	O
safe	O
state	O
and	O
invoking	O
a	O
computer	B-Device
reboot	I-Device
.	O
</s>
<s>
Microcontrollers	B-Architecture
often	O
include	O
an	O
integrated	O
,	O
on-chip	O
watchdog	B-Application
.	O
</s>
<s>
In	O
other	O
computers	O
the	O
watchdog	B-Application
may	O
reside	O
in	O
a	O
nearby	O
chip	O
that	O
connects	O
directly	O
to	O
the	O
CPU	B-Device
,	O
or	O
it	O
may	O
be	O
located	O
on	O
an	O
external	O
expansion	B-Device
card	I-Device
in	O
the	O
computer	O
's	O
chassis	O
.	O
</s>
<s>
Watchdog	B-Application
timers	I-Application
are	O
commonly	O
found	O
in	O
embedded	B-Architecture
systems	I-Architecture
and	O
other	O
computer-controlled	O
equipment	O
where	O
humans	O
cannot	O
easily	O
access	O
the	O
equipment	O
or	O
would	O
be	O
unable	O
to	O
react	O
to	O
faults	O
in	O
a	O
timely	O
manner	O
.	O
</s>
<s>
In	O
such	O
systems	O
,	O
the	O
computer	O
cannot	O
depend	O
on	O
a	O
human	O
to	O
invoke	O
a	O
reboot	B-Device
if	O
it	O
hangs	B-General_Concept
;	O
it	O
must	O
be	O
self-reliant	O
.	O
</s>
<s>
For	O
example	O
,	O
remote	O
embedded	B-Architecture
systems	I-Architecture
such	O
as	O
space	O
probes	O
are	O
not	O
physically	O
accessible	O
to	O
human	O
operators	O
;	O
these	O
could	O
become	O
permanently	O
disabled	O
if	O
they	O
were	O
unable	O
to	O
autonomously	O
recover	O
from	O
faults	O
.	O
</s>
<s>
In	O
robots	B-Algorithm
and	O
other	O
automated	O
machines	O
,	O
a	O
fault	O
in	O
the	O
control	O
computer	O
could	O
cause	O
equipment	O
damage	O
or	O
injuries	O
before	O
a	O
human	O
could	O
react	O
,	O
even	O
if	O
the	O
computer	O
is	O
easily	O
accessed	O
.	O
</s>
<s>
A	O
watchdog	B-Application
timer	I-Application
is	O
usually	O
employed	O
in	O
cases	O
like	O
these	O
.	O
</s>
<s>
Watchdog	B-Application
timers	I-Application
are	O
also	O
used	O
to	O
monitor	O
and	O
limit	O
software	O
execution	O
time	O
on	O
a	O
normally	O
functioning	O
computer	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
watchdog	B-Application
timer	I-Application
may	O
be	O
used	O
when	O
running	O
untrusted	O
code	O
in	O
a	O
sandbox	O
,	O
to	O
limit	O
the	O
CPU	B-Device
time	O
available	O
to	O
the	O
code	O
and	O
thus	O
prevent	O
some	O
types	O
of	O
denial-of-service	O
attacks	O
.	O
</s>
<s>
In	O
real-time	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
,	O
a	O
watchdog	B-Application
timer	I-Application
may	O
be	O
used	O
to	O
monitor	O
a	O
time-critical	O
task	O
to	O
ensure	O
it	O
completes	O
within	O
its	O
maximum	O
allotted	O
time	O
and	O
,	O
if	O
it	O
fails	O
to	O
do	O
so	O
,	O
to	O
terminate	O
the	O
task	O
and	O
report	O
the	O
failure	O
.	O
</s>
<s>
The	O
act	O
of	O
restarting	O
a	O
watchdog	B-Application
timer	I-Application
is	O
commonly	O
referred	O
to	O
as	O
kicking	O
the	O
watchdog	B-Application
.	O
</s>
<s>
Kicking	O
is	O
typically	O
done	O
by	O
writing	O
to	O
a	O
watchdog	B-Application
control	O
port	B-Architecture
or	O
by	O
setting	O
a	O
particular	O
bit	O
in	O
a	O
register	B-General_Concept
.	O
</s>
<s>
Alternatively	O
,	O
some	O
tightly	O
coupled	O
watchdog	B-Application
timers	I-Application
are	O
kicked	O
by	O
executing	O
a	O
special	O
machine	B-Language
language	I-Language
instruction	O
.	O
</s>
<s>
An	O
example	O
of	O
this	O
is	O
the	O
CLRWDT	O
(	O
clear	O
watchdog	B-Application
timer	I-Application
)	O
instruction	O
found	O
in	O
the	O
instruction	O
set	O
of	O
some	O
PIC	B-Architecture
microcontrollers	I-Architecture
.	O
</s>
<s>
In	O
computers	O
that	O
are	O
running	O
operating	B-General_Concept
systems	I-General_Concept
,	O
watchdog	B-Application
restarts	O
are	O
usually	O
invoked	O
through	O
a	O
device	B-Application
driver	I-Application
.	O
</s>
<s>
For	O
example	O
,	O
in	O
the	O
Linux	B-Application
operating	I-Application
system	I-Application
,	O
a	O
user	B-Operating_System
space	I-Operating_System
program	O
will	O
kick	O
the	O
watchdog	B-Application
by	O
interacting	O
with	O
the	O
watchdog	B-Application
device	B-Application
driver	I-Application
,	O
typically	O
by	O
writing	O
a	O
zero	O
character	O
to	O
or	O
by	O
calling	O
a	O
KEEPALIVE	B-Protocol
ioctl	B-Operating_System
.	O
</s>
<s>
The	O
device	B-Application
driver	I-Application
,	O
which	O
serves	O
to	O
abstract	O
the	O
watchdog	B-Application
hardware	O
from	O
user	B-Operating_System
space	I-Operating_System
programs	O
,	O
may	O
also	O
be	O
used	O
to	O
configure	O
the	O
time-out	O
period	O
and	O
start	O
and	O
stop	O
the	O
timer	O
.	O
</s>
<s>
Some	O
watchdog	B-Application
timers	I-Application
will	O
only	O
allow	O
kicks	O
during	O
a	O
specific	O
time	O
window	O
.	O
</s>
<s>
The	O
window	O
timing	O
is	O
usually	O
relative	O
to	O
the	O
previous	O
kick	O
or	O
,	O
if	O
the	O
watchdog	B-Application
has	O
not	O
yet	O
been	O
kicked	O
,	O
to	O
the	O
moment	O
the	O
watchdog	B-Application
was	O
enabled	O
.	O
</s>
<s>
If	O
the	O
computer	O
attempts	O
to	O
kick	O
the	O
watchdog	B-Application
before	O
or	O
after	O
the	O
window	O
,	O
the	O
watchdog	B-Application
will	O
not	O
be	O
restarted	O
,	O
and	O
in	O
some	O
implementations	O
this	O
will	O
be	O
treated	O
as	O
a	O
fault	O
and	O
trigger	O
corrective	O
action	O
.	O
</s>
<s>
A	O
watchdog	B-Application
timer	I-Application
is	O
said	O
to	O
be	O
enabled	O
when	O
operating	O
and	O
disabled	O
when	O
idle	O
.	O
</s>
<s>
Upon	O
power-up	O
,	O
a	O
watchdog	B-Application
may	O
be	O
unconditionally	O
enabled	O
or	O
it	O
may	O
be	O
initially	O
disabled	O
and	O
require	O
an	O
external	O
signal	O
to	O
enable	O
it	O
.	O
</s>
<s>
In	O
some	O
systems	O
the	O
reset	O
signal	O
is	O
directly	O
used	O
to	O
enable	O
the	O
watchdog	B-Application
.	O
</s>
<s>
In	O
others	O
,	O
the	O
reset	O
signal	O
is	O
delayed	O
so	O
that	O
the	O
watchdog	B-Application
will	O
become	O
enabled	O
at	O
some	O
later	O
time	O
following	O
the	O
reset	O
.	O
</s>
<s>
This	O
delay	O
allows	O
time	O
for	O
the	O
computer	O
to	O
boot	O
before	O
the	O
watchdog	B-Application
is	O
enabled	O
.	O
</s>
<s>
Without	O
this	O
delay	O
,	O
the	O
watchdog	B-Application
would	O
timeout	O
and	O
invoke	O
a	O
subsequent	O
reset	O
before	O
the	O
computer	O
can	O
run	O
its	O
application	O
software	O
—	O
the	O
software	O
which	O
kicks	O
the	O
watchdog	B-Application
—	O
and	O
the	O
system	O
would	O
become	O
stuck	O
in	O
an	O
endless	O
cycle	O
of	O
incomplete	O
reboots	B-Device
.	O
</s>
<s>
Watchdog	B-Application
timers	I-Application
come	O
in	O
many	O
configurations	O
,	O
and	O
many	O
allow	O
their	O
configurations	O
to	O
be	O
altered	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
watchdog	B-Application
and	O
CPU	B-Device
may	O
share	O
a	O
common	O
clock	O
signal	O
as	O
shown	O
in	O
the	O
block	O
diagram	O
below	O
,	O
or	O
they	O
may	O
have	O
independent	O
clock	O
signals	O
.	O
</s>
<s>
A	O
basic	O
watchdog	B-Application
timer	I-Application
has	O
a	O
single	O
timer	O
stage	O
which	O
,	O
upon	O
timeout	O
,	O
typically	O
will	O
reset	O
the	O
CPU	B-Device
:	O
</s>
<s>
Two	O
or	O
more	O
timers	O
are	O
sometimes	O
cascaded	O
to	O
form	O
a	O
multistage	O
watchdog	B-Application
timer	I-Application
,	O
where	O
each	O
timer	O
is	O
referred	O
to	O
as	O
a	O
timer	O
stage	O
,	O
or	O
simply	O
a	O
stage	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
block	O
diagram	O
below	O
shows	O
a	O
three-stage	O
watchdog	B-Application
.	O
</s>
<s>
In	O
a	O
multistage	O
watchdog	B-Application
,	O
only	O
the	O
first	O
stage	O
is	O
kicked	O
by	O
the	O
processor	O
.	O
</s>
<s>
Typically	O
,	O
single-stage	O
watchdog	B-Application
timers	I-Application
are	O
used	O
to	O
simply	O
restart	O
the	O
computer	O
,	O
whereas	O
multistage	O
watchdog	B-Application
timers	I-Application
will	O
sequentially	O
trigger	O
a	O
series	O
of	O
corrective	O
actions	O
,	O
with	O
the	O
final	O
stage	O
triggering	O
a	O
computer	O
restart	O
.	O
</s>
<s>
Watchdog	B-Application
timers	I-Application
may	O
have	O
either	O
fixed	O
or	O
programmable	O
time	O
intervals	O
.	O
</s>
<s>
Some	O
watchdog	B-Application
timers	I-Application
allow	O
the	O
time	O
interval	O
to	O
be	O
programmed	O
by	O
selecting	O
from	O
among	O
a	O
few	O
selectable	O
,	O
discrete	O
values	O
.	O
</s>
<s>
Typically	O
,	O
watchdog	B-Application
time	O
intervals	O
range	O
from	O
ten	O
milliseconds	O
to	O
a	O
minute	O
or	O
more	O
.	O
</s>
<s>
In	O
a	O
multistage	O
watchdog	B-Application
,	O
each	O
timer	O
may	O
have	O
its	O
own	O
,	O
unique	O
time	O
interval	O
.	O
</s>
<s>
A	O
watchdog	B-Application
timer	I-Application
may	O
initiate	O
any	O
of	O
several	O
types	O
of	O
corrective	O
action	O
,	O
including	O
maskable	B-Application
interrupt	I-Application
,	O
non-maskable	B-General_Concept
interrupt	I-General_Concept
,	O
hardware	B-Operating_System
reset	I-Operating_System
,	O
fail-safe	B-General_Concept
state	O
activation	O
,	O
power	O
cycling	O
,	O
or	O
combinations	O
of	O
these	O
.	O
</s>
<s>
Depending	O
on	O
its	O
architecture	O
,	O
the	O
type	O
of	O
corrective	O
action	O
or	O
actions	O
that	O
a	O
watchdog	B-Application
can	O
trigger	O
may	O
be	O
fixed	O
or	O
programmable	O
.	O
</s>
<s>
Some	O
computers	O
(	O
e.g.	O
,	O
PC	O
compatibles	O
)	O
require	O
a	O
pulsed	O
signal	O
to	O
invoke	O
a	O
hardware	B-Operating_System
reset	I-Operating_System
.	O
</s>
<s>
In	O
such	O
cases	O
,	O
the	O
watchdog	B-Application
typically	O
triggers	O
a	O
hardware	B-Operating_System
reset	I-Operating_System
by	O
activating	O
an	O
internal	O
or	O
external	O
pulse	O
generator	O
,	O
which	O
in	O
turn	O
creates	O
the	O
required	O
reset	O
pulses	O
.	O
</s>
<s>
In	O
embedded	B-Architecture
systems	I-Architecture
and	O
control	O
systems	O
,	O
watchdog	B-Application
timers	I-Application
are	O
often	O
used	O
to	O
activate	O
fail-safe	B-General_Concept
circuitry	O
.	O
</s>
<s>
When	O
activated	O
,	O
the	O
fail-safe	B-General_Concept
circuitry	O
forces	O
all	O
control	O
outputs	O
to	O
safe	O
states	O
(	O
e.g.	O
,	O
turns	O
off	O
motors	O
,	O
heaters	O
,	O
and	O
high-voltages	O
)	O
to	O
prevent	O
injuries	O
and	O
equipment	O
damage	O
while	O
the	O
fault	O
persists	O
.	O
</s>
<s>
In	O
a	O
two-stage	O
watchdog	B-Application
,	O
the	O
first	O
timer	O
is	O
often	O
used	O
to	O
activate	O
fail-safe	B-General_Concept
outputs	O
and	O
start	O
the	O
second	O
timer	O
stage	O
;	O
the	O
second	O
stage	O
will	O
reset	O
the	O
computer	O
if	O
the	O
fault	O
cannot	O
be	O
corrected	O
before	O
the	O
timer	O
elapses	O
.	O
</s>
<s>
Watchdog	B-Application
timers	I-Application
are	O
sometimes	O
used	O
to	O
trigger	O
the	O
recording	O
of	O
system	O
state	O
information	O
—	O
which	O
may	O
be	O
useful	O
during	O
fault	O
recovery	O
—	O
or	O
debug	B-Device
information	O
(	O
which	O
may	O
be	O
useful	O
for	O
determining	O
the	O
cause	O
of	O
the	O
fault	O
)	O
onto	O
a	O
persistent	B-Application
medium	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
above	O
diagram	O
shows	O
a	O
likely	O
configuration	O
for	O
a	O
two-stage	O
watchdog	B-Application
timer	I-Application
.	O
</s>
<s>
This	O
event	O
will	O
start	O
the	O
Stage2	O
timer	O
and	O
,	O
simultaneously	O
,	O
notify	O
the	O
computer	O
(	O
by	O
means	O
of	O
a	O
non-maskable	B-General_Concept
interrupt	I-General_Concept
)	O
that	O
a	O
reset	O
is	O
imminent	O
.	O
</s>
<s>
Until	O
Stage2	O
times	O
out	O
,	O
the	O
computer	O
may	O
attempt	O
to	O
record	O
state	O
information	O
,	O
debug	B-Device
information	O
,	O
or	O
both	O
.	O
</s>
<s>
A	O
watchdog	B-Application
timer	I-Application
provides	O
automatic	O
detection	O
of	O
catastrophic	O
malfunctions	O
that	O
prevent	O
the	O
computer	O
from	O
kicking	O
it	O
.	O
</s>
<s>
However	O
,	O
computers	O
often	O
have	O
other	O
,	O
less-severe	O
types	O
of	O
faults	O
which	O
do	O
not	O
interfere	O
with	O
kicking	O
,	O
but	O
which	O
still	O
require	O
watchdog	B-Application
oversight	O
.	O
</s>
<s>
To	O
support	O
these	O
,	O
a	O
computer	O
system	O
is	O
typically	O
designed	O
so	O
that	O
its	O
watchdog	B-Application
timer	I-Application
will	O
be	O
kicked	O
only	O
if	O
the	O
computer	O
deems	O
the	O
system	O
functional	O
.	O
</s>
<s>
The	O
computer	O
determines	O
whether	O
the	O
system	O
is	O
functional	O
by	O
conducting	O
one	O
or	O
more	O
fault	O
detection	O
tests	O
and	O
will	O
kick	O
the	O
watchdog	B-Application
only	O
if	O
all	O
tests	O
have	O
passed	O
.	O
</s>
<s>
In	O
computers	O
that	O
are	O
running	O
an	O
operating	B-General_Concept
system	I-General_Concept
and	O
multiple	B-Operating_System
processes	I-Operating_System
,	O
a	O
single	O
,	O
simple	O
test	O
might	O
be	O
insufficient	O
to	O
guarantee	O
normal	O
operation	O
,	O
as	O
it	O
could	O
fail	O
to	O
detect	O
a	O
subtle	O
fault	O
condition	O
and	O
therefore	O
allow	O
the	O
watchdog	B-Application
to	O
be	O
kicked	O
even	O
though	O
a	O
fault	O
condition	O
exists	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
the	O
case	O
of	O
the	O
Linux	B-Application
operating	I-Application
system	I-Application
,	O
a	O
user-space	B-Operating_System
watchdog	B-Application
daemon	B-Operating_System
may	O
simply	O
kick	O
the	O
watchdog	B-Application
periodically	O
without	O
performing	O
any	O
tests	O
.	O
</s>
<s>
As	O
long	O
as	O
the	O
daemon	B-Operating_System
runs	O
normally	O
,	O
the	O
system	O
will	O
be	O
protected	O
against	O
serious	O
system	O
crashes	O
such	O
as	O
a	O
kernel	B-Operating_System
panic	I-Operating_System
.	O
</s>
<s>
To	O
detect	O
less	O
severe	O
faults	O
,	O
the	O
daemon	B-Operating_System
can	O
be	O
configured	O
to	O
perform	O
tests	O
that	O
cover	O
resource	O
availability	O
(	O
e.g.	O
,	O
sufficient	O
memory	B-General_Concept
and	O
file	B-Application
handles	I-Application
,	O
reasonable	O
CPU	B-Device
time	O
)	O
,	O
evidence	O
of	O
expected	O
process	O
activity	O
(	O
e.g.	O
,	O
system	B-Operating_System
daemons	I-Operating_System
running	O
,	O
specific	O
files	O
being	O
present	O
or	O
updated	O
)	O
,	O
overheating	O
,	O
and	O
network	O
activity	O
,	O
and	O
system-specific	O
test	O
scripts	O
or	O
programs	O
can	O
also	O
be	O
run	O
.	O
</s>
<s>
Upon	O
discovery	O
of	O
a	O
failed	O
test	O
,	O
the	O
computer	O
may	O
attempt	O
to	O
perform	O
a	O
sequence	O
of	O
corrective	O
actions	O
under	O
software	O
control	O
,	O
culminating	O
with	O
a	O
software-initiated	O
reboot	B-Device
.	O
</s>
<s>
If	O
the	O
software	O
fails	O
to	O
invoke	O
a	O
reboot	B-Device
,	O
the	O
watchdog	B-Application
timer	I-Application
will	O
timeout	O
and	O
invoke	O
a	O
hardware	B-Operating_System
reset	I-Operating_System
.	O
</s>
<s>
In	O
effect	O
,	O
this	O
is	O
a	O
multistage	O
watchdog	B-Application
timer	I-Application
in	O
which	O
the	O
software	O
comprises	O
the	O
first	O
and	O
intermediate	O
timer	O
stages	O
and	O
the	O
hardware	B-Operating_System
reset	I-Operating_System
the	O
final	O
stage	O
.	O
</s>
<s>
In	O
a	O
Linux	B-Application
system	O
,	O
for	O
example	O
,	O
the	O
watchdog	B-Application
daemon	B-Operating_System
could	O
attempt	O
to	O
perform	O
a	O
software-initiated	O
restart	O
,	O
which	O
can	O
be	O
preferable	O
to	O
a	O
hardware	B-Operating_System
reset	I-Operating_System
as	O
the	O
file	O
systems	O
will	O
be	O
safely	O
unmounted	B-Application
and	O
fault	O
information	O
will	O
be	O
logged	O
.	O
</s>
