xref: /minix3/minix/lib/libsys/arch/earm/tsc_util.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc 
2*433d6423SLionel Sambuc #include <stdio.h>
3*433d6423SLionel Sambuc #include <time.h>
4*433d6423SLionel Sambuc #include <sys/times.h>
5*433d6423SLionel Sambuc #include <sys/types.h>
6*433d6423SLionel Sambuc #include <minix/u64.h>
7*433d6423SLionel Sambuc #include <minix/config.h>
8*433d6423SLionel Sambuc #include <minix/const.h>
9*433d6423SLionel Sambuc #include <minix/minlib.h>
10*433d6423SLionel Sambuc #include <machine/archtypes.h>
11*433d6423SLionel Sambuc 
12*433d6423SLionel Sambuc #include "sysutil.h"
13*433d6423SLionel Sambuc 
14*433d6423SLionel Sambuc #ifndef CONFIG_MAX_CPUS
15*433d6423SLionel Sambuc #define CONFIG_MAX_CPUS 1
16*433d6423SLionel Sambuc #endif
17*433d6423SLionel Sambuc 
18*433d6423SLionel Sambuc #define MICROHZ		1000000		/* number of micros per second */
19*433d6423SLionel Sambuc #define MICROSPERTICK(h)	(MICROHZ/(h))	/* number of micros per HZ tick */
20*433d6423SLionel Sambuc 
21*433d6423SLionel Sambuc static u32_t calib_hz = 600000000;
22*433d6423SLionel Sambuc 
tsc_64_to_micros(u64_t tsc)23*433d6423SLionel Sambuc u32_t tsc_64_to_micros(u64_t tsc)
24*433d6423SLionel Sambuc {
25*433d6423SLionel Sambuc 	u64_t tmp;
26*433d6423SLionel Sambuc 
27*433d6423SLionel Sambuc 	tmp =  tsc / calib_hz;
28*433d6423SLionel Sambuc 	return (u32_t) tmp;
29*433d6423SLionel Sambuc }
30*433d6423SLionel Sambuc 
tsc_to_micros(u32_t low,u32_t high)31*433d6423SLionel Sambuc u32_t tsc_to_micros(u32_t low, u32_t high)
32*433d6423SLionel Sambuc {
33*433d6423SLionel Sambuc 	return tsc_64_to_micros(make64(low, high));
34*433d6423SLionel Sambuc }
35*433d6423SLionel Sambuc 
36