From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423435AbcB0DOq (ORCPT ); Fri, 26 Feb 2016 22:14:46 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:36733 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422813AbcB0DO1 (ORCPT ); Fri, 26 Feb 2016 22:14:27 -0500 From: John Stultz To: lkml Cc: Alexander Kuleshov , Thomas Gleixner , Prarit Bhargava , Richard Cochran , Ingo Molnar , John Stultz Subject: [PATCH 1/2] clocksource: introduce clocksource_freq2mult() Date: Fri, 26 Feb 2016 19:14:13 -0800 Message-Id: <1456542854-22104-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456542854-22104-1-git-send-email-john.stultz@linaro.org> References: <1456542854-22104-1-git-send-email-john.stultz@linaro.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Kuleshov The clocksource_khz2mult() and clocksource_hz2mult() share similar code wihch calculates a mult from the given frequency. Both implementations in differ only in value of a frequency. This patch introduces the clocksource_freq2mult() helper with generic implementation of mult calculation to prevent code duplication. Cc: Thomas Gleixner Cc: Prarit Bhargava Cc: Richard Cochran Cc: Ingo Molnar Signed-off-by: Alexander Kuleshov Signed-off-by: John Stultz --- include/linux/clocksource.h | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 6013021..a307bf6 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h @@ -118,6 +118,23 @@ struct clocksource { /* simplify initialization of mask field */ #define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1) +static inline u32 clocksource_freq2mult(u32 freq, u32 shift_constant, u64 from) +{ + /* freq = cyc/from + * mult/2^shift = ns/cyc + * mult = ns/cyc * 2^shift + * mult = from/freq * 2^shift + * mult = from * 2^shift / freq + * mult = (from<