<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Improve comments about __builtin_readcyclecounter"
   href="https://bugs.llvm.org/show_bug.cgi?id=40377">40377</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Improve comments about __builtin_readcyclecounter
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Documentation
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>General docs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>pgut001@cs.auckland.ac.nz
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The documentation currently says:

  Note that even if present, its use may depend on run-time privilege or other
  OS controlled state.

but this is somewhat misleading in terms of indicating how risky use of
__builtin_readcyclecounter is on non-x86 systems.  That is, it's technically
accurate, but doesn't convey how bad the situation really is.  For example on
ARM systems access to the Performance Monitoring Unit (PMU) is privileged,
which means that any use of __builtin_readcyclecounter will lead to an illegal
instruction trap (unless a custom kernel patch is applied to allow user-space
access or some similar measure is taken).  The current note doesn't really
convey this, it just says "this might not work in some cases" when, at least in
the case of ARM CPUs, it's guaranteed to fail.  I would suggest amending the
wording to something like:

  On non-x86 systems, use of __builtin_readcyclecounter is often dependent on
  runtime privilege, and may lead to protection or instruction faults if
  called from non-kernel-mode code.  It is recommended that the usability of
  this intrinsic be evaluated in a small test program before using it in
  actual code.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>