From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753369AbbHUGtn (ORCPT ); Fri, 21 Aug 2015 02:49:43 -0400 Received: from mga11.intel.com ([192.55.52.93]:49460 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751900AbbHUGtm (ORCPT ); Fri, 21 Aug 2015 02:49:42 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,720,1432623600"; d="scan'208";a="545880468" Message-ID: <55D6C961.9040303@intel.com> Date: Fri, 21 Aug 2015 09:46:57 +0300 From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: Thomas Gleixner CC: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Andy Lutomirski , linux-kernel@vger.kernel.org, Stephane Eranian , Andi Kleen Subject: Re: [PATCH V2] perf: x86: Improve accuracy of perf/sched clock References: <1438118085-3641-1-git-send-email-adrian.hunter@intel.com> 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 On 20/08/15 22:31, Thomas Gleixner wrote: > On Wed, 29 Jul 2015, Adrian Hunter wrote: >> @@ -239,6 +239,8 @@ static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu) >> unsigned long long tsc_now, ns_now; >> struct cyc2ns_data *data; >> unsigned long flags; >> + u64 mult; >> + u32 shft = 32; >> >> local_irq_save(flags); >> sched_clock_idle_sleep_event(); >> @@ -256,12 +258,17 @@ static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu) >> * time function is continuous; see the comment near struct >> * cyc2ns_data. >> */ >> - data->cyc2ns_mul = >> - DIV_ROUND_CLOSEST(NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR, >> - cpu_khz); >> - data->cyc2ns_shift = CYC2NS_SCALE_FACTOR; >> + mult = (u64)NSEC_PER_MSEC << 32; >> + mult += cpu_khz / 2; >> + do_div(mult, cpu_khz); >> + while (mult > U32_MAX) { >> + mult >>= 1; >> + shft -= 1; >> + } > > This is an open coded variant of clocks_calc_mult_shift(). Can we > please use that one? Sure. clocks_calc_mult_shift() does a division on each shift which is a bit slower (avoids a 1-bit rounding error but that will never be more than 1 in 2^32 in this case), and the 'maxsec' functionality is not needed because mul_u64_u32_shr() is used to avoid 64-bit overflow. I will send V3.