Browse Source

[linux] Add timer

Add linux timer API.

Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Piotr Jaroszyński 14 years ago
parent
commit
01a4c244db

+ 1
- 0
src/config/defaults/linux.h View File

@@ -8,6 +8,7 @@
8 8
  */
9 9
 
10 10
 #define CONSOLE_LINUX
11
+#define TIMER_LINUX
11 12
 
12 13
 #define IMAGE_SCRIPT
13 14
 

+ 18
- 0
src/include/ipxe/linux/linux_timer.h View File

@@ -0,0 +1,18 @@
1
+#ifndef _IPXE_LINUX_TIMER_H
2
+#define _IPXE_LINUX_TIMER_H
3
+
4
+/** @file
5
+ *
6
+ * iPXE timer API for Linux
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#ifdef TIMER_LINUX
13
+#define TIMER_PREFIX_linux
14
+#else
15
+#define TIMER_PREFIX_linux __linux_
16
+#endif
17
+
18
+#endif /* _IPXE_LINUX_TIMER_H */

+ 1
- 0
src/include/ipxe/timer.h View File

@@ -45,6 +45,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
45 45
 
46 46
 /* Include all architecture-independent I/O API headers */
47 47
 #include <ipxe/efi/efi_timer.h>
48
+#include <ipxe/linux/linux_timer.h>
48 49
 
49 50
 /* Include all architecture-dependent I/O API headers */
50 51
 #include <bits/timer.h>

+ 80
- 0
src/interface/linux/linux_timer.c View File

@@ -0,0 +1,80 @@
1
+/*
2
+ * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
+ */
18
+
19
+FILE_LICENCE(GPL2_OR_LATER);
20
+
21
+#include <ipxe/timer.h>
22
+
23
+#include <linux_api.h>
24
+
25
+/** @file
26
+ *
27
+ * iPXE timer API for linux
28
+ *
29
+ */
30
+
31
+/**
32
+ * Delay for a fixed number of microseconds
33
+ *
34
+ * @v usecs		Number of microseconds for which to delay
35
+ */
36
+static void linux_udelay(unsigned long usecs)
37
+{
38
+	linux_usleep(usecs);
39
+}
40
+
41
+/**
42
+ * Get number of ticks per second
43
+ *
44
+ * @ret ticks_per_sec	Number of ticks per second
45
+ */
46
+static unsigned long linux_ticks_per_sec(void)
47
+{
48
+	return 1000;
49
+}
50
+
51
+/**
52
+ * Get current system time in ticks
53
+ *
54
+ * linux doesn't provide an easy access to jiffies so implement it by measuring
55
+ * the time since the first call to this function.
56
+ *
57
+ * @ret ticks		Current time, in ticks
58
+ */
59
+static unsigned long linux_currticks(void)
60
+{
61
+	static struct timeval start;
62
+	static int initialized = 0;
63
+
64
+	if (! initialized) {
65
+		linux_gettimeofday(&start, NULL);
66
+		initialized = 1;
67
+	}
68
+
69
+	struct timeval now;
70
+	linux_gettimeofday(&now, NULL);
71
+
72
+	unsigned long ticks = (now.tv_sec - start.tv_sec) * linux_ticks_per_sec();
73
+	ticks += (now.tv_usec - start.tv_usec) / (long)(1000000 / linux_ticks_per_sec());
74
+
75
+	return ticks;
76
+}
77
+
78
+PROVIDE_TIMER(linux, udelay, linux_udelay);
79
+PROVIDE_TIMER(linux, currticks, linux_currticks);
80
+PROVIDE_TIMER(linux, ticks_per_sec, linux_ticks_per_sec);

Loading…
Cancel
Save