Sleep function

> Time consuming: 4.271115(f), 507790068(d),2180941736368477599(I64d),

1075006000
And why the tmdelay is 5, it print out is : 1075006000

No, as I already pointed out you cannot print a 64-bit value using %d; it
will give the wrong answer. The fact that you believe decimal is useful
is part of the confusion; to make sense of it, you have to print it in
hex. And you simply cannot use a 32-bit format to print a 64-bit value on
the stack; you have to understand how printf and friends advance the
variable-argument pointer to make sense of what you are seeing. If you
did three different print statements, each one of which printed out
exactly one value, it would still be incorrect, but only one of them would
be incorrect. But three formats in the same print statement, one of which
is a mismatch for the argument size, is guaranteed to deliver nonsense.
So until you stop trying to print out nonsense, there is little point to
wondering why you have nonsense. You ASKED it to print out the incorrect
values. So don’t complain when it does exactly what you asked it to do.
joe


NTDEV is sponsored by OSR

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Wrong approach. You are saying that you have to add a delay to make an
incorrect driver work correctly. The correct solution is to modify the
driver so that it does not have a problem. Otherwise, you are trying to
use a feature over which you have no control and whose behavior is not
predictable to compensate for an error in the driver.

And it is worth noting that although you refer to “getting the interrupt”,
a USB driver will NEVER see an interrupt; what it will see is the
completion notification from USBD and lower drivers.
joe

I don’t agree with delay make the ISO transfer worse.
Neither get rid of ISO transfer.

I have to make clear about my design now:

  1. aim to verify, my USB device ISO in transfer and its data is correct

  2. out data using bulk transfer, make sure the out data, device received
    is correct compare to ISO out

  3. Once device get 16K bulk data, in FW ISR, it start prepare 16K data for
    ISO in, in 16 DP.

  4. If device did not prepare the 16K ready, when get host ACK in, device
    will reply with 0 length packet DP
    If device finished 16K data, it reply host ACK IN with DPs

  5. So delay between the Write and Read is
    give device enough time to prepare 16K data, and delay the host send out
    ACK IN to device.


NTDEV is sponsored by OSR

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Can you get the bandwidth guarantees that ISO provides if you use bulk?
This could be one of the parameters of the OP’s design. It’s been too
many years since I last read the USB spec.
joe

With the bulk transfer from the device, you would not have to have a
delay. The host could be getting data as the device is preparing it and
making available for transfers. And also if the data is corrupted on the
wire, it would be automatically resent. Not so with ISO. This is why ISO
should be discouraged, except for very few applications.


NTDEV is sponsored by OSR

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>Can you get the bandwidth guarantees that ISO provides if you use bulk? This could be one of the parameters of the OP’s design.

ISO allows up to 3 packets of 512B per microframe per ISO pipe. This is 24 packets per millisecond, total 12 MB/s. His 16K transfer will take at least 1.5 ms.

With bulk, one can easily have 45+ MB/s, and the transfer would take a single 1ms frame.

He’s using bulk transfers for upload, anyway, so there is no time guarantee. And he could have posted TX and RX URBs at the same time, which could have allowed to start recieving data even in the same frame as the transmit is over.

On Mon, Feb 11, 2013 at 11:13 PM, wrote:
>>Can you get the bandwidth guarantees that ISO provides if you
> use bulk? This could be one of the parameters of the OP’s design.
>
> ISO allows up to 3 packets of 512B per microframe per ISO pipe.
> This is 24 packets per millisecond, total 12 MB/s. His 16K transfer
> will take at least 1.5 ms.

For high speed high bandwith isoc endpoint, it is 3 packets of
1024B per microframer, so it is 24MB/s, not 12MB/s.

> With bulk, one can easily have 45+ MB/s, and the transfer would take
> a single 1ms frame.

I’ve seen many report about this. Is 45MB/s sustainable across different
systems? I’ve seen report that some system have problems catching up,
including recent systems.
Ref: http://libusb.6.n5.nabble.com/Transfer-Speed-Problem-with-IN-Bulk-Transfers-at-Certain-Computers-td5711155.html

