Discussion:
[pyusb-users] "large" writes fail?
Karl Palsson
2015-08-30 02:17:41 UTC
Permalink
It's quite possible I'm doing something wrong in my device firmware, but
I'm not sure how my device side can care, so...

My device firmware is meant to be compatible with the linux gadget zero
source/sink function, so I should be able to write as much as I like to
it. And, mostly, this seems to be true. I can write 64, 640, 1000,
5000, bigger and bigger, but around 400k, it starts to fail the
assertions. The exact number of bytes written out is not consistent
every time, but is around 450000. What causes this, and is it
something I'm doing?

def test_write_perf2(self):
ts = datetime.datetime.now()
txc = 0
data = [x & 0xff for x in range(500 * 1024)]
w = self.ep_out.write(data)
self.assertEqual(w, len(data), "Should have written all bytes plz")
txc += w
te = datetime.datetime.now() - ts
print("wrote %s bytes in %s for %s kps" % (txc, te, self.tput(txc, te)))


Failure
Traceback (most recent call last):
File "/home/karlp/src/libopencm3-examples/tests/gadget-zero/test_gadget0.py", line 172, in test_write_perf2
self.assertEqual(w, len(data), "Should have written all bytes plz")
AssertionError: 455680 != 512000 : Should have written all bytes plz

Failure
Traceback (most recent call last):
File "/home/karlp/src/libopencm3-examples/tests/gadget-zero/test_gadget0.py", line 172, in test_write_perf2
self.assertEqual(w, len(data), "Should have written all bytes plz")
AssertionError: 456896 != 512000 : Should have written all bytes plz


Cheers,
Karl P

- --
Sent using Mailpile, Free Software from www.mailpile.is
Jeffrey Nichols
2015-08-30 13:42:47 UTC
Permalink
Hi Karl,

Is it possible you're exceeding the default timeout for write() with
your large data set? I just checked pyusb's source, and it looks like if
you don't pass a timeout it uses 1000. That would explain why you're
sending some data, but not all of it.

Try changing self.ep_out.write(data) to self.ep_out.write(data,
timeout=0) or self.ep_out.write(data, timeout=10000) and see if that helps.

Best Regards,
Jeff

Jeffrey Nichols
Suprock Technologies, LLC
Phone: (603) 479-3408
Fax: (888) 629-4158
www.suprocktech.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
It's quite possible I'm doing something wrong in my device firmware, but
I'm not sure how my device side can care, so...
My device firmware is meant to be compatible with the linux gadget zero
source/sink function, so I should be able to write as much as I like to
it. And, mostly, this seems to be true. I can write 64, 640, 1000,
5000, bigger and bigger, but around 400k, it starts to fail the
assertions. The exact number of bytes written out is not consistent
every time, but is around 450000. What causes this, and is it
something I'm doing?
ts = datetime.datetime.now()
txc = 0
data = [x & 0xff for x in range(500 * 1024)]
w = self.ep_out.write(data)
self.assertEqual(w, len(data), "Should have written all bytes plz")
txc += w
te = datetime.datetime.now() - ts
print("wrote %s bytes in %s for %s kps" % (txc, te, self.tput(txc, te)))
Failure
File "/home/karlp/src/libopencm3-examples/tests/gadget-zero/test_gadget0.py", line 172, in test_write_perf2
self.assertEqual(w, len(data), "Should have written all bytes plz")
AssertionError: 455680 != 512000 : Should have written all bytes plz
Failure
File "/home/karlp/src/libopencm3-examples/tests/gadget-zero/test_gadget0.py", line 172, in test_write_perf2
self.assertEqual(w, len(data), "Should have written all bytes plz")
AssertionError: 456896 != 512000 : Should have written all bytes plz
Cheers,
Karl P
- --
Sent using Mailpile, Free Software from www.mailpile.is
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
iQIcBAEBAgAGBQJV4mfFAAoJEBmotQ/U1cr2HZgP/3gGUg4LzudZInQuK/iD+7hi
YHTlj8f9lT9pi/t26gnZ+wyARI4x5FB6RX3fzxsSYFPsuNMuMAHcixJ4i0cVS5vg
I+Ys1ztJh8tsdfmeRSLVJIlHvt3h+qWifNHJLJ70T/W739a+3oaw0E0qZ92hqFG+
vBet5Qf9G0ROhHmdoSKvl506Hsg5gak4oReWflLkS1ebtQD4nT1rTVCD3neGdPeB
QbCQEeAYfxJ4/tiUrQZ4CciNnqlIQqYV/osbefsFCrBAkxXD61q9GZjWOhP9gJeT
yzwzarICFihaFuz2gWmTW3wIU3PWi6653Dil/C30bjL59nuIS1X5+tNNxoVyqyUo
/k2s8LvEkKAls4rW0gptK4RQ3kas0XwKzgCtLWv/9zbd6tVzVtwovvwjFY0GW9yd
FlotAmK6lyBqa9Am4wTAhnwqdmDRLWpfeBxqUnN1b+Twq/3KCtakV9S/yqhcVTXv
/tCG68uQcL0+ZsYS0Y6bfrXQu9i3S4ARGgkmZBkAUc08tDMdnNZIvhhE1q5XY8Os
BI5Xr3AFmRPjxL9w99ILvYoEBBH0mOqc5Kkmg55qkdfCwkUdy07rlYH97tFpL/tE
J0Ty4t7jcmDrUgPzIECxEyKsfKEEw7cDsxF2uZK1B/cImQwV23ZZUIVfkGY/NtG9
lfB4Mpkp0sZn+WkVz8d3
=tLE0
-----END PGP SIGNATURE-----
------------------------------------------------------------------------------
_______________________________________________
pyusb-users mailing list
https://lists.sourceforge.net/lists/listinfo/pyusb-users
k***@tweak.net.au
2015-08-30 15:39:06 UTC
Permalink
Post by Jeffrey Nichols
Hi Karl,
Is it possible you're exceeding the default timeout for write() with
your large data set? I just checked pyusb's source, and it looks like if
you don't pass a timeout it uses 1000. That would explain why you're
sending some data, but not all of it.
Try changing self.ep_out.write(data) to self.ep_out.write(data,
timeout=0) or self.ep_out.write(data, timeout=10000) and see if that helps.
Excellent, that was indeed the culprit. After I'd sent this, I was
moving on to reads, which get a different thoughput (different problem!)
and were failing at a different amount, but some back of the envelope
maths says it was the same time there :)

Setting timeout=0 fixes both of these nicely.

Thanks muchly,
Karl Palsson

Loading...