* [patch] perf_event_open.2: update time_shift sample code
@ 2016-10-21 4:38 Vince Weaver
2016-10-21 6:45 ` Michael Kerrisk (man-pages)
0 siblings, 1 reply; 2+ messages in thread
From: Vince Weaver @ 2016-10-21 4:38 UTC (permalink / raw)
To: Michael Kerrisk (man-pages)
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Adrian Hunter,
Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
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-e7X0jjDqjFGHXe+LvDLADg@public.gmane.org>
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
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [patch] perf_event_open.2: update time_shift sample code
2016-10-21 4:38 [patch] perf_event_open.2: update time_shift sample code Vince Weaver
@ 2016-10-21 6:45 ` Michael Kerrisk (man-pages)
0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk (man-pages) @ 2016-10-21 6:45 UTC (permalink / raw)
To: Vince Weaver
Cc: mtk.manpages, linux-man, linux-kernel, Adrian Hunter,
Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
On 10/21/2016 06:38 AM, Vince Weaver wrote:
>
> 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).
Thanks, Vince.
Applied.
Cheers,
Michael
> 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
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-10-21 6:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-21 4:38 [patch] perf_event_open.2: update time_shift sample code Vince Weaver
2016-10-21 6:45 ` Michael Kerrisk (man-pages)
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).