> He’s using bulk transfers for upload, anyway, so there is no time guarantee.
> And he could have posted TX and RX URBs at the same time, which could
> have allowed to start recieving data even in the same frame as the transmit
> is over.
>


Xiaofan

workingmailing@163.com wrote:

FW is doing:
Bulk out data to device, device received the 16KB, generate the interrupt, in the ISR, it prepare 16KB for ISO in, response the Host ACK IN.

App is doing:
Write 16KB –> delay(time) –> Read(16KB).

2. Even I think 2ms is enough for device to prepare 16KB for ISO in, but it happened the first DP is 0 length packet, and the after 15 DP is 1KB in the 16KB read.
So I change the delay to 5ms, it also happen the same case.

SO in this case, I think maybe device prepare the buffer/data for ISO in take more than 2ms/5ms sometimes.

But why it take so long, as each 1KB only take 15us.

It might only takes 15us inside your device, but remember that your iso
pipe is gated not only by the max packet size, but by the interval. For
example, if you have a full speed device, and you specify a max packet
size of 512 bytes and an interval of 1, it is going to take 32ms to
transfer 16k bytes.

Based on your description, it sounds like you shouldn’t be using an
isochronous pipe at all.

What’s the processor in your device? Most of the microprocessors in the
generic USB chips can’t possibly prepare 1kB of data in 15us. In the
Cypress FX2, for example, the processor runs about 4 MIPs.

  1. Second,

After check the struct:
typedef union _ LARGE_INTEGER
{
struct
{
DWORD LowPart;
LONG HighPart;
};
LONGLONG QuadPart;
} LARGE_INTEGER;

it is a union,

  1. in what case, we use it as struct , and in what case, we use it as LONGLONG?

A union just provides multiple ways to access the same piece of memory.
When NT was developed, the Microsoft compilers did not have a
fundamental 64-bit data type. So, you had to use HighPart and LowPart
to access the upper and lower halves. Today, the compiler has a
built-in __int64 type (which is what LONGLONG is), so it’s usually more
convenient to use QuadPart.

  1. does LARGE_INTEGER have relationship with OS system, and hardware such CPU, and PCIe?

I don’t know what that means. A LARGE_INTEGER is just a 64-bit
integer. If the Microsoft compilers had had __int64 in 1989, the
LARGE_INTEGER structure would not exist.

  1. QuadPart is a 64 bit variable, it is print with %I64d,
    but some code example type change it as:
    double dqFreq=(double)nFreq.QuadPart;

Here is my print result:
Freq-QuadPart:
2435898(d), 10462102246391808(I64d), 0.000000(f)
dqFreq:
0(d), 1094882717(I64d), 0.000000(f)

why they have different in %I64d and %d, and why it is 0 in %f mode?

Because neither of those are actually printing what you THINK they are
printing. Remember that the printf function does not really know the
types of the variables you are sending. It just gets bytes on the
stack. It has to TRUST that you are telling the truth. In this case
you are lying.

I assume your statement was:
printf( “%d(d) %I64d(I64d) %f(f)\n”, nFreq.QuadPart, nFreq.QuadPart,
nFreq.QuadPart );

When you pass nFreq.QuadPart, it gets pushed on the stack as a 64-bit
quantity. So, when printf is called, the stack looks like this:

esp –> return address
esp+4 –> pointer to format string
esp+8 –> nFreq.LowPart
esp+12 –> nFreq.HighPart
esp+16 –> nFreq.LowPart
esp+20 –> nFreq.HighPart
esp+24 –> nFreq.LowPart
esp+28 –> nFreq.HighPart

