linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "tip-bot2 for Arnd Bergmann" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Arnd Bergmann <arnd@arndb.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
	linux-kernel@vger.kernel.org
Subject: [tip: timers/core] time: Optimize ns_to_timespec64()
Date: Tue, 12 Nov 2019 07:22:44 -0000	[thread overview]
Message-ID: <157354336402.29376.17172070392776098039.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20191108203435.112759-3-arnd@arndb.de>

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     20d087368d38c7350a4519a3b316ef7eb2504692
Gitweb:        https://git.kernel.org/tip/20d087368d38c7350a4519a3b316ef7eb2504692
Author:        Arnd Bergmann <arnd@arndb.de>
AuthorDate:    Fri, 08 Nov 2019 21:34:25 +01:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Tue, 12 Nov 2019 08:15:15 +01:00

time: Optimize ns_to_timespec64()

ns_to_timespec64() calls div_s64_rem(), which is a rather slow function on
32-bit architectures, as it cannot take advantage of the do_div()
optimizations for constant arguments.

Open-code the div_s64_rem() function in ns_to_timespec64(), so a constant
divider can be passed into the optimized div_u64_rem() function.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20191108203435.112759-3-arnd@arndb.de
---
 kernel/time/time.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/kernel/time/time.c b/kernel/time/time.c
index 5c54ca6..45a3589 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -550,18 +550,21 @@ EXPORT_SYMBOL(set_normalized_timespec64);
  */
 struct timespec64 ns_to_timespec64(const s64 nsec)
 {
-	struct timespec64 ts;
+	struct timespec64 ts = { 0, 0 };
 	s32 rem;
 
-	if (!nsec)
-		return (struct timespec64) {0, 0};
-
-	ts.tv_sec = div_s64_rem(nsec, NSEC_PER_SEC, &rem);
-	if (unlikely(rem < 0)) {
-		ts.tv_sec--;
-		rem += NSEC_PER_SEC;
+	if (likely(nsec > 0)) {
+		ts.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
+		ts.tv_nsec = rem;
+	} else if (nsec < 0) {
+		/*
+		 * With negative times, tv_sec points to the earlier
+		 * second, and tv_nsec counts the nanoseconds since
+		 * then, so tv_nsec is always a positive number.
+		 */
+		ts.tv_sec = -div_u64_rem(-nsec - 1, NSEC_PER_SEC, &rem) - 1;
+		ts.tv_nsec = NSEC_PER_SEC - rem - 1;
 	}
-	ts.tv_nsec = rem;
 
 	return ts;
 }

  parent reply	other threads:[~2019-11-12  7:22 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-08 20:34 [PATCH 0/8] y2038: bug fixes from y2038 work Arnd Bergmann
2019-11-08 20:34 ` [PATCH 1/8] y2038: timex: remove incorrect time_t truncation Arnd Bergmann
2019-11-10 20:44   ` Deepa Dinamani
2019-11-12  7:16   ` [tip: timers/urgent] ntp/y2038: Remove " tip-bot2 for Arnd Bergmann
2019-11-08 20:34 ` [PATCH 2/8] timekeeping: optimize ns_to_timespec64 Arnd Bergmann
2019-11-10 20:46   ` Deepa Dinamani
2019-11-12  7:22   ` tip-bot2 for Arnd Bergmann [this message]
2019-11-08 20:34 ` [PATCH 3/8] powerpc: fix vdso32 for ppc64le Arnd Bergmann
2019-11-20 19:13   ` [Y2038] " Ben Hutchings
2019-11-20 19:35     ` Arnd Bergmann
2019-11-20 21:49       ` Ben Hutchings
2019-11-21 10:02         ` Arnd Bergmann
2019-11-21 15:56           ` Ben Hutchings
2019-11-08 20:34 ` [PATCH 4/8] ipmi: kill off 'timespec' usage again Arnd Bergmann
2019-11-08 22:11   ` Corey Minyard
2019-11-09 11:23     ` Arnd Bergmann
2019-11-08 20:34 ` [PATCH 5/8] netfilter: xt_time: use time64_t Arnd Bergmann
2019-11-15 22:43   ` Pablo Neira Ayuso
2019-11-08 20:34 ` [PATCH 6/8] lp: fix sparc64 LPSETTIMEOUT ioctl Arnd Bergmann
2019-11-20 19:27   ` [Y2038] " Ben Hutchings
2019-11-20 19:46     ` Arnd Bergmann
2019-11-20 22:10       ` Ben Hutchings
2019-11-21 14:04         ` Arnd Bergmann
2019-11-21 16:00           ` Ben Hutchings
2019-11-08 20:34 ` [PATCH 7/8] ppdev: fix PPGETTIME/PPSETTIME ioctls Arnd Bergmann
2019-11-20 19:29   ` [Y2038] " Ben Hutchings
2019-11-21 14:06     ` Arnd Bergmann
2019-11-08 20:34 ` [PATCH 8/8] Input: input_event: fix struct padding on sparc64 Arnd Bergmann
2019-11-11 18:28   ` Dmitry Torokhov
2019-11-11 19:18     ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=157354336402.29376.17172070392776098039.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).