|
Message-ID: <CAO6moYvRndzizm+7Q3TbyB_TYr6PatkkS9mw=OMszti5=iBB1w@mail.gmail.com>
Date: Fri, 30 Nov 2018 21:51:39 +1100
From: Xan Phung <xan.phung@...il.com>
To: musl@...ts.openwall.com
Subject: stdio glitch & questions
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
Content of type "text/html" skipped
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.