<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <font face="Open Sans, Calibri, sans-serif">It would be possible to
      avoid that TCGETS ioctl since the immediately preceding fstat
      shows that the file is a regular file and not a device. However,
      I'm not sure how easy it would be for the library to make that
      optimization.<br>
      <br>
      The Haskell implementation actually makes less syscalls than the
      Rust one, because Rust reads the file in very small chunks
      (32,32,64,128,64) whereas Haskell reads one big chunk (8192) which
      is sufficient to contain the entire file. I think it's unlikely
      that the extra ioctl outweighs the multiple extra reads. However,
      if you use the -r option with strace to include timestamps in the
      output, you'll be able to see just how long each syscall is
      taking. On my system, they all take about the same amount of time.<br>
      <br>
      It would also be worth using time on the program, to see how much
      of the CPU time is in user space vs kernel.<br>
    </font><br>
    <div class="moz-cite-prefix">On 2019-05-10 9:35 AM, Brandon Allbery
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAKFCL4We8m5iN=HvV2BS1Yo8iDvHdyVLEq_9hmMUpW4nOBbq+g@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">The ioctl is standard, including in C unless you
        are using open() directly: it checks to see if the opened file
        is a terminal, to determine whether to set block or line
        buffering.</div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Fri, May 10, 2019 at 11:09
          AM Magicloud Magiclouds <<a
            href="mailto:magicloud.magiclouds@gmail.com"
            moz-do-not-send="true">magicloud.magiclouds@gmail.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">So
          this is what I got. Seems like both calls two
          stat(stat/newfstatat)<br>
          for dir checking and uid checking. But when open file for
          reading,<br>
          there is an ioctl call (maybe from System.IO.Strict) which
          seems<br>
          failed, for Haskell. I want to test the case without
          System.IO.Strict.<br>
          But have no idea how to get exception catching works with lazy<br>
          readFIle.<br>
          <br>
          For Haskell implenmentation,<br>
          ```<br>
          stat("/proc/230", {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0<br>
          stat("/proc/230", {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0<br>
          openat(AT_FDCWD, "/proc/230/stat",
          O_RDONLY|O_NOCTTY|O_NONBLOCK) = 23<br>
          fstat(23, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0<br>
          ioctl(23, TCGETS, 0x7ffe88c18090)       = -1 ENOTTY
          (Inappropriate<br>
          ioctl for device)<br>
          read(23, "230 (scsi_eh_5) S 2 0 0 0 -1 212"..., 8192) = 155<br>
          read(23, "", 8192)                      = 0<br>
          close(23)<br>
          ```<br>
          For Rust implenmentation,<br>
          ```<br>
          newfstatat(3, "1121", {st_mode=S_IFDIR|0555, st_size=0, ...},<br>
          AT_SYMLINK_NOFOLLOW) = 0<br>
          stat("/proc/1121", {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0<br>
          open("/proc/1121/stat", O_RDONLY|O_CLOEXEC) = 4<br>
          fcntl(4, F_SETFD, FD_CLOEXEC)           = 0<br>
          fstat(4, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0<br>
          read(4, "1121 (ibus-engine-sim) S 1077 10", 32) = 32<br>
          read(4, "77 1077 0 -1 4194304 425 0 1 0 5", 32) = 32<br>
          read(4, "866 1689 0 0 20 0 3 0 3490 16454"..., 64) = 64<br>
          read(4, "4885264596992 94885264603013 140"..., 128) = 128<br>
          read(4, "0724521155542 140724521155575 14"..., 256) = 64<br>
          read(4, "", 192)                        = 0<br>
          close(4)<br>
          ```<br>
        </blockquote>
      </div>
    </blockquote>
  </body>
</html>