CN104168217A - Scheduling method and device for first in first out queue - Google Patents
Scheduling method and device for first in first out queue Download PDFInfo
- Publication number
- CN104168217A CN104168217A CN201410404736.5A CN201410404736A CN104168217A CN 104168217 A CN104168217 A CN 104168217A CN 201410404736 A CN201410404736 A CN 201410404736A CN 104168217 A CN104168217 A CN 104168217A
- Authority
- CN
- China
- Prior art keywords
- queue
- team
- counting
- buffer memory
- atomic ratio
- 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.)
- Granted
Links
Landscapes
- Memory System Of A Hierarchy Structure (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The invention discloses a scheduling method and device for a first in first out (FIFO) queue. According to the scheme, no spin lock is used, a current head count H and a current tail count T of the FIFO queue are read through atomic operation, and whether other cores execute enqueuing or dequeuing operation and count operation of an actual enqueuing or dequeuing count is judged in an atomic comparing exchange function. According to the scheduling method and device for the first in first out queue, the range needing a protection code segment of multi-core mutual exclusion operation is very small, expenditure for multi-core locking and unlocking is avoided, and the scheduling efficiency of multi-core equipment for the FIFO queue can be improved.
Description
Technical field
The present invention relates to data communication field, particularly a kind of first-in first-out (First In First Out, FIFO) array dispatching method and device.
Background technology
Fifo queue is the most basic a kind of queue form that data communications equipment is supported, adopts the form of independent queue, can the multiple data messages of buffer memory, and queue length is conventionally configurable, and data message completes queue scheduling in the mode of first in first out.
At present, in existing multiple nucleus system, realize fifo queue, conventionally with the mode of spin lock (spin lock) complete into, go out the scheduling of team, while realizing the scheduling of fifo queue in spin lock mode, multiple cores are carried out queue with contention mode mutual exclusion and are joined the team and go out team, to join the team as example, in the time that operation is joined the team in certain core execution, can attempt the operation of joining the team to lock, if locked successfully, locking in the whole process of successfully having joined the team to message, the operation of can not concurrent execution joining the team of other cores, can only wait for and joining the team after operation release, other core could by plunder join the team lock mode carry out the operation of joining the team, therefore under spin lock pattern, the team's operation of joining the team out is still similar to single thread mode, its essence remains a producer, a consumer's model, joining the team and go out the process of team can not be concurrent.And, because multinuclear spin lock self locks, the CPU expense of release is larger, reduced CPU handling property.
In addition, multinuclear spin lock waits in the mode of spin, and the process that team was joined the team, went out in queue is all in critical zone, and the program code segment limit of carrying out mutual exclusion protection is larger, cannot give full play to the concurrent advantage of multinuclear.
Visible, in multiple nucleus system, realize fifo queue in spin lock mode, the scheduling performance of queue is had to considerable influence.
Summary of the invention
In view of this, one of object of the embodiment of the present invention is to propose a kind of array dispatching method, while adopting spin lock to realize fifo queue scheduling, adds release expense large, the enumeration problem of multinuclear concurrent processing poor-performing for solving multinuclear equipment.
Further, the method comprises:
In the time that message is joined the team: obtain rear of queue counting T assignment to buffer memory variable Tcur with atomic read operation, when judge current queue less than time, judge at atomic ratio whether current rear of queue counting T equals described buffer memory variable Tcur in compared with swap block, if equate, current queue tail counting T is pointed to next position to be joined the team at described atomic ratio in compared with swap block, if unequal, described atomic ratio directly returns to the value of current rear of queue counting T compared with swap block; Whether discriminant function return value equate with described buffer memory variable Tcur value, using described buffer memory variable Tcur, queue total length S remainder income value carried out the message operation of joining the team if equate as the position of joining the team; Described in returning if unequal, obtain the step of rear of queue counting T assignment to buffer memory variable Tcur with atomic read operation, again carry out the above-mentioned step of joining the team;
In the time that message goes out group: obtain queue heads counting H assignment to buffer memory variable Hcur with atomic read operation, in the time judging current queue not as sky, judge at atomic ratio whether current queue head counting H equals described buffer memory variable Hcur in compared with swap block, if equate, current queue head counting H is pointed to next at described atomic ratio in compared with swap block and treat out group position, if unequal, described atomic ratio directly returns to the value of current queue head counting H compared with swap block; Discriminant function return value and described buffer memory variable Hcur, go out team operation to queue total length S remainder income value as going out group position execution message using described buffer memory variable Hcur if equate; Turn back to if unequal and described obtain the step of queue heads counting H assignment to buffer memory variable Hcur with atomic read operation, again carry out above-mentioned go out group step;
Wherein, described rear of queue counting T and queue heads counting H are atom variable.
In certain embodiments, described queue total length S is more than or equal to queue configured length L and check figure N sum, and described queue configured length L is the maximum number of pre-configured queue buffer memory message, the processor core number that described check figure N is multinuclear equipment.
In certain embodiments, it is described in the time that message is joined the team, judge current queue less than method be: judge that buffer memory variable Tcur deducts described variable queue heads counting H and whether is less than 0 with queue configured length L sum, be less than 0 expression queue less than, otherwise expression queue is full.
In certain embodiments, described in the time that message goes out group, judge that current queue for empty method is not: deduct rear of queue counting T with Hcur, in the time that difference is less than 0, represent that queue is for empty, otherwise represent that queue be sky.
In certain embodiments, described queue is counted H and rear of queue counting T by queue heads and is expressed unrolling after range limit and realize recycling of queue storage space reaching it.
Another object of the embodiment of the present invention is to propose a kind of First Input First Output dispatching device, and this device comprises joins the team module and goes out group module;
The described module of joining the team comprises:
The pretreatment unit of joining the team, for obtaining rear of queue counting T assignment with atomic read operation to buffer memory variable Tcur, and judges that whether current queue full, queue less than time instruction atomic ratio carry out compared with crosspoint;
Join the team atomic ratio compared with crosspoint, join the team atomic ratio compared with swap block for carrying out, judge at the atomic ratio of joining the team whether current rear of queue counting T equals described buffer memory variable Tcur in compared with swap block, if equate, current queue tail counting T is pointed to next position to be joined the team at the described atomic ratio of joining the team in compared with swap block, if unequal, the atomic ratio of joining the team described in directly returns to the value of current rear of queue counting T compared with swap block;
Whether the judging unit of joining the team, equate with described buffer memory variable Tcur value compared with the return value of swap block for the atomic ratio of joining the team described in judging, if equate, the instruction unit of joining the team carries out, and ELSE instruction pretreatment unit is carried out again;
The unit of joining the team, for carrying out the message operation of joining the team as the position of joining the team to queue total length S remainder income value using described buffer memory variable Tcur;
Described go out group module comprise:
Go out group pretreatment unit, for obtaining queue heads counting H assignment with atomic read operation to buffer memory variable Hcur, and judge whether current queue is sky, instruction goes out group atomic ratio and carries out compared with crosspoint if not empty;
Go out group atomic ratio compared with crosspoint, be used for carrying out out group atomic ratio compared with swap block, judge whether current queue head counting H equals described buffer memory variable Hcur in compared with swap block going out group atomic ratio, if equate, described go out group atomic ratio current queue head counting H is pointed to next in compared with swap block and treats out group position, if unequal, go out group atomic ratio described in and directly return compared with swap block the value of current queue head counting H;
Go out group judging unit, for judging group atomic ratio compared with swap block return value and described buffer memory variable Hcur, if equate, instruction goes out group unit and carries out, and ELSE instruction goes out group pretreatment unit and carries out execution again;
Go out group unit, for queue total length S remainder income value being gone out to team's operation as going out group position execution message using described buffer memory variable Hcur;
Wherein, described rear of queue counting T and queue heads counting H are atom variable.
In certain embodiments, described queue total length S is more than or equal to queue configured length L and check figure N sum, and described queue configured length L is the maximum number of pre-configured queue buffer memory message, the processor core number that described check figure N is multinuclear equipment.
In certain embodiments, the described pretreatment unit of joining the team judges that the whether full method of current queue is: judge that buffer memory variable Tcur deducts described variable queue heads counting H and whether queue configured length L sum is less than 0, be less than 0 expression queue less than, otherwise represent queue full.
In certain embodiments, described in, go out group pretreatment unit and judge whether current queue is that empty method is: deduct rear of queue counting T with Hcur, in the time that difference is less than 0, represent that queue is not for empty, otherwise represent that queue is empty.
In certain embodiments, described in, join the team atomic ratio compared with crosspoint and described in go out group atomic ratio and count H and rear of queue counting T compared with crosspoint by queue heads and realize recycling of queue storage space reaching unrolling after its expression range limit.
With respect to prior art, the present invention has following advantage:
The present invention program does not use spin lock, with atomic operation read fifo queue as front counting H and tail counting T, complete judging whether that other core is carried out and join the team or go out team's operation and the actual counting operation of joining the team or going out team's counting in compared with swap block at atomic ratio.In the present invention, need the scope of protecting code section of multinuclear mutually exclusive operation very little, do not have multinuclear to lock and the expense of release, can improve the dispatching efficiency of multinuclear equipment to fifo queue.
Brief description of the drawings
The accompanying drawing that forms an embodiment of the present invention part is used to provide the further understanding to the embodiment of the present invention, and schematic description and description of the present invention is used for explaining the present invention, does not form inappropriate limitation of the present invention.In the accompanying drawings:
The queue data structure schematic diagram using without the many consumers' of the many producers of support of spin lock fifo queue dispatching method under a kind of multiple nucleus system that Fig. 1 provides for the embodiment of the present invention;
Under a kind of multiple nucleus system that Fig. 2 provides for the embodiment of the present invention without the method flow diagram of joining the team of the message in the many consumers' of the many producers of support of spin lock fifo queue dispatching method;
Under a kind of multiple nucleus system that Fig. 3 provides for the embodiment of the present invention, go out group method flow diagram without the message in the many consumers' of the many producers of support of spin lock fifo queue dispatching method;
Under a kind of multiple nucleus system that Fig. 4 provides for the embodiment of the present invention without the many consumers' of the many producers of support of spin lock fifo queue dispatching device structural representation.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is only the present invention's part embodiment, instead of whole embodiment.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtaining under creative work prerequisite, belong to the scope of protection of the invention.
It should be noted that, in the situation that not conflicting, the feature in the embodiment of the present invention and embodiment can combine mutually.
Below in conjunction with accompanying drawing, each preferred embodiment of the present invention is described further:
The queue data structure schematic diagram using without the many consumers' of the many producers of support of spin lock fifo queue dispatching method under the multiple nucleus system that Fig. 1 provides for the embodiment of the present invention; in an embodiment of the present invention; queue data structure adopts structure of arrays; each array location is a message pointer; point to the internal storage location of actual storage message; the present invention does not limit the data structure of this queue; the data structure that can realize arbitrarily the inventive method for example also can adopt list structure within all should being included in protection scope of the present invention.As shown in Figure 1, wherein:
Queue configured length L: for queue needs the maximum message segment number of buffer memory message, can be configured according to system parameters, for being more than or equal to 1 positive integer.Because queue is subject to the restriction of system resource, can not infinite buffer message, need to there is a buffer memory upper limit, this upper limit is the maximum message segment number of buffer memory, and this value can be different in each equipment, and the present invention is not specifically limited.
Check figure N: for the processor core number of multinuclear equipment, as the number of central processing unit CPU, this value can be obtained from operating system.
Queue total length S: be the total message buffer size of queue, i.e. what queue was total can buffer memory message number, by calculating gained, be more than or equal to L+N, generally designate as L+N.
Queue heads counting H: the position of heading in record queue.Conventionally being initialized as 0, is atom variable, and with atomic way executable operations, in the time reaching this variable expression range limit value, will be reset is 0.
Rear of queue counting T: the position of message trailer in record queue.Conventionally being initialized as 0, is atom variable, and with atomic way executable operations, in the time reaching this variable expression range limit value, will be reset is 0.
Queue buffer is expressed unrolling after range limit and is realized recycling of queue storage space reaching it to count end to end, for example T is initialized as 0, in the time that it is double byte 16 bit, its expression scope is 0~65535, and in the time that its value exceedes 65535, will be reset is 0 to realize the operation of unrolling.
Based on above-mentioned queue data structure, under a kind of multiple nucleus system that the embodiment of the present invention provides, without the many consumers' of the many producers of support of spin lock fifo queue dispatching method, the method comprising the steps of:
In the time that message is joined the team: obtain rear of queue counting T assignment to buffer memory variable Tcur with atomic read operation, when judge current queue less than time, judge at atomic ratio whether current rear of queue counting T equals described buffer memory variable Tcur in compared with swap block, if equate, current queue tail counting T is pointed to next position to be joined the team (for example T being done to increment operator) at described atomic ratio in compared with swap block, if unequal, described atomic ratio directly returns to the value of current rear of queue counting T compared with swap block; Whether discriminant function return value equate with described buffer memory variable Tcur value, if equate using described buffer memory variable Tcur queue total length S remainder income value (being Tcur%S) as the position execution message of the joining the team operation of joining the team; Described in returning if unequal, obtain the step of rear of queue counting T assignment to buffer memory variable Tcur with atomic read operation, again carry out the above-mentioned step of joining the team;
Wherein, whether atomic ratio, compared with judging in swap block that the object whether current rear of queue counting T equals buffer memory variable Tcur is judge before this atomic operation of execution, has other core to carry out the operation of joining the team, thereby causes current T and to obtain before Tcur different.
In the time that message goes out group: obtain queue heads counting H assignment to buffer memory variable Hcur with atomic read operation, in the time judging current queue not as sky, judge at atomic ratio whether current queue head counting H equals described buffer memory variable Hcur in compared with swap block, if equate, current queue head counting H is pointed to next at described atomic ratio in compared with swap block and treat out group position (for example H being done to increment operator), if unequal, described atomic ratio directly returns to the value of current queue head counting H compared with swap block; Discriminant function return value and described buffer memory variable Hcur, go out team operation to queue total length S remainder income value (being Hcur%S) as going out group position execution message using described buffer memory variable Hcur if equate; Turn back to if unequal and described obtain the step of queue heads counting H assignment to buffer memory variable Hcur with atomic read operation, again carry out above-mentioned go out group step.
Wherein, whether atomic ratio, compared with judging in swap block that the object whether current rear of queue counting H equals buffer memory variable Hcur is judge before carrying out this atomic operation, has other core to carry out team and operates, thereby causes current H and to obtain before Hcur different.
Known by above-mentioned steps, in the array dispatching method that the embodiment of the present invention provides, do not use the mode of spin lock solve multinuclear concurrent join the team or go out team cause dispatching wrong problem, the present invention is realized queue heads counting H and tail counting T and is adopted atomic operation to its shift count operation by atom variable, be limited to (being within the scope of atomic operation) in less scope by joining the team and going out group multinuclear critical zone, many many consumers of producer fifo queue scheduling models are realized, can bring into play greatly the concurrent advantage of multi-core CPU, improve the queue processing performance of datacom device.
Under a kind of multiple nucleus system that Fig. 2 provides for the embodiment of the present invention without the method flow diagram of joining the team of the message in the many consumers' of the many producers of support of spin lock fifo queue dispatching method, suppose in this embodiment, the initial condition of current queue is: queue configured length L is 100, check figure N is 8, queue total length S (being L+N) is 108, and queue heads counting H is 500, and rear of queue counting T is 599, join the team in process whole, H remains unchanged.The message step of joining the team is as follows:
Step 201, obtain the value of rear of queue counting atom variable T with atomic read operation, and assignment is to buffer memory variable Tcur;
For example, when T value is 599, read value assignment that function atomic_read (T) reads T to Tcur by atom, the value of Tcur is 599.
Step 202, deduct atom variable queue heads counting H and queue configured length L sum with Tcur, judge that whether queue full, in the time that difference is less than 0, represent queue less than, perform step 203, otherwise perform step 206;
For example when H be that 500, L is 100 o'clock, judge whether Tcur-(H+L) is less than zero, and in the time that Tcur is 599, difference is less than zero, illustrate queue less than, otherwise illustrate queue full.
Step 203, complete compared with swap block by atomic ratio: judge whether current queue tail counting T equals described buffer memory variable Tcur, if equate, rear of queue is counted to T at atomic ratio in compared with swap block and add 1, and the value of returning to former rear of queue counting T adds value before 1 to intermediate variable Told, if unequal, directly return to the value of current queue tail counting T to intermediate variable Told.
In the embodiment of the present invention, use atomic ratio compared with swap block atomic_cmpxchg (a, b, c), wherein a is atom variable, and b and c are target component.Each number leads to operating system all provides (comprising Linux etc.) operational processes of atom types of variables and one group of atom variable, the atom variable operation of atom variable a being carried out in compared with swap block at atomic ratio in the present invention has atomicity, can ensure the concurrent correctness that writes atom variable critical zone.
This atomic ratio comprises compared with the function of swap block: atom variable a and target component b compare, if a equates with b, value before the value that a is exchanged into target component c and returns to atom variable a exchanges, if a and b are unequal, directly returns to the value of atom variable a.This functional procedure Atomicity, can not interrupt.
It is atomic_cmpxchg (T compared with swap block form that for example this step is carried out atomic ratio, Tcur, Tcur+1), suppose in the time carrying out this former subfunction, T=Tcur, illustrate before this function of execution, do not have other core to carry out the operation of joining the team, in this former subfunction, atom variable T is added to 1 (by the value assignment of Tcur+1 to T), and the value of returning to former T is to Told, for example Tcur be 599, T current be also 599 o'clock, in this former subfunction, T becomes 600, and function return value be 599 give Told.Suppose in the time carrying out this former subfunction, T ≠ Tcur, illustrate before this function of execution, there are other cores to carry out the operation of joining the team, the value that this former subfunction is directly returned to current atom variable T is to Told, and for example Tcur is that 599, T currency is 600, this former subfunction is not done any operation to T, directly returns to 600 value to Told.
Whether step 204, relatively judgement by Told and Tcur, in the time carrying out atomic ratio compared with swap block, have the operation of joining the team of other cores, if while having the Told of being ≠ Tcur, return to step 201, if while being not Told=Tcur, perform step 205;
Step 205, according to buffer memory variable Tcur, the value using buffer memory variable Tcur after to queue total length S remainder is carried out the message operation of joining the team as the position of joining the team, flow process finishes.
In this step, preserved by buffer memory variable Tcur in the position of joining the team because message is actual, so the operation of joining the team of other cores will can not affect the operation of joining the team of current message after atomic ratio is compared with swap block.
Step 206, dropping packets, process ends.
Under a kind of multiple nucleus system that Fig. 3 embodiment of the present invention provides, go out group method flow diagram without the message in the many consumers' of the many producers of support of spin lock fifo queue dispatching method, suppose in this embodiment, the initial condition of current queue is: queue configured length L is 100, check figure N is 8, queue total length S (being L+N) is 108, and queue heads counting H is 550, and rear of queue counting T is 600, whole go out in group process, T remains unchanged.It is as follows that message goes out group step:
Step 301, obtain the value of queue heads counting atom variable H with atomic read operation, and assignment is to buffer memory variable Hcur;
For example, when H value is 550, read value assignment that function atomic_read (H) reads H to Hcur by atom, the value of Hcur is 550.
Step 302, deduct atom variable rear of queue counting T with Hcur, judge whether queue is empty, in the time that difference is less than 0, represent that queue, for sky, performs step 303, otherwise process ends;
For example, when T is that 600, Hcur is, judge that Hcur-T is less than zero at 550 o'clock, illustrate that queue, not for empty, can carry out message and go out team's operation, otherwise explanation queue be empty, can not carry out message and go out team's operation.
Step 303, complete compared with swap block by atomic ratio: judge whether current queue head counting H equals described buffer memory variable Hcur, if equate, queue heads is counted to H at atomic ratio in compared with swap block and add 1, and the value of returning to former queue heads counting H adds value before 1 to intermediate variable Hold, if unequal, directly return to the value of current queue head counting H to intermediate variable Hold.
Carrying out atomic ratio as this step is atomic_cmpxchg (H compared with swap block form, Hcur, Hcur+1), suppose in the time carrying out this former subfunction, H=Hcur, illustrates carrying out before this function, does not have other core to carry out team's operation, in this former subfunction, atom variable H is added to 1 (by the value assignment of Hcur+1 to H), and the value of returning to former H is to Hold.Suppose that in the time carrying out this former subfunction H ≠ Hcur illustrates carrying out before this function, have other cores to carry out team's operation, the value that this former subfunction is directly returned to current atom variable H is to Hold.
Whether step 304, relatively judgement by Hold and Hcur, in the time carrying out atomic ratio compared with swap block, have other cores to make team's operation, if while having the Hold of being ≠ Hcur, return to step 301, if while being not Hold=Hcur, and execution step 305;
Step 305, according to buffer memory variable Hcur, the value using buffer memory variable Hcur after to queue total length S remainder is carried out message and is gone out team's operation as going out group position, flow process finishes.
In this step, preserved by buffer memory variable Hcur in the position that goes out team because message is actual, so the team's operation that goes out of other cores operates the team that can not affect current message after atomic ratio is compared with swap block.
The reason that in the embodiment of the present invention, S is set as to S >=H+L is below described:
In the embodiment of the present invention, step 303 (P3) is queue heads atom variable H operation, step 305 (P4) is the operation of the actual dequeue of message, between step 303 and 305, there is the time difference in several cpu clocks cycle (relevant with concrete CPU, conventionally between 0 to 20 clock cycle), the operation to H in step 303 first completes, and goes out after team operates and complete in step 305.
In the embodiment of the present invention, step 203 (P1) is rear of queue atom variable T operation, step 205 (P2), P2 is the operation that actual message enters queue, between step 203 and 205, there is the time difference (relevant with concrete CPU, conventionally between 0 to 20 clock cycle) in several cpu clocks cycle, in step 203, the operation of T first completes, and after the operation of joining the team, completes in step 205.
If there is no the restriction of S >=L+N, but S=L, there are the following problems so:
In the time that queue is expired (when H equals T), suppose to have two CPU, CPU1 carries out out team's (step 303 and 305), CPU2 carries out and joins the team (step 203 and step 205), the operation that completes out team and join the team with the order of step 303 → step 203 → step 205 → step 305 in absolute time.
CPU1 performs step after 303 processes, and H has discharged a spatial cache, and CPU2 has met the condition of joining the team, execution step 203, perform step subsequently 205, like this step 305 of CPU1 message dequeue actual go out the CPU2 message of joining the team in step 205, cause dispatching mistake.
Queue buffer area provides the expansion buffering area (being that queue buffer total length S is more than or equal to queue configured length L+ check figure N) of extra CPU number, even if all like this CPU are simultaneously concurrent, the team that goes out of the queue buffer that also can avoid the counting of joining the team (being T%S) of the queue buffer that rear of queue atom variable T calculates to unroll calculating to queue heads atom variable H counts (H%S).
The embodiment of the present invention is by atom variable and operation thereof, be limited to (within the scope of atomic operation) in less scope by joining the team and going out group multinuclear critical zone, many many consumers of producer fifo queue scheduling models are realized, can bring into play greatly the concurrent advantage of multi-core CPU, improve the queue processing performance of datacom device.
Based on said method embodiment, the embodiment of the present invention also provides under a kind of multiple nucleus system the fifo queue dispatching device without the many consumers of the many producers of support of spin lock, its structural representation as shown in Figure 4:
Based on the principle identical with said method embodiment, the embodiment of the present invention also provides a kind of First Input First Output dispatching device, and as shown in Figure 4, this device 400 comprises the functional module structure schematic diagram of this device: the module of joining the team 410 and go out group module 420;
The module of joining the team 410 comprises:
The pretreatment unit 411 of joining the team, for obtaining rear of queue counting T assignment with atomic read operation to buffer memory variable Tcur, and judges that whether current queue full, queue less than time instruction atomic ratio carry out compared with crosspoint;
Join the team atomic ratio compared with crosspoint 412, join the team atomic ratio compared with swap block for carrying out, judge at the atomic ratio of joining the team whether current rear of queue counting T equals described buffer memory variable Tcur in compared with swap block, if equate, current queue tail counting T is pointed to next position to be joined the team at the described atomic ratio of joining the team in compared with swap block, if unequal, the atomic ratio of joining the team described in directly returns to the value of current rear of queue counting T compared with swap block;
Whether the judging unit 413 of joining the team, equate with described buffer memory variable Tcur value compared with the return value of swap block for the atomic ratio of joining the team described in judging, if equate, the instruction unit of joining the team carries out, and ELSE instruction pretreatment unit is carried out again;
The unit 414 of joining the team, for carrying out the message operation of joining the team as the position of joining the team to queue total length S remainder income value using described buffer memory variable Tcur;
Going out group module 420 comprises:
Go out group pretreatment unit 421, for obtaining queue heads counting H assignment with atomic read operation to buffer memory variable Hcur, and judge whether current queue is sky, instruction goes out group atomic ratio and carries out compared with crosspoint if not empty;
Go out group atomic ratio compared with crosspoint 422, be used for carrying out out group atomic ratio compared with swap block, judge whether current queue head counting H equals described buffer memory variable Hcur in compared with swap block going out group atomic ratio, if equate, described go out group atomic ratio current queue head counting H is pointed to next in compared with swap block and treats out group position, if unequal, go out group atomic ratio described in and directly return compared with swap block the value of current queue head counting H;
Go out group judging unit 423, for judging group atomic ratio compared with swap block return value and described buffer memory variable Hcur, if equate, instruction goes out group unit and carries out, and ELSE instruction goes out group pretreatment unit and carries out execution again;
Go out group unit 424, for queue total length S remainder income value being gone out to team's operation as going out group position execution message using described buffer memory variable Hcur;
Wherein, described rear of queue counting T and queue heads counting H are atom variable.
Queue total length S is more than or equal to queue configured length L and check figure N sum, and queue configured length L is the maximum number of pre-configured queue buffer memory message, and check figure N is the processor core number of multinuclear equipment.
Further, the pretreatment unit 411 of joining the team judges that the whether full method of current queue is: judge that buffer memory variable Tcur deducts described variable queue heads counting H and whether queue configured length L sum is less than 0, be less than 0 expression queue less than, otherwise represent queue full.
Further, go out group pretreatment unit 421 and judge whether current queue is that empty method is: deduct rear of queue counting T with Hcur, in the time that difference is less than 0, represent that queue is not for empty, otherwise represent that queue is empty.
Further, join the team atomic ratio compared with crosspoint 412 and go out group atomic ratio and count H and rear of queue counting T compared with crosspoint 422 by queue heads and realize recycling of queue storage space reaching unrolling after its expression range limit.
Obviously, those skilled in the art should be understood that, above-mentioned of the present invention each module or each step can realize with general calculation element, they can concentrate on single calculation element, or be distributed on the network that multiple calculation elements form, alternatively, they can be realized with the executable program code of calculation element, thereby, they can be stored in storage device and be carried out by calculation element, or they are made into respectively to each integrated circuit modules, or the multiple modules in them or step are made into single integrated circuit module to be realized.Like this, the present invention is not restricted to any specific hardware and software combination.Described storage device is nonvolatile memory, as: ROM/RAM, flash memory, magnetic disc, CD etc.
The foregoing is only preferred embodiment of the present invention, in order to limit the present invention, within the spirit and principles in the present invention not all, any amendment of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.
Claims (10)
1. a First Input First Output dispatching method, is characterized in that, the method comprises:
In the time that message is joined the team: obtain rear of queue counting T assignment to buffer memory variable Tcur with atomic read operation, when judge current queue less than time, judge at atomic ratio whether current rear of queue counting T equals described buffer memory variable Tcur in compared with swap block, if equate, current queue tail counting T is pointed to next position to be joined the team at described atomic ratio in compared with swap block, if unequal, described atomic ratio directly returns to the value of current rear of queue counting T compared with swap block; Whether discriminant function return value equate with described buffer memory variable Tcur value, using described buffer memory variable Tcur, queue total length S remainder income value carried out the message operation of joining the team if equate as the position of joining the team; Described in returning if unequal, obtain the step of rear of queue counting T assignment to buffer memory variable Tcur with atomic read operation, again carry out the above-mentioned step of joining the team;
In the time that message goes out group: obtain queue heads counting H assignment to buffer memory variable Hcur with atomic read operation, in the time judging current queue not as sky, judge at atomic ratio whether current queue head counting H equals described buffer memory variable Hcur in compared with swap block, if equate, current queue head counting H is pointed to next at described atomic ratio in compared with swap block and treat out group position, if unequal, described atomic ratio directly returns to the value of current queue head counting H compared with swap block; Discriminant function return value and described buffer memory variable Hcur, go out team operation to queue total length S remainder income value as going out group position execution message using described buffer memory variable Hcur if equate; Turn back to if unequal and described obtain the step of queue heads counting H assignment to buffer memory variable Hcur with atomic read operation, again carry out above-mentioned go out group step;
Wherein, described rear of queue counting T and queue heads counting H are atom variable.
2. method according to claim 1, it is characterized in that, described queue total length S is more than or equal to queue configured length L and check figure N sum, and described queue configured length L is the maximum number of pre-configured queue buffer memory message, the processor core number that described check figure N is multinuclear equipment.
3. method according to claim 2, is characterized in that,
Described in the time that message is joined the team, judge current queue less than method be: judge that buffer memory variable Tcur deducts described variable queue heads counting H and whether is less than 0 with queue configured length L sum, be less than 0 expression queue less than, otherwise expression queue is full.
4. method according to claim 2, is characterized in that,
Described in the time that message goes out group, judge that current queue for empty method is not: deduct rear of queue counting T with Hcur, in the time that difference is less than 0, represent that queue is for empty, otherwise represent that queue be sky.
5. method according to claim 2, is characterized in that,
Described queue is counted H and rear of queue counting T by queue heads and is expressed unrolling after range limit and realize recycling of queue storage space reaching it.
6. a First Input First Output dispatching device, is characterized in that, this device comprises joins the team module and goes out group module;
The described module of joining the team comprises:
The pretreatment unit of joining the team, for obtaining rear of queue counting T assignment with atomic read operation to buffer memory variable Tcur, and judges that whether current queue full, queue less than time instruction atomic ratio carry out compared with crosspoint;
Join the team atomic ratio compared with crosspoint, join the team atomic ratio compared with swap block for carrying out, judge at the atomic ratio of joining the team whether current rear of queue counting T equals described buffer memory variable Tcur in compared with swap block, if equate, current queue tail counting T is pointed to next position to be joined the team at the described atomic ratio of joining the team in compared with swap block, if unequal, the atomic ratio of joining the team described in directly returns to the value of current rear of queue counting T compared with swap block;
Whether the judging unit of joining the team, equate with described buffer memory variable Tcur value compared with the return value of swap block for the atomic ratio of joining the team described in judging, if equate, the instruction unit of joining the team carries out, and ELSE instruction pretreatment unit is carried out again;
The unit of joining the team, for carrying out the message operation of joining the team as the position of joining the team to queue total length S remainder income value using described buffer memory variable Tcur;
Described go out group module comprise:
Go out group pretreatment unit, for obtaining queue heads counting H assignment with atomic read operation to buffer memory variable Hcur, and judge whether current queue is sky, instruction goes out group atomic ratio and carries out compared with crosspoint if not empty;
Go out group atomic ratio compared with crosspoint, be used for carrying out out group atomic ratio compared with swap block, judge whether current queue head counting H equals described buffer memory variable Hcur in compared with swap block going out group atomic ratio, if equate, described go out group atomic ratio current queue head counting H is pointed to next in compared with swap block and treats out group position, if unequal, go out group atomic ratio described in and directly return compared with swap block the value of current queue head counting H;
Go out group judging unit, for judging group atomic ratio compared with swap block return value and described buffer memory variable Hcur, if equate, instruction goes out group unit and carries out, and ELSE instruction goes out group pretreatment unit and carries out execution again;
Go out group unit, for queue total length S remainder income value being gone out to team's operation as going out group position execution message using described buffer memory variable Hcur;
Wherein, described rear of queue counting T and queue heads counting H are atom variable.
7. device according to claim 6, it is characterized in that, described queue total length S is more than or equal to queue configured length L and check figure N sum, and described queue configured length L is the maximum number of pre-configured queue buffer memory message, the processor core number that described check figure N is multinuclear equipment.
8. device according to claim 7, is characterized in that,
The described pretreatment unit of joining the team judges that the whether full method of current queue is: judge that buffer memory variable Tcur deducts described variable queue heads counting H and whether is less than 0 with queue configured length L sum, be less than 0 expression queue less than, otherwise expression queue is full.
9. device according to claim 7, is characterized in that,
Described go out group pretreatment unit judge whether current queue is that empty method is: deduct rear of queue counting T with Hcur, in the time that difference is less than 0, represent that queue is for empty, otherwise represent that queue be sky.
10. device according to claim 7, is characterized in that,
Described join the team atomic ratio compared with crosspoint and described in go out group atomic ratio and count H and rear of queue counting T compared with crosspoint by queue heads and realize recycling of queue storage space reaching unrolling after its expression range limit.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410404736.5A CN104168217B (en) | 2014-08-15 | 2014-08-15 | A kind of First Input First Output dispatching method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410404736.5A CN104168217B (en) | 2014-08-15 | 2014-08-15 | A kind of First Input First Output dispatching method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN104168217A true CN104168217A (en) | 2014-11-26 |
CN104168217B CN104168217B (en) | 2018-01-09 |
Family
ID=51911851
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410404736.5A Active CN104168217B (en) | 2014-08-15 | 2014-08-15 | A kind of First Input First Output dispatching method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104168217B (en) |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105868031A (en) * | 2016-03-24 | 2016-08-17 | 车智互联(北京)科技有限公司 | A data transmission device and method |
CN108153596A (en) * | 2017-12-15 | 2018-06-12 | 珠海金山网络游戏科技有限公司 | A kind of message treatment method and device based on lock-free queue |
CN108234351A (en) * | 2017-12-05 | 2018-06-29 | 山东超越数控电子股份有限公司 | A kind of data packet fault-tolerant processing module and method |
CN108491276A (en) * | 2018-03-26 | 2018-09-04 | 武汉斗鱼网络科技有限公司 | function call management method and device |
CN109375990A (en) * | 2018-09-29 | 2019-02-22 | 长沙新弘软件有限公司 | A kind of annular chain meter method based on atomic operation |
CN109656515A (en) * | 2018-11-16 | 2019-04-19 | 深圳证券交易所 | Operating method, device and the storage medium of queue message |
CN110046049A (en) * | 2018-01-15 | 2019-07-23 | 迈普通信技术股份有限公司 | Queue management method, device and data communications equipment |
CN110362348A (en) * | 2018-04-09 | 2019-10-22 | 武汉斗鱼网络科技有限公司 | A kind of method, apparatus and electronic equipment of queue access data |
CN112702275A (en) * | 2020-12-29 | 2021-04-23 | 迈普通信技术股份有限公司 | Method, device, network equipment and computer storage medium based on packet-by-packet forwarding |
CN113176896A (en) * | 2021-03-19 | 2021-07-27 | 中盈优创资讯科技有限公司 | Method for randomly taking out object based on single-in single-out lock-free queue |
CN113377295A (en) * | 2021-08-13 | 2021-09-10 | 北京华云安信息技术有限公司 | Data storage and reading method, device and equipment for multi-producer single-consumer |
CN116149573A (en) * | 2023-04-19 | 2023-05-23 | 苏州浪潮智能科技有限公司 | Method, system, equipment and medium for processing queue by RAID card cluster |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20030196010A1 (en) * | 1998-09-09 | 2003-10-16 | Microsoft Corporation | Non-blocking concurrent queues with direct node access by threads |
CN101183304A (en) * | 2006-11-13 | 2008-05-21 | 国际商业机器公司 | Concurrent, non-blocking, lock-free queue and method, apparatus, and computer program product for implementing same |
US20090249356A1 (en) * | 2008-03-31 | 2009-10-01 | Xin He | Lock-free circular queue in a multiprocessing system |
CN102638410A (en) * | 2012-04-28 | 2012-08-15 | 迈普通信技术股份有限公司 | Lock-free parallel traffic scheduling method and system |
CN103294753A (en) * | 2012-01-30 | 2013-09-11 | 辉达公司 | Lock-free fifo |
CN103338157A (en) * | 2013-07-01 | 2013-10-02 | 杭州华三通信技术有限公司 | Internuclear data message caching method and equipment of multinuclear system |
CN103473031A (en) * | 2013-01-18 | 2013-12-25 | 龙建 | Cooperative concurrent message bus, driving member assembly model and member disassembly method |
-
2014
- 2014-08-15 CN CN201410404736.5A patent/CN104168217B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20030196010A1 (en) * | 1998-09-09 | 2003-10-16 | Microsoft Corporation | Non-blocking concurrent queues with direct node access by threads |
CN101183304A (en) * | 2006-11-13 | 2008-05-21 | 国际商业机器公司 | Concurrent, non-blocking, lock-free queue and method, apparatus, and computer program product for implementing same |
US20090249356A1 (en) * | 2008-03-31 | 2009-10-01 | Xin He | Lock-free circular queue in a multiprocessing system |
CN103294753A (en) * | 2012-01-30 | 2013-09-11 | 辉达公司 | Lock-free fifo |
CN102638410A (en) * | 2012-04-28 | 2012-08-15 | 迈普通信技术股份有限公司 | Lock-free parallel traffic scheduling method and system |
CN103473031A (en) * | 2013-01-18 | 2013-12-25 | 龙建 | Cooperative concurrent message bus, driving member assembly model and member disassembly method |
CN103338157A (en) * | 2013-07-01 | 2013-10-02 | 杭州华三通信技术有限公司 | Internuclear data message caching method and equipment of multinuclear system |
Non-Patent Citations (1)
Title |
---|
王肇国: "面向高可伸缩和可移植的众核全系统模拟器的设计与实现", 《中国优秀说是学位论文全文数据库信息科技辑》 * |
Cited By (16)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105868031A (en) * | 2016-03-24 | 2016-08-17 | 车智互联(北京)科技有限公司 | A data transmission device and method |
CN108234351A (en) * | 2017-12-05 | 2018-06-29 | 山东超越数控电子股份有限公司 | A kind of data packet fault-tolerant processing module and method |
CN108153596A (en) * | 2017-12-15 | 2018-06-12 | 珠海金山网络游戏科技有限公司 | A kind of message treatment method and device based on lock-free queue |
CN110046049A (en) * | 2018-01-15 | 2019-07-23 | 迈普通信技术股份有限公司 | Queue management method, device and data communications equipment |
CN108491276A (en) * | 2018-03-26 | 2018-09-04 | 武汉斗鱼网络科技有限公司 | function call management method and device |
CN108491276B (en) * | 2018-03-26 | 2021-04-27 | 武汉斗鱼网络科技有限公司 | Function call management method and device |
CN110362348A (en) * | 2018-04-09 | 2019-10-22 | 武汉斗鱼网络科技有限公司 | A kind of method, apparatus and electronic equipment of queue access data |
CN109375990B (en) * | 2018-09-29 | 2021-07-20 | 长沙新弘软件有限公司 | Ring linked list method based on atomic operation |
CN109375990A (en) * | 2018-09-29 | 2019-02-22 | 长沙新弘软件有限公司 | A kind of annular chain meter method based on atomic operation |
CN109656515A (en) * | 2018-11-16 | 2019-04-19 | 深圳证券交易所 | Operating method, device and the storage medium of queue message |
CN112702275A (en) * | 2020-12-29 | 2021-04-23 | 迈普通信技术股份有限公司 | Method, device, network equipment and computer storage medium based on packet-by-packet forwarding |
CN113176896A (en) * | 2021-03-19 | 2021-07-27 | 中盈优创资讯科技有限公司 | Method for randomly taking out object based on single-in single-out lock-free queue |
CN113377295A (en) * | 2021-08-13 | 2021-09-10 | 北京华云安信息技术有限公司 | Data storage and reading method, device and equipment for multi-producer single-consumer |
CN113377295B (en) * | 2021-08-13 | 2021-12-10 | 北京华云安信息技术有限公司 | Data storage and reading method, device and equipment for multi-producer single-consumer |
CN116149573A (en) * | 2023-04-19 | 2023-05-23 | 苏州浪潮智能科技有限公司 | Method, system, equipment and medium for processing queue by RAID card cluster |
CN116149573B (en) * | 2023-04-19 | 2023-07-14 | 苏州浪潮智能科技有限公司 | Method, system, equipment and medium for processing queue by RAID card cluster |
Also Published As
Publication number | Publication date |
---|---|
CN104168217B (en) | 2018-01-09 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN104168217A (en) | Scheduling method and device for first in first out queue | |
US8364844B2 (en) | Deadlock-free class routes for collective communications embedded in a multi-dimensional torus network | |
EP2441013B1 (en) | Shared resource multi-thread processor array | |
TWI522908B (en) | A method for executing blocks of instructions using a microprocessor architecture having a register view, source view, instruction view, and a plurality of register templates | |
TWI522912B (en) | A method for emulating a guest centralized flag architecture by using a native distributed flag architecture | |
EP2480979B1 (en) | Unanimous branch instructions in a parallel thread processor | |
US8689237B2 (en) | Multi-lane concurrent bag for facilitating inter-thread communication | |
US7055151B1 (en) | Systems and methods for multi-tasking, resource sharing and execution of computer instructions | |
CN101320360A (en) | Message queuing system for parallel integrated circuit and related operation method | |
US20110179229A1 (en) | Store-operate-coherence-on-value | |
TW201504948A (en) | A method for executing multithreaded instructions grouped into blocks | |
CN101194245A (en) | Packet processor with wide register set architecture | |
CN105045632A (en) | Method and device for implementing lock free queue in multi-core environment | |
Bhatt et al. | Group Mutual Exclusion in O (log n) RMR | |
CN104615445A (en) | Equipment IO queue method based on atomic operation | |
CN103176837A (en) | Lock-free message queue implementation method based on reversal single linked list | |
EP2804102B1 (en) | Parallel atomic increment | |
US8761188B1 (en) | Multi-threaded software-programmable framework for high-performance scalable and modular datapath designs | |
US9116739B2 (en) | Fast and scalable concurrent queuing system | |
CN116204289A (en) | Process data processing method, terminal equipment and storage medium | |
CN105637475B (en) | Concurrent access method and system | |
CN112463218B (en) | Instruction emission control method and circuit, data processing method and circuit | |
WO2009110497A1 (en) | Simd processor array system and data transfer method thereof | |
Suvorova | An approach for development of RISC-V based transport layer controller | |
US10032119B1 (en) | Ordering system that employs chained ticket release bitmap block functions |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
CB02 | Change of applicant information |
Address after: 310052 Binjiang District Changhe Road, Zhejiang, China, No. 466, No. Applicant after: Xinhua three Technology Co., Ltd. Address before: 310052 Binjiang District Changhe Road, Zhejiang, China, No. 466, No. Applicant before: Huasan Communication Technology Co., Ltd. |
|
CB02 | Change of applicant information | ||
GR01 | Patent grant | ||
GR01 | Patent grant |