Usb Max Transfer Size

Discussion in 'Windows Vista Drivers' started by Charly Wu, Mar 3, 2008.

  1. Charly Wu

    Charly Wu Guest


    What is the definition of USB Max Transfer Size.
    In bulkusb src i noticed there are a few variable which i think related to
    1. in bulkpnp.c: Interface->Pipe.MaximumTransferSize =

    2. in bulkusb.h BULKUSB_MAX_TRANSFER_SIZE 256,

    3. in bulkusb.inf, Registry entry MaximumTransferSize, 4096

    How are those three variables related?
    How are they used in DispatchReadWrite,

    What is the general rule in setting them in order to maximize throughput
    How will those value affect ReadFile? can I request as much data as I want


    Charly Wu, Mar 3, 2008
    1. Advertisements

  2. It's referring to the maximum size of the data area in the URB that
    you submit to the host controller. Basically, this value means
    different things on different OSes, and is actually ignored much of
    the time. See here:
    Ultimately, I think you'll need to experiment. I've actually read
    several folks say that pending many (like 32) small URBs (say, 8K to
    32K in size) is the best way to get the highest performance.
    ReadFile is going to come into your driver's upper edge, not the lower
    edge facing the HC. If your driver doesn't do any buffering, the size
    in ReadFile will probably become your URB size. If it does buffer,
    then the two are probably not directly related.

    So yes you can request as much data as you want, it is up to your
    driver to decide how many bytes actually are fulfilled when the
    ReadFile request completes.
    chris.aseltine, Mar 3, 2008
    1. Advertisements

  3. What is the definition of USB Max Transfer Size.
    Starting from some OSes (XP SP?) it is just plain ignored.
    Maxim S. Shatskih, Mar 3, 2008
  4. starting on XP gold it was ignored. it was only used on win2k.

    Doron Holan [MSFT], Mar 4, 2008
  5. Charly Wu

    Charly Wu Guest


    Is there anything I can do to optimize bulkusb.sys?

    for example:
    in BulkUsb_DispatchReadWrite:
    removing uncessary checking on:
    2. breaking of totalLength into stageLength -> since now in XP SP2 there;s
    no limit of bulk transfer

    our hardware implements circular buffer of 25KB

    or u think i need to look at other factor or implementation?


    Charly Wu, Mar 5, 2008
  6. Charly Wu

    Tim Roberts Guest

    What makes you think it needs to be optimized? Nowhere in this thread have
    you actually mentioned anything about a specific problem.
    That's not what they said. They said MaximumTransferSize was not used.
    There is still a limit.
    Does that mean that you need to read in units of 25KB? Or just that you
    need to read 512-byte packets continuously so that the buffer doesn't

    To get maximum throughput, you must have multiple URBs outstanding at once.
    If you ever get to the start of a USB frame and you do not have a request
    already queued, you will miss that frame.
    Tim Roberts, Mar 5, 2008
  7. Charly Wu

    Charly Wu Guest

    Hi Tim,

    My device only supports USB 2.0 FullSpeed, bulk-in endpoint.

    he driver is bulkusb.sys from DDk 2600.1106
    I changed the BULKUSB_MAX_TRANSFER_SIZE in bulkusb.h to 8192 bytes

    my application does an overlapped readfile requesting 4096 or 8192 bytes per
    my throughput calculation is simply the accumulative number of bytes
    returned divided by the time from the start of the return of the first read
    until the time when the number of bytes threshold is reached. then then
    reading stop

    bStart = 0;
    total = 0;
    bSTOP = FALSE;
    bRet = readFile (hHandle, buffer, 8192, &readLen)

    getOverlappedResult(&readLen, TRUE) // blocking

    memcpy(largeBuffer, buffer, readLen);

    start = current time;
    bStart = 1;

    if (total >=MAX)
    end time = current time
    thput = total / (end-time)
    bSTOP = TRUE;


    the throughput i get was around

    I need more than this.. at least 8Mbps


    Charly Wu, Mar 5, 2008
  8. So when Tim told you to pend multiple URBs at the device, what made
    you decide to totally ignore him?
    chris.aseltine, Mar 5, 2008
  9. Charly Wu

    Charly Wu Guest

    Hi Chris,

    It's not that I ignore him.. it's just I dont have experience in driver
    and I dont know what it means to pend multiple urbs in term of
    implementation in bulkusb driver.

    Perhaps u can give me some light or reference

    Charly Wu, Mar 6, 2008
  10. I actually don't know much about bulkusb, but based on the code you
    gave, it looks like bulkusb converts IRP_MJ_READ requests into bulk IN

    If that's the case, then one solution would be to issue multiple
    ReadFile() calls simultaneously from your user-mode app, and then
    probably use WaitForMultipleObjects() to wait on the array of (all of
    the) overlapped completion events for them. When any of them
    completes, issue another, then wait on all again.

    Another solution is to put a buffer in your bulkusb driver, and then
    use a system thread to always issue bulk reads to the device (again,
    several at a time). Then the IRP_MJ_READ's from your user app would
    just deplete the driver's buffer.

    Or just convert to KMDF and use a continuous reader, which is by far
    the easiest.
    chris.aseltine, Mar 6, 2008
  11. Charly Wu

    Tim Roberts Guest

    But it's only overlapped by name, right? You aren't actually overlapping

    Here's the problem. USB is a scheduled bus. If you do not have a request
    queued up and ready to read when the host controller driver is scheduling
    the next frame, you will miss the ENTIRE frame, and will keep on missing
    frames until the frame AFTER your request gets back to the host controller
    Even with maximum overlapping, there's no guarantee you can get 8 Mbps.
    That's close to the maximum achievable at full-speed.
    Tim Roberts, Mar 7, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.