With one read( ) or write( ) at a time, can we increase the bulk data size over USB interface? For example, I want to transfer chunk of 1024 (1K) bytes data and if the device has limitations of only开发者_StackOverflow社区 64bytes, is there any way I can increase the packet size for read( ) and write( ) system call over USB?
Is there any limitation on size of data transfer over USB in a host->device environment?
thank you.
-AD
If it is read(), write() file-system call you are talking about?
Then, AFAIK, you have little or no control over the data scheduling policy of the underlying device. Having said that, it is always better from the application to queue a large chunk of data, such that the number of COMMAND-RESPONSE transactional overhead comes down.
BTW, if you are talking about BUS LEVEL READ & WRITE transaction, then in USB2.0, MAXIMUM BULK PACKET SIZE supported is 512 bytes (which is same as the size of 1 sector in most storage devices), and which is good enough.
And many times, these PIPES will have PING-PONG implementation in the host buffer, which will mean, anything over 1024 bytes, will effectively wait some-where in the upper layers of the physical hardware (like the Host PC cache ~~~)
The bigger, the better As a general rule, the more you send, the faster USB transfers will be (bulk). I think we hit the sweet-spot at 2MB chunks. The only limitation is the size of buffer your host controller can handle.
A bit of why The protocol times the bus in 1ms (full speed) 1/8ms(high speed) chunks. During which 0-~15 bulk packets can be sent (64B/512B full/high speed).
It takes time to setup a USB transfer in the controller and to handle its completion.
An example of a 10byte transfer of full speed: ms0 - setup OHCI to transfer 10bytes ms1 - 10bytes are transferred (this might actually happen on the next 1ms interval) ms2 - interrupt to notify of completion. - 3ms to send 10bytes
Example of 640byte transfer: ms0 - setup OHCI ms1 - transfer 640bytes ms3 - interrupt - 3ms to send 640bytes.
I guess you get the picture.
The IO buffer size of the device does not change the above assertion, as larger host/device transfers avoid the setup/handling overhead.
Example of very slow device and 256byte transfer ms0 - setup OHCI ms1 - send 64, get NAKs.. ms2 - send 64, get NAKs.. ms3 - send 64, get NAKs.. ms4 - send 64, get NAKs.. ms5 - interrupt
Hope this helps
To directly answer your question, you can't increase the max-packet size. It's defined by USB as it is for a number of reasons.
However, the actual max packet size doesn't limit the transfer size at the SW level. With a 64-byte max-packet size, you can still set up a much larger transfer with a single URB. In fact, that's the only way to get reasonably high bandwidth in bulk - your SW should be working at the USB "transfer" level, not packet level.
The shorter packet size does cause some extra overhead on the wire (more headers, CRC, and inter-packet gaps) but that's on the order of 5-10%. And you can't change it anyway.
精彩评论