background image

Serial ATA Native Command Queuing 

an event to be signaled or by receiving a callback.  Since the call returns immediately, the 
application can continue to do useful work, including issuing more read or write file functions.   

The preferred method for writing an application that needs to make several different file accesses 
is to issue all of the file accesses using non-blocking I/O calls.  Then the application can use 
events or callbacks to determine when individual calls have completed.  If there are a large 
number of I/Os, on the order of four to eight, by issuing all of the I/Os at the same time the total 
time to retrieve all of the data can be cut in half. 

Using Asynchronous I/O in Windows* 

In Windows* applications, there are two main functions used for accessing files called ReadFile 
and WriteFile.  In a typical application, these functions are used in a blocking, or synchronous, 
manner.  An example is shown below of reading 1KB from a file using ReadFile: 

 

bStatus = ReadFile( 

hFile,  

 

// Handle to file to read from 

pBuffer,  

 

// Pointer to buffer to place data in 

1024,   

 

// Want to read 1024 bytes from the file 

&numBytesRead,  

// Number of bytes read from the file 

NULL);  

 

// Synchronous so overlapped parameter is NULL 

 

// 
// Code for checking the status value and ensuring there were not any errors. 
// 
... 

 

When this call is made, it does not return until all of the data is read from the file.  During this 
time, the application cannot do any useful work nor can it issue any more I/O calls within this 
thread. 

A preferred method for reading data from a file is to use ReadFile and WriteFile in an 
asynchronous manner by opening the file using the flag FILE_FLAG_OVERLAPPED.  The same 
example is shown below using the asynchronous mechanism. 

 
// 
// Fill in the OVERLAPPED structure used for asynchronous IO. 
// 
overlap.offset = 0;  

 

// Offset in the file to start reading from 

overlap.offsetHigh = 0; 

 

// Upper 32-bits of offset 

overlap.hEvent = hEvent;         // Event to trigger when complete, initialized  

// using CreateEvent() 

 
// 
// Make the call to start reading the file. 
// 
bStatus = ReadFile( 

hFile,  

 

// Handle to file to read from 

pBuffer,  

 

// Pointer to buffer to place data in 

1024,   

 

// Want to read 1024 bytes from the file 

&numBytesRead, 

// Number of bytes read from the file 

 

9

*Other names and brands may be claimed as the property of others.

Summary of Contents for ST3250620AS - Barracuda 250GB 7200 RPM 16MB Cache SATA 3.0Gb/s Perpendicular Recording Hard Drive

Page 1: ...July 2003 Serial ATA Native Command Queuing An Exciting New Performance Feature for Serial ATA A JOINT WHITEPAPER BY Intel Corporation and Seagate Technology www intel com www seagate com...

Page 2: ...mands to be outstanding within a drive at the same time Drives that support NCQ have an internal queue where outstanding commands can be dynamically rescheduled or re ordered along with the necessary...

Page 3: ...onal Position Ordering to optimally re order commands to maximize performance Seek Latency Optimization Seek latencies are caused by the time it takes the read write head to position and settle over t...

Page 4: ...ve almost simultaneously Higher RPM spindles are one approach to reduce rotational latencies However increasing RPM spindle rates carries a substantial additional cost Rotational latencies can also be...

Page 5: ...nding a DMA Setup FIS Frame Information Structure to the host controller This FIS specifies the tag of the command for which the DMA is being set up Based on the tag value the host controller will loa...

Page 6: ...s written with the particular register values and then the Command register is written with the command opcode The difference between queued and non queued commands is what happens after the command i...

Page 7: ...alled Auto Activate which can eliminate one FIS transfer during a write command One important note for HBA designers is that new commands cannot be issued between the DMA Setup FIS and the completion...

Page 8: ...the drive can return a Set Device Bits FIS without a host handshake it is possible to receive two Set Device Bits FISes very close together in time If the second Set Device Bits FIS arrives before hos...

Page 9: ...ointer to buffer to place data in 1024 Want to read 1024 bytes from the file numBytesRead Number of bytes read from the file NULL Synchronous so overlapped parameter is NULL Code for checking the stat...

Page 10: ...50 Wait up to 50 milliseconds for completion could be infinity Check the value of dwResult and also call GetOverlappedResult to ensure that each IO that completed was with good status As can be seen...

Page 11: ...ntroller Interface AHCI definition Amber holds a BSE in Computer Engineering from the University of Michigan and has been with Intel for 6 years Joni Clark Product Marketing Manager Seagate Technology...

Page 12: ...Serial ATA Native Command Queuing 12...

Reviews: