1 /*
2  * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*
8  * @file	linux/time.c
9  * @brief	Linux libmetal time handling.
10  */
11 
12 #include <unistd.h>
13 #include <time.h>
14 #include <metal/time.h>
15 
16 #define NS_PER_S        (1000 * 1000 * 1000)
17 
metal_get_timestamp(void)18 unsigned long long metal_get_timestamp(void)
19 {
20 	unsigned long long t = 0;
21 	struct timespec tp;
22 	int r;
23 
24 	r = clock_gettime(CLOCK_MONOTONIC, &tp);
25 	if (r == -1) {
26 		metal_log(METAL_LOG_ERROR, "clock_gettime failed!\n");
27 		return t;
28 	}
29 	t = tp.tv_sec * (NS_PER_S);
30 	t += tp.tv_nsec;
31 
32 	return t;
33 }
34 
35