-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.c
executable file
·53 lines (47 loc) · 1019 Bytes
/
timer.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "timer.h"
t_timer* timer_init(int val,void (*handler)(void*),void* handler_arg,void* ref)
{
t_timer* timer = NULL;
timer = kmalloc(sizeof(t_timer));
timer->val = val;
timer->handler = handler;
timer->handler_arg = handler_arg;
timer->ref = ref;
}
void timer_free(t_timer* timer)
{
if (timer->ref != NULL)
{
ll_delete_node(timer->ref);
timer->ref = NULL;
}
kfree(timer);
}
void timer_set(t_timer* timer,long val)
{
if (timer->ref == NULL)
{
timer->val = val;
timer->ref = ll_append(system.timer_list,timer);
}
else
{
timer->val = val;
}
}
void timer_reset(t_timer* timer)
{
if (timer->ref != NULL)
{
ll_delete_node(timer->ref);
timer->ref = NULL;
timer->val = 0;
}
}
void rdtscl(unsigned long long *ll)
//inline static __attribute__((always_inline)) void rdtscl(unsigned long long *ll)
{
unsigned int lo, hi;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
*ll = ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
}