Background technology
As CPU(Central Processing Unit, CPU) by PCI(Peripheral Component Interconnect, periphery component interconnection) or PCIE(Peripheral Component Interconnect Express, quick periphery component interconnection) etc. when bus is connected with business interface, generally all adopting BD(Buffer Descriptor, buffer memory descriptor) transmitting-receiving that realizes message of the mode of queue processes.The main contents of BD are as shown in table 1, and each BD points to a Buffer(buffer memory), this Buffer is for buffer memory message data, and BD itself is comprising the descriptor to this message, as shown in table 1, in BD, mainly comprises:
Valid(is effective) sign: in indication Buffer, whether comprise effective message data;
SOP(Start of Packet, packet header)/EOP(End of Packet, bag tail): whether the message data in indication Buffer packet header or bag tail;
CMD(Command, order)/Status(state): whether the message data of indication in Buffer be wrong etc.;
Message length: represent the message data length in Buffer;
Buffer address: represent the Buffer address that this BD points to.
Valid sign |
SOP/EOP sign |
CMD/Status indication |
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 receives BD and points to a Buffer who has allocated internal memory in advance;
Target(target) plant maintenance Head(head) pointer, Head pointer always points to first BD for preparing to receive message; When Target equipment is received a message, message data is write to Buffer corresponding to Head pointed BD, message descriptor is write to the BD of Head pointed, then Head pointer is moved to forward and point to next BD;
Host(main frame) plant maintenance Tail(tail) pointer, Tail pointer always points to first BD that has received message, according to the information in this BD, from corresponding Buffer, taking out message processes, then the control information of BD is reverted to initial value, and for this BD redistributes a new Buffer, Tail pointer is moved to forward simultaneously and point to next BD.Wherein, the control information of BD mainly refers to: Valid sign, SOP/EOP sign, CMD/Status indication and message length.
In actual applications, Target equipment is the board in distributed system for example, and Host equipment is the CPU in distributed system for example.
From the operation mechanism of the queue of BD shown in Fig. 1, can find out: between the BD of reception BD queue and BD, exist a kind of ordinal relation: only handle current BD and could process next BD, and exist synchronized relation one to one between BD and message.
Fig. 2 has provided existing Target equipment to the schematic diagram of Host equipment transmission data, as shown in Figure 2, when Target equipment is received message to Host device transmission, transmission sequence is such: Target equipment first writes first message to a Buffer of Host equipment, then to BD corresponding to this buffer, write the descriptor of first message, next Buffer to Host equipment writes second message again, then to BD corresponding to this Buffer, write the descriptor of second message, the rest may be inferred.
Summary of the invention
The invention provides BD queue maintaining method and the equipment of receiving, to improve the fault-tolerance that receives BD queue.
Technical scheme of the present invention is achieved in that
A reception buffer memory descriptor BD queue maintaining method, the method comprises:
When target Target equipment is during by buffer memory Buffer corresponding to message write head Head pointed BD, message descriptor is write to this BD, Head pointer is moved to forward and points to next BD;
Target equipment is made snapshot by strategy to receiving the state of BD queue, and this state snapshot is synchronized to main frame Host equipment, and this state snapshot comprises the real-time status that receives the BD in BD queue: effective or invalid.
Described Target equipment further comprises after this state snapshot is synchronized to Host equipment:
Host equipment is checked the BD of tail Tail pointed, read effective Valid sign of this BD, if this sign indication engineering noise, from state snapshot, read the state of this BD, if this state is " effectively ", confirm that the real state of this BD is " effectively ", confirm the information dropout in this BD, Tail pointer is moved to forward and points to next BD, the state of this BD in state snapshot is updated to engineering noise by " effectively "; If this state is engineering noise, confirm the real engineering noise of this BD, be not for further processing.
The Valid sign that described Host equipment reads this BD further comprises afterwards:
If this Valid sign indication " effectively " is taken out message data and is given upper layer module processing from the corresponding Buffer of this BD, Tail pointer is moved to forward simultaneously and point to next BD, the state of this BD in state snapshot is updated to engineering noise.
Described Target equipment is made snapshot by strategy to receiving the state of BD queue, and this state snapshot is synchronized to Host equipment comprises:
Target equipment periodic ground to the state of whole reception BD queue once or gradation make snapshot, and state snapshot is synchronized to Host equipment;
Or, when Target device discovery preset number in the clock cycle Tail pointer do not move forward, and when Head pointer and Tail pointer are unequal, start constantly to the state of whole reception BD queue once or gradation make snapshot, and state snapshot is synchronized to Host equipment, until that Tail pointer stops while moving is forward synchronous.
A reception buffer memory descriptor BD queue maintaining method, the method comprises:
Main frame Host equipment is checked the BD of tail Tail pointed, read effective Valid sign of this BD, if this sign indication engineering noise, from the state snapshot of reception BD queue, read the state of this BD, if this state is " effectively ", confirm that the real state of this BD is " effectively ", confirm the information dropout in this BD, Tail pointer is moved to forward and points to next BD, the state of this BD in state snapshot is updated to engineering noise by " effectively "; If this state is engineering noise, confirm the real engineering noise of this BD, be not for further processing;
Wherein, described state snapshot is synchronously from Target equipment and comprised the real-time status that receives the BD in BD queue: effective or invalid.
Described Host equipment further comprises after reading the Valid sign of this BD:
If this sign indication " effectively " is taken out message data and is given upper layer module processing from the corresponding Buffer of this BD, Tail pointer is moved to forward simultaneously and point to next BD, the state of this BD in state snapshot is updated to engineering noise.
A target Target equipment, this equipment comprises:
Message writing module: when by buffer memory Buffer corresponding to message write head Head pointed buffer memory descriptor BD, message descriptor is write to this BD, Head pointer is moved to forward and points to next BD;
State snapshot synchronization module: make snapshot by strategy to receiving the state of BD queue, and this state snapshot is synchronized to main frame Host equipment, this state snapshot comprises the real-time status that receives the BD in BD queue: effective or invalid.
Described state snapshot synchronization module is made snapshot by strategy to receiving the state of BD queue, and this state snapshot is synchronized to Host equipment comprises:
Periodically to the state of whole reception BD queue once or gradation make snapshot, and state snapshot is synchronized to Host equipment;
Or, when Target device discovery preset number in the clock cycle Tail pointer do not move forward, and when Head pointer and Tail pointer are unequal, start constantly to the state of whole reception BD queue once or gradation make snapshot, and state snapshot is synchronized to Host equipment, until that Tail pointer stops while moving is forward synchronous.
A main frame Host equipment, this equipment comprises:
State snapshot receives preserves module: the state snapshot of the reception buffer memory descriptor BD queue that receiving target Target equipment is sent, this state snapshot has comprised the real-time status that receives the BD in BD queue: effective or invalid, and the state snapshot of the reception BD queue of preserving with this state snapshot update self;
Message read module: the BD that checks tail Tail pointed, read effective Valid sign of this BD, if this sign indication engineering noise, from state snapshot, receive the state that reads this BD the state snapshot of preserving module preservation, if this state is " effectively ", the real state of confirming this BD is " effectively ", confirm the information dropout in this BD, Tail pointer is moved to forward and points to next BD, and the state that state snapshot is received to this BD in the state snapshot of preserving module preservation is updated to engineering noise; If this state is engineering noise, confirm the real engineering noise of this BD, be not for further processing.
The Valid sign that described message read module reads this BD is further used for afterwards, if this sign indication " effectively ", from the corresponding buffer memory Buffer of this BD, take out message data and give upper layer module processing, Tail pointer is moved to forward simultaneously and point to next BD, and the state that state snapshot is received to this BD in the state snapshot of preserving module preservation is updated to engineering noise.
Visible, the present invention can improve the fault-tolerance that receives BD queue.
Embodiment
Below in conjunction with drawings and the specific embodiments, the present invention is further described in more detail.
Existing BD queue operation mechanism is analyzed to discovery: if the transfer of data on physical bus is not lost completely, can guarantee that so the transmission of message, reception & disposal normally carry out all the time.But in actual use scenes, any data/address bus all can not guarantee that the data of transmitting in bus do not lose completely, especially when physical data bus connects topological more complicated, all the more so when hardware signal environment is more severe, very likely because the deteriorated loss that causes data message of moment of physical signalling.The transfer of data of current various high-speed buses is generally all based on message or data block rather than based on byte stream, and a bus operation completes the transmission of a blocks of data, so the loss of data is also the loss of a complete message or data block.
If physical bus hardware signal is deteriorated suddenly sometime, may cause the BD that certain message is corresponding to lose when bus transfer, and this loss can not put up with for current BD queue mechanism.As shown in Figure 3, suppose that Target equipment is by physical bus during to Host equipment transmission data, Bd2 has lost:
1) when initial, the Tail pointed Bd1 of Host plant maintenance; Valid sign indication in Host device discovery Bd1 effectively, is taken out message and is given upper layer module processing, and move Tail pointed Bd2 from corresponding Buffer according to Bd1; Because the information of Bd2 has been lost in bus, but Host device-aware less than, thereby Host equipment thinks that according to the Valid sign in Bd2 Bd2 is invalid, it is all invalid implying the later Bd3 of Bd2, Bd4 etc. simultaneously, so, Host equipment can think that current reception BD queue is empty mistakenly, does not have message etc. pending, and therefore Tail pointer also can not move forward again;
2) follow-up message can trigger Target equipment and continues to move forward Head pointer, until Head pointer catch up with Tail pointer, Target equipment can think and receive BD queue full, and idle never again BD can receive message, therefore also moves no longer forward Head pointer;
3) Tail pointer will be waited until that Bd2 becomes effectively always and just moves forward; And Head pointer will be waited until that Tail pointer has moved forward and could continue to receive message always, this has just entered all transfixions of a kind of blocked state: Head and Tail pointer, and follow-up message is all received to be come up, and has all abandoned.
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, its concrete steps are as follows:
Step 401: when Target equipment receives a message, message is write to Buffer corresponding to Head pointed BD, message descriptor is write to this BD, Head pointer is moved to forward and points to next BD.
Step 402:Target equipment is made snapshot by strategy to receiving the state of BD queue, and this state snapshot is synchronized to Host equipment, and this state snapshot comprises the real-time status that receives the BD in BD queue: effective or invalid.
If write message descriptor in a BD, in the corresponding Buffer of this BD, write message, the state of this BD is " effectively ", 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.Such as, if one receives in BD queue and has 8 BD, its state snapshot can represent with the bitmap of 8 bits of 1 byte.As: whole reception BD queue is empty, and its bitmap is exactly 0; Whole reception BD queue is for full, and its bitmap is exactly 0xFF; Front 4 BD that receive BD queue are effective, and its bitmap is 0xF0.
Here, it should be noted that, if it is longer to receive BD queue, its state snapshot is also long, and for example: receiving BD queue length is 1024, its state snapshot bitmap needs 128 bytes, like this, if when every next state snapshot changes, all state snapshot is synchronized to Host equipment, can takies more transfer resource.Therefore, can set in actual applications and make snapshot to receiving the state of BD queue, and the strategy that this state snapshot is synchronized to Host equipment is as follows:
Strategy 1) snapshot is made to the state gradation of whole reception BD queue and gradation is synchronized to Host equipment in Target equipment periodic ground,, whole reception BD queue is divided into n(n>1) individual unit, in order, successively the state of each unit is made snapshot and is synchronized to Host equipment.
For example: receiving BD queue length is 1024, be made as Bd0~1023, be divided into 8 unit, the length of each unit is 128 bits, and, for the first time only to first unit, the state of Bd0~Bd127 is made snapshot and is synchronized to Host equipment, for the second time only to second unit, the state that is Bd128~Bd255 is made snapshot and is synchronized to Host equipment, and the rest may be inferred, loops.
Strategy 2) when Target device discovery preset number in the clock cycle Tail pointer do not move forward, and when Head pointer and Tail pointer are unequal, start constantly to the state of whole reception BD queue once or gradation make snapshot and be synchronized to Host equipment, until that Tail pointer stops while moving is forward synchronous.
Head pointer is caught up with Tail pointer, and in the preset number clock cycle, Tail pointer does not all move forward, and this explanation receives BD queue and entered congestion state.If Head pointer does not catch up with Tail pointer, or although Head pointer has caught up with Tail pointer, Tail pointer is at continuous updating, and explanation reception BD queue does not occur congested.
Target equipment interconnection is received the state of BD queue and is made snapshot, is specially: the state of the BD between Head and Tail pointer is all set to " effectively ", the state of other BD is all set to engineering noise.
Step 403: when Host equipment receives the state snapshot that Target equipment sends, execution step 404~410.
The state snapshot of the reception BD queue that step 404:Host equipment is preserved with this state snapshot update self.
Certainly, if this state snapshot is target equipment, send for the first time, Host equipment is directly preserved.
Step 405:Host equipment, will be from Buffer during reading out data, be checked the BD of Tail pointed, reads the Valid sign of this BD, judges that whether this Valid sign indicates " effectively ", if so, performs step 410; Otherwise, execution step 406.
Step 406:Host equipment judges the state that whether has comprised this BD in the state snapshot of the reception BD queue of self preserving, and if so, performs step 407; Otherwise, execution step 409.
As the above-mentioned explanation to step 402, in order to reduce the taking of transfer resource, Target equipment may not can be synchronized to Host equipment by state snapshot in real time, simultaneously when synchronous regime snapshot, also may not can that the state of all BD is all disposable synchronous.
Step 407:Host equipment judges whether the state of this BD in state snapshot is " effectively ", if so, performs step 408; Otherwise, execution step 409.
Step 408:Host equipment confirms that the real state of this BD is " effectively ", confirm the information dropout in this BD, Tail pointer is moved to forward and point to next BD, in the state snapshot that self is preserved, the state of this BD is updated to engineering noise by " effectively ", and this flow process finishes.
Now, without for BD redistributes Buffer, this BD is corresponding original Buffer still, for the purpose of reliable, and can be by the reserved area zero clearing of this Buffer.
Step 409:Host equipment is not for further processing, and this flow process finishes.
If the Valid of BD sign indication engineering noise, in state snapshot, the state of this BD is also engineering noise simultaneously, and Host equipment can confirm that the state of this BD is engineering noise really.
Step 410:Host equipment reads Buffer address from this BD, according to this Buffer address, find corresponding Buffer, from this Buffer, take out message data and give upper layer module processing, then the control information of BD is reverted to initial value, and redistribute a new Buffer for this BD, Tail pointer is moved to forward simultaneously and point to next BD, the state of this BD in state snapshot is updated to engineering noise.
When Target equipment is not synchronously come the state of BD of Tail pointed, Host equipment is processed according to existing method.
Below provide application example of the present invention:
Still take Fig. 3 as example, adopt the present invention, Target equipment can be made snapshot and be synchronized to Host equipment receiving the state of BD queue by strategy.
Still suppose that Bd2 loses
: when Tail pointed Bd2, although the Valid sign indication in Bd2 is invalid, but the state snapshot that Host equipment can send according to Target equipment, learn that Bd2 should be effective, thereby the information in Bd2 of learning is lost in bus, therefore, Host equipment continues to move forward Tail pointer to Bd3.So just blocked state can be absorbed in.
The composition schematic diagram of the Target equipment that Fig. 5 provides for the embodiment of the present invention, as shown in Figure 5, it mainly comprises: message writing module 51 and state snapshot synchronization module 52, wherein:
Message writing module 51: when message being write to Buffer corresponding to Head pointed BD, message descriptor is write to this BD, Head pointer is moved to forward and points to next BD.
State snapshot synchronization module 52: make snapshot by strategy to receiving the state of BD queue, and this state snapshot is synchronized to main frame Host equipment, this state snapshot comprises the real-time status that receives the BD in BD queue: effective or invalid.
Wherein, state snapshot synchronization module 52 is made snapshot by strategy to receiving the state of BD queue, and this state snapshot is synchronized to Host equipment comprises:
Periodically to the state of whole reception BD queue once or gradation make snapshot, and state snapshot is synchronized to Host equipment;
Or, when Target device discovery preset number in the clock cycle Tail pointer do not move forward, and when Head pointer and Tail pointer are unequal, start constantly to the state of whole reception BD queue once or gradation make snapshot, and state snapshot is synchronized to Host equipment, until that Tail pointer stops while moving is forward synchronous.
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 mainly comprises: state snapshot receives preserves module 61 and message read module 62, wherein:
State snapshot receives preserves module 61: the state snapshot of the reception BD queue that reception Target equipment is sent, this state snapshot has comprised the real-time status that receives the BD in BD queue: effective or invalid, and the state snapshot of the reception BD queue of preserving with this state snapshot update self.
Message read module 62: the BD that checks Tail pointed, read the Valid sign of this BD, if this sign indication engineering noise, from state snapshot, receive the state that reads this BD the state snapshot of preserving module 61 preservations, if this state is " effectively ", the real state of confirming this BD is " effectively ", confirm the information dropout in this BD, Tail pointer is moved to forward and points to next BD, and the state that state snapshot is received to this BD in the state snapshot of preserving module 61 preservations is updated to engineering noise; If this state is engineering noise, confirm the real engineering noise of this BD, be not for further processing.
Wherein, after message read module 62 reads the Valid sign of this BD, be further used for, if this sign indication " effectively ", from the corresponding Buffer of this BD, take out message data and give upper layer module processing, Tail pointer is moved to forward simultaneously and point to next BD, the state of this BD in state snapshot is updated to engineering noise.
From the embodiment of the present invention, can find out: by maintenance, receive the real-time status of each BD BD queue, make Host equipment can learn whether BD loses, thereby improved fault-tolerance and the reliability that receives BD queue.
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 modification of making, be equal to replacement, improvement etc., within all should being included in the scope of protection of the invention.