Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1579982img; Wed, 27 Feb 2019 01:40:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IZUNgHZd3BNK3DGS/LIG7jByJAS8deYWOgKlqu8Cdu+wRJATwsUDKSs6F3EVOCoE5a3IvXH X-Received: by 2002:a17:902:509:: with SMTP id 9mr1200706plf.94.1551260455340; Wed, 27 Feb 2019 01:40:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551260455; cv=none; d=google.com; s=arc-20160816; b=JnkLkTE+65hdX7129bHlDcXrglI1oN71FfeP34RUz3WpuFRxpMx9KdqiAQznqpM/Ix 3QKvO3uSblQ4E9FTFib+xB06x0nmAHyd3P742V/BQuA8HW6EDkrnSbQLT6BmqfU+h0oP 3GIXOQTBwCNCROiS6/E0wSln2cbrNgdxI9C+AH14gsMrFDSi5cIk4Y3a2+Jjbn+CZHvY g1JescW6UrVNbnvKwSbmuSkSAQ50hpGloJ6oVTlg28Y8xP7roC8LFN5EIZhuIUftjUMD bog9vwDAeTHZkbg1fYR+5T5Bb5DmU/S/+1V2sTHrgQnGoAoEw5xNTq8wDMEmk9T5pDXi f+yw== 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=sPjUuGeM/S2fcL9kybP996ztJXQdQo0zDqWGPYai/Z0=; b=y5CHxQ6bwTugttMHYTJ6ajXHtiYCjUCNlTUCSKrY+rksN6tLDU65g2FdJeRDTjuTxK m8sDU92OmmkDoPEdBXb545Nt+ffVOK2gg1Uw5g23rHyOIvgNJCJ5VPvVfURzuaupW2bW FbviGtOhJI/n+3CMiirq4KAu3tgJZmtl9vdiGfuTllEhlZIdb1In1lSSENuZQc8ELRk4 vW4YSqlhKm1L4ydtmBPw76RLfvU60BouySBrT2V62VQT7RZbhEAHIDjjOhU6G9yHwttU Hh/HChXbPddKkeeZ8P6WkkM/+fcx70lv2W7OHut2vX1IGwDeU2+Z8XpGMV32gqGeYmV8 Yspg== 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 gn8si15074407plb.321.2019.02.27.01.40.40; Wed, 27 Feb 2019 01:40:55 -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 S1729015AbfB0Jit (ORCPT + 99 others); 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: 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. 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 * -- 2.16.2