From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753640AbcIDJ52 (ORCPT ); Sun, 4 Sep 2016 05:57:28 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:38851 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752156AbcIDJ5X (ORCPT ); Sun, 4 Sep 2016 05:57:23 -0400 From: Nicolai Stange To: Nicolai Stange Cc: Thomas Gleixner , John Stultz , linux-kernel@vger.kernel.org Subject: Re: [RFC v5 21/23] clockevents: initial support for mono to raw time conversion References: <20160904010200.17200-1-nicstange@gmail.com> <20160904012852.17814-10-nicstange@gmail.com> Date: Sun, 04 Sep 2016 11:50:56 +0200 In-Reply-To: <20160904012852.17814-10-nicstange@gmail.com> (Nicolai Stange's message of "Sun, 4 Sep 2016 03:28:50 +0200") Message-ID: <878tv8gfi7.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nicolai Stange writes: > +static u32 __clockevents_calc_adjust_freq(u32 mult_ce_raw, u32 mult_cs_mono, > + u32 mult_cs_raw) > +{ > + u64 adj; > + int sign; > + > + if (mult_cs_raw >= mult_cs_mono) { > + sign = 0; > + adj = mult_cs_raw - mult_cs_mono; > + } else { > + sign = 1; > + adj = mult_cs_mono - mult_cs_raw; > + } > + > + adj *= mult_ce_raw; > + adj += mult_cs_mono / 2; > + do_div(adj, mult_cs_mono); > + > + if (!sign) { > + /* > + * Never increase mult by more than 12.5%, > + * c.f. __clockevents_update_bounds(). > + */ > + adj = max_t(u64, adj, mult_ce_raw / 8); This is wrong and should read as min_t(...), of course -- it's an upper bound. > + if (U32_MAX - mult_ce_raw < adj) > + return U32_MAX; > + return mult_ce_raw + (u32)adj; > + } > + if (adj >= mult_ce_raw) > + return 1; > + return mult_ce_raw - (u32)adj; > +}