This is macppc, goes on top of your diff from
Thu, 11 Jun 2020 16:27:03 +0300.

Do integrate this small diff into your big diff.  If you need to
change the macppc code but can't build it, then do the change, and
allow me or someone else to build it.  I'm gkoehler@.

macppc is a simple arch: there is only 1 timecounter, where
tk->tk_user == 1; and we will probably never add another timecounter.
The pointer _tc_get_timecount seems unnecessary, because macppc never
sets the pointer to NULL.  The function tc_get_timecount might work as
a static inline function, but then it would need to be in a header
(libc/arch/powerpc/usertc.h?) and not in usertc.c.

I don't check tk->tk_count.  If the count is 2 or 3, then we can
ignore it, because we only handle tk->tk_user == 1.  If the count is
0, then the kernel should not give us a timekeep page with
tk->tk_user == 1.  I don't know that tk->tk_count needs to exist.

I don't check tc == NULL (but you do in amd64).  The only caller
tc_delta() in libc/sys/microtime.c never passes NULL.

In my last mail (31 May), I wanted to #include <machine/cpu.h> and
call ppc_mftb().  I change my mind.  It is more difficult to change
the kernel headers to expose ppc_mftb() outside _KERNEL, and easier
to copy the __asm, so I copy the __asm.    --George

--- lib/libc/arch/powerpc/gen/usertc.c.before   Sat Jun 13 21:28:50 2020
+++ lib/libc/arch/powerpc/gen/usertc.c  Sat Jun 13 21:38:52 2020
@@ -18,4 +18,19 @@
 #include <sys/types.h>
 #include <sys/timetc.h>
 
-int (*const _tc_get_timecount)(struct timekeep *, uint64_t *) = NULL;
+int
+tc_get_timecount(struct timekeep *tk, uint64_t *tc)
+{
+       uint64_t tb;
+       uint32_t scratch;
+
+       if (tk->tk_user != 1)
+               return -1;
+
+       __asm volatile ("1: mftbu %0; mftb %L0; mftbu %1;"
+           " cmpw 0,%0,%1; bne 1b" : "=r"(tb), "=r"(scratch));
+       *tc = tb;
+       return 0;
+}
+int (*const _tc_get_timecount)(struct timekeep *, uint64_t *)
+       = tc_get_timecount;
--- sys/arch/macppc/macppc/machdep.c.before     Sat Jun 13 18:07:27 2020
+++ sys/arch/macppc/macppc/machdep.c    Sat Jun 13 18:07:38 2020
@@ -351,7 +351,7 @@
 }
 
 /* timekeep number of user accesible clocks */
-int tk_nclocks = 0;
+int tk_nclocks = 1;
 
 /*
  * safepri is a safe priority for sleep to set for a spin-wait
--- sys/arch/macppc/macppc/clock.c.before       Sat Jun 13 18:39:58 2020
+++ sys/arch/macppc/macppc/clock.c      Sat Jun 13 18:40:10 2020
@@ -57,7 +57,7 @@
 static int32_t ticks_per_intr;
 
 static struct timecounter tb_timecounter = {
-       tb_get_timecount, NULL, 0x7fffffff, 0, "tb", 0, NULL, 0
+       tb_get_timecount, NULL, 0x7fffffff, 0, "tb", 0, NULL, 1
 };
 
 /* calibrate the timecounter frequency for the listed models */

Reply via email to