4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

The Linux Watchdog driver API

Last updated at Posted at 2020-05-27


Docs » Linux Watchdog Support » The Linux Watchdog driver API

The Linux Watchdog driver API

Last reviewed: 10/05/2007

Copyright 2002 Christer Weingel wingel@nano-system.com

Some parts of this document are copied verbatim from the sbc60xxwdt driver which is (c) Copyright 2000 Jakob Oestergaard <jakob@ostenfeld.dk>

このドキュメントの一部は、(c) Copyright 2000 Jakob Oestergaard <jakob@ostenfeld.dk>の、sbc60xx wdt driverからそのままコピーしました。

This document describes the state of the Linux 2.4.18 kernel.

このドキュメントは、Linux 2.4.18 kernelの状態で記述されています。

Introduction

A Watchdog Timer (WDT) is a hardware circuit that can reset the computer system in case of a software fault. You probably knew that already.

Watchdog Timer (WDT)は、ソフトウェアトラブルが発生したケースでコンピュータシステムをリセットできるハードウェア回路です。このことは既に知っているかもしれません。

Usually a userspace daemon will notify the kernel watchdog driver via the /dev/watchdog special device file that userspace is still alive, at regular intervals. When such a notification occurs, the driver will usually tell the hardware watchdog that everything is in order, and that the watchdog should wait for yet another little while to reset the system. If userspace fails (RAM error, kernel bug, whatever), the notifications cease to occur, and the hardware watchdog will reset the system (causing a reboot) after the timeout occurs.

通常、ユーザー空間のdaemonは、ユーザー空間で生きている/dev/watchdog special device fileを介して、カーネルのwachdog driverにまだ生存していることを定期的に通知します。そのような通知が発生したら、driverは通常hardware watchdogへすべてが正常であることを通知し、watchdogはまだもう少しシステムをリセットするのを待つ必要があることを通知します。もし、ユーザー空間で問題(RAMのトラブル、カーネルのバグ、その他)があった場合、通史は発生しなくなり、hardware watchdogは、タイムアウトが発生した後、システムをリセットします(つまり再起動が発生します)。

The Linux watchdog API is a rather ad-hoc construction and different drivers implement different, and sometimes incompatible, parts of it. This file is an attempt to document the existing usage and allow future driver writers to use it as a reference.

Linux watchdog API はその場しのぎの構造です。異なるドライバーが異なる実装をし、互換性がなく、その一部を実装しています。このファイルでは、既存の使用方法をドキュメント化し、従来のドライバー作成者が参照できるようにする試みです。

The simplest API

All drivers support the basic mode of operation, where the watchdog activates as soon as /dev/watchdog is opened and will reboot unless the watchdog is pinged within a certain time, this time is called the timeout or margin. The simplest way to ping the watchdog is to write some data to the device. So a very simple watchdog daemon would look like this source file: see samples/watchdog/watchdog-simple.c

全てのドライバーは、処理に関する基本的なモードをサポートしています。watchdogは、/dev/watchdogが開かれると速やかに有効化されます。そして、watchdogへの一定時間の通知が無くなったらリブートをします。この時間を、timeoutあるいはmarginと呼びます。もっとも単純な、watchdogへpingする方法は、deviceに何らかのデータを書き込む事です。したがって、非常に単純なwatchdog daemonは、次のソースファイルのようになります。 samples/watchdog/watchdog-simple.c を参照してください。、

A more advanced driver could for example check that a HTTP server is still responding before doing the write call to ping the watchdog.

より高度なドライバは、たとえば、ウォッチドッグにpingするための書き込み呼び出しを行う前に、HTTPサーバーがまだ応答していることを確認できます。

When the device is closed, the watchdog is disabled, unless the “Magic Close” feature is supported (see below). This is not always such a good idea, since if there is a bug in the watchdog daemon and it crashes the system will not reboot. Because of this, some of the drivers support the configuration option “Disable watchdog shutdown on close”, CONFIG_WATCHDOG_NOWAYOUT. If it is set to Y when compiling the kernel, there is no way of disabling the watchdog once it has been started. So, if the watchdog daemon crashes, the system will reboot after the timeout has passed. Watchdog devices also usually support the nowayout module parameter so that this option can be controlled at runtime.

