1 /* $NetBSD: getsecs.c,v 1.11 2013/11/03 01:02:37 christos Exp $ */ 2 3 #include <sys/param.h> 4 5 #include <machine/cpu.h> 6 #include <netinet/in.h> 7 #include <netinet/in_systm.h> 8 9 #include <lib/libsa/stand.h> 10 #include <lib/libsa/net.h> 11 12 #include "include/prom.h" 13 #include "include/rpb.h" 14 15 satime_t getsecs(void)16getsecs(void) 17 { 18 static uint64_t tnsec; 19 static uint64_t lastpcc; 20 uint64_t curpcc; 21 22 if (tnsec == 0) { 23 tnsec = 1; 24 lastpcc = alpha_rpcc() & 0xffffffff; 25 26 #if 0 27 uint64_t wrapsecs = (0xffffffff / 28 ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq) + 1; 29 printf("getsecs: cc freq = %lu, time to wrap = %lu\n", 30 ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq, wrapsecs); 31 #endif 32 } 33 34 curpcc = alpha_rpcc() & 0xffffffff; 35 if (curpcc < lastpcc) 36 curpcc += 0x100000000; 37 38 tnsec += ((curpcc - lastpcc) * 1000000000) / ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq; 39 lastpcc = curpcc; 40 41 return (tnsec / 1000000000); 42 } 43