JP2014119964A - Computer system and program - Google Patents
Computer system and program Download PDFInfo
- Publication number
- JP2014119964A JP2014119964A JP2012274665A JP2012274665A JP2014119964A JP 2014119964 A JP2014119964 A JP 2014119964A JP 2012274665 A JP2012274665 A JP 2012274665A JP 2012274665 A JP2012274665 A JP 2012274665A JP 2014119964 A JP2014119964 A JP 2014119964A
- Authority
- JP
- Japan
- Prior art keywords
- deadlock
- lock
- thread
- exclusive control
- control information
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Abstract
Description
本発明は、計算機システムおよびプログラムに係り、特に、マルチスレッドで動作する計算機システムにおいて、デッドロックを検出し、デッドロック発生前の回避とデッドロック発生後の解消を行う計算機システムおよびプログラムに関する。 The present invention relates to a computer system and a program, and more particularly, to a computer system and a program for detecting a deadlock in a computer system that operates in a multi-thread and avoiding it before occurrence of deadlock and eliminating it after occurrence of deadlock.
近年、様々なシステムにおいてマルチスレッド環境で稼働するソフトウェアが普及している。マルチスレッド環境では、OS(Operating System)がソフトエア内の実行単位をスレッドで管理する。OSは、スレッドに対しCPU(Central Processing Unit)が時間割り当てのスケジューリングを行う。スレッドは、OSからCPU時間を割り当てられた時間だけ動作することができる。 In recent years, software operating in a multi-thread environment has become widespread in various systems. In a multi-thread environment, an OS (Operating System) manages execution units in software using threads. In the OS, a CPU (Central Processing Unit) schedules time allocation for threads. The thread can operate only for a time allocated by the OS from the CPU time.
したがって、CPUを複数備えるマルチスレッド環境では、スレッドを並列に実行し高速化できる。しかし、処理を並列に実行することにより、デッドロックと呼ばれる問題が発生する。 Therefore, in a multi-thread environment including a plurality of CPUs, threads can be executed in parallel to increase the speed. However, a problem called deadlock occurs when the processes are executed in parallel.
ここで、デッドロックとは複数のスレッドまたはプロセスなどの処理単位がリソースを共有する場合において、リソース解放漏れやリソースを占有(Lock)中の処理単位が互いにリソースの解放(Unlock)を待ち続け、処理を再開できずに停止している状態である。ここで、プロセスとはプログラムの実行単位であり、プログラム内で利用している変数や状態を保持し、1つ以上のスレッドから構成される。 Here, deadlock means that when processing units such as a plurality of threads or processes share resources, processing units that are omission of resource release or occupy resources (Lock) continue to wait for resource release (Unlock), The process cannot be resumed and is stopped. Here, a process is an execution unit of a program and holds variables and states used in the program and is composed of one or more threads.
デッドロックが発生したプロセスは、異常終了しない。このため、ソフトウェアの使用者、開発者が異常の発生直後に気付かない。また、ソフトウェアの開発者が異常に気付いたとしても、スレッドの挙動確認や解析に時間がかかる。そこで、デッドロックを防ぎ、解決する技術が重要となってくる。 The process in which the deadlock occurred does not terminate abnormally. For this reason, software users and developers do not notice immediately after the occurrence of an abnormality. Even if a software developer notices an abnormality, it takes time to check and analyze the behavior of the thread. Therefore, technology for preventing and solving deadlocks becomes important.
特許文献1には、デッドロックが二重以上のロック取得するスレッド同士で発生する点に着目し、大域的なロックを追加している。つまり、二重以上のロックを取得するスレッドに対し、大域的なロックを取得する制約を設ける。これによって、二重以上のロックを取得するスレッドを制限し、デッドロックを防止する。さらに、大域的なロックを一律に取得するのではなく、条件を付けることで性能低下を抑えている。
また、特許文献2では、ロック取得および解除に対してAPI関数フックを行い、スレッド毎に共有リソースに対して「ロック中」および「ロック取得中」の情報を取得し、その組み合わせによってデッドロックを検出する計算機システムおよびプログラムが提案されている。ここで、API関数とは、OSやミドルウェアが提供するアプリケーションおよびソフトウェア開発向けのインタフェースであり、共通ライブラリの形で提供される。また、API関数フックとは、API関数の処理を横取りし、利用者が独自に定義した処理を行うことである。また、「ロック中」とは、スレッドがリソースを占有中により他のスレッドがリソースにアクセスできない状態である。一方、「ロック取得中」とは他のスレッドが占有中のリソースが解放されるのを待ってからロックしようとしている状態である。
Further, in
特許文献2は、これらの情報を組み合わせ、具体的には、リソースAを「ロック中」でリソースBを「ロック取得中」のスレッド1と、リソースAを「ロック取得中」でリソースBを「ロック中」のスレッド2が同時に存在すると、互いにリソースが解放されるのを待ち続けるデッドロックとして検出できる。デッドロック検出後は、発生経路を記憶して冗長系にフェールオーバすることで、フェールオーバ先でデッドロックの再発を防止する。ここで、フェールオーバとは、正常時に冗長構成の計算機でデータの同期を取っておき、障害が発生した計算機から残りの正常な計算機にデータを引継ぎ、処理を継続する動作である。
特許文献1に記載の技術は、ロックの取得を連続で行う必要があり、多重ロックを取得する時点で予め必要なロックが全て既知であることが前提条件となる。実際のプログラムでは、経路によって必要なロックが異なるため、予め必要なロックを全て取得することは困難であり、必要なロックを全て取得できなかった場合、デッドロックが発生する。
The technique described in
特許文献2に記載の技術は、デッドロックの再発を防げる。しかし、別経路でデッドロックが発生する度にフェールオーバを行う必要がある。フェールオーバ実行中は、本来実行しなければならない処理を実行できず、本来提供したいサービスに影響が出てしまう。また、切替え可能な計算機が無ければフェールオーバできないため、可能な限りフェールオーバ実施を避けるべきである。
特許文献1と特許文献2を組み合わせたとしても、デッドロック発生後の復帰手段がないため、容易には解決できない。
The technique described in
Even if
本発明の代表的な一形態によると、複数のスレッドを実行する計算機システムであって、計算機システムは、少なくとも一つのプロセッサと、メモリとを備え、計算機システムで動作するソフトウェア内で第一のスレッドと第一のスレッドを監視するための監視スレッドを実行し、第一のスレッドの排他制御の情報を保持するための監視情報領域と、第一のスレッド用にデッドロック回避用の領域および情報と、メモリ内容を復元するための退避領域と、をメモリに保持し、第一のスレッドと監視スレッドは監視情報領域に排他制御の情報を格納し、第一のスレッドはメモリ内容を退避領域に格納し、監視スレッドが監視情報領域からデッドロックを検出し、監視スレッドはデッドロックが発生する可能性がある第一のスレッドに対し、デッドロック回避用領域に排他制御を追加し、第一のスレッドでデッドロックが発生した場合、第一のスレッドの処理を退避位置に戻し、かつ、退避領域からメモリ内容を復元することでデッドロックを解消する。 According to a typical embodiment of the present invention, a computer system that executes a plurality of threads, the computer system including at least one processor and a memory, and a first thread in software operating in the computer system. And a monitoring information area for executing the monitoring thread for monitoring the first thread and holding the exclusive control information of the first thread, an area and information for deadlock avoidance for the first thread, The save area for restoring the memory contents is held in the memory, the first thread and the monitoring thread store exclusive control information in the monitor information area, and the first thread stores the memory contents in the save area The monitoring thread detects a deadlock from the monitoring information area, and the monitoring thread de- When exclusive control is added to the lock avoidance area and a deadlock occurs in the first thread, the deadlock is prevented by returning the processing of the first thread to the save position and restoring the memory contents from the save area. Eliminate.
上述した課題は、複数の処理スレッドと、監視スレッドとを並列実行する計算機システムであって、プロセッサと、メモリとを備え、前記処理スレッドは、排他制御情報を収集および蓄積し、多重排他制御情報を前記監視スレッドに送信し、前記監視スレッドは、前記多重排他制御情報を蓄積し、前記多重排他制御情報間にデッドロックを引き起こす組み合わせを検出したとき、当該組み合わせの多重排他制御情報の復帰場所に排他制御を追加する計算機システムにより、達成できる。 The problem described above is a computer system that executes a plurality of processing threads and a monitoring thread in parallel, and includes a processor and a memory, and the processing threads collect and accumulate exclusive control information, and multiple exclusive control information To the monitoring thread, and when the monitoring thread accumulates the multiple exclusive control information and detects a combination that causes a deadlock between the multiple exclusive control information, the monitoring thread returns to the return location of the multiple exclusive control information of the combination. This can be achieved by a computer system that adds exclusive control.
また、コンピュータを、排他制御情報を収集および蓄積し、多重排他制御情報を前記監視スレッドに送信する処理スレッド、前記多重排他制御情報を蓄積し、前記多重排他制御情報間にデッドロックを引き起こす組み合わせを検出したとき、当該組み合わせの多重排他制御情報の復帰場所に排他制御を追加する監視スレッド、として機能させるプログラムにより、達成できる。 In addition, the computer collects and accumulates exclusive control information, a processing thread that transmits multiple exclusive control information to the monitoring thread, a combination that accumulates the multiple exclusive control information and causes a deadlock between the multiple exclusive control information. When detected, this can be achieved by a program that functions as a monitoring thread that adds exclusive control to the return location of the multiple exclusive control information of the combination.
本発明によって、デッドロックを自動検出し、フェールオーバを実施せずにデッドロック状態から正常な状態に復帰できる。 According to the present invention, it is possible to automatically detect a deadlock and return from a deadlock state to a normal state without performing a failover.
以下、本発明の実施の形態について、実施例を用い図面を参照しながら詳細に説明する。なお、実質同一部位には同じ参照番号を振り、説明は繰り返さない。 Hereinafter, embodiments of the present invention will be described in detail with reference to the drawings using examples. The same reference numerals are assigned to substantially the same parts, and the description will not be repeated.
実施例1は、通信装置のように特定の処理を繰り返す計算機を説明する。
図1を参照して、最小構成のハードウェアの通信装置を説明する。図1において、通信装置100は、プロセッサ101と、メモリ102と、NIF(Network InterFace)103とを具備する。
The first embodiment describes a computer that repeats a specific process like a communication device.
With reference to FIG. 1, a hardware communication apparatus having a minimum configuration will be described. In FIG. 1, the
プロセッサ101は、CPU等の演算装置であり、OSやアプリケーションプログラム等のソフトウェアを実行する。メモリ102は、主記憶装置であり、プロセッサ101がソフトウェア実行時に、プログラム実行バイナリおよびプログラムが使用するデータを格納する。NIF103は、通信装置100とは別の装置とパケットを送受信するためのインタフェースである。各ハードウェアブロックは、バス110−1、110−2によって相互に接続するため、互いに命令メッセージ及びデータを送信することが可能である。
The
なお、本実施例を適用するためには、プロセッサ101がマルチタスクに対応している必要がある。ここで、マルチタスクとは演算装置が複数の処理を切換えながら複数の処理を実行する方式であり、汎用計算機のプロセッサでは、そのほとんどがマルチタスクに対応している。
In order to apply this embodiment, the
また、通信装置100は、物理的に一つの計算機によって実装されてもよいし、少なくとも一つの計算機が提供する仮想的な計算機によって実装されてもよい。
The
図2を参照して、ソフトウェアのスレッド構成と、ロックを記録するためのフック処理を説明する。図2のサブルーチンに関しては、別途、後述の図を用いて詳述する。図2において、スレッドは、通信装置の呼制御などを行う複数の処理スレッド200と、処理スレッド200が正常に動作しているか否かを判定する監視スレッド210から成る。
With reference to FIG. 2, a software thread configuration and a hook process for recording a lock will be described. The subroutine shown in FIG. 2 will be described in detail later with reference to the following drawings. In FIG. 2, the thread includes a plurality of
処理スレッド200は、起動後、パケット受信などのイベントを待つ(S202)。処理スレッド200は、パケットを受信し(S203)、送信するパケットを加工し(S204)、送信する(S205)動作を繰返す。スレッド起動からパケット送信までは、ソフトウェアバイナリの変更は行わない。
The
処理スレッド200は、フック処理220とロックレコードテーブル700を用意しておく。フック処理220は、パケット処理のステップ203とパケット加工のステップ204とパケット送信のステップ205で呼び出されるすべてのLock命令500およびUnlock命令600を横取りするフック関数の集合である。フック処理220では、Lock命令500が呼び出された際に、別途定義するサブルーチンLock命令550を呼び出す。また、Unlock命令600が呼び出された際に、別途定義するサブルーチンUnlock命令650を呼び出す。なお、サブルーチンLock命令550は、図4で後述し、サブルーチンUnlock命令650は、図5で後述する。フック処理220は、一時的にロックレコードをロックレコードテーブル700に保存する。このうち、多重ロックレコードと判断した場合は、多重ロックレコード450を、監視スレッド210のキュー230に追加する。
The
監視スレッド210は、プログラムカウンタが、サブルーチン多重ロックレコード処理900に到達した際に、キュー230に多重ロックレコード450が入っているか調べ、多重ロックレコード450がキュー230に入っていた場合は、多重ロックレコードテーブル800に、多重ロックレコード450を追加する。なお、サブルーチン多重ロックレコード処理900は、図8を用いて詳述する。
When the program counter reaches the subroutine multiple
上述した手順により、スレッド起動とイベント待ちのステップ202とパケット受信のステップ203とパケット加工のステップ204とパケット送信のステップ205を、変更することなく、ロック情報をロックレコードテーブル700に記録することができる。
According to the procedure described above, the lock information can be recorded in the lock record table 700 without changing the
また、監視スレッド210は、起動後、チェック周期であるか否かを判定し、チェック周期であればデッドロックチェック処理(S300)を行い、チェック周期でなければ多重ロックレコード処理(S900)を行う動作を繰返す。ここで、チェック周期は開発者や使用者が指定する時間や回数以外にも、排他制御の統計から自動的に算出しても良い。デッドロックチェック処理は、図9を用いて、後述する。
Further, the
本実施例では、監視スレッド210がデッドロックチェック処理を繰り返し実行する。これにより、デッドロックを検出し、デッドロック発生前に検出した場合は、デッドロックを回避し、デッドロック発生と同時にデッドロックを検出した場合はデッドロック状態からの解消処理を行い、デッドロックを自動的に解決する。なお、本実施例では監視スレッドを監視専用としているが、監視スレッドに別の役割を持たせることや、処理スレッド側に監視動作を追加することも可能である。このことにより、スレッド数を増やす必要が無く、メモリ量やCPUリソースを節約する利点がある。
In the present embodiment, the
図3を参照して、デッドロックチェック動作の検出処理に利用するロックレコード400および多重ロックレコード450を説明する。
With reference to FIG. 3, the
図3(a)において、ロックレコード400は、ネスト数401、ロックハンドル402、復帰場所403から成る。ロックレコード400は、処理スレッド200が個々に管理する排他制御の記録である。ここで、ネスト数401は、排他制御の深さである。ロックハンドル402は、排他制御に必要な識別子である。復帰場所403は、デッドロック退避用領域である。
In FIG. 3A, the
図3(b)において、多重ロックレコード450は、項番451、ロック順序452、復帰場所403、追加ロックハンドル453から成る。多重ロックレコード450は、監視スレッド210が管理する排他制御組合せパターンの記録である。ここで、項番451は、多重ロックレコードを管理するための識別子である。ロック順序452は、ロックハンドル402を取得した順序である。追加ロックハンドル453は、デッドロック回避用のロックハンドルである。
3B, the
ロックレコード400は、図6に示すロックレコードテーブル700で管理する。多重ロックレコード450は、図7に示す多重ロックレコードテーブル800で管理する。ロックレコードテーブル700は、処理スレッド200が個々に管理するテーブルである。ロックレコードテーブル700は、処理スレッド200がその時点で取得している排他制御を示す。ロックレコードテーブル700は、ロック取得命令(以下、Lock命令、本実施例では、pthread_mutex_lock)とロック解放命令(以下、Unlock命令、本実施例では、pthread_mutex_unlock)にフックを行って取得する。ここで、フックとは処理を横取りし、使用者が定義した処理をプロセッサ101に行わせる処理である。
The
具体的には、Linux(登録商標)系OSのLD_PRELOAD環境変数と共有ライブラリを用いたAPI関数フックで実現できる。LD_PRELOAD環境変数を指定しない状態では、pthread_mutex_lock関数およびpthread_mutex_unlock関数は、libpthread.soという共有ライブラリの関数が実行される。しかし、LD_PRELOAD環境変数で、共有ライブラリファイル名を指定すると、関数名から実行する関数へのアドレス解決順序を入れ替え、LD_PRELOAD環境変数で指定した、共有ライブラリを優先的に検索する。指定する共有ライブラリに、pthread_mutex_lock関数とpthread_mutex_unlock関数を定義することにより、libpthread.soのpthread_mutex_lock関数およびpthread_mutex_unlock実行前に、共有ライブラリの関数を実行することができる。共有ライブラリのpthread_mutex_lock関数およびpthread_mutex_unlock関数にて、libpthread.soのpthread_mutex_lock関数およびpthread_mutex_unlock関数を呼び出すことにより、Lock命令へのフックおよびUnlock命令へのフックを実現することができる。 Specifically, it can be realized by an API function hook using a LD_PRELOAD environment variable of a Linux (registered trademark) OS and a shared library. In a state where the LD_PRELOAD environment variable is not specified, the pthread_mutex_lock function and the pthread_mutex_unlock function are set to libpthread. A function of a shared library called so is executed. However, if the shared library file name is specified by the LD_PRELOAD environment variable, the address resolution order from the function name to the function to be executed is changed, and the shared library specified by the LD_PRELOAD environment variable is preferentially searched. By defining the pthread_mutex_lock function and the pthread_mutex_unlock function in the specified shared library, the libthread. The functions of the shared library can be executed before executing the pthread_mutex_lock function and the pthread_mutex_unlock function of the so. In the shared library pthread_mutex_lock function and pthread_mutex_unlock function, By calling the pthread_mutex_lock function and the pthread_mutex_unlock function of the so, a hook to the Lock instruction and a hook to the Unlock instruction can be realized.
図4を参照して、Lock命令のフローチャートとフック有りLock命令のフローチャートを説明する。また、図5を参照して、Unlock命令のフローチャートとフック有りUnlock命令のフローチャートを説明する。 With reference to FIG. 4, the flowchart of the Lock instruction and the flowchart of the Lock instruction with hook will be described. In addition, a flowchart of the Unlock instruction and a flowchart of the Unlock instruction with a hook will be described with reference to FIG.
図4Aにおいて、Lock命令を開始すると、処理スレッド200は、ロックハンドルが取得可能か判定する(S501)。取得可能であれば、処理スレッド200は、ロックハンドルを取得し(S504)、処理を終了する。ステップ501でロックハンドルが取得不可であれば、ロックハンドルが解放されるまで待ち(S503)、ロックハンドルを取得する(S504)。
In FIG. 4A, when the Lock instruction is started, the
図4Bにおいて、フック有りLock命令を開始すると、処理スレッド200は、ロックレコードの記録追加処理を実施する(S551)。ロックレコードの記録追加処理は、取得しようとしているロックハンドルをロックレコードに登録し、ロックレコードテーブル700に追加する処理である。追加後、処理スレッド200は、ロックレコードテーブル700のネスト数401が2以上か判定する(S552)。判定結果が2以上の場合、処理スレッド200は、ロックレコードテーブル700に登録中の全ロックレコード400から多重ロックレコード450を作成し、監視スレッド210のキュー230にエンキューする(S553)。エンキュー完了後およびネスト数401が2未満の場合、処理スレッド200は、Lock命令を実行し(S500)、フック有りLock関数を完了する。
In FIG. 4B, when the lock instruction with hook is started, the
図5Aにおいて、Unlock命令を開始すると、処理スレッド200は、ロックハンドルを解放し(S601)、Unlock命令を終了する。
図5Bにおいて、フック有りUnlock命令650を開始すると、処理スレッド200は、Unlock命令を実行する(S600)。処理スレッド200は、処理完了後にロックレコードの記録削除処理を行い(S651)、フック有りUnlock命令を完了する。
In FIG. 5A, when the Unlock instruction is started, the
In FIG. 5B, when the Unlock instruction with
フック有りLock命令のロックレコードの記録追加処理のステップ551と、フック有りUnlock命令のロックレコードの記録削除処理のステップ651によって、処理スレッド200は、取得しているロックハンドルを最新の状態として反映することができる。
The
図6を参照して、ロックハンドルテーブル700の状態遷移を説明する。図6において、フック220によって、ロックハンドルAを取得した状態701から、フック有りLock(B)でロックハンドルBを取得すると状態702になり、さらにフック有りUnlock(B)でロックハンドルBを解放すると状態703になる。
The state transition of the lock handle table 700 will be described with reference to FIG. In FIG. 6, from the
状態702ではネスト数401が2以上になるため、フック有りLock命令において、処理スレッド200は、多重ロックレコード450を作成する。ロックレコードテーブル700が状態702であれば、作成する多重ロックレコード450のロック順序452はA→B、復帰場所403はFuncABとなり、作成した多重ロックレコード450を監視スレッド210のキュー230にエンキューする。なお、多重ロックレコード450の項番451と追加ロックハンドル453は、監視スレッド210が後で登録する。なお、デッドロックは、二重以上のロックハンドル402を取得した処理スレッド200同士で発生するため、ネスト数401が2以上の場合のみ、多重ロックレコード450を作成すれば良い。
In the
処理スレッド200が多重ロックレコード450をキュー230にエンキュー後、監視スレッド210は、多重ロックレコード処理900で多重ロックレコードテーブル800へ登録する。多重ロックレコードテーブル800は、図7に示す多重ロックレコード450を蓄積するテーブルであり、多重ロックレコード450を持たない状態801から始まる。なお、図7は、フローチャートの中で説明する。
After the
図8を参照して、多重ロックレコード処理によって、未登録の多重ロックレコードを追加する処理を説明する。図8において、多重ロックレコード処理を開始すると、監視スレッド210は、キュー230に多重ロックレコードがあるか判定する(S901)。多重ロックレコードがある場合、監視スレッド210は、多重ロックレコードテーブル800に未登録か判定する(S902)。未登録であれば、監視スレッド210は、多重ロックレコードテーブルに登録して(S903)、多重ロックレコード処理を終了する。なお、多重ロックレコードが未登録か否かの判定は、ロック順序および復帰場所が一致しているか否かで判定する。多重ロックレコードがキュー230に無い場合、または多重ロックレコードが登録済みの場合、監視スレッド210は、多重ロックレコード処理を終了する。この操作によって、図7において、多重ロックレコード450を保持していない状態801から、未登録の多重ロックレコード(A→B)を受取り、受取った順に項番451を登録することで、状態802になる。
With reference to FIG. 8, a process of adding an unregistered multiple lock record by multiple lock record processing will be described. In FIG. 8, when the multiple lock record process is started, the
図2に示したように、監視スレッド210は、多重ロックレコードテーブル800に対し、チェック周期以外では多重ロックレコード処理900を行い、チェック周期であれば図9に示すデッドロックチェック処理300を行う。
As shown in FIG. 2, the
図9において、デッドロックチェック処理を開始すると、監視スレッド210は、デッドロック検出処理を実行する(S310)。監視スレッド210は、デッドロックを検出したか判定する(S320)。YESのとき、監視スレッド210は、デッドロック回避処理を実行する(S330)。監視スレッド210は、検出したデッドロックが発生しているか判定する(S340)。YESのとき、監視スレッド210は、デッドロック解消処理を実行して(S350)、終了する。ステップ320またはステップ340でNOのとき、監視スレッド210は、デッドロック検出処理を終了する。
In FIG. 9, when the deadlock check process is started, the
図10を参照して、デッドロック検出処理を説明する。図10において、デッドロック検出処理を開始すると、監視スレッド210は、比較未実施の多重ロックレコードがあるか判定する(S311)。ここで、比較未実施の多重ロックレコードとは、多重ロックレコードテーブル800に含まれる多重ロックレコードの組合せのうち、デッドロック検出の為の比較を実施していない多重ロックレコードの集合である。デッドロック検出処理の開始時点では全多重ロックレコードが比較未実施となる。未比較の多重ロックレコードがある場合、監視スレッド210は、その中から候補XとYを選択する(S312)。監視スレッド210は、候補XとYにデッドロックの可能性があるか判定する(S313)。デッドロックの可能性がある場合、監視スレッド210は、デッドロックパターンとして登録し(S314)、ステップ311へ戻る。全ての比較が完了後(S311:NO)、監視スレッド210は、終了する。
The deadlock detection process will be described with reference to FIG. In FIG. 10, when the deadlock detection process is started, the
ステップ313でデッドロックの可能性あるか否かを判定する単純な方法としては、候補XとYのロック順序452から一致するロックハンドルを抜出し、その順序が逆転しているか否かを判定する方法が挙げられる。
As a simple method for determining whether or not there is a possibility of deadlock in step 313, a method is used in which a matching lock handle is extracted from the
図7に戻って、多重ロックレコードテーブルが状態803であれば、ロックハンドルAのみが一致し、順序逆転はないため、デッドロックは発生しないと判定する。また、多重ロックレコードテーブルが状態804であれば、3種類の多重ロックレコードの全組合せ3通りで比較し、項番1と項番3の多重ロックレコードでロックハンドルAとBが一致し、かつ順序逆転が発生しているため、デッドロックとして検出できる。
Returning to FIG. 7, if the multiple lock record table is in the
なお、多重ロックレコードテーブル800は、多重ロックレコードを蓄積していくため、過去の多重ロックレコードから発生確率が低いデッドロックでも検出することが可能になる。しかし、多重ロックレコードを蓄積し続けると記憶領域を圧迫するため、必要に応じて古い情報を削除しても良い。また、未比較の多重ロックレコード450は、多重ロックレコードテーブル800に新規登録する際に発生するため、多重ロックレコード処理900のステップ903後にデッドロック検出処理を実行しても良い。
Note that since the multiple lock record table 800 accumulates multiple lock records, it is possible to detect even a deadlock having a low occurrence probability from past multiple lock records. However, if the multiple lock records are continuously accumulated, the storage area is compressed, so old information may be deleted as necessary. In addition, since an uncompared
図11を参照して、デッドロック回避処理を説明する。図11において、監視スレッド210は、デッドロックを検出した多重ロックレコードの組合せ(最低でも2つ)を受取り、その多重ロックレコードの中で追加ロックハンドル453が登録されているかを確認する(S331)。追加ロックハンドル453が全ての多重ロックレコードに登録されていない場合(NO)、監視スレッド210は、追加ロックハンドル453を新規確保(GlobalABとする)し、多重ロックレコードの追加ロックハンドル453にGlobalABを登録して(S332)、デッドロック回避処理を終了する。
The deadlock avoidance process will be described with reference to FIG. In FIG. 11, the
ステップ331で追加ロックハンドル453を登録済みの場合(YES)、監視スレッド210は、登録している追加ロックハンドル453が1種類かを確認する(S333)。登録済みの追加ロックハンドル453が1種類(GlobalXXとする)の場合(YES)、監視スレッド210は、未登録の追加ロックハンドル453にGlobalXXを登録して(S334)、デッドロック回避処理を終了する。
If the additional lock handle 453 has been registered in step 331 (YES), the
ステップ333で登録されている追加ロックハンドル453が複数(GlobalXX、GlobalYYとする)の場合(NO)、監視スレッド210は、ロックハンドルを新規確保(GlobalXYとする)し、未登録の追加ロックハンドル453と、受取った多重ロックレコードのGlobalXXとGlobalYYをGlobalXYで登録または上書き登録する(S335)。さらに、監視スレッド210は、多重ロックテーブル800の中から、追加ロックハンドル453にGlobalXXまたはGlobalYYを登録しているレコードをGlobalXYで上書き登録する(S336)。監視スレッド210は、上書き登録によって不要となったGlobalXXとGlobalYYのメモリ領域を削除する(S337)。追加ロックハンドル453の登録が完了後、監視スレッド210は、デッドロック回避処理を終了する。
なお、追加ロックハンドル453が複数となるのは、ネスト数が3以上の場合である。
When there are a plurality of additional lock handles 453 registered in Step 333 (referred to as GlobalXX and GlobalYY) (NO), the
Note that there are a plurality of additional lock handles 453 when the number of nests is three or more.
デッドロック回避処理により、具体的には、図7において、多重ロックレコードテーブル800が状態804であれば、項番1と項番3の多重ロックレコードを検出し、両方とも追加ロックハンドル453を登録していないため、追加ロックハンドル(GlobalAB)を新規確保し、登録することで状態805となる。
Specifically, if the multiple lock record table 800 in FIG. 7 is in the
デッドロック回避処理で登録した追加ロックハンドル453は、多重ロックレコードに登録している復帰場所にてスコープドロックし、デッドロック発生の可能性がある箇所を追加した排他制御で覆い込む。状態804では(A)→(B)と(B)→(A)の順番でロックハンドルを取得していたが、状態805で追加ロックハンドルにより(GlobalAB)→(A)→(B)と(GlobalAB)→(B)→(A)という順番になるため、GlobalABによってデッドロックを防止できる。なお、スコープドロックとは、Lock命令を開始後、関数などの有効範囲(スコープ)終了時に自動でUnlock命令を実行するための仕組みであり、リソース解放漏れを防ぐことが可能になる。
The additional lock handle 453 registered in the deadlock avoidance process is scoped locked at the return location registered in the multiple lock record, and is covered with exclusive control to which a portion where a deadlock may occur is added. In the
また、追加ロックハンドル453を上書き登録することにより、過去に検出したデッドロックパターン(具体的には、A→B→C、D→C→B)と新たに検出したデッドロックパターン(E→C→B)で同一の追加ロックハンドル453を指定するため、デッドロックを全て防止できる。また、追加ロックハンドル453を一種類だけとし、全てのデッドロックパターンで同一の追加ロックハンドルを利用してすることも可能である。
Further, by overwriting and registering the
ロックレコードテーブル700や多重ロックレコードテーブル800の復帰場所403は、デッドロックを防止できる箇所(プログラム上のアドレス)を指定する必要がある。その指定する方法は、チェックポイント方式と関数フック方式がある。チェックポイント方式は、復帰場所をソフトウェアの開発者がチェックポイントとして明示的に指定する方式である。一方、関数フック方式は、C言語やC++言語で記述したソフトウェアのソースコードビルド時に「−finstrument−functions」オプションを指定することにより、関数の開始時と終了時にフックできるため、デッドロック要因となるLock命令を含む関数の開始箇所を、自動的に指定する方式である。
As the
デッドロック検出と同時にデッドロックが発生している場合は回避できないため、デッドロック解消処理を実施する。なお、デッドロックが発生しているか判定するには、チェック周期の際に処理スレッド200に応答があるか確認し、応答がない、かつ処理スレッド200のロックレコードテーブル700がデッドロックの可能性を検出した多重ロックレコードを含む場合に、デッドロック状態と判定する。
Since deadlock cannot be avoided when deadlock is detected at the same time, deadlock elimination processing is performed. In order to determine whether or not a deadlock has occurred, it is confirmed whether or not there is a response to the
図12を参照して、デッドロック解消処理を説明する。デッドロック解消処理を開始すると、監視スレッド210は、プログラムカウンタに復帰場所を設定する(S351)。監視スレッド210は、メモリ内容をデッドロック発生前の状態に復元する(S352)。監視スレッド210は、デッドロック要因のロックハンドルを解放して(S353)、デッドロック解消処理を終了する。
With reference to FIG. 12, the deadlock elimination processing will be described. When the deadlock elimination process is started, the
プログラムカウンタは、プロセッサ101がプログラム上で次に実行する命令のアドレスを指す。各スレッドは、各々プログラムカウンタを保持しているため、プログラムカウンタを書き換えることにより、任意のスレッドが次に実行する命令のアドレスを任意のアドレスに変更することができる。したがって、プログラムカウンタを多重ロックレコードテーブル800に登録した復帰場所403を指定する。処理スレッド200は、追加ロックハンドル(GlobalAB)取得から処理を再開し、デッドロック再発を防止する。
The program counter indicates the address of the instruction that the
次に、デッドロック発生時点で既にメモリ内容が書き換わり、メモリに更新途中のデータが保持されている可能性がある。このため、メモリ内容をデッドロック発生前の状態に戻すことで、データの整合性を維持する。 Next, there is a possibility that the memory contents are already rewritten at the time of occurrence of the deadlock, and the data being updated is held in the memory. For this reason, data consistency is maintained by returning the memory contents to the state before the deadlock occurs.
図13を参照して、メモリ復元を説明する。メモリ復元では、まず、メモリ102内でデッドロック発生前メモリ内容1300のスナップショットを取り、メモリ内容をコピーする(状態1301)。ここで、スナップショットの際に名前付きメモリマップを利用することで、デッドロック発生後に必要なメモリを検索することができる。その後、デッドロック発生を検出した時点で、メモリ内容が状態1302のように値が書き換わっていたとしても、スナップショット1301をメモリ状態1302に上書きすることで、メモリ内容を復元できる。なお、スナップショットは、フック有りLock命令内で実行すれば、デッドロック発生前のメモリ内容を保持することができる。
The memory restoration will be described with reference to FIG. In the memory restoration, first, a snapshot of the
図12に戻って、ステップ353において、処理スレッド200の取得済みロックハンドルの内、デッドロック要因となっているロックハンドル(A)および(B)と、その間に取得したロックハンドルを解放することで、Unlock待ちで停止している処理スレッド200が復帰場所FuncABから処理を再開することが可能になる。
Returning to FIG. 12, in
以上により、デッドロック検出、回避、解消が可能となった。
本実施例によれば、多重ロックを取得する時点で予め必要なロックが全て既知である前提条件が不要となり、どのようなソフトウェアにも汎用的に適用可能となる。また、デッドロックが発生しても、フェールオーバを実施することなく処理を再開できるため、ソフトウェアの信頼性および稼働率を向上することができる。
As described above, deadlock can be detected, avoided, and resolved.
According to the present embodiment, the precondition that all necessary locks are known in advance at the time of acquiring the multiple lock is not necessary, and can be applied to any software for general purposes. In addition, even if a deadlock occurs, the process can be resumed without performing a failover, so that the software reliability and operating rate can be improved.
100…通信装置、101…プロセッサ、102…メモリ、103…NIF、110…バス、200…処理スレッド、210…監視スレッド、220…フック、230…キュー、400…ロックレコード、450…多重ロックレコード、500…Lock命令、550…フック有りLock命令、600…Unlock命令、650…フック有りUnlock命令、700…ロックレコードテーブル、800…多重ロックレコードテーブル、1301…スナップショット
DESCRIPTION OF
Claims (5)
プロセッサと、メモリとを備え、
前記処理スレッドは、排他制御情報を収集および蓄積し、多重排他制御情報を前記監視スレッドに送信し、
前記監視スレッドは、前記多重排他制御情報を蓄積し、前記多重排他制御情報間にデッドロックを引き起こす組み合わせを検出したとき、当該組み合わせの多重排他制御情報の復帰場所に排他制御を追加することを特徴とする計算機システム。 A computer system that executes a plurality of processing threads and a monitoring thread in parallel,
A processor and memory;
The processing thread collects and accumulates exclusive control information, sends multiple exclusive control information to the monitoring thread,
The monitoring thread accumulates the multiple exclusive control information, and when detecting a combination that causes a deadlock between the multiple exclusive control information, adds the exclusive control to the return location of the multiple exclusive control information of the combination. A computer system.
前記処理スレッドは、前記排他制御情報を、ロック取得命令とロック解放命令へのフックを利用して収集することを特徴とする計算機システム。 The computer system according to claim 1,
The computer system according to claim 1, wherein the processing thread collects the exclusive control information using a hook to a lock acquisition instruction and a lock release instruction.
前記監視スレッドは、デッドロック要因となるロック取得命令を含む関数の開始時と、ロック解放命令を含む関数の終了時とにフックして、復帰場所を指定することを特徴とする計算機システム。 The computer system according to claim 1,
The computer system is characterized in that the monitoring thread hooks at the start of a function including a lock acquisition instruction that causes a deadlock and at the end of a function including a lock release instruction, and specifies a return location.
デッドロック発生前にメモリ内容のスナップショットを取得し、
デッドロック発生後に、前記スナップショットからメモリ内容を復元し、
プログラムカウンタ位置を復帰場所に変更し、
デッドロックの要因となった排他制御を解放することによって、デッドロック状態から復元することを特徴とする計算機システム。 The computer system according to claim 1,
Take a snapshot of the memory contents before the deadlock occurs,
After the deadlock occurs, restore the memory contents from the snapshot,
Change the program counter position to the return position,
A computer system that restores from a deadlock state by releasing exclusive control that caused a deadlock.
排他制御情報を収集および蓄積し、多重排他制御情報を前記監視スレッドに送信する処理スレッド、
前記多重排他制御情報を蓄積し、前記多重排他制御情報間にデッドロックを引き起こす組み合わせを検出したとき、当該組み合わせの多重排他制御情報の復帰場所に排他制御を追加する監視スレッド、
として機能させるプログラム。 Computer
A processing thread that collects and accumulates exclusive control information and sends multiple exclusive control information to the monitoring thread,
A monitoring thread that accumulates the multiple exclusive control information and adds exclusive control to the return location of the multiple exclusive control information of the combination when a combination that causes a deadlock between the multiple exclusive control information is detected;
Program to function as.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2012274665A JP2014119964A (en) | 2012-12-17 | 2012-12-17 | Computer system and program |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2012274665A JP2014119964A (en) | 2012-12-17 | 2012-12-17 | Computer system and program |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2014119964A true JP2014119964A (en) | 2014-06-30 |
JP2014119964A5 JP2014119964A5 (en) | 2015-01-15 |
Family
ID=51174748
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2012274665A Pending JP2014119964A (en) | 2012-12-17 | 2012-12-17 | Computer system and program |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP2014119964A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP5950124B2 (en) * | 2011-05-12 | 2016-07-13 | 日本電気株式会社 | Deadlock prevention device, deadlock prevention method, and program |
WO2019006997A1 (en) * | 2017-07-01 | 2019-01-10 | 武汉斗鱼网络科技有限公司 | Program deadlock detection method, storage medium, device and system |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH0816430A (en) * | 1994-06-27 | 1996-01-19 | Mitsubishi Electric Corp | Parallel program tracing device |
JPH09258995A (en) * | 1996-03-19 | 1997-10-03 | Toshiba Corp | Computer system |
JP2009271858A (en) * | 2008-05-09 | 2009-11-19 | Toshiba Corp | Computing system and program |
WO2012153722A1 (en) * | 2011-05-12 | 2012-11-15 | 日本電気株式会社 | Deadlock prevention system, deadlock prevention method, and programs |
-
2012
- 2012-12-17 JP JP2012274665A patent/JP2014119964A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH0816430A (en) * | 1994-06-27 | 1996-01-19 | Mitsubishi Electric Corp | Parallel program tracing device |
JPH09258995A (en) * | 1996-03-19 | 1997-10-03 | Toshiba Corp | Computer system |
JP2009271858A (en) * | 2008-05-09 | 2009-11-19 | Toshiba Corp | Computing system and program |
WO2012153722A1 (en) * | 2011-05-12 | 2012-11-15 | 日本電気株式会社 | Deadlock prevention system, deadlock prevention method, and programs |
Non-Patent Citations (2)
Title |
---|
JPN6015029076; 近藤敦,他2名: 'PCクラスタを用いた分散処理システムClopにおける動的負荷分散方式の実装と評価' 情報処理学会研究報告 2001-ARC-142 2001-HPC-85 第2001巻,第22号, 20010309, pp.145-150, 社団法人情報処理学会 * |
JPN6015029077; Jim Dugger: 'C++におけるマルチスレッド' C MAGAZINE 第8巻,第4号, 19960401, pp.19-23, ソフトバンク株式会社 * |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP5950124B2 (en) * | 2011-05-12 | 2016-07-13 | 日本電気株式会社 | Deadlock prevention device, deadlock prevention method, and program |
WO2019006997A1 (en) * | 2017-07-01 | 2019-01-10 | 武汉斗鱼网络科技有限公司 | Program deadlock detection method, storage medium, device and system |
CN109213576A (en) * | 2017-07-01 | 2019-01-15 | 武汉斗鱼网络科技有限公司 | Program deadlock detection method, storage medium, equipment and system |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Guo et al. | Rex: Replication at the speed of multi-core | |
CN106790694B (en) | Distributed system and scheduling method of target object in distributed system | |
US8661450B2 (en) | Deadlock detection for parallel programs | |
US20190004908A1 (en) | Data protection using checkpoint restart for cluster shared resources | |
US20050034014A1 (en) | Consistent asynchronous checkpointing of multithreaded application programs based on semi-active or passive replication | |
US7917909B2 (en) | Detecting deadlocks in interop-debugging | |
JP6397053B2 (en) | System and method for providing distributed transaction locks in a transaction middleware machine environment | |
JP5648187B2 (en) | Computer system and monitoring method | |
Goldberg et al. | Restoring consistent global states of distributed computations | |
US11675622B2 (en) | Leader election with lifetime term | |
US8788474B2 (en) | Inode event notification for cluster file systems | |
van Dongen et al. | A performance analysis of fault recovery in stream processing frameworks | |
Rezaei et al. | Snapify: Capturing snapshots of offload applications on xeon phi manycore processors | |
US8132174B2 (en) | Concurrency management in cluster computing of business applications | |
Benz et al. | Building global and scalable systems with atomic multicast | |
US8893137B2 (en) | Transaction-based shared memory protection for high availability environments | |
Saad et al. | Transactional forwarding: Supporting highly-concurrent stm in asynchronous distributed systems | |
Hursey | Coordinated checkpoint/restart process fault tolerance for MPI applications on HPC systems | |
US10324811B2 (en) | Opportunistic failover in a high availability cluster | |
JP2014119964A (en) | Computer system and program | |
Stewart et al. | Transparent fault tolerance for scalable functional computation | |
US20230333945A1 (en) | Scalable Low-Loss Disaster Recovery for Data Stores | |
US10798146B2 (en) | System and method for universal timeout in a distributed computing environment | |
Gankevich et al. | Subordination: providing resilience to simultaneous failure of multiple cluster nodes | |
KR102284952B1 (en) | Dynamic saving of registers in transactions |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
RD02 | Notification of acceptance of power of attorney |
Free format text: JAPANESE INTERMEDIATE CODE: A7422 Effective date: 20140908 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20141120 |
|
A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20141120 |
|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20150713 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20150721 |
|
A02 | Decision of refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A02 Effective date: 20160209 |