From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751819AbcBFHoB (ORCPT ); Sat, 6 Feb 2016 02:44:01 -0500 Received: from mail-lf0-f46.google.com ([209.85.215.46]:36100 "EHLO mail-lf0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750754AbcBFHn7 (ORCPT ); Sat, 6 Feb 2016 02:43:59 -0500 From: Alexander Kuleshov To: Thomas Gleixner , John Stultz Cc: linux-kernel@vger.kernel.org, Alexander Kuleshov Subject: [PATCH] clocksource: introduce clocksource_freq2mult() Date: Sat, 6 Feb 2016 13:39:58 +0600 Message-Id: <1454744398-23937-1-git-send-email-kuleshovmail@gmail.com> X-Mailer: git-send-email 2.7.0.25.gfc10eb5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Alexander Kuleshov --- 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<