デバイスがクローズされたとき、watchdogは無効化されます、"Magic Close"機能がサポートされていない場合には(下記を参照してください)。これは、常に良い考えではありません。もし、watchdog daemonにバグがあり、それがクラッシュしたとき、systemはrebootできないでしょう。そのため、ドライバーの中には、"Diasable watchdog shutdown on close", CONFIG_WATCHDOG_NOWAYOUTの設定オプションをサポートするものがあります。もしカーネルをコンパイルする際に、これがYに設定されている場合、watchdogが一度開始したら止める手段はありません。そのため、watchdog daemonがクラッシュしたら、systemはtimeoutが経過した後にリブートされます。Watchdog devicesはまた通常、実行時にこのオプションを制御するためのnowayout module parameterをサポートしています。

Magic Close feature

If a driver supports “Magic Close”, the driver will not disable the watchdog unless a specific magic character ‘V’ has been sent to /dev/watchdog just before closing the file. If the userspace daemon closes the file without sending this special character, the driver will assume that the daemon (and userspace in general) died, and will stop pinging the watchdog without disabling it first. This will then cause a reboot if the watchdog is not re-opened in sufficient time.

”Magic Close"をドライバーがサポートしている場合、driverはwatchdogspecific magic character "V"が/dev/watchdogに、ファイルをクローズする前に送信することなく無効化することはできません。ユーザー空間daemonは、特殊な文字列を送信することなく、ファイルをクローズすると、ドライバーはdaemon(そして、一般的にはユーザー空間)が死亡し、それを始めて停止する事なく、watchdogへの通知が停止したとみなします。watchdogが十分な時間内に再度開かれない場合、これにより再起動が発生します。

The ioctl API

All conforming drivers also support an ioctl API.

準拠する全てのドライバは、ioctl APIもまたサポートします。

Pinging the watchdog using an ioctl:

ioctlを用いたwatchdogへの通知。

All drivers that have an ioctl interface support at least one ioctl, KEEPALIVE. This ioctl does exactly the same thing as a write to the watchdog device, so the main loop in the above program could be replaced with:

ioctl interface を有するドライバーは、少なくともKEEPALIVEのインターフェイスをサポートします。このioctlは、watchdog deviceへの書き込みと同じことです、そのため、前期プログラムでのmain loopは以下のように書き直せます。

while (1) {
        ioctl(fd, WDIOC_KEEPALIVE, 0);
        sleep(10);
}

the argument to the ioctl is ignored.

ioctlの引数は無効です。

Setting and getting the timeout

For some drivers it is possible to modify the watchdog timeout on the fly with the SETTIMEOUT ioctl, those drivers have the WDIOF_SETTIMEOUT flag set in their option field. The argument is an integer representing the timeout in seconds. The driver returns the real timeout used in the same variable, and this timeout might differ from the requested one due to limitation of the hardware:

ドライバーの中には、watchdog timeoutをSETTIMEOUT ioctlによって実行中に変更する事ができる者もあります。これらのドライバは、option fieldに、WDIOF_SETTIMEOUT flagが設定されています引数は整数型で、timeoutの秒数を示します。ドライバーは同じ変数を使った実際のタイムアウトを返却します。このtimeoutは、ハードウェアの制限により、要求されたものと異なる場合がありまsう。

int timeout = 45;
ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
printf("The timeout was set to %d seconds\n", timeout);

This example might actually print “The timeout was set to 60 seconds” if the device has a granularity of minutes for its timeout.

この例では、デバイスのタイムアウトが分単位の粒度であるならば、実際の出力が、“The timeout was set to 60 seconds”となります。

Starting with the Linux 2.4.18 kernel, it is possible to query the current timeout using the GETTIMEOUT ioctl:

Linux 2.4.18 kernelから、GETTIMEOUT ioctlによって現在のtimeoutを要求する事もできます。


ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
printf("The timeout was is %d seconds\n", timeout);

Pretimeouts

