Background technology
SATA(Serial Advanced Technology Attachment) being a kind of high-speed serial bus, is one of disk interface agreement of widespread use.It is fast that SATA has transmission speed, supports hot plug, carries out advantages such as efficient height.SATA adopts point-to-point mode to connect, and an end is called SATA controller (SATA Host), and the other end is called SATA equipment (SATA Device).The SATA controller has two kinds of patterns: IDE pattern and AHCI pattern.That commonly used is AHCI(Advanced Host Controller Interface now) pattern, data transfer mode efficiently can be provided, support the formation of NCQ(native command, Native Comand Quening) technology, Auto Activate for DMA(DMA self-activation) technology or the like.
The AHCI pattern of SATA controller, to the monolithic disk read-write, and the polylith disk read-write provides data transfer mode efficiently.Nowadays, in storage system, often need as a whole parallel use is done in the binding of polylith disk, (for example: RAID) obtain higher disk access speed.In the prior art, by software with the disk of polylith binding as a virtual disk.Mainly be operating as read and write for virtual disk: for example a data block writes virtual disk, data block need be divided into a plurality of little data blocks and give corresponding SATA controller respectively and write physical disk.Need to carry out data in the process and split,, need carry out the data assembling equally for reading virtual disk.
But because single SATA controller only is responsible for single disk access, not contact between a plurality of disks is so traditional SATA controller can't be finished fractionation and assembling to data.Like this, the fractionation of data can only be finished by software with assembling, needs extra metadata cache, repeatedly memory copying.Increase the complexity of data processing in this process, consumed a large amount of software and hardware resources, certainly will influence overall performance.
Summary of the invention
The objective of the invention is at the described the deficiencies in the prior art of background technology, invent a kind of based on SATA control, the method that the data block of the virtual disk (RAID system) that can be bound into the polylith disk splits, assembles is in the hope of improving the overall performance of storage system.
Use the SATA controller of the inventive method, contain Physical layer, link layer, transport layer, wherein, transport layer is connected with system bus, adopts the AHCI pattern, specifically comprises following module composition:
Link layer interface module, bus interface module, read dma module, write dma module, register, port controlling module, fault processing module.
The inventive method comprises the fractionation of write data and assembling two parts of read data:
At first set three variablees:
1. sign binding disk number is remembered and is made disk_num;
2. data block splits and the base unit of assembling, and note is made block_size;
3. start offset is remembered and is made offset;
Based on above-mentioned setting, the method for splitting of writing in the data in magnetic disk piece process is:
The port controlling module is read from internal memory and is write disk associative operation descriptor and write register module, comprises above-mentioned three variablees in the descriptor; Write dma module and from register, take out data start address (data_base_addr) and above-mentioned three variablees.Read dma module and begin peek from the data block start address of internal memory and (data_base_addr+offset) position of start offset sum, peek length is that data block splits and the base unit of assembling (block_size), peeks successively from memory address by a sequence rules then.This rule is: the address of at every turn peeking is that the product (data_base_addr+offset+ (disk_num * block_size)) of binding disk number and base unit is added in the address of peeking last time, peek length is constant, exceeds current write operation end addresses scope up to the peek address.
Read the data chunk process of assembling of disk:
The port controlling module is read disk associative operation descriptor and is write register module from internal memory, comprise above-mentioned three variablees in the descriptor.Read dma module and from register, take out data start address and three variablees, from disk, read the data that length is base unit (block_size), the data_base_addr+offset position of write memory, for the second time the reading of data write memory data_base_addr+offset+ (position of disk_num * block_size).Successively backward, each write memory address for last time the address add disk_num * block_size, length is constant, exceeds current read operation end addresses scope up to the address.
Preferred default data piece splits and the base unit of assembling is 512 bytes.
The invention has the beneficial effects as follows: realization SATA controller is finished simultaneously when reading and writing data data block is split and assembling, is applied to many disk storage systems such as RAID, can improve overall performance.
Embodiment
As Fig. 1, the present invention is based on the SATA controller, and this SATA controller transport layer is made up of following module:
Ll_if: the link layer interface module, be responsible for data transmit-receive with link layer.
Bus_if: bus interface module, be responsible for the visit of transport layer to bus.
Rd_dma: read dma module, be responsible for reading of data write memory from disk.
Wr_dma: write dma module, be responsible for that reading of data writes disk from internal memory.
Reg_file: register, deposit control register information and status information.
Port_ctrl: the port controlling module, be responsible for sata port control and monitoring.
Err_ctrl: the fault processing module, be responsible for error reporting and processing.
As Fig. 2, forming the RAID system with 4 disks is example, disk disk 0, disk1, disk2, the disk3 binding, become virtual disk virtual disk, each disk has a data block data to write to a SATA controller control should be arranged in the internal memory, this data block is by d0, d1, d2 ... several small data pieces constitute, and reference position is data_base_
addr。Below with the process of a read-write of this condition stub with clearer elaboration the present invention.
At first set variable: 1. sign is bound disk number disk_num; 2. identification data block splits and the base unit block_size that assembles, and present embodiment is given tacit consent to 512 bytes, a sector size; 3. identify start offset offset.
The process that writes:
The SATA controller of disk0 begins peek from the reference position (data_base_addr) of data in EMS memory piece data, gets 512 bytes (block_size) length small data piece d0 is write disk0.(disk_num * block_size), d4 writes disk with the small data piece, and (disk_num * block_size), d8 writes disk with the small data piece to skip 4 512 bytes once more to skip 4 512 bytes then.Successively up to the end of data block data.
The SATA controller of disk1 is skipped 1 512 byte (data_base_addr+offset+ (disk_num * block_size)) from the reference position (data_base_addr) of data in EMS memory piece data and is begun peek, gets 512 bytes (block_size) length small data piece d1 is write disk1.(disk_num * block_size), d5 writes disk with the small data piece, and (disk_num * block_size), d9 writes disk with the small data piece to skip 4 512 bytes once more to skip 4 512 bytes then.Successively up to the end of data block data.
The SATA controller of disk2 is skipped 2 512 bytes (data_base_addr+offset+ (disk_num * block_size)) from the reference position of data in EMS memory piece data and is begun peek, gets 512 byte lengths small data piece d2 is write disk2.Skip 4 512 bytes then, d6 writes disk with the small data piece, skips 4 512 bytes once more, and d10 writes disk with the small data piece.Successively up to the end of data block data.
The SATA controller of disk3 is skipped 3 512 bytes from the reference position of data in EMS memory piece data and is begun peek, gets 512 byte lengths small data piece d3 is write disk3.Skip 4 512 bytes then, d7 writes disk with the small data piece, skips 4 512 bytes once more, and d11 writes disk with the small data piece.Successively up to the end of data block data.
4 SATA controllers are finished when writing disk, and what every disk was written into respectively is a bit of of data block data, and also just having finished with 512 bytes is the data fractionation work of unit.
If read the virtual disk operation:
The SATA controller of disk0 sense data piece d0 from disk is placed on the space reference position (data_base_addr) of distributing for data block data in the internal memory, from disk, get the initial position of skipping 4 512 bytes of 512 byte data piece d4 write memory allocation space (disk_num * block_size) again, and then take out 512 byte data piece d8 write memories from disk, successively up to the end of data block data.
The SATA controller of disk1 sense data piece d1 from disk is placed on the initial position of distributing for data block data in the internal memory (data_base_addr+offset) that adds 1 512 byte offset, space, from disk, get 512 bytes (block_size) data block d5 write memory again and skip 4 512 bytes (position of disk_num * block_size) again, and then take out 512 byte data piece d9 write memories from disk, successively up to the end of data block data.
The SATA controller of disk2 sense data piece d2 from disk is placed on the initial position of distributing for data block data in the internal memory that adds 2 512 byte offset, space, from disk, get the position that 512 byte data piece d6 write memories are skipped 4 512 bytes more again, and then take out 512 byte data piece d10 write memories from disk, successively up to the end of data block data.
The SATA controller of disk3 sense data piece d3 from disk is placed on the initial position of distributing for data block data in the internal memory that adds 3 512 byte offset, space, from disk, get the position that 512 byte data piece d7 write memories are skipped 4 512 bytes more again, and then take out 512 byte data piece d11 write memories from disk, successively up to the end of data block data.
4 SATA controllers finish read disk in, also finished assembling to data block data.
Shown in Figure 3 forms virtual disk by 4 disks, the embodiment of another one check disk.
According to the present invention, it is as follows to set variable:
SATA controller 0:
disk_num?=?4;
block_size?=?0x200;
offset?=?0x000;
SATA controller 1:
disk_num?=?3;
block_size?=?0x200;
offset?=?0x200;
SATA controller 2:
disk_num?=?3;
block_size?=?0x200;
offset?=?0x400;
SATA controller 3:
disk_num?=?3;
block_size?=?1;
offset?=?0x600;
SATA controller 4:
num?=?0;
block?=?1;
offset?=?0x0。
The DMA of SATA controller 4 takes out checking data from P_buf, write disk.
According to the method for the invention, the SATA controller carries out data and splits when writing disk.RAID controller calculation check value P writes disk synchronously.Whole reading and writing method and embodiment one are similar, repeat no more.