Date: Tue, 9 Jun 2015 14:28:37 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Sebastian Huber <sebastian.huber@embedded-brains.de> Cc: freebsd-hackers@freebsd.org, phk@phk.freebsd.dk Subject: Re: [PATCH v3] timecounters: Fix timehand generation read/write Message-ID: <20150609112837.GL2499@kib.kiev.ua> In-Reply-To: <5576C90A.9010807@embedded-brains.de> References: <1433331966-27548-1-git-send-email-sebastian.huber@embedded-brains.de> <1433838715-22850-1-git-send-email-sebastian.huber@embedded-brains.de> <20150609105526.GK2499@kib.kiev.ua> <5576C90A.9010807@embedded-brains.de>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jun 09, 2015 at 01:07:54PM +0200, Sebastian Huber wrote:
> You still need the compiler memory barriers in the UP case (at least
> with GCC 4.9 on PowerPC), e.g. something like this:
Fair.
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index 9dca0e8..01c61bd 100644
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -189,6 +190,33 @@ tc_delta(struct timehands *th)
tc->tc_counter_mask);
}
+static u_int
+tc_getgen(struct timehands *th)
+{
+
+#ifdef SMP
+ return (atomic_load_acq_int(&th->th_generation));
+#else
+ u_int gen;
+
+ gen = th->th_generation;
+ __compiler_membar();
+ return (gen);
+#endif
+}
+
+static void
+tc_setgen(struct timehands *th, u_int newgen)
+{
+
+#ifdef SMP
+ atomic_store_rel_int(&th->th_generation, newgen);
+#else
+ __compiler_membar();
+ th->th_generation = newgen;
+#endif
+}
+
/*
* Functions for reading the time. We have to loop until we are sure that
* the timehands that we operated on was not updated under our feet. See
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150609112837.GL2499>
