Jeff Garzik schrieb:
> Is there a possibility of do_read being re-entered during that window?
> I agree its a problem but the solution sounds racy?
do_read may be reentered. In that case some of the samples land in one read,
the other part in the other read.
This is not a problem, however. UNIX never made any guarantees about
read from or writes to the same fd. Take pipes for example, they don't
guarantee read or write atomicity either. Well, they do guarantee it
if they are all less than PIPEBUF in size. But so do we, the limit
is not called PIPEBUF, but fragment.
> I disagree; I think the idea at aleast is correct: if contention
> exists, it implies that I/O needs to be completed.
Well, it depends what the semaphore is supposed to do. If you (ab)use
it as a waitqueue, then yes, the idea is correct. If you only use it
to guard short critical sections, then the cost of reissuing the syscall
is greater than just waiting for the semaphore to be released.
This is the patch I've tested yesterday. It worked so far.
There is however an unrelated problem that happens both with and without
patch. Sometimes playback sound is very distorted, until I either press
stop, then the remaining second or so continues undistortedly, or I try
to debug the problem. Debugging is anyway difficult without reasonable
docs. It may be a PCI bridge latency issue, as the VIA northbridge my
board uses is fairly crappy.
Tom
--------------91FB347F1E3060146B5D1265
Content-Type: application/octet-stream;
name="via82cxxx_audio.diff"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="via82cxxx_audio.diff"
LS0tIHZpYTgyY3h4eF9hdWRpby5jLjEuMS4xNQlUaHUgU2VwIDIwIDE1OjQxOjMwIDIwMDEK
KysrIHZpYTgyY3h4eF9hdWRpby5jCVRodSBTZXAgMjAgMTY6MTU6MDUgMjAwMQpAQCAtMTIs
MTAgKzEyLDE3IEBACiAgKiB0aGUgZHJpdmVyJ3MgV2Vic2l0ZSBhdAogICogaHR0cDovL2d0
Zi5vcmcvZ2FyemlrL2RyaXZlcnMvdmlhODJjeHh4LwogICoKKyAqIFRob21hcyBTYWlsZXIs
IDIwMDEtMDktMjA6CisgKiAgIC0gdW5sb2NrIHN5c2NhbGxfc2VtIGR1cmluZyBzbGVlcGlu
ZyBpbiByZWFkL3dyaXRlCisgKiAgIC0gcmV0dXJuIGJ5dGUgY291bnQgaW4gY2FzZSBvZiBw
YXJ0aWFsIHRyYW5z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nM9JWRcbiIsIGF0b21pY19yZWFkICgmY2hhbi0+bl9mcmFncykpOwotCQlpbnRlcnJ1cHRp
YmxlX3NsZWVwX29uICgmY2hhbi0+d2FpdCk7CisJCXNjaGVkdWxlKCk7CisKKwkJaWYgKChy
ZXQgPSB2aWFfc3lzY2FsbF9kb3duIChjYXJkLCBub25ibG9jaykpKQorCQkJYnJlYWs7CiAK
IAkJaWYgKHNpZ25hbF9wZW5kaW5nIChjdXJyZW50KSkgewogCQkJRFBSSU5USyAoIkVYSVQs
IHJldHVybmluZyAtRVJFU1RBUlRTWVNcbiIpOwotCQkJcmV0dXJuIC1FUkVTVEFSVFNZUzsK
KwkJCXJldCA9IC1FUkVTVEFSVFNZUzsKKwkJCWJyZWFrOwogCQl9CiAJfQorICAgICAgICBz
ZXRfY3VycmVudF9zdGF0ZShUQVNLX1JVTk5JTkcpOworICAgICAgICByZW1vdmVfd2FpdF9x
dWV1ZSgmY2hhbi0+d2FpdCwgJndhaXQpOworCWlmIChyZXQpCisJCXJldHVybiByZXQ7CiAK
ICNpZmRlZiBWSUFfREVCVUcKIAl7CkBAIC0yNDA4LDcgKzI0OTYsNyBAQAogCiBvdXQ6CiAJ
RFBSSU5USyAoIkVYSVQsIHJldHVybmluZyAwXG4iKTsKLQlyZXR1cm4gMDsKKwlyZXR1cm4g
cmV0OwogfQogCiAK
--------------91FB347F1E3060146B5D1265--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/