Some watchdog timers can be set to have a trigger go off before the actual time they will reset the system. This can be done with an NMI, interrupt, or other mechanism. This allows Linux to record useful information (like panic information and kernel coredumps) before it resets:

Watcjdog timerの中には、システムを再起動する実際の時刻の前にトリガーを設定できるものがあります。これは、NMI、割り込みあるいはほかのメカニズムを利用できます。これにより、Linuxが有益な情報(例えば、panic informationやkernel coredumps)を、再起動する前に残すことができます。

pretimeout = 10;
ioctl(fd, WDIOC_SETPRETIMEOUT, &pretimeout);

Note that the pretimeout is the number of seconds before the time when the timeout will go off. It is not the number of seconds until the pretimeout. So, for instance, if you set the timeout to 60 seconds and the pretimeout to 10 seconds, the pretimeout will go off in 50 seconds. Setting a pretimeout to zero disables it.

pretimeoutは、timeoutが発動する前の秒単位の時間であることに注意してください。これは、pretimeoutまでの時間ではありません。そのため、例えば、timeoutを60秒に、pretimeoutを10秒にセットしたら、pretimeoutは50秒の段階で発動します。pretimeoutを0に設定する事で無効化できます。

There is also a get function for getting the pretimeout:

pretimeoutを取得する関数もまたあります。

ioctl(fd, WDIOC_GETPRETIMEOUT, &timeout);
printf("The pretimeout was is %d seconds\n", timeout);

Not all watchdog drivers will support a pretimeout.

Watchdog driverの全てが、pretimeoutをサポートしているわけではありません。

Get the number of seconds before reboot

Some watchdog drivers have the ability to report the remaining time before the system will reboot. The WDIOC_GETTIMELEFT is the ioctl that returns the number of seconds before reboot:

Watchdog driverの中には、systemが再起動する前の残り時間を通知する機能を有したものもあります。WDIOC_GETTIMELEFTは、再起動前の秒数を返却するioctlです。

ioctl(fd, WDIOC_GETTIMELEFT, &timeleft);
printf("The timeout was is %d seconds\n", timeleft);

Environmental monitoring

All watchdog drivers are required return more information about the system, some do temperature, fan and power level monitoring, some can tell you the reason for the last reboot of the system. The GETSUPPORT ioctl is available to ask what the device can do:

全てのwatchdog driverは、システムに関する多くの詳細情報を返却する必要があります。温度、ファン、電源レベルのモニターをするものもあります。最後にシステムをリブートした要因として通知するものもあります。GETSUPPORT ioctlは、デバイスが何ができるのを問い合わせることができます。

struct watchdog_info ident;
ioctl(fd, WDIOC_GETSUPPORT, &ident);

the fields returned in the ident struct are:

ident 構造体のfieldにはは以下の通りです。

identity a string identifying the watchdog driver
firmware_version the firmware version of the card if available
options a flags describing what the device supports

identity watchdog driverの識別子文字列
firmware_version 有効ならばcardのファームバージョン
options デバイスがサポートしているフラグ記述子。

the options field can have the following bits set, and describes what kind of information that the GET_STATUS and GET_BOOT_STATUS ioctls can return. [FIXME – Is this correct?]

option fieldには、下記のビットを競ってすることができ、GET_STATUSやGET_BOOT_STATUS ioctlにおって情報を返すことができます[FIXME - これは本当?]

WDIOF_OVERHEAT Reset due to CPU overheat
The machine was last rebooted by the watchdog because the thermal limit was exceeded:

WDIOF_OVERHEAT CPUのオーバーヒートで再起動する
このマシンは、温度限界に達したため、watchdogによって最後の再起動が行われました。

WDIOF_FANFAULT Fan failed
A system fan monitored by the watchdog card has failed

WDIOF_FANFAULT Fan failed
このシステムは、watchdog cardによって監視されているfanが故障しました。

WDIOF_EXTERN1 External relay 1
External monitoring relay/source 1 was triggered. Controllers intended for real world applications include external monitoring pins that will trigger a reset.

