Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp256765img; Wed, 27 Feb 2019 21:47:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IY4F6egQr06vMyzIVggxpqS8pccPWZ7Y9h9Y3G1R4r//RF0isnFlKZjFtZHNFZ/Qsqm1Dkg X-Received: by 2002:a17:902:8b83:: with SMTP id ay3mr5874965plb.1.1551332844980; Wed, 27 Feb 2019 21:47:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551332844; cv=none; d=google.com; s=arc-20160816; b=uwlF6neE3NJ73p2h5bUmPbB88WDgI+uvIYsJ+MLqJZK4Rh9HLrAQOeADDEK7V7s5G1 czI/2jiNoyxxD1pF8nqlWepZGnpEoTgbz4ltj0Bb6jVS28M/BP9bqEtPjkEtNWWDVHn/ AEjOR8mo+2dAKDMpu2hG92NDu5L1C2SHxNlTkgIb82lRzis+643VYV1B8nb4vUCq1RD+ 1ZtJd90ujr4Qo+vmad7351gRZMjt5cdzTaswzYR0iHCNigozp0UsN65nBFGGPweWlDzY 9Ov992y+wHGjVzYCKNl0xh72Dg8gxzdMTUC3XHg6RcuPZCsqjOXkXnDB+XPvdeda9+ha Cuug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from; bh=WVZx13G3oBbDtiLKvNopMMKCckB0O1HBegdU3huhZYw=; b=zpkVElBUo+M1O7q5yNgsF6xArCL+UJkEK4EfePdU4evjdC7CH4X8hqtA39VfqV9Rwp f8EKf0Vp0xiBaAtBFgq8e/hYpm5Vi1iOzBYZZlS5PoQ1KKpz+C92DK6F36JVspTCfuJa 8OGfBRdl6Y54DT1XKvIn8VTBc3pSvq/M+vHHSPRRF7jO/px0WLOqp/KspPDz9CPrJHUs 0OSNO2P9lX6oxVZYMkaJaYDCJQTqiKeXLnGHaR3pwnWHPHEwqJGScM4ZaSvPVNjKNCo9 mYSyJpaDM+T217YFoB3Uh8VyhOMMjq0PsE14UoeolbAUKF7WaLIAXXeRkr2y2qH5cSI1 8liw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2si6421233pgv.10.2019.02.27.21.46.38; Wed, 27 Feb 2019 21:47:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730638AbfB1FNl (ORCPT + 99 others); Thu, 28 Feb 2019 00:13:41 -0500 Received: from mx137-tc.baidu.com ([61.135.168.137]:33502 "EHLO tc-sys-mailedm05.tc.baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725899AbfB1FNl (ORCPT ); Thu, 28 Feb 2019 00:13:41 -0500 Received: from localhost (cp01-cos-dev01.cp01.baidu.com [10.92.119.46]) by tc-sys-mailedm05.tc.baidu.com (Postfix) with ESMTP id F3AF31EBA004; Thu, 28 Feb 2019 13:13:26 +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][v2] time: Introduce jiffies64_to_msecs() Date: Thu, 28 Feb 2019 13:13:26 +0800 Message-Id: <1551330806-12502-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org there is a similar helper in net/netfilter/nf_tables_api.c, this maybe become a common request someday, so move it to time.c Signed-off-by: Zhang Yu Signed-off-by: Li RongQing --- v1-->v2: using jiffies64_to_msecs in nf_tables_api.c include/linux/jiffies.h | 1 + kernel/time/time.c | 10 ++++++++++ net/netfilter/nf_tables_api.c | 4 +--- 3 files changed, 12 insertions(+), 3 deletions(-) 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 * diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index e1a88ba2249e..8763b2798788 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -3184,9 +3184,7 @@ static int nf_msecs_to_jiffies64(const struct nlattr *nla, u64 *result) static __be64 nf_jiffies64_to_msecs(u64 input) { - u64 ms = jiffies64_to_nsecs(input); - - return cpu_to_be64(div_u64(ms, NSEC_PER_MSEC)); + return cpu_to_be64(jiffies64_to_msecs(input)); } static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx, -- 2.16.2