Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754406AbcJUGpa (ORCPT ); Fri, 21 Oct 2016 02:45:30 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:35632 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753806AbcJUGp1 (ORCPT ); Fri, 21 Oct 2016 02:45:27 -0400 Subject: Re: [patch] perf_event_open.2: update time_shift sample code To: Vince Weaver References: Cc: mtk.manpages@gmail.com, linux-man@vger.kernel.org, linux-kernel@vger.kernel.org, Adrian Hunter , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo From: "Michael Kerrisk (man-pages)" Message-ID: <98ab0d01-901a-49ef-7402-20613d30bf98@gmail.com> Date: Fri, 21 Oct 2016 08:45:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1625 Lines: 54 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 > > 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/