WDIOF_EXTERN1 外部要因1
外部監視要因/ソース1のトリガーが発生しました。現実世界のアプリケーションのためのコントローラーには、リセットをトリガーするためのpinが含まれます。

WDIOF_EXTERN2 External relay 2
External monitoring relay/source 2 was triggered

WDIOF_EXTERN2 External relay 2
外部監視要因/ソース1のトリガーが発生しました。

WDIOF_POWERUNDER Power bad/power fault
The machine is showing an undervoltage status

WDIOF_POWERUNDER 電源不正/電源故障
このマシンでは、低電圧状態が見られました。

WDIOF_CARDRESET Card previously reset the CPU
The last reboot was caused by the watchdog card

WDIOF_CARDRESET Card previously reset the CPU
watchdog cardによって最終リブートが引き起こされました。

WDIOF_POWEROVER Power over voltage
The machine is showing an overvoltage status. Note that if one level is under and one over both bits will be set - this may seem odd but makes sense.

WDIOF_POWEROVER 過電流電源

このマシンでは、過電流状態を検知しました。1つのレベルが下になり、1つのレベルが両方のビットに設定される場合、これは奇妙に見えるかもしれませんが、理にかなっていることに注意してください。

WDIOF_KEEPALIVEPING Keep alive ping reply
The watchdog saw a keepalive ping since it was last queried.

WDIOF_KEEPALIVEPING Keep alive ping reply
watchdogは最後の要求から、keepalive 通知を検知しました。

WDIOF_SETTIMEOUT Can set/get the timeout
The watchdog can do pretimeouts.

WDIOF_SETTIMEOUT Can set/get the timeout
Watchdogは、pretimeoutを実行できます。

WDIOF_PRETIMEOUT Pretimeout (in seconds), get/set
For those drivers that return any bits set in the option field, the GETSTATUS and GETBOOTSTATUS ioctls can be used to ask for the current status, and the status at the last reboot, respectively:

WDIOF_PRETIMEOUT Pretimeout (in seconds), get/set
option fieldにセットされたbitを返却するドライバでは、現在の状態や最後に再起動した時点での状態を確認するのに、GETSTATUSやGETBOOTSTATUS ioctlを利用できます。以下のように…

int flags;
ioctl(fd, WDIOC_GETSTATUS, &flags);

or

ioctl(fd, WDIOC_GETBOOTSTATUS, &flags);

Note that not all devices support these two calls, and some only support the GETBOOTSTATUS call.

全てのドライバがこれら2つの呼び出しをサポートしているわけではなく、GETBOOTSTATUS callだけをサポートしているものもあることに注意してください。

Some drivers can measure the temperature using the GETTEMP ioctl. The returned value is the temperature in degrees fahrenheit:

ドライバーの中には、GETTEMP icotlを用いて気温を計測できるものもあります。戻り値は、fahrenheit度の気温です。


int temperature;
ioctl(fd, WDIOC_GETTEMP, &temperature);

Finally the SETOPTIONS ioctl can be used to control some aspects of the cards operation:

最期に、SETOPTION ioctlはいくつかのcard operationの側面に対して、指示を出すことができます。

int options = 0;
ioctl(fd, WDIOC_SETOPTIONS, &options);

The following options are available:

下記オプションが有効です。

WDIOS_DISABLECARD Turn off the watchdog timer
WDIOS_ENABLECARD Turn on the watchdog timer
WDIOS_TEMPPANIC Kernel panic on temperature trip

WDIOS_DISABLECARD ウォッチドックタイマーを停止
WDIOS_ENABLECARD ウィッチドックタイマーを起動
WDIOS_TEMPPANIC 温度要因でkernel panicを発生

[FIXME – better explanations]


もともと、Linux Kernelのソースコードの一部なので、GPLv2扱いになる(はずの認識)。

https://www.kernel.org/doc/html/latest/index.html

Licensing documentation

The following describes the license of the Linux kernel source code (GPLv2), how to properly mark the license of individual files in the source tree, as well as links to the full license text.

https://www.kernel.org/doc/html/latest/process/license-rules.html#kernel-licensing

4
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?