Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752656AbbKCAL1 (ORCPT ); Mon, 2 Nov 2015 19:11:27 -0500 Received: from mga09.intel.com ([134.134.136.24]:3505 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751299AbbKCALY (ORCPT ); Mon, 2 Nov 2015 19:11:24 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,236,1444719600"; d="scan'208";a="677019563" From: Jacob Pan To: Peter Zijlstra Cc: Thomas Gleixner , LKML , Arjan van de Ven , Paul Turner , Len Brown , Srinivas Pandruvada , Tim Chen , Andi Kleen , Rafael Wysocki , Jacob Pan Subject: [RFC PATCH 1/3] ktime: add a roundup function Date: Mon, 2 Nov 2015 16:10:26 -0800 Message-Id: <1446509428-5616-2-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446509428-5616-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1446509428-5616-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1133 Lines: 37 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; +} /** * ktime_to_timespec_cond - convert a ktime_t variable to timespec * format only if the variable contains data -- 1.9.1 -- 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/