mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vince Weaver <vincent.weaver@maine.edu>
To: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
Cc: linux-man@vger.kernel.org, linux-kernel@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: [patch] perf_event_open.2: update time_shift sample code
Date: Fri, 21 Oct 2016 00:38:06 -0400 (EDT)	[thread overview]
Message-ID: <alpine.DEB.2.20.1610210036000.3240@macbook-air> (raw)


Linux 4.3 (b20112edeadf0b8a1416de061caa4beb11539902) improved
the accuracy of the clock/ns conversion routines.  As a result
the shift factor can now be 32.  This value is directly
exported in the perf_event_open() mmap page, and this
potentially breaks the sample code that shifts 1 left by
the shift value.

Add a cast in the sample code so that a proper 64-bit value
results from the shift.  This is the same change that was
made to the sample code in include/uapi/linux/perf_event.h
in Linux 4.4 (b9511cd761faafca7a1acc059e792c1399f9d7c6).

Signed-off-by: Vince Weaver <vincent.weaver@maine.edu>

diff --git a/man2/perf_event_open.2 b/man2/perf_event_open.2
index ae15cc6..fade28c 100644
--- a/man2/perf_event_open.2
+++ b/man2/perf_event_open.2
@@ -1619,7 +1619,7 @@ delta since
     u64 quot, rem;
     u64 delta;
     quot = (cyc >> time_shift);
-    rem = cyc & ((1 << time_shift) \- 1);
+    rem = cyc & (((u64)1 << time_shift) \- 1);
     delta = time_offset + quot * time_mult +
             ((rem * time_mult) >> time_shift);
 .fi
@@ -1664,7 +1664,7 @@ And vice versa:
 
 .nf
     quot = cyc >> time_shift;
-    rem  = cyc & ((1 << time_shift) - 1);
+    rem  = cyc & (((u64)1 << time_shift) - 1);
     timestamp = time_zero + quot * time_mult +
         ((rem * time_mult) >> time_shift);
 .fi

             reply	other threads:[~2016-10-21  4:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-21  4:38 Vince Weaver [this message]
2016-10-21  6:45 ` Michael Kerrisk (man-pages)

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=alpine.DEB.2.20.1610210036000.3240@macbook-air \
    --to=vincent.weaver@maine.edu \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mtk.manpages@gmail.com \
    --cc=peterz@infradead.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®