summaryrefslogtreecommitdiff
path: root/minix/lib/libsys/sys_hz.c
blob: 1f2c776585e8ee2d6381f5deb477b9d3e2cc0713 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <minix/u64.h>
#include <minix/config.h>
#include <minix/const.h>

#include "sysutil.h"

static u32_t Hz;

u32_t
sys_hz(void)
{
	if(Hz <= 0) {
		int r;
		/* Get HZ. */
		if((r=sys_getinfo(GET_HZ, &Hz, sizeof(Hz), 0, 0)) != OK) {
			Hz = DEFAULT_HZ;
			printf("sys_hz: can not get HZ: error %d.\nUsing default HZ = %u\n",
			    r, (unsigned int) Hz);
		}
	}

	return Hz;
}

u32_t
micros_to_ticks(u32_t micros)
{
        u32_t ticks;

        ticks = (u32_t)(((u64_t)micros * sys_hz()) / 1000000);
        if(ticks < 1) ticks = 1;

        return ticks;
}