【0001】
【発明の属する技術分野】
この発明は、タスクの動作の優先順位を管理する方法であって、特にビットマップにワード毎にインディックスを付して検索性能の向上を図った優先順位検索方法に関するものである。
【0002】
【従来の技術】
コンピュータ装置に設けられているCPUには、上記タスク動作の優先順位を管理する手段が備えられている。この優先順位を管理するために、タスク動作の優先順位と1対1に対応するビットマップを用い、このビットを検索することにより、次に動作させるタスクの検索を行っている(例えば、特許文献1参照。)。
【0003】
上記のようなタスクの優先順位と1対1に対応するビットマップの場合、例えば、優先度が32ビット以下であると、ビットマップが1ワードに収まって効率的である。しかし、優先度が上記CPUの1ワードに収まらない長いビットマップにおいては、ワード配列を用いた、図5に示すようなビットマップを用いている。
【0004】
図5は、32ビット・ワードを32個並べてサイズ「1024」のビットマップを表現した説明図である。図5において、1個の四角形の桝目が「1」ビットを表し、その四角形の桝目内の数字はビットの(0から始まる)位置番号で、その位置番号は、「0000」から「1023」まである。
【0005】
上記のようなビットマップにおいて、ビットの並び順で最初の「1」であるビットを検索するには、ビットマップを構成するワード配列のワードを順番に調べていって「0」でない最初のワードを見つけ、そのワード内で「1」のビットを探す方法が採られている。(後述の図6、図7のフローチャート参照)
また、ビットマップに対する上記のような検索は、高速に行いたいので、専用のCPU命令を持たせることもある。
【0006】
図6は、長いビットマップから「1」のビットを検索するフローチャートで、この図6においては、図5で示したビットマップから、「1」であるビットで最大の位置番号を持つものを探して、その位置番号を得ることを条件とするものである。なお、位置番号「0」(0000)のビットは、必ず「1」であるとする。
【0007】
図6において、まず、ステップS1で位置番号「31」をワード「W」とし、ステップS2でワード「W」が「0」か(YES)、「0」でないか(NO)を判定し、「YES」ならステップS3で「W−1」をワード「W」とする処理をした後、ステップS2にて再び処理を行なう。ステップS2で「NO」ならステップS4の処理を行なう。
【0008】
ステップS4の処理は、後述する図7に示す処理を呼び出して行なう。ステップS4では、ワード「W」で「1」である最下位ビット位置を探して「b」とする。この「b」は、ステップS5に示す式に入力して演算処理され、位置番号「num」を得る。
【0009】
図7は、1ワードのビットマップから「1」のビットを検索するフローチャートで、1ワードのビットマップ(word)から、「1」であるビットで最下位のものを探してLSBを「0」、MSBを「31」とするビット位置を得ることを条件とするものである。なお、ワードは「0」でないものとする。
【0010】
図7において、ステップS11にて「0」を位置番号「num」とした後、ステップS12にて下位16ビットが「0」であるかどうかを判定し、「YES」ならステップS13の処理を行ない、「NO」ならステップS14の判定処理を行なう。ステップS13では、下位16ビットが「0」ならば上位16ビットに「1」がある処理(num←num+16)を、また、左へ16ビットシフトの処理(word←word>>16)を行なう。
【0011】
次に、ステップS14では、下位8ビットが「0」であるかどうかを判定し、「YES」ならステップS15の処理を行ない、「NO」ならステップS16の判定処理を行なう。ステップS15では、下位8ビットが「0」ならば上位8ビットに「1」がある処理(num←num+8)を、また、左へ8ビットシフトの処理(word←word>>8)を行なう。以下順次、4ビット、2ビット、1ビットの処理をステップS21まで行なう。
【0012】
【特許文献1】
特開平5−342022号公報(第2頁−第3頁、図1−図4)。
【0013】
【発明が解決しようとする課題】
通常、ビットマップの検索は、配列の添字順に線形に行われるので、演算時間はビットマップの長さに比例して長くなる。従って、ビットマップが長いと検索性能の低下が生じる。このため、専用のCPU命令が無い場合は、特にその検索性能の低下が著しくなる問題が起こる。
【0014】
この発明は、上記の事情に鑑みてなされたもので、ビットマップにインデックスを付けることにより、大きなビットマップの場合でも検索性能の向上を図ることができる優先順位検索方法を提供することを課題とする。
【0015】
【課題を解決するための手段】
この発明は、上記の課題を達成するために、第1発明は、タスクの動作の優先順位を管理する方法であって、その優先順位を、ワード配列を用いてビットマップで表現し、このビットマップにワード毎のインデックスを付して、各ワード毎にビット「1」が立っているかどうかを、他のデータを用いて管理し、他のデータの各ビットと1対1の対応関係を持ち、ビット「1」が立っているとき、ワードに「1」のビットがあることを確認した後、他のデータを用いて最下位の「1」ビットを検索することを特徴とする優先順位検索方法である。
【0016】
第2発明は、前記ビットマップのサイズが大きいときには、ビットマップ毎にインデックスを2段以上にすることを特徴とする優先順位検索方法である。
【0017】
【発明の実施の形態】
以下この発明の実施の形態を図面に基づいて説明する。図1はこの発明の実施の第1形態を示す説明図で、この実施の第1形態は、優先度付き実行待ちタスクから最高優先度のタスクを探す方法である。
【0018】
リアルタイムOS(オペレーティング・システム)のスケジューラでは、実行待ちタスクの中から優先度の高いタスクを効率的に見つけ出すために優先度毎にタスクをキュー(待ち行列)に繋ぐ手段を採っている。
【0019】
ここで、優先度数が少ない(例えば、一桁)場合には、キューの数も少ないので、高優先度のキューから順に空きか、否かのチェックを行なっていっても大した負荷にはならない。例えば、優先度が「32」ビット以下であると、ビットマップが「1」ワードに収まって効率的である。
【0020】
しかし、優先度数が多い(例えば、数十〜数千)場合には、高優先度のキューから順に空きか、否かをチェックするのでは、ビットマップ自体が大きくなって検索が効率的でない。そこで、各キューが空きか、否かをビットマップに表現して、検索の効率化を図ることを、見出したのが、上記図1の実施の第1形態である。
【0021】
図1は、ビットマップBTMにインデックスINDを付けて検索の効率化を図った説明図で、32ビット・ワードを32個並べてサイズ「1024」のビットマップBTMにインデックスINDを付けたものである。そして、インデックスINDの各ビットは、図1に示したように対応付けた各ワードが「0」のとき「0」とし、「0」でないときに「1」とする。
【0022】
図1において、優先度は「0」〜「1023」を採り、数字が大きいほど優先度が高いものとする。OS(オペレーティング・システム)は予め実行可能キューが空きでない優先度に対応するビットマップBTMの位置番号のビットを「1」にしてあるものとする。また、アイドルタスクがあるために、優先度「0」のキューは空きでなく、ビットマップBTMの位置番号「0」は必ず「1」であるとする。
【0023】
スケジューラは、インデックス付きビットマップBTMから「1」である最大の位置番号を検索して、キューが空きでない最高の優先度を取得し、対応するキューから次に実行するべきタスクを選択する。
【0024】
インデックス付きビットマップBTMの検索では、まずインデックスINDに対して図7に示すフローチャート(アルゴリズム)を使用して「1」である最下位ビットの位置を得、これから「1」である最大の位置番号のビットを含むワードの添字番号を計算する。
【0025】
次に、この「0」でないワードに対して図7に示すアルゴリズムを使用して、「1」である最下位ビットを得、これと先ほどのワードの添字番号とからビットマップの位置番号を図2に示すフローチャートのように計算する。
【0026】
図2はインデックス付きビットマップで「1」のビットを検索するフローチャートで、このフローチャートでは、図1に示したビットマップから、「1」であるビットで最大の位置番号を持つものを探して、その位置番号を得る。なお、位置番号「0」のビットは、必ず「1」であるとする。
【0027】
図2において、ステップS31で図7の処理を呼び出し、インデックスで「1」である最下位ビット位置をワード「W」とする。そのワード「W」をステップS32の処理で「31−W」をワード「W」とする。
【0028】
その後、ステップS33で再び図7の処理を呼び出して、ワード「W」で「1」である最下位ビット位置を「b」と処理する。この「b」をステップS34に示す式(num←W*32+31−b)で演算処理して終了し、その演算結果として位置番号「num」を得る。
【0029】
図3はこの発明の実施の第2形態を示す説明図で、この第2形態は、大きなビットマップから「1」のビットを検索するものである。上記第1形態では、サイズ「1024」以下程度のビットマップから「1」であるビットで位置番号が最大のものを検索した。
【0030】
さらに、大きいビットマップでも、第1形態で示したインデックスを、1ワードから2ワード以上にすれば同じ様な処理ができる。このように処理に基づいた方法が図3に示すインデックスを2段以上にしたものである。
【0031】
図3は、インデックスを、主インデックスM−IND、副インデックスSB1−IND〜SBn−INDとして、ビットマップが大きくなった場合の例で、32ビット・ワードを「1024」個並べてサイズ「32768」のビットマップを2段インデックスで作った例である。主インデックスM−INDおよび副インデックスSB1−IND,SB2−INDの各ビットは、図3で対応付けた各ワードが「0」のとき「0」とし、「0」でないときに「1」とする。
【0032】
ビットマップがさらに大きい場合、3段、4段のインデックスへの拡張も容易である。インデックスの段数を増加することで一段ごとに32倍ずつ大きなビットマップを扱える。
【0033】
図4は、実施の第2形態における2段インデックス付きビットマップで「1」のビットを検索するフローチャートで、このフローチャートでは、図3で示したビットマップから、「1」であるビットで最大の位置番号を持つものを探してその位置番号を得る。なお、位置番号「0」のビットはかならず「1」であるとする。
【0034】
図4において、ステップS41で図7の処理を呼び出して、インデックスで「1」である最下位ビット位置を「W」とする。次に、ステップS42で「31−W」を「W」とする。
【0035】
その後、図7の処理を呼び出して、ステップS43で副索引[W]で「1」である最下位ビット位置を「X」とする。次にこの「X」をステップS44で「31−X」をワード「X」とする。
【0036】
ステップS44で得られたワード「X」をステップS45で図7の処理を再び呼び出して、ワード「X」で「1」である最下位ビット位置を「b」として、ステップS46の式(W*1024+X*32+31−b)を用いて演算し、位置番号「num」とする。
【0037】
上記各実施の形態においては、コンピュータ装置を用いて処理される。コンピュータ装置には、図示しないが外部記憶装置などの入出力装置などが使用されている。
【0038】
【発明の効果】
以上述べたように、この発明によれば、ビットマップにインデックスを付けることにより、サイズ「1000」程度のビットマップで検索性能を向上させることができる。また、インデックス付けを複数多段で行なうことにより、更に大きなビットマップでも検索性能を向上させることができる。
【図面の簡単な説明】
【図1】この発明の実施の第1形態を示す説明図。
【図2】インデックス付きビットマップで「1」のビットを検索するフローチャート。
【図3】この発明の実施の第2形態を示す説明図。
【図4】実施の第2形態における2段インデックス付きビットマップで1のビットを検索するフローチャート。
【図5】32ビット・ワードを32個並べてサイズ「1024」のビットマップを表現した説明図。
【図6】長いビットマップから「1」のビットを検索するフローチャート。
【図7】1ワードのビットマップから「1」のビットを検索するフローチャート。
【符号の説明】
IND…インデックス
BTM…ビットマップ
num…位置番号[0001]
TECHNICAL FIELD OF THE INVENTION
The present invention relates to a method for managing priorities of task operations, and more particularly to a priority search method in which a bitmap is indexed for each word to improve search performance.
[0002]
[Prior art]
The CPU provided in the computer device has means for managing the priority of the task operation. In order to manage the priority, a bit map corresponding to the priority of the task operation in a one-to-one correspondence is used to search for this bit, thereby searching for a task to be operated next (for example, see Patent Document 1). 1).
[0003]
In the case of a bitmap corresponding to the task priorities one-to-one as described above, for example, if the priority is 32 bits or less, the bitmap fits in one word and is efficient. However, in a long bitmap whose priority does not fit in one word of the CPU, a bitmap using a word array as shown in FIG. 5 is used.
[0004]
FIG. 5 is an explanatory diagram expressing a 32-bit word by arranging 32 32-bit words. In FIG. 5, one square cell represents "1" bit, and the number in the square cell is a position number (starting from 0) of a bit, and the position numbers are from "0000" to "1023". is there.
[0005]
To search for the first "1" bit in the bit order in the bitmap as described above, the first word that is not "0" is checked by sequentially examining the words of the word array constituting the bitmap. And a method of searching for a “1” bit in the word. (Refer to the flowcharts of FIGS. 6 and 7 described below)
In addition, since the above search for the bitmap is desired to be performed at high speed, a dedicated CPU instruction may be provided.
[0006]
FIG. 6 is a flowchart for searching for a bit of "1" from a long bitmap. In FIG. 6, the bitmap shown in FIG. 5 is searched for a bit of "1" having the largest position number. And the position number must be obtained. It is assumed that the bit of the position number “0” (0000) is always “1”.
[0007]
6, first, in step S1, the position number "31" is set to the word "W", and in step S2, it is determined whether the word "W" is "0" (YES) or not "0" (NO). If "YES", a process of changing "W-1" to the word "W" is performed in step S3, and then the process is performed again in step S2. If "NO" in the step S2, the process of the step S4 is performed.
[0008]
The process in step S4 is performed by calling a process shown in FIG. In step S4, the least significant bit position that is "1" in the word "W" is searched for and set to "b". This “b” is input to the equation shown in step S5 and is subjected to arithmetic processing to obtain a position number “num”.
[0009]
FIG. 7 is a flowchart for searching for a bit of “1” from a bit map of one word, searching for the least significant bit of “1” from a bit map (word) of one word and setting the LSB to “0”. , MSB are set to "31". Note that the word is not “0”.
[0010]
In FIG. 7, after "0" is set to the position number "num" in step S11, it is determined in step S12 whether the lower 16 bits are "0", and if "YES", the process in step S13 is performed. If "NO", the determination processing of step S14 is performed. In step S13, if the lower 16 bits are "0", a process in which the upper 16 bits have "1" (num ← num + 16) and a process of shifting 16 bits to the left (word ← word >> 16) are performed.
[0011]
Next, in step S14, it is determined whether or not the lower 8 bits are "0". If "YES", the process in step S15 is performed, and if "NO", the determination process in step S16 is performed. In step S15, if the lower 8 bits are "0", a process in which the upper 8 bits have "1" (num ← num + 8) and a process of shifting left by 8 bits (word ← word >> 8) are performed. Thereafter, processing of 4 bits, 2 bits, and 1 bit is sequentially performed until step S21.
[0012]
[Patent Document 1]
JP-A-5-342022 (pages 2 to 3, FIGS. 1 to 4).
[0013]
[Problems to be solved by the invention]
Normally, the search of the bitmap is performed linearly in the order of the subscripts of the array, so that the operation time increases in proportion to the length of the bitmap. Therefore, if the bitmap is long, the search performance is reduced. For this reason, when there is no dedicated CPU instruction, there is a problem that the search performance is significantly reduced.
[0014]
The present invention has been made in view of the above circumstances, and an object of the present invention is to provide a priority search method capable of improving search performance even for a large bitmap by indexing the bitmap. I do.
[0015]
[Means for Solving the Problems]
In order to achieve the above object, a first aspect of the present invention is a method for managing the priority of a task operation. The priority is expressed by a bit map using a word array, and An index is assigned to each word in the map, and whether or not bit “1” is set for each word is managed using other data, and has a one-to-one correspondence with each bit of other data. , When the bit "1" is set, it is confirmed that the word has the bit of "1", and then the least significant "1" bit is searched using other data. Is the way.
[0016]
A second invention is a priority search method characterized in that when the size of the bitmap is large, the index is set to two or more stages for each bitmap.
[0017]
BEST MODE FOR CARRYING OUT THE INVENTION
Hereinafter, embodiments of the present invention will be described with reference to the drawings. FIG. 1 is an explanatory diagram showing a first embodiment of the present invention. This first embodiment is a method of searching for a task with the highest priority from tasks with a priority to be executed.
[0018]
The scheduler of a real-time OS (operating system) employs means for connecting tasks to a queue (queue) for each priority in order to efficiently find a task with a high priority from tasks waiting to be executed.
[0019]
Here, when the number of priorities is small (for example, one digit), the number of queues is also small. Therefore, even if checking is performed in order from the queue with the highest priority to whether or not it is empty, it does not become a significant load. . For example, if the priority is less than or equal to "32" bits, the bitmap will fit in a "1" word, which is efficient.
[0020]
However, when the number of priorities is large (for example, several tens to several thousands), it is not efficient to search in order from a high priority queue to see if the queue is empty, because the bitmap itself becomes large and the search is not efficient. Therefore, the first embodiment of FIG. 1 has been found to express whether each queue is empty or not in a bitmap to improve the efficiency of the search.
[0021]
FIG. 1 is an explanatory diagram in which an index IND is added to a bitmap BTM to improve the efficiency of search. In this figure, 32 32-bit words are arranged and a bitmap BTM having a size of “1024” is provided with an index IND. Each bit of the index IND is set to “0” when the associated word is “0” as shown in FIG. 1, and is set to “1” when the associated word is not “0”.
[0022]
In FIG. 1, the priority ranges from “0” to “1023”, and the higher the number, the higher the priority. It is assumed that the OS (operating system) has previously set the bit of the position number of the bitmap BTM corresponding to the priority at which the executable queue is not empty to “1”. It is also assumed that the queue of priority “0” is not empty because there is an idle task, and the position number “0” of the bitmap BTM is always “1”.
[0023]
The scheduler searches the indexed bitmap BTM for the maximum position number “1”, acquires the highest priority in which the queue is not empty, and selects the next task to be executed from the corresponding queue.
[0024]
In the search of the indexed bitmap BTM, first, the position of the least significant bit which is “1” is obtained for the index IND by using the flowchart (algorithm) shown in FIG. Calculate the subscript number of the word containing the bits of.
[0025]
Next, using the algorithm shown in FIG. 7 for the word other than "0", the least significant bit of "1" is obtained, and the position number of the bit map is figured out from this and the subscript number of the previous word. The calculation is performed as shown in the flowchart of FIG.
[0026]
FIG. 2 is a flowchart for searching the bit of "1" in the indexed bitmap. In this flowchart, the bitmap shown in FIG. 1 is searched for the bit having "1" having the largest position number. Get the position number. It is assumed that the bit of the position number “0” is always “1”.
[0027]
In FIG. 2, the process of FIG. 7 is called in step S31, and the least significant bit position whose index is “1” is set as a word “W”. The word “W” is set to the word “W” in the process of step S32 and “31−W” is set to the word “W”.
[0028]
Thereafter, in step S33, the process of FIG. 7 is called again, and the least significant bit position of “1” in the word “W” is processed as “b”. This “b” is processed by the equation (num ← W * 32 + 31−b) shown in step S34 and the processing is terminated, and the position number “num” is obtained as the calculation result.
[0029]
FIG. 3 is an explanatory diagram showing a second embodiment of the present invention. In the second embodiment, a bit of "1" is searched from a large bit map. In the first embodiment, the bit having the maximum position number of the bit “1” is searched from the bitmap having the size of “1024” or less.
[0030]
Further, even for a large bitmap, the same processing can be performed by changing the index shown in the first embodiment from one word to two or more words. Thus, the method based on the processing is such that the index shown in FIG.
[0031]
FIG. 3 shows an example in which the index is set to the main index M-IND and the sub-indexes SB1-IND to SBn-IND, and the bitmap becomes large. In this example, "1024" 32-bit words are arranged and the size is "32768". This is an example in which a bitmap is created using a two-stage index. Each bit of the main index M-IND and the sub-indexes SB1-IND and SB2-IND is set to "0" when each word associated in FIG. 3 is "0", and is set to "1" when each word is not "0". .
[0032]
If the bitmap is even larger, it is easy to expand to a three-stage or four-stage index. By increasing the number of index stages, a bitmap that is 32 times larger for each stage can be handled.
[0033]
FIG. 4 is a flowchart for searching for the bit of “1” in the two-stage indexed bitmap according to the second embodiment. In this flowchart, from the bitmap shown in FIG. Find the one with the position number and get the position number. It is assumed that the bit of the position number “0” is always “1”.
[0034]
In FIG. 4, the process of FIG. 7 is called in step S41, and the least significant bit position whose index is “1” is set to “W”. Next, "31-W" is set to "W" in step S42.
[0035]
Thereafter, the process of FIG. 7 is called, and the least significant bit position of “1” in the sub index [W] is set to “X” in step S43. Next, this “X” is made into a word “X” by “31-X” in step S44.
[0036]
The process of FIG. 7 is called again in step S45 for the word “X” obtained in step S44, and the least significant bit position of “1” in word “X” is set to “b”, and the expression (W * 1024 + X * 32 + 31-b) to obtain a position number "num".
[0037]
In each of the above embodiments, processing is performed using a computer device. Although not shown, an input / output device such as an external storage device is used for the computer device.
[0038]
【The invention's effect】
As described above, according to the present invention, the indexing of a bitmap can improve the search performance with a bitmap having a size of about "1000". Also, by performing indexing in multiple stages, search performance can be improved even with a larger bitmap.
[Brief description of the drawings]
FIG. 1 is an explanatory view showing a first embodiment of the present invention.
FIG. 2 is a flowchart for searching for a “1” bit in an indexed bitmap.
FIG. 3 is an explanatory view showing a second embodiment of the present invention.
FIG. 4 is a flowchart for searching for one bit in a two-stage indexed bitmap according to the second embodiment;
FIG. 5 is an explanatory diagram expressing a 32-bit size bitmap by arranging 32 32-bit words.
FIG. 6 is a flowchart for searching for a “1” bit from a long bitmap.
FIG. 7 is a flowchart for searching for a bit of “1” from a bit map of one word.
[Explanation of symbols]
IND: Index BTM: Bitmap num: Position number