This invention relates to a method and apparatus for aligning bytes in a block of data consisting of a plurality of words, each consisting of predetermined number of bytes of predetermined bit length. The invention finds particular, (but not exclusive use) in aligning bytes on a word boundary during a block data transfer, for example, at an interface between memory and peripheral devices in computer systems. The byte alignment method can also be used with advantage in translating the encapsulation of a protocol labelled data block, for example, in switching data from Ethernet to ATM.
Where network software performs protocol conversions, headers and trailers in the protocol labels can be modified and bytes can thereby become misaligned with a word boundary. This can slow up a data transfer. By way of example, in a computer system having a processor with a word size of 32 bits, a 32-bit wide memory and a 32-bit wide memory to network interface, (e.g. as in an ATM network where a basic transmission operation sends an ATM cell by writing thirteen 32-bit words to the interface), the transfer will be efficient when the data to be transmitted is aligned on a word boundary in memory. In this case, the processor initiates a data transfer and each word will be copied from memory to the network device. However, if the data is aligned with an arbitrary byte boundary, rather than a word boundary, transfer will be slower. The processor must then either copy and then re-align the data before starting the transfer operation, or it must construct and write the words individually to the network device.
The invention seeks to solve the foregoing problem. At least in a preferred embodiment, it may be considered as an enhancement to data transfer that enables a byte to be shifted in order to be aligned bytes with a word boundary prior to or during the transfer.
WO-A-94/07199 implements a two stage sort and requires the use of individual byte lane valid bits for operation. This results in the output word (32 bits) having possible invalid bytes within the stream. The intention is to allow arbitrary streams of DMA data to be re-aligned with minimal processor intervention. EP-A-94304589.8 incorporates byte alignment logic into a peripheral itself and the byte alignment logic is similar to the WO-A-94/07199 byte lane valid bits, but it also has individual mask bits supplied by some external control logic. U.S. Pat. No. 5,168,561 discloses byte alignment technique which uses a carrier register and a data selector with four 4:1 multiplexers.
Features of the invention are defined by the attached claims.
The invention can be embodied, in practice, so that:
This provides a rapid way to re-align multiple different streams of data all of which are on different boundaries.
The byte alignment method of the invention can be advantageously used in translating the encapsulation of a protocol labelled data block by the steps of:
In the latter method, the old trailer can also be removed and replaced with a new trailer whereby the byte alignment method is also used to determine any byte misalignment in the new trailer as well as in the new header. The new header, the original data block and the new trailer are then transferred (into storage) with any necessary byte shift in the data block to compensate for the byte misalignment.
The advantage of such method of translation is that there is no unnecessary copying of the data block.
The latter method can be incorporated in suitable apparatus having respective means for carrying out the steps of the method.
A preferred embodiment of the invention will now be described with reference to the accompanying drawings, in which:
It can be seen in
A further example of the mode of operation is given below (in which there is a one byte misalignment) in which misalignment bits 01 control the switching operation.
The diagrams show consecutive bytes in memory, with each column being the bytes of one word starting on a 32-bit address boundary.
Data starts at ‘address mod 4=1’:
The alignment register is then loaded with the values 1, 2 and 3 (the bytes before the first word boundary) and the offset value 1.
After transferring the second word the data looks like:
The byte alignment register of the invention is useful in handling network protocols in computer systems, and more particularly in the translation of the encapsulation of a protocol data block without unnecessary copying of the enclosed data.
Consider a computer system connected to one or more networks, and running protocol bridging or routing software. The computer system has a processor with a word size of 32 bits, 32-bit wide memory, and 32-bit wide Direct Memory Access (DMA) interfaces to its network ports.
Each bridging or routing operation involves:
Step 3 can account for a high proportion of the total processor time spent dealing with the packet. The format conversion may be necessary either because the source and destination networks are of different hardware types (e.g. Ethernet and ATM) or because they are different virtual networks on the same physical layer (e.g. IP on LANE Emulation and Classical IP, both running over ATM).
In general, a network packet (for example an Ethernet frame or an IP packet) consists of a protocol header, the data being transported, and a protocol trailer, laid out in memory as shown:
After the packet has passed through the bridge or router, it contains exactly the same data, but may have a new header and trailer (with changed sizes) corresponding to the new protocol encapsulation:
There are two main methods known in the prior art for arranging to transmit the reformatted packet:
The scatter/gather method is efficient, but cannot be used directly on a computer system which has memory and I/O organised as 32-bit words. Since the original packet was received starting on a word memory boundary, the data within it may not be on a word boundary. Also, the new header and trailer may not be an exact number of words in length. Thus the new packet cannot be transmitted directly via the 32-bit DMA interface to the network.
An embodiment of the invention allows the transmission to be handled efficient as follows. Assume the new header and trailer are constructed starting on word boundaries:
Further refinements are possible. For example, the New Header could be constructed so that it ended on an alignment complementary to that of the start of the Data, and the Trailer could be aligned to match the end of the Data. By copying the odd bytes from the start and end of the Data to the New Header and Trailer respectively, the whole transfer could be completed as 3 DMA operations with no intermediate adjustments of the residue register.
Number | Date | Country | Kind |
---|---|---|---|
GB 9724027.9 | Nov 1997 | GB | national |
Number | Date | Country | |
---|---|---|---|
Parent | 09529739 | Jun 2000 | US |
Child | 10772580 | Feb 2004 | US |