From patchwork Wed Feb 27 09:38:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li RongQing X-Patchwork-Id: 1048782 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baidu.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 448VxW2WJzz9s4Z for ; Wed, 27 Feb 2019 20:38:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726356AbfB0Jit (ORCPT ); Wed, 27 Feb 2019 04:38:49 -0500 Received: from mx140-tc.baidu.com ([61.135.168.140]:31697 "EHLO tc-sys-mailedm06.tc.baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725881AbfB0Jis (ORCPT ); Wed, 27 Feb 2019 04:38:48 -0500 Received: from localhost (cp01-cos-dev01.cp01.baidu.com [10.92.119.46]) by tc-sys-mailedm06.tc.baidu.com (Postfix) with ESMTP id 7EF48263C004; Wed, 27 Feb 2019 17:38:33 +0800 (CST) From: Li RongQing To: netfilter-devel@vger.kernel.org, linux-kernel@vger.kernel.org, sboyd@kernel.org, tglx@linutronix.de, john.stultz@linaro.org Subject: [PATCH] time: Introduce jiffies64_to_msecs() Date: Wed, 27 Feb 2019 17:38:33 +0800 Message-Id: <1551260313-2926-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.1 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org there is a similar helper in net/netfilter/nf_tables_api.c, this maybe become a common request someday. and avoid to call div_64 at some condition Signed-off-by: Li RongQing --- include/linux/jiffies.h | 1 + kernel/time/time.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h index fa928242567d..1b6d31da7cbc 100644 --- a/include/linux/jiffies.h +++ b/include/linux/jiffies.h @@ -297,6 +297,7 @@ static inline u64 jiffies_to_nsecs(const unsigned long j) } extern u64 jiffies64_to_nsecs(u64 j); +extern u64 jiffies64_to_msecs(u64 j); extern unsigned long __msecs_to_jiffies(const unsigned int m); #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) diff --git a/kernel/time/time.c b/kernel/time/time.c index 2edb5088a70b..0083eb711fb7 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -719,6 +719,16 @@ u64 jiffies64_to_nsecs(u64 j) } EXPORT_SYMBOL(jiffies64_to_nsecs); +u64 jiffies64_to_msecs(const u64 j) +{ +#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) + return (MSEC_PER_SEC / HZ) * j; +#else + return div_u64(j * HZ_TO_MSEC_NUM, HZ_TO_MSEC_DEN); +#endif +} +EXPORT_SYMBOL(jiffies64_to_msecs); + /** * nsecs_to_jiffies64 - Convert nsecs in u64 to jiffies64 *