Skip to content

Instantly share code, notes, and snippets.

@ryo
Created November 11, 2018 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryo/89faf74852c20a84af17a12704fe3e16 to your computer and use it in GitHub Desktop.
Save ryo/89faf74852c20a84af17a12704fe3e16 to your computer and use it in GitHub Desktop.
cvs -q diff -aup gtmr.c
Index: gtmr.c
===================================================================
RCS file: /src/cvs/cvsroot-netbsd/src/sys/arch/arm/cortex/gtmr.c,v
retrieving revision 1.37
diff -a -u -p -r1.37 gtmr.c
--- gtmr.c 30 Oct 2018 10:38:11 -0000 1.37
+++ gtmr.c 31 Oct 2018 06:13:06 -0000
@@ -315,6 +315,34 @@ gtmr_intr(void *arg)
return 1;
}
+void gtmr_fixup(void); /* if you want fixup from ddb, "call gtmr_fixup" */
+
+void
+gtmr_fixup(void)
+{
+ struct gtmr_softc * const sc = &gtmr_sc;
+ uint64_t now;
+ int s;
+
+ if (sc->sc_autoinc == 0)
+ return;
+
+ s = splclock();
+
+ now = gtmr_read_cntvct(sc);
+ if (now < curcpu()->ci_lastintr) {
+ printf("cpu%d: detect cntvc was rollbacked: "
+ "0x%"PRIx64" -> 0x%"PRIx64" (%+"PRId64"). fixup\n",
+ curcpu()->ci_index,
+ curcpu()->ci_lastintr, now, now - curcpu()->ci_lastintr);
+
+ curcpu()->ci_lastintr = now;
+ gtmr_cntv_tval_write(sc->sc_autoinc);
+ }
+
+ splx(s);
+}
+
void
setstatclockrate(int newhz)
{
@@ -325,5 +353,6 @@ gtmr_get_timecount(struct timecounter *t
{
struct gtmr_softc * const sc = tc->tc_priv;
arm_isb(); // we want the time NOW, not some instructions later.
+ gtmr_fixup();
return (u_int) gtmr_read_cntvct(sc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment