This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 While hunting a performance bottleneck related to writing files on a microcontroller I noticed an inconsistency in newlib for unbuffered files. While doing an fread() with a large buffer results in a call to read() with the same buffer and size, a call to fwrite() breaks the buffer in multiple calls to write() each up to BUFSIZ in size. This may cause performance issues, and for reference glibc seems to even try to pass large buffers untouched also if the files are fully buffered, at least that's what a simple test using strace on Linux has shown. This simple patch makes the behaviour of fwrite() consistent with fread(). 2013-10-21 Terraneo Federico <fede.tft@hotmail.it> * libc/stdio/fvwrite.c: Do not break buffers for unbuffered files -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSZOdvAAoJECkLFtN5Xr9fM2oH/A7NJZx/v48gPZpRQ7TSD0Qk WGjr7vR0lU6D+CWwmHjj6x8utPOKZSRGFmvK1SQN9Aui8foP+qSTylt8gvGOAgEx xtyXPrOPJp4X17IxYG251ggDF0vEWcypkzUCDLv1ZdGVqoNb6Oq9Hc6MqQzJwrqd bM4hx2rF65/o48+ARJ6ziFPHcbdZZPlpsl1KmiK9p7M3/NvkYtcwrVpP0t27QPjl kZmF/Ho6kmZH4uL0L7aqsayOpwqStjtPB15/F0FNFHeEgg9Yp3LBZ5KHjzi8rlF7 DfineuQBktcPyikP0KM9WfwfoSxaUMWsUbqvdENOYOnqlSNigqyDKIq2hrnHsak= =wFdl -----END PGP SIGNATURE-----
diff -ruN a/newlib/libc/stdio/fvwrite.c b/newlib/libc/stdio/fvwrite.c --- a/newlib/libc/stdio/fvwrite.c 2011-12-20 10:06:58.000000000 +0100 +++ b/newlib/libc/stdio/fvwrite.c 2013-10-21 00:40:03.155412978 +0200 @@ -89,12 +89,12 @@ if (fp->_flags & __SNBF) { /* - * Unbuffered: write up to BUFSIZ bytes at a time. + * Unbuffered: write one buffer at a time. */ do { GETIOV (;); - w = fp->_write (ptr, fp->_cookie, p, MIN (len, BUFSIZ)); + w = fp->_write (ptr, fp->_cookie, p, len); if (w <= 0) goto err; p += w;
Attachment:
fvwrite.patch.sig
Description: Binary data
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |