OSDN Git Service

Ignore NaCl st_blksize of 0 and buffer writes to raw_fd_ostream.
authorJan Voung <jvoung@chromium.org>
Tue, 3 Mar 2015 18:22:00 +0000 (10:22 -0800)
committerJan Voung <jvoung@chromium.org>
Tue, 3 Mar 2015 18:22:00 +0000 (10:22 -0800)
The default LLVM raw_fd_ostream buffer size is based on stat'ing the
FD and then checking st_blksize. Unfortunately, in the NaCl sandboxed
build of pnacl-sz, NaCl's syscall returns st_blksize of 0 which makes
the writes unbuffered. There is a comment in "src/trusted/service_runtime/include/bits/stat.h":

  nacl_abi_blksize_t nacl_abi_st_blksize;   /* not implemented */

And the " src/trusted/desc/" implementation sets this to 0.

This results in half a million write syscalls to translate the GCC pexe,
which roughly doubles the translation time in sandboxed mode vs
unsandboxed mode.

Manually set a buffer size (Linux st_blksize seems to be about
4KB for comparison). This drops the number of write syscalls
to about 200 for translating the GCC pexe.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4091
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/969403003

src/main.cpp

index eddb94e..4763f3e 100644 (file)
@@ -340,6 +340,9 @@ int main(int argc, char **argv) {
     std::error_code EC;
     raw_fd_ostream *FdOs =
         new raw_fd_ostream(OutputFilename, EC, sys::fs::F_None);
+    // NaCl sets st_blksize to 0, and LLVM uses that to pick the
+    // default preferred buffer size. Set to something non-zero.
+    FdOs->SetBufferSize(1 << 14);
     Os.reset(FdOs);
     if (EC) {
       *Ls << "Failed to open output file: " << OutputFilename << ":\n"