Browse Source

[time] Add Linux time source using gettimeofday()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
6ed905aba2

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

15
 #define SMBIOS_LINUX
15
 #define SMBIOS_LINUX
16
 #define SANBOOT_NULL
16
 #define SANBOOT_NULL
17
 #define ENTROPY_LINUX
17
 #define ENTROPY_LINUX
18
-#define TIME_NULL
18
+#define TIME_LINUX
19
 
19
 
20
 #define DRIVERS_LINUX
20
 #define DRIVERS_LINUX
21
 
21
 

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

1
+#ifndef _IPXE_LINUX_TIME_H
2
+#define _IPXE_LINUX_TIME_H
3
+
4
+/** @file
5
+ *
6
+ * Linux time source
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#ifdef TIME_LINUX
13
+#define TIME_PREFIX_linux
14
+#else
15
+#define TIME_PREFIX_linux __linux_
16
+#endif
17
+
18
+#endif /* _IPXE_LINUX_TIME_H */

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

44
 
44
 
45
 /* Include all architecture-independent time API headers */
45
 /* Include all architecture-independent time API headers */
46
 #include <ipxe/null_time.h>
46
 #include <ipxe/null_time.h>
47
+#include <ipxe/linux/linux_time.h>
47
 
48
 
48
 /* Include all architecture-dependent time API headers */
49
 /* Include all architecture-dependent time API headers */
49
 #include <bits/time.h>
50
 #include <bits/time.h>

+ 0
- 1
src/include/linux_api.h View File

37
 #include <linux/types.h>
37
 #include <linux/types.h>
38
 #include <linux/posix_types.h>
38
 #include <linux/posix_types.h>
39
 typedef __kernel_pid_t pid_t;
39
 typedef __kernel_pid_t pid_t;
40
-typedef __kernel_time_t time_t;
41
 typedef __kernel_suseconds_t suseconds_t;
40
 typedef __kernel_suseconds_t suseconds_t;
42
 typedef __kernel_loff_t loff_t;
41
 typedef __kernel_loff_t loff_t;
43
 #include <linux/time.h>
42
 #include <linux/time.h>

+ 45
- 0
src/interface/linux/linux_time.c View File

1
+/*
2
+ * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
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 (at your option) 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 Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ */
19
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+/** @file
23
+ *
24
+ * Linux time source
25
+ *
26
+ */
27
+
28
+#include <stdint.h>
29
+#include <errno.h>
30
+#include <linux_api.h>
31
+#include <ipxe/time.h>
32
+
33
+/**
34
+ * Get current time in seconds
35
+ *
36
+ * @ret time		Time, in seconds
37
+ */
38
+static time_t linux_now ( void ) {
39
+	struct timeval now;
40
+
41
+	linux_gettimeofday ( &now, NULL );
42
+	return now.tv_sec;
43
+}
44
+
45
+PROVIDE_TIME ( linux, time_now, linux_now );

Loading…
Cancel
Save