1*6527ec4eSchristos /* $NetBSD: getsecs.c,v 1.11 2013/11/03 01:02:37 christos Exp $ */ 2015e898cSperry 38644dce0Scgd #include <sys/param.h> 46774aca1Sthorpej 51e3d90c8She #include <machine/cpu.h> 66774aca1Sthorpej #include <netinet/in.h> 76774aca1Sthorpej #include <netinet/in_systm.h> 86774aca1Sthorpej 96774aca1Sthorpej #include <lib/libsa/stand.h> 106774aca1Sthorpej #include <lib/libsa/net.h> 116774aca1Sthorpej 128644dce0Scgd #include "include/prom.h" 138644dce0Scgd #include "include/rpb.h" 148644dce0Scgd 1569cf32a7Stsutsui satime_t getsecs(void)166774aca1Sthorpejgetsecs(void) 178644dce0Scgd { 18ab4ced3eStsutsui static uint64_t tnsec; 19*6527ec4eSchristos static uint64_t lastpcc; 20ab4ced3eStsutsui uint64_t curpcc; 218644dce0Scgd 228644dce0Scgd if (tnsec == 0) { 238644dce0Scgd tnsec = 1; 248644dce0Scgd lastpcc = alpha_rpcc() & 0xffffffff; 258644dce0Scgd 263bd3e625Scgd #if 0 27*6527ec4eSchristos uint64_t wrapsecs = (0xffffffff / 28*6527ec4eSchristos ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq) + 1; 29ab4ced3eStsutsui printf("getsecs: cc freq = %lu, time to wrap = %lu\n", 308644dce0Scgd ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq, wrapsecs); 313bd3e625Scgd #endif 328644dce0Scgd } 338644dce0Scgd 348644dce0Scgd curpcc = alpha_rpcc() & 0xffffffff; 358644dce0Scgd if (curpcc < lastpcc) 368644dce0Scgd curpcc += 0x100000000; 378644dce0Scgd 388644dce0Scgd tnsec += ((curpcc - lastpcc) * 1000000000) / ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq; 398644dce0Scgd lastpcc = curpcc; 408644dce0Scgd 418644dce0Scgd return (tnsec / 1000000000); 428644dce0Scgd } 43