Patent Publication Number: US-8988951-B2

Title: Method and device for writing block data to an embedded DRAM free of address conflicts

Description:
CROSS-REFERENCE TO RELATED APPLICATIONS 
     This application claims priority to Chinese Patent Application No. 201110036954.4, filed on Feb. 12, 2011, which is hereby incorporated by reference in its entirety. 
     FIELD OF THE INVENTION 
     The embodiments of the present invention relate to data processing technologies, and in particular, to a method and a device for writing data. 
     BACKGROUND OF THE INVENTION 
     Packet buffer is one of dispensable key technologies in a modern communication device A main function of the packet buffer is to provide buffer for a data block. An Embedded Random Access Memory (Embedded Random Access Memory, referred to as EDRAM) is used to buffer a data packet, and an the EDRAM may be internally divided into a plurality of banks (Banks), which are configured to store a data block and a corresponding write-in address. Generally speaking, writing a data block in a bank needs one or more clock periods. When a data block is being written in a bank, another data block cannot be written in or read from the bank; and another data block can not be written in or read from the bank till the data block is successfully written in the bank. Similarly, reading a data block from a bank needs one or more clock periods (the clock period is in consistent with a clock period of writing a data block in a bank). When reading a data block from a bank, another data block cannot be read from or write in the bank; and another data block can not be read from or written in the bank till the data block is successfully read from the bank. 
     In the prior art, after a write-in request including a data block is received, a write-in address is selected at random, and then the data block is written in a bank corresponding to the selected write-in address. Selection of the write-in address is random, therefore, write-in addresses that are continuously selected may correspond to the same bank; or a bank corresponding to a selected write-in address that is currently reading another data block. Under this circumstance, a conflict may occur when a data block is written in a bank; or a conflict may occur when a data block is read from a bank, which results in the data blocks being unable to be written continuously, or data blocks being unable to be continuously read in a packet manner, so that working efficiency of the EDRAM is reduced. 
     SUMMARY OF THE INVENTION 
     Embodiments of the present invention provide a method and a device for writing data, so as to avoid problems in the prior art regarding the occurrence of a conflict when a data block is written in a bank and the occurrence of a conflict occurs when a data block is read from a bank. 
     A method for writing data provided in an embodiment of the present invention includes: 
     receiving a data block that is to be written in an EDRAM; 
     obtaining, according to a status of a bank in the EDRAM, usable addresses corresponding to usable banks in the EDRAM; 
     selecting an address from the usable addresses as a write-in address of the data block; and 
     writing the data block in a bank corresponding to the write-in address. 
     A device for writing data further provided in an embodiment of the present invention includes: 
     a data receiving module, configured to receive a data block that is to be written in an EDRAM; 
     an address obtaining module, configured to obtain, according to a status of a bank in the EDRAM, usable addresses corresponding to usable banks in the EDRAM; 
     an address selection module, configured to select an address from the usable addresses as a write-in address of the data block; and 
     a data write-in module, configured to write the data block in a bank that is corresponding to the write-in address. 
     In the embodiments of the present invention, a data block to be written in an EDRAM is received, according to a status of a bank in the EDRAM, usable addresses corresponding to usable banks in the EDRAM are obtained, and an address is selected from the usable addresses as a write-in address of the data block, so that the data block can be written in a bank corresponding to the selected write-in address. The bank corresponding to the selected write-in address is a usable bank, therefore, data blocks can be written continuously, and can be continuously read in a form of a data packet, so that the problems in the prior art that a conflict occurs when a data block is written in a bank and a conflict occurs when a data block is read from a bank can be avoided, and work efficiency of the EDRAM is improved. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
       To describe the technical solutions in the embodiments of the present invention or in the prior art more clearly, the accompanying drawings required for describing the embodiments or the prior art are introduced briefly in the following. A 
       The accompanying drawings in the following description are only some embodiments of the present invention, and persons of ordinary skill in the art may also derive other drawings from these accompanying drawings. 
         FIG. 1  is a schematic flow chart of a method for writing data according to a first embodiment of the present invention; 
         FIG. 2  is a schematic structural diagram of a device for writing data according to a second embodiment of the present invention; and 
         FIG. 3  is another schematic structural diagram of a device for writing data according to the second embodiment of the present invention. 
     
    
    
     DETAILED DESCRIPTION OF THE EMBODIMENTS 
     In order to make the objectives, technical solutions, and advantages of embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention are clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present invention. The embodiments in the following description are merely a part rather than all of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention. 
       FIG. 1  is a schematic flow chart of a method for writing data according to a first embodiment of the present invention. As shown in  FIG. 1 , the method for writing data in this embodiment may include the following steps: 
     Step  101 : Receive a data block that is to be written in an EDRAM. 
     Step  102 : Obtain, according to a status of a bank in the EDRAM, usable addresses corresponding to usable banks in the EDRAM. 
     Specifically, in this step, if data is not being written in nor read from a bank in the EDRAM, determine that the bank is a usable bank; and then obtain a usable address corresponding to the usable bank, so that working efficiency of the EDRAM can be improved. 
     Optionally, in this step, according to the number of stored data blocks in the usable banks, a bank where the number of stored data blocks is the smallest may be selected from the usable banks as a write-in bank of the data block; and a usable address corresponding to the write-in bank is obtained. In this way, it can be ensured that data blocks in each bank are even, so that a load balance of the EDRAM is achieved, and the work efficiency of the EDRAM is further improved. Specifically, a counter may be used to record the number of data blocks that are stored in each bank. If one data block is written in a bank, a 1 is added to a value of a counter corresponding to the bank. If one data block is read from a bank, a 1 is deducted from a value of a counter corresponding to the bank. 
     Step  103 : Select an address from the usable addresses as a write-in address of the data block. 
     Step  104 : Write the data block in a bank corresponding to the write-in address. 
     In this embodiment of the present invention, a data block to be written in an EDRAM is received, according to a status of a bank in the EDRAM, usable addresses corresponding to usable banks in the EDRAM are obtained, and an address is selected from the usable addresses as a write-in address of the data block, so that the data block can be written in a bank corresponding to the selected write-in address. The bank corresponding to the selected write-in address is a usable bank, therefore, data blocks can be written continuously, and can be continuously read in a form of a data packet, so that problems in the prior art that a conflict occurs when a data block is written in a bank and a conflict occurs when a data block is read from a bank can be avoided, and the work efficiency of the EDRAM is improved. 
     It may be understood by persons skilled in the art that in this embodiment, a write-in address in an address pool is actually divided into several address segments, where each address segment is respectively corresponding to a bank. When a data block is read from a bank, a write-in address corresponding to the data block is reclaimed. Specifically, the address may be reclaimed according to an address segment to which the write-in address belongs. Write-in addresses corresponding to the same bank are reclaimed to the same address segment, so that the write-in address can be selected and used again. 
     It should be noted that: the preceding method embodiments are described as a combination of a series of actions for simple description. Persons skilled in the art may be informed that the present invention is not limited by a sequence of the described actions. In the present invention, some steps may be implemented in another sequence or be implemented at the same time. In addition, persons skilled in the art will also understand that, the embodiments described in the specification are all exemplary embodiments, where actions and modules involved are not necessarily essential to the present invention. 
     In the preceding description, each embodiment is described with a particular emphasis, and for a part that is not described in one embodiment, reference may be made to a relevant description of another embodiment. 
       FIG. 2  is a schematic structural diagram of a device for writing data according to a second embodiment of the present invention. As shown in  FIG. 2 , a device for writing data provided in this embodiment may include a data receiving module  21 , an address obtaining module  22 , an address selection module  23  and a data write-in module  24 . The data receiving module  21  is configured to receive a data block that is to be written in an EDRAM. The address obtaining module  22  is configured to obtain, according to a status of a bank in the EDRAM, usable addresses corresponding to usable banks in the EDRAM. The address selection module  23  is configured to select, from the usable addresses obtained by the address obtaining module  22 , an address as a write-in address of the data block. The data write-in module  24  is configured to write the data block in a bank that corresponds to the write-in address selected by the address selection module  23 . 
     The method provided in the first embodiment of the present application may be implemented by the device for writing data provided in this embodiment of the present application. 
     In this embodiment, after the data receiving module receives a data block that is to be written in an EDRAM, the address obtaining module obtains, according to a status of a bank in the EDRAM, usable addresses corresponding to usable banks in the EDRAM. Then, the address selection module may select, from the usable addresses obtained by the address obtaining module, an address as a write-in address of the data block, so that the data write-in module can write the data block in a bank that corresponds to the write-in address selected by the address selection module. The bank corresponding to the write-in address that is selected by the address selection module is a usable bank, therefore, data blocks can be written continuously, and can be continuously read in a form of a data packet. Thus, the problems in the prior art that a conflict occurs when a data block is written in a bank and a conflict occurs when a data block is read from a bank can be avoided, and work efficiency of the EDRAM is improved. 
     Moreover, as shown in  FIG. 3 , the address obtaining module  22  in this embodiment of the present application may include a determining unit  221  and an obtaining unit  222 . The determining unit  221  is configured to, if data is not being written in nor read from a bank in an EDRAM, determine that the bank is a usable bank. The obtaining unit  222  is configured to obtain a usable address corresponding to the usable bank. Specifically, the obtaining unit  222  may select a bank where the number of stored data blocks is the smallest as a write-in bank of the data block; and then obtain a usable address corresponding to the write-in bank. In this way, it can be ensured that data blocks in each bank are even, so that a load balance of the EDRAM is achieved, and the work efficiency of the EDRAM is further improved. 
     Persons of ordinary skill in the art may understand that all or a part of the steps of the preceding method embodiments may be implemented by a program instructing relevant hardware. The program may be stored in a computer readable storage medium. When the program runs, the steps of the preceding method embodiments are performed. The storage medium may include any medium that is capable of storing program codes, such as an ROM, an RAM, a magnetic disk, or a compact disk. 
     Finally, it should be noted that the preceding embodiments are merely used for describing the technical solutions of the present invention, but are not intended to limit the present invention. It should be understood by persons of ordinary skill in the art that although the present invention has been described in detail with reference to the preceding embodiments, modifications may still be made to the technical solution described in each preceding embodiment, or equivalent replacements may be made to some technical features in the technical solutions, however, such modifications or replacements will not make the essence of the corresponding technical solutions depart from the spirit and scope of the technical solutions in the embodiments of the present invention.