-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathshannon_time.c
More file actions
132 lines (113 loc) · 2.77 KB
/
Copy pathshannon_time.c
File metadata and controls
132 lines (113 loc) · 2.77 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "shannon_time.h"
#include <linux/jiffies.h>
#include <linux/time.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/version.h>
#include <asm/param.h>
int get_HZ(void)
{
return HZ;
}
// timer.h
void shannon_init_timer(shannon_timer_list *timer)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
init_timer((struct timer_list *)timer);
((struct timer_list *)timer)->function = NULL;
#else
__init_timer((struct timer_list *)timer, NULL, 0);
#endif
}
void shannon_add_timer(shannon_timer_list *timer, unsigned long expires)
{
((struct timer_list *)timer)->expires = expires;
add_timer((struct timer_list *)timer);
}
int shannon_del_timer_sync(shannon_timer_list *timer)
{
return del_timer_sync((struct timer_list *)timer);
}
int shannon_del_timer(shannon_timer_list *timer)
{
return del_timer((struct timer_list *)timer);
}
int shannon_mod_timer(shannon_timer_list *timer, unsigned long expires)
{
return mod_timer((struct timer_list *)timer, expires);
}
int shannon_timer_pending(shannon_timer_list * timer)
{
return timer_pending((struct timer_list *)timer);
}
void shannon_set_timer_context(shannon_timer_list *timer, void (*f)(shannon_timer_list *))
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
((struct timer_list *)timer)->data = (unsigned long)timer;
((struct timer_list *)timer)->function = (void (*) (unsigned long))f;
#else
((struct timer_list *)timer)->function = (void (*) (struct timer_list *))f;
#endif
}
int shannon_timer_has_function(shannon_timer_list *timer)
{
return ((struct timer_list *)timer)->function ? 1 : 0;
}
// delay.h
void shannon_msleep(unsigned int msecs)
{
msleep(msecs);
}
void shannon_udelay(unsigned long usecs)
{
udelay(usecs);
}
unsigned long get_jiffies(void)
{
return jiffies;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
void shannon_getnstimeofday(struct shannon_timeval *tv)
{
struct timespec time;
getnstimeofday(&time);
tv->tv_sec = time.tv_sec;
tv->tv_usec = time.tv_nsec/1000;
}
#else
void shannon_getnstimeofday(struct shannon_timeval *tv)
{
struct timespec64 time;
ktime_get_real_ts64(&time);
tv->tv_sec = time.tv_sec;
tv->tv_usec = time.tv_nsec / 1000;
}
#endif
void shannon_do_gettimeofday(struct shannon_timeval *tv)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
struct timeval time;
do_gettimeofday(&time);
tv->tv_sec = time.tv_sec;
tv->tv_usec = time.tv_usec;
#else
shannon_getnstimeofday(tv);
#endif
}
// jiffies.h
unsigned int shannon_jiffies_to_msecs(const unsigned long j)
{
return jiffies_to_msecs(j);
}
unsigned int shannon_jiffies_to_usecs(const unsigned long j)
{
return jiffies_to_usecs(j);
}
unsigned long shannon_msecs_to_jiffies(const unsigned int m)
{
return msecs_to_jiffies(m);
}
unsigned long shannon_usecs_to_jiffies(const unsigned int u)
{
return usecs_to_jiffies(u);
}