From: Xan Phung <xan.phung@gmail.com>
To: musl@lists.openwall.com
Subject: stdio glitch & questions
Date: Fri, 30 Nov 2018 21:51:39 +1100 [thread overview]
Message-ID: <CAO6moYvRndzizm+7Q3TbyB_TYr6PatkkS9mw=OMszti5=iBB1w@mail.gmail.com> (raw)
[-- 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 --]
next reply other threads:[~2018-11-30 10:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-30 10:51 Xan Phung [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAO6moYvRndzizm+7Q3TbyB_TYr6PatkkS9mw=OMszti5=iBB1w@mail.gmail.com' \
--to=xan.phung@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).