Tagged Command Queuing
From Wikipedia, the free encyclopedia
-
TCQ redirects here; it is also the IATA code for the Crnl. FAP Carlos Ciriani Santa Rosa International Airport in Tacna, Peru.
TCQ stands for the Tagged Command Queuing technology built into certain PATA and SCSI hard drives. It allows the operating system to send multiple read and write requests to a hard drive. TCQ is not identical in function to the more efficient Native Command Queuing (NCQ) used by SATAII drives.
Before TCQ, an operating system was only able to send one request at a time. In order to boost performance, it had to decide the order of the requests based on its own, possibly incorrect, idea of what the hard drive was doing. With TCQ, the drive can make its own decisions about how to order the requests (and in turn relieve the operating system from having to do so). The result is that TCQ can improve the overall performance of a hard drive.
[edit] Overview
Typically, sectors nearest the current location of the drive's read/write head are serviced first. The second-nearest location is serviced second, and so on. The queue is constantly being added to and re-ordered based upon new incoming read/write requests and the new position of the read/write head following the last read/write operation. The reordering algorithm is drive-dependent, and may vary from drive to drive. However, the host computer does not need to know what the algorithm is, or how it works.
This queuing mechanism is also sometimes referred to as "elevator seeking", as the image of the metaphorical elevator with a very limited maximum speed, trying to service multiple requests without excessive amounts of going up and down explains the idea rather well.
For example, assume an elevator is servicing a building with five floors, with the elevator currently residing on the bottom floor. Suppose tenants on the second, fourth, and fifth floors push the elevator call button to leave the building, but in the following order: 5-2-4. If the elevator serviced these requests in the order they were received, it would go to the top floor, then back down to the second floor, then back up to the fourth floor, and then finally back to the first floor to deliver the passengers. This is clearly very inefficient, because floors with waiting passengers are bypassed on the way to other floors. Furthermore, the elevator travels much further overall, increasing wear and tear. Modern elevators will realize this and re-order the service queue to a more efficient order such as 5-4-2.
[edit] Comparison of TCQ and NCQ
The principal idea of both TCQ and NCQ is exactly the same, although the two have differing implementations. NCQ is designed with consumers in mind, while TCQ is suited for complicated data storage systems.
Tagged Command Queuing has been available in SCSI drives since mid-1990s, when it was added to the SCSI-2 standard. Command queuing was also included in the ATA-4 standard several years later (under the name TCQ as well). Unlike with SCSI, it failed to get widely adopted into ATA drives.
It is worth noting that TCQ supports a deeper queue than NCQ. TCQ supports as many as 216 queued commands (although it is typical for a drive to only support 64), while NCQ only supports as many as 32. Depending on the drive access pattern, the difference in queue length may not make a great difference in practice.
Tagged Command Queuing also allows a more flexible tagging mechanism than Native Command Queuing. Both NCQ and TCQ support simple tags, which allow the drive to execute command in any order it chooses. The word "native" in the name of NCQ refers exactly to how it is completely up to the individual hard disk to decide the optimal order, all requests being of equal importance. But TCQ supports two other modes in addition to simple tags: The initiator can specify that commands be executed in the order sent by the initiator, or the initiator can send a high-priority command to the head of the queue.
TCQ can cause performance drop in lightly queued workloads where the benefit of queuing is outweighed by the significant overhead of the protocol. NCQ addresses that and some other shortcomings of ATA TCQ.
TCQ protocol requires a handshake between the host and the device for each and every command completion. To complete a command in TCQ, the host actually has to issue a new command, called Service, to the device to determine the command to complete. There is no mechanism in TCQ to complete multiple commands at the same time without host intervention. This overhead adds a significant amount of latency to the TCQ. NCQ on the other hand, has a status return mechanism, working without host handshakes. The drive may issue command completions for multiple commands even at the same time.
TCQ has two interrupts for every command. There is no means to combine these interrupts because each step in the TCQ protocol requires a host handshake. There is one interrupt for setting up the DMA engine for a data transfer and another interrupt for completing the command. NCQ has a maximum of one interrupt per command. The number of interrupts per command is often less than one when interrupts are combined. Interrupts may be combined by the drive if it completes multiple commands at the same time. That means that NCQ has a low interrupt overhead compared to TCQ.
TCQ specifies that the drive causes an interrupt when it is ready to transfer data. The host processes the interrupt and determines that the SERV bit is set in the Status register. This means that the drive is ready to proceed with the data transfer for a particular command. Next the host must issue the Service command to the device to determine the tag of the command the data transfer is for. After the Service command is complete, the host can setup the DMA engine for that command. The interrupt service latency and Service command overhead can be a substantial performance penalty. In NCQ, the drive directly selects the DMA context for a data transfer without host intervention. The drive selects the DMA context by sending a packet to the host controller specifying the tag/identifier of the command that the data transfer is for. The host controller hardware then loads the scatter/gather table pointer for that command (based on the tag value) into the DMA engine. Then the DMA transfer may immediately proceed. TCQ does not support this mechanism for DMA transfers and thus it is slower and inefficient.
For the above mentioned reasons it is quite obvious than NCQ is much better than TCQ. As far as data throughput is concerned in accordance with the above TCQ overheads(handshake and interrupts), it must be noted that their effects are somehow minimized due to the fact that TCQ drives are usually found in SMP servers which have the processing power to manipulate such workload.
Finally NCQ has better Power Efficiency compared to TCQ because it uses less than half interrupts for any given transfer and thus consumes less power.