[rtems commit] timecounter: Load the currently selected tc once in tc_windup()

Sebastian Huber sebh at rtems.org
Mon Nov 15 08:15:17 UTC 2021


Module:    rtems
Branch:    master
Commit:    c3a68059d8a9a149c5c82550f37316cc41e390ec
Changeset: http://git.rtems.org/rtems/commit/?id=c3a68059d8a9a149c5c82550f37316cc41e390ec

Author:    Mark Johnston <markj at FreeBSD.org>
Date:      Fri Oct 29 14:29:22 2021 -0400

timecounter: Load the currently selected tc once in tc_windup()

Reported by:	Sebastian Huber <sebastian.huber at embedded-brains.de>
Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32729

---

 cpukit/score/src/kern_tc.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
index a2e79b0..be3b4c2 100644
--- a/cpukit/score/src/kern_tc.c
+++ b/cpukit/score/src/kern_tc.c
@@ -127,6 +127,13 @@ atomic_store_rel_int(Atomic_Uint *i, u_int val)
 
 	_Atomic_Store_uint(i, val, ATOMIC_ORDER_RELEASE);
 }
+
+static inline void *
+atomic_load_ptr(void *ptr)
+{
+
+	return ((void *)_Atomic_Load_uintptr(ptr, ATOMIC_ORDER_RELAXED));
+}
 #endif /* __rtems__ */
 
 /*
@@ -1576,6 +1583,7 @@ _Timecounter_Windup(struct bintime *new_boottimebin,
 #endif /* __rtems__ */
 {
 	struct bintime bt;
+	struct timecounter *tc;
 	struct timehands *th, *tho;
 	uint32_t delta, ncount, ogen;
 	int i;
@@ -1610,9 +1618,10 @@ _Timecounter_Windup(struct bintime *new_boottimebin,
 	 * changing timecounters, a counter value from the new timecounter.
 	 * Update the offset fields accordingly.
 	 */
+	tc = atomic_load_ptr(&timecounter);
 	delta = tc_delta(th);
-	if (th->th_counter != timecounter)
-		ncount = timecounter->tc_get_timecount(timecounter);
+	if (th->th_counter != tc)
+		ncount = tc->tc_get_timecount(tc);
 	else
 		ncount = 0;
 #ifdef FFCLOCK
@@ -1678,20 +1687,20 @@ _Timecounter_Windup(struct bintime *new_boottimebin,
 	bintime2timespec(&bt, &th->th_nanotime);
 
 	/* Now is a good time to change timecounters. */
-	if (th->th_counter != timecounter) {
+	if (th->th_counter != tc) {
 #ifndef __rtems__
 #ifndef __arm__
-		if ((timecounter->tc_flags & TC_FLAGS_C2STOP) != 0)
+		if ((tc->tc_flags & TC_FLAGS_C2STOP) != 0)
 			cpu_disable_c2_sleep++;
 		if ((th->th_counter->tc_flags & TC_FLAGS_C2STOP) != 0)
 			cpu_disable_c2_sleep--;
 #endif
 #endif /* __rtems__ */
-		th->th_counter = timecounter;
+		th->th_counter = tc;
 		th->th_offset_count = ncount;
 #ifndef __rtems__
-		tc_min_ticktock_freq = max(1, timecounter->tc_frequency /
-		    (((uint64_t)timecounter->tc_counter_mask + 1) / 3));
+		tc_min_ticktock_freq = max(1, tc->tc_frequency /
+		    (((uint64_t)tc->tc_counter_mask + 1) / 3));
 #endif /* __rtems__ */
 		recalculate_scaling_factor_and_large_delta(th);
 #ifdef FFCLOCK



More information about the vc mailing list