Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Jun 2021 05:08:12 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: f027b4f41fb1 - stable/13 - vdso: lower precision of vdso implementation of CLOCK_MONOTONIC_FAST and CLOCK_UPTIME_FAST
Message-ID:  <202106300508.15U58CDJ097081@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=f027b4f41fb1b748070928175cdf2f57baf66c3a

commit f027b4f41fb1b748070928175cdf2f57baf66c3a
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-06-22 23:24:08 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-06-30 04:42:06 +0000

    vdso: lower precision of vdso implementation of CLOCK_MONOTONIC_FAST and CLOCK_UPTIME_FAST
    
    (cherry picked from commit 60b0ad10dd0fc7ff6892ecc7ba3458482fcc064c)
---
 lib/libc/sys/__vdso_gettimeofday.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/libc/sys/__vdso_gettimeofday.c b/lib/libc/sys/__vdso_gettimeofday.c
index 4c1f4bda23e1..c1457a54d37e 100644
--- a/lib/libc/sys/__vdso_gettimeofday.c
+++ b/lib/libc/sys/__vdso_gettimeofday.c
@@ -106,6 +106,30 @@ binuptime(struct bintime *bt, struct vdso_timekeep *tk, bool abs)
 	return (0);
 }
 
+static int
+getnanouptime(struct bintime *bt, struct vdso_timekeep *tk)
+{
+	struct vdso_timehands *th;
+	uint32_t curr, gen;
+
+	do {
+		if (!tk->tk_enabled)
+			return (ENOSYS);
+
+		curr = atomic_load_acq_32(&tk->tk_current);
+		th = &tk->tk_th[curr];
+		gen = atomic_load_acq_32(&th->th_gen);
+		*bt = th->th_offset;
+
+		/*
+		 * Ensure that the load of th_offset is completed
+		 * before the load of th_gen.
+		 */
+		atomic_thread_fence_acq();
+	} while (curr != tk->tk_current || gen == 0 || gen != th->th_gen);
+	return (0);
+}
+
 static struct vdso_timekeep *tk;
 
 #pragma weak __vdso_gettimeofday
@@ -154,9 +178,11 @@ __vdso_clock_gettime(clockid_t clock_id, struct timespec *ts)
 		break;
 	case CLOCK_MONOTONIC:
 	case CLOCK_MONOTONIC_PRECISE:
-	case CLOCK_MONOTONIC_FAST:
 	case CLOCK_UPTIME:
 	case CLOCK_UPTIME_PRECISE:
+		error = binuptime(&bt, tk, false);
+		break;
+	case CLOCK_MONOTONIC_FAST:
 	case CLOCK_UPTIME_FAST:
 		error = getnanouptime(&bt, tk);
 		break;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106300508.15U58CDJ097081>