Background technology
When CPU(Central Processing Unit, CPU) pass through PCI(Peripheral
Component Interconnect, periphery component interconnection) or PCIE(Peripheral Component
Interconnect Express, quick periphery component interconnection) etc. bus when being connected with business interface, the most all use BD
The mode of (Buffer Descriptor, buffer descriptor) queue realizes the transmitting-receiving of message and processes.The main contents of BD such as table
Shown in 1, each BD all points to a Buffer(caching), this Buffer is used for caching message data, and it is right that BD itself then comprises
The description information of this message, as shown in table 1, mainly comprises in BD:
Valid(is effective) mark: whether instruction Buffer comprises effective message data;
SOP(Start of Packet, packet header)/EOP(End of Packet, bag tail): the message in instruction Buffer
Data whether packet header or bag tail;
CMD(Command, order)/Status(state): indicate the message data in Buffer the most wrong;
Message length: represent the message data length in Buffer;
Buffer address: represent the Buffer address that this BD points to.
Valid identifies |
SOP/EOP identifies |
CMD/Status indicates |
Message length |
The structural representation of table 1BD
Fig. 1 is the operation mechanism schematic diagram of existing BD queue, as shown in Figure 1:
CPU is responsible for storage allocation, creates and receives BD queue, and this queue is a circle queue, and each reception BD all points to
One piece of Buffer having allocated internal memory in advance;
Target(target) plant maintenance Head(head) pointer, Head pointer always points at first and prepares to receive message
BD;When Target equipment receives a message, message data is write Head pointer and points to Buffer corresponding to BD, by message
The BD that description information write Head pointer points to, then moves forward the next BD of sensing by Head pointer;
Host(main frame) plant maintenance Tail(tail) pointer, Tail pointer always points at first and has been received message
BD, takes out Message processing according to the information in this BD from corresponding Buffer, is then initial value by the control Information recovering of BD,
And redistribute one piece of new Buffer for this BD, Tail pointer is moved to forward the next BD of sensing simultaneously.Wherein, BD
Control information refers mainly to: Valid mark, SOP/EOP mark, CMD/Status instruction and message length.
In actual applications, the board in Target equipment such as distributed system, Host equipment such as distributed system
In CPU.
From the operation mechanism of BD queue shown in Fig. 1 it can be seen that also exist a kind of suitable between BD and BD of reception BD queue
Order relation: only processed current BD and could process next also existing between BD, and BD and message and synchronize one to one
Relation.
Fig. 2 gives the existing Target equipment schematic diagram to Host equipment transmission data, as in figure 2 it is shown, work as
Target equipment receives message when Host device transmission, and transmission sequence is such that Target equipment first to Host equipment
One Buffer writes first message, then to the description information of BD first message of write corresponding for this buffer, then to
Next Buffer of Host equipment writes second message, then to the description of BD second message of write corresponding for this Buffer
Information, the rest may be inferred.
Summary of the invention
The present invention provides reception BD queue maintenance method and apparatus, to improve the fault-tolerance receiving BD queue.
The technical scheme is that and be achieved in that:
A kind of reception buffer descriptor BD queue maintenance method, the method includes:
When message write head Head pointer is pointed to caching Buffer corresponding for BD by target Target equipment, message is retouched
The information of stating writes this BD, and Head pointer moves forward the next BD of sensing;
The state receiving BD queue is made snapshot by strategy by Target equipment, and this state snapshot is synchronized to main frame Host
Equipment, this state snapshot comprises the real-time status of the BD received in BD queue: effective or invalid.
After this state snapshot is synchronized to Host equipment by described Target equipment, farther include:
Host equipment checks the BD that tail Tail pointer points to, and reads effective Valid mark of this BD, if the instruction of this mark
Engineering noise, then read the state of this BD from state snapshot, if this state is " effectively ", then confirms that the real state of this BD is
" effectively ", confirms the information dropout in this BD, Tail pointer moves forward the next BD of sensing, by this BD in state snapshot
State be updated to engineering noise by " effectively ";If this state is engineering noise, then confirms the real engineering noise of this BD, locate the most further
Reason.
Described Host equipment read this BD Valid mark after farther include:
If this Valid mark instruction " effectively ", then from this BD correspondence Buffer, take out message data give upper layer module
Process, Tail pointer is moved to forward the next BD of sensing simultaneously, the state of this BD in state snapshot is updated to engineering noise.
The state receiving BD queue is made snapshot by strategy by described Target equipment, and this state snapshot is synchronized to Host
Equipment includes:
The state of whole reception BD queue disposably or is by several times made snapshot by Target device periodically ground, and by state
Snapshot is synchronized to Host equipment;
Or, when Target equipment finds that Tail pointer does not moves forward within preset number the clock cycle, and Head
When pointer is unequal with Tail pointer, start constantly disposably or by several times the state of whole reception BD queue to be made snapshot,
And state snapshot is synchronized to Host equipment, until stop when Tail pointer moves forward synchronizing.
A kind of reception buffer descriptor BD queue maintenance method, the method includes:
Main frame Host equipment checks the BD that tail Tail pointer points to, and reads effective Valid mark of this BD, if this mark refers to
Show engineering noise, then from the state snapshot receiving BD queue, read the state of this BD, if this state is " effectively ", then confirm this BD
Real state be " effectively ", confirm the information dropout in this BD, Tail pointer moved to forward the next BD of sensing, by shape
In state snapshot, the state of this BD is updated to engineering noise by " effectively ";If this state is engineering noise, then confirm the real engineering noise of this BD,
It is not for further processing;
Wherein, described state snapshot synchronizes from Target equipment the real-time status that contains the BD received in BD queue:
Effective or invalid.
After described Host equipment reads the Valid mark of this BD, farther include:
If this mark instruction " effectively ", then from this BD correspondence Buffer, take out message data give upper layer module process,
Tail pointer is moved to forward the next BD of sensing simultaneously, the state of this BD in state snapshot is updated to engineering noise.
A kind of target Target equipment, this equipment includes:
Message writing module: when message write head Head pointer being pointed to caching Buffer corresponding to buffer descriptor BD
Time, the information that described by message writes this BD, and Head pointer moves forward the next BD of sensing;
State snapshot synchronization module: by strategy, the state receiving BD queue is made snapshot, and this state snapshot is synchronized to
Main frame Host equipment, this state snapshot comprises the real-time status of the BD received in BD queue: effective or invalid.
The state receiving BD queue is made snapshot by strategy by described state snapshot synchronization module, and is synchronized by this state snapshot
Include to Host equipment:
Periodically the state of whole reception BD queue disposably or is by several times made snapshot, and state snapshot is synchronized to
Host equipment;
Or, when Target equipment finds that Tail pointer does not moves forward within preset number the clock cycle, and Head
When pointer is unequal with Tail pointer, start constantly disposably or by several times the state of whole reception BD queue to be made snapshot,
And state snapshot is synchronized to Host equipment, until stop when Tail pointer moves forward synchronizing.
A kind of main frame Host equipment, this equipment includes:
State snapshot receives and preserves module: receive the shape receiving buffer descriptor BD queue that target Target equipment is sent
State snapshot, this state snapshot contains the real-time status of the BD received in BD queue: effective or invalid, with this state snapshot more
The state snapshot of the new reception BD queue self preserved;
Message read module: check the BD that tail Tail pointer points to, reads effective Valid mark of this BD, if this mark
Instruction engineering noise, then receive from state snapshot and preserve the state reading this BD the state snapshot that module preserves, if this state is
" effectively ", then confirm that the real state of this BD is " effectively ", confirm the information dropout in this BD, moved to forward by Tail pointer
Point to next BD, state snapshot is received the state of this BD in the state snapshot that module preserves that preserves and is updated to engineering noise;If
This state is engineering noise, then confirm the real engineering noise of this BD, be not for further processing.
Described message read module read this BD Valid mark after be further used for, if this mark instruction " effectively ",
Then from this BD correspondence caching Buffer, take out message data and give upper layer module process, Tail pointer is moved to forward simultaneously
Point to next BD, and, state snapshot is received the state of this BD in the state snapshot that module preserves that preserves and is updated to engineering noise.
Visible, the present invention can improve the fault-tolerance receiving BD queue.
Detailed description of the invention
Below in conjunction with the accompanying drawings and specific embodiment the present invention is further described in more detail.
It is analyzed existing BD queue operation mechanism finding: if the data on physical bus are transmitted entirely without losing
Lose, then ensure that the transmission of message, reception process and be normally carried out all the time.But in actual use scene, Ren Heyi
Kind data/address bus all can not be completely secured in bus the data of transmission and not lose, and especially connects topology when physical data bus
More complicated, hardware signal environment is all the more so time more severe, it is most likely that because the moment deterioration of physical signalling causes number
It is believed that the loss of breath.The data transmission of current various high-speed bus is typically all based on message or data block rather than based on word
Throttling, a bus operation completes the transmission of a blocks of data, so, the loss of data is also a complete message or number
Loss according to block.
If physical bus hardware signal deteriorates suddenly sometime, then the BD that certain message is corresponding may be caused in bus
Lost during transmission, and this loss, current BD queue mechanism be can not put up with.As shown in Figure 3, it is assumed that Target
Equipment is when by physical bus to Host equipment transmission data, and Bd2 lost, then:
1), time initially, the Tail pointer of Host plant maintenance points to Bd1;Host equipment finds that the Valid mark in Bd1 refers to
It is shown with effect, then from corresponding Buffer, takes out message according to Bd1 and give upper layer module process, and move Tail pointer sensing Bd2;
Because the information of Bd2 lost in bus, but Host device-aware less than, thus Host equipment is according to the Valid in Bd2
Mark thinks that Bd2 is invalid, and it is all invalid for imply Bd3, Bd4 etc. later for Bd2 simultaneously, so, Host equipment can mistake
Thinking that current to receive BD queue empty by mistake, do not have message etc. pending, Tail pointer the most also will not move further along;
2) follow-up message can trigger Target equipment and move the most forward Head pointer, until Head pointer catch up with Tail
Pointer, Target equipment will be considered that reception BD queue full, idle never again BD can receive message, move the most further along
Dynamic Head pointer;
3) Tail pointer Bd2 to be waited until becomes and effectively moves the most forward;And Head pointer Tail to be waited until refers to
Pin has moved forward and just can continue to message, and this has been put into a kind of blocked state: Head and Tail pointer all transfixions,
And follow-up message is all received to come up, all abandon.
As can be seen here, current BD queue operation mechanism is that the BD that cannot bear physical layer loses.
The maintaining method flow chart of the reception BD queue that Fig. 4 provides for the embodiment of the present invention, as shown in Figure 4, it specifically walks
Rapid as follows:
Step 401: when Target equipment receives a message, writes Head pointer sensing BD corresponding by message
Buffer, the information that described by message writes this BD, and Head pointer moves forward the next BD of sensing.
The state receiving BD queue is made snapshot by strategy by step 402:Target equipment, and is synchronized to by this state snapshot
Host equipment, this state snapshot comprises the real-time status of the BD received in BD queue: effective or invalid.
If a BD being written with message describe information, i.e. this BD correspondence Buffer is written with message, then the shape of this BD
State is " effectively ", and otherwise, the state of this BD is engineering noise.
In actual applications, state snapshot can represent by a bitmap, the corresponding BD of each bit in bitmap.Ratio
As, if one receives in BD queue and has 8 BD, then its state snapshot can represent with the bitmap of the 8 of 1 byte bit.
As: whole reception BD queue is empty, then its bitmap is exactly 0;Whole reception BD queue is full, then its bitmap is exactly 0xFF;Receive
Front 4 BD of BD queue are effective, then its bitmap is 0xF0.
Here, if it should be noted that reception BD queue is longer, then its state snapshot is also longer, such as: receive BD
Queue length is 1024, then its state snapshot bitmap need 128 bytes, so, if when each state snapshot changes, all incite somebody to action
State snapshot is synchronized to Host equipment, then can take more transfer resource.Therefore, can set reception in actual applications
The state of BD queue makees snapshot, and the strategy that this state snapshot is synchronized to Host equipment is as follows:
Strategy 1) state of whole reception BD queue is made snapshot by several times on Target device periodically ground and gradation is synchronized to
Host equipment, i.e. whole reception BD queue is divided into n(n > 1) individual unit, in order, the state to each unit successively
Make snapshot and be synchronized to Host equipment.
Such as: receiving BD queue length is 1024, is set to Bd0~1023, is then divided into 8 unit, each unit
A length of 128 bits, then for the first time only to first unit, i.e. the state of Bd0~Bd127 is made snapshot and is synchronized to Host and sets
Standby, second time is only to second unit, i.e. the state of Bd128~Bd255 is made snapshot and is synchronized to Host equipment, and the rest may be inferred,
Circulation is carried out.
Tactful 2) find that Tail pointer does not moves forward within preset number the clock cycle when Target equipment, and Head
When pointer is unequal with Tail pointer, start constantly disposably or by several times the state of whole reception BD queue to be made snapshot also
It is synchronized to Host equipment, until stopping when Tail pointer moves forward synchronizing.
In Head pointer catches up with Tail pointer, and preset number clock cycle, Tail pointer does not all move forward, and this says
Bright reception BD queue comes into congestion state.If Head pointer does not catch up with Tail pointer, or, although Head pointer chases after
Gone up Tail pointer, but Tail pointer is at continuous updating, then explanation reception BD queue does not occurs congested.
Target equipment interconnection is received the state of BD queue and is made snapshot, particularly as follows: by the BD's between Head and Tail pointer
State is both configured to " effectively ", and the state of other BD is both configured to engineering noise.
Step 403: when Host equipment receives the state snapshot that Target equipment is sent, performs step 404~410.
Step 404:Host equipment updates the state snapshot of the reception BD queue self preserved with this state snapshot.
Certainly, send for the first time if this state snapshot is target equipment, then Host equipment directly preserves.
Step 405:Host equipment, when to read data from Buffer, checks the BD that Tail pointer points to, and reading should
The Valid mark of BD, it is judged that this Valid identifies whether to indicate " effectively ", if so, performs step 410;Otherwise, step is performed
406。
Step 406:Host equipment judges whether contain this BD's in the state snapshot of the reception BD queue self preserved
State, if so, performs step 407;Otherwise, step 409 is performed.
Such as the above-mentioned explanation to step 402, taking transfer resource to reduce, Target equipment is possible will not be real-time
State snapshot is synchronized to Host equipment by ground, simultaneously when synchronous regime snapshot, it is also possible to will not be by the state of all BD all
Secondary property synchronizes.
Step 407:Host equipment judges that in state snapshot, whether the state of this BD is " effectively ", if so, performs step
408;Otherwise, step 409 is performed.
Step 408:Host equipment confirms that the real state of this BD is " effectively ", confirms the information dropout in this BD, then will
Tail pointer moves forward the next BD of sensing, and in the state snapshot preserve self, the state of this BD is updated to by " effectively "
Engineering noise, this flow process terminates.
Now, it is not necessary to redistribute Buffer for BD, the most corresponding original Buffer of this BD, for the sake of reliable, can
The reserved area of this Buffer is reset.
Step 409:Host equipment is not for further processing, and this flow process terminates.
If the Valid mark instruction engineering noise of BD, in state snapshot, the state of this BD is also engineering noise simultaneously, then Host sets
The standby state that can confirm that this BD is engineering noise really.
Step 410:Host equipment reads Buffer address from this BD, finds correspondence according to this Buffer address
Buffer, takes out message data from this Buffer and gives upper layer module and process, be then initial by the control Information recovering of BD
Value, and redistribute one piece of new Buffer for this BD, Tail pointer is moved to forward the next BD of sensing simultaneously, by state
In snapshot, the state of this BD is updated to engineering noise.
When Target equipment does not synchronizes the state of the BD that Tail pointer points to, Host equipment is according to existing method
Carry out processing.
The application example of the present invention given below:
Still as a example by Fig. 3, using the present invention, it is the most same that the state receiving BD queue can be made snapshot by strategy by Target equipment
Step is to Host equipment.
It is still assumed that Bd2 loses
Then: when Tail pointer points to Bd2, although the Valid mark instruction in Bd2 is invalid, but Host equipment can root
The state snapshot sent according to Target equipment, learns that Bd2 should be effective, thus the information in Bd2 of learning is in bus
On lose, therefore, Host equipment continues to move forward Tail pointer to Bd3.Thus will not be absorbed in blocked state.
The composition schematic diagram of the Target equipment that Fig. 5 provides for the embodiment of the present invention, as it is shown in figure 5, it specifically includes that report
Literary composition writing module 51 and state snapshot synchronization module 52, wherein:
Message writing module 51: when message being write Head pointer and pointing to Buffer corresponding for BD, message is described letter
Breath writes this BD, and Head pointer moves forward the next BD of sensing.
State snapshot synchronization module 52: by strategy, the state receiving BD queue is made snapshot, and this state snapshot is synchronized
To main frame Host equipment, this state snapshot comprises the real-time status of the BD received in BD queue: effective or invalid.
Wherein, the state receiving BD queue is made snapshot by strategy by state snapshot synchronization module 52, and by this state snapshot
It is synchronized to Host equipment include:
Periodically the state of whole reception BD queue disposably or is by several times made snapshot, and state snapshot is synchronized to
Host equipment;
Or, when Target equipment finds that Tail pointer does not moves forward within preset number the clock cycle, and Head
When pointer is unequal with Tail pointer, start constantly disposably or by several times the state of whole reception BD queue to be made snapshot,
And state snapshot is synchronized to Host equipment, until stop when Tail pointer moves forward synchronizing.
The composition schematic diagram of the Host equipment that Fig. 6 provides for the embodiment of the present invention, as shown in Figure 6, it specifically includes that state
Snapshot receives and preserves module 61 and message read module 62, wherein:
State snapshot receives and preserves module 61: receive the state snapshot of the reception BD queue that Target equipment is sent, this shape
State snapshot contains the real-time status of the BD received in BD queue: effective or invalid, updates self with this state snapshot and preserves
The state snapshot of reception BD queue.
Message read module 62: check the BD that Tail pointer points to, reads the Valid mark of this BD, if the instruction of this mark
Engineering noise, then receive from state snapshot and preserve the state reading this BD the state snapshot that module 61 preserves, if this state is for " to have
Effect ", then confirm that the real state of this BD is " effectively ", confirm the information dropout in this BD, Tail pointer is moved to forward finger
To next BD, state snapshot is received the state of this BD in the state snapshot that module 61 preserves that preserves and is updated to engineering noise;If
This state is engineering noise, then confirm the real engineering noise of this BD, be not for further processing.
Wherein, after message read module 62 reads the Valid mark of this BD, it is further used for, if the instruction of this mark " has
Effect ", then from this BD correspondence Buffer, take out message data give upper layer module process, Tail pointer is moved to forward simultaneously
Point to next BD, the state of this BD in state snapshot is updated to engineering noise.
From the embodiment of the present invention it can be seen that receive the real-time status of each BD BD queue by safeguarding so that Host
Equipment can learn whether BD loses, thus improves fault-tolerance and the reliability receiving BD queue.
The foregoing is only presently preferred embodiments of the present invention, not in order to limit the present invention, all essences in the present invention
Within god and principle, any modification, equivalent substitution and improvement etc. done, within should be included in the scope of protection of the invention.