Now, the first thing in your format string is %d. printf assumes that
you gave it a 32-bit quantity, so it pulls one dword from the stack (in
this case, it gets the LowPart). Next, there is a %I64d. printf
assumes that you gave it a 64-bit quantity, so it pulls two dwords from
the stack. But since you lied about the first parameter, it’s going to
get the two halves in the wrong order. When it sees the %f, it assumes
you gave it a double-precision floating point value. But, what you gave
it was a 64-bit integer, and in this case the two halves are swapped
because you lied on the first parameter.

The same thing happens in your second example. Floating point values
are pushed on the stack as 64-bit quantities, but again you have TOLD it
that your first thing is a 32-bit integer. After that, the rest of the
items are screwed up because the stack is messed up.

You cannot print a floating point value with %d, nor print an integer
value with %f. printf cannot do any conversions, because it has no way
of figuring out what you sent. It has to believe you. When you lie to
printf, you get garbage results.

These are pretty fundamental C questions. You ought to be able to
answer these questions yourself before you start working on drivers.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

xxxxx@flounder.com wrote:

Can you get the bandwidth guarantees that ISO provides if you use bulk?

No, but there are damned few designs that actually need a bandwidth
guarantee, and in virtually every one of those cases an interrupt pipe
is a better choice anyway.

Isochronous pipes really have very, very, very few legitimate use
cases. That’s partly why they still aren’t supported in WinUSB, or by
the KMDF continuous reader – no one has presented Microsoft with a
sufficiently compelling business case for adding it.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Xiaofan Chen wrote:

On Mon, Feb 11, 2013 at 11:13 PM, wrote:
>> With bulk, one can easily have 45+ MB/s, and the transfer would take
>> a single 1ms frame.
> I’ve seen many report about this. Is 45MB/s sustainable across different
> systems? I’ve seen report that some system have problems catching up,
> including recent systems.

Yes, and Chris has to take a drink because this was mentioned. Some
host controllers can reliably sustain 45-50 MB/s, but many can’t seem to
beat 35 MB/s on a consistent basis.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

>I’ve seen many report about this. Is 45MB/s sustainable across different systems?

Don’t know about different systems, but I was getting such performance 6 years ago under Windows XP.

workingmailing@163.com wrote:

I don’t agree with delay make the ISO transfer worse.
Neither get rid of ISO transfer.

I have to make clear about my design now:

  1. aim to verify, my USB device ISO in transfer and its data is correct
  2. out data using bulk transfer, make sure the out data, device received is correct compare to ISO out
  3. Once device get 16K bulk data, in FW ISR, it start prepare 16K data for ISO in, in 16 DP.

What do you mean by “DP”?

  1. If device did not prepare the 16K ready, when get host ACK in, device will reply with 0 length packet DP
    If device finished 16K data, it reply host ACK IN with DPs

  2. So delay between the Write and Read is
    give device enough time to prepare 16K data, and delay the host send out ACK IN to device.

But you don’t have to do this. You can send your requests immediately,
and keep recirculating them until you get your data. There’s no reason
to wait.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thanks for all the info. I find it useful, since so much was made about
isochronous pipes when USB was new. It sounds like the utility of ISO
should now be classified as “harmful urban legend”.
joe

>Can you get the bandwidth guarantees that ISO provides if you use bulk?
> This could be one of the parameters of the OP’s design.

ISO allows up to 3 packets of 512B per microframe per ISO pipe. This is 24
packets per millisecond, total 12 MB/s. His 16K transfer will take at
least 1.5 ms.

With bulk, one can easily have 45+ MB/s, and the transfer would take a
single 1ms frame.

He’s using bulk transfers for upload, anyway, so there is no time
guarantee. And he could have posted TX and RX URBs at the same time, which
could have allowed to start recieving data even in the same frame as the
transmit is over.


NTDEV is sponsored by OSR

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Tim Roberts wrote:

>> With bulk, one can easily have 45+ MB/s, and the transfer
>> would take a single 1ms frame.
>
> I’ve seen many report about this. Is 45MB/s sustainable across
> different systems? I’ve seen report that some system have problems
> catching up,including recent systems.

Yes, and Chris has to take a drink because this was mentioned.

Glug glug… :slight_smile: