mailing list of musl libc
 help / color / mirror / code / Atom feed
* stdio glitch & questions
@ 2018-11-30 10:51 Xan Phung
  2018-11-30 16:09 ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: Xan Phung @ 2018-11-30 10:51 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 2043 bytes --]

Hi,

A few questions about stdio:

(1) I notice __toread.c uses angular quotes for <stdio_impl.h> whereas all
other source files use "stdio_impl.h".  I assume the latter is correct and
__toread.c's use of angular quotes was a glitch & it should really be
double quotes... is that correct?

(2) I notice vfprintf first tries to call printf_core with f=0 (line 667)
then calls printf_core again with f set to the actual file to receive
output (line 682).  Why is printf_core called twice?  I struggle to
understand the purpose of the first call with f=0.

(3) When I do a step thru the __fwritex function to understand how printf
works, I notice the resulting writev system calls pass on the output data
as a two element iovec array, with the 1st element comprising all line
buffered text up to & including the last variable data item, and then the
2nd element comprising the residual format string trailing the last
variable data item (more often than not just a single '\n').

For example, printf("error: %s\n", msg) would put all text up to &
including %s text in first iovec and the second iovec contains only '\n'.
I understand the rationale of this is to avoid copying the final '\n' to
the buffer at f->wpos.  (There is actually guaranteed space in the buffer
itself due to a check at line 10 of fwrite.c).  The use the array of 2x
iovec's presumably then relies on Linux kernel scatter-gather I/O to then
optimally handle the iovec array, ie: that the writev() of 2x iovec is more
efficient than avoiding the copy of a few additional bytes (often a single
'\n' byte) into f->wpos, and then using a single write() syscall.

Isn't this a big assumption?  With Linux itself, can we really know that
Linux device drivers are smart enough to do writev() optimally?  Also,
there is a lot of interest in porting musl to non-Linux os's, many of which
do not have writev().  (I am porting musl to WebAssembly and to Plan 9).

I can prepare a patch of a version using write() instead of writev() if
there is interest in this...

regards
Xan Phung

[-- Attachment #2: Type: text/html, Size: 2420 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-12-01  8:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-30 10:51 stdio glitch & questions Xan Phung
2018-11-30 16:09 ` Rich Felker
2018-11-30 22:15   ` Xan Phung
2018-12-01  0:02     ` Rich Felker
2018-12-01  2:42       ` Xan Phung
2018-12-01  3:17         ` Rich Felker
2018-12-01  8:02           ` Xan Phung

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).