Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932446AbbKMULE (ORCPT ); Fri, 13 Nov 2015 15:11:04 -0500 Received: from mail-ig0-f169.google.com ([209.85.213.169]:36977 "EHLO mail-ig0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754225AbbKMULD (ORCPT ); Fri, 13 Nov 2015 15:11:03 -0500 MIME-Version: 1.0 In-Reply-To: <1447444387-23525-2-git-send-email-jacob.jun.pan@linux.intel.com> References: <1447444387-23525-1-git-send-email-jacob.jun.pan@linux.intel.com> <1447444387-23525-2-git-send-email-jacob.jun.pan@linux.intel.com> Date: Fri, 13 Nov 2015 12:11:01 -0800 Message-ID: Subject: Re: [PATCH 1/4] ktime: add a roundup function From: John Stultz To: Jacob Pan Cc: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , LKML , Arjan van de Ven , Srinivas Pandruvada , Len Brown , Rafael Wysocki , Eduardo Valentin , Paul Turner Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1622 Lines: 50 On Fri, Nov 13, 2015 at 11:53 AM, Jacob Pan wrote: > ktime roundup function can be used to keep timer aligned and > prevent drift for recurring timeouts. > > Signed-off-by: Jacob Pan > --- > include/linux/ktime.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/include/linux/ktime.h b/include/linux/ktime.h > index 2b6a204..2e293fa 100644 > --- a/include/linux/ktime.h > +++ b/include/linux/ktime.h > @@ -233,6 +233,16 @@ static inline ktime_t ktime_sub_us(const ktime_t kt, const u64 usec) > > extern ktime_t ktime_add_safe(const ktime_t lhs, const ktime_t rhs); > > +static inline ktime_t ktime_roundup(ktime_t x, ktime_t y) > +{ > + u64 temp_tv64; > + > + temp_tv64 = x.tv64 + y.tv64 - 1; > + temp_tv64 = div64_u64(temp_tv64, y.tv64); > + x.tv64 = temp_tv64 * y.tv64; > + > + return x; > +} Could you add a comment as to what the function does, and use some better variable names here to make it more immediately obvious what is being done here? Something like: /** * ktime_roundup - Rounds value up to interval chunk * @ value: Value to be rounded up * @ interval: interval size to round up to * * Rounds a value up to the next higher multiple of an interval size */ static inline ktime ktime_roundup(ktime_t value, ktime_t interval) thanks -john -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/