aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-dpdk/include/odp/api/plat/time_inlines.h
blob: 6c14d6c40b54698630f033813322b39bcfea400b (plain)
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
/* Copyright (c) 2018, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

#ifndef ODP_PLAT_TIME_INLINES_H_
#define ODP_PLAT_TIME_INLINES_H_

#include <stdint.h>

#include <odp/api/align.h>

#include <odp/api/abi/cpu_time.h>

/** @cond _ODP_HIDE_FROM_DOXYGEN_ */

#define _ODP_TIMESPEC_SIZE 16

typedef odp_time_t (*time_cur_fn)(void);
typedef uint64_t (*time_res_fn)(void);

typedef struct time_handler_ {
	time_cur_fn     time_cur;
	time_res_fn     time_res;

} time_handler_t;

typedef struct _odp_time_global_t {
	/* Storage space for struct timespec. Posix headers are not included
	 * here to avoid application exposure. */
	uint8_t ODP_ALIGNED(_ODP_TIMESPEC_SIZE) timespec[_ODP_TIMESPEC_SIZE];

	int             use_hw;
	uint64_t        hw_start;
	uint64_t        hw_freq_hz;
	/* DPDK specific */
	time_handler_t  handler;

} _odp_time_global_t;

extern _odp_time_global_t _odp_time_glob;

odp_time_t _odp_timespec_cur(void);

static inline odp_time_t _odp_time_cur_gen(void)
{
	if (_odp_time_glob.use_hw) {
		odp_time_t time;

		time.count = _odp_cpu_global_time() - _odp_time_glob.hw_start;
		return time;
	}

	return _odp_timespec_cur();
}

static inline odp_time_t _odp_time_cur(void)
{
	return _odp_time_glob.handler.time_cur();
}

#ifndef _ODP_NO_INLINE
	/* Inline functions by default */
	#define _ODP_INLINE static inline
	#define odp_time_local   __odp_time_local
	#define odp_time_global  __odp_time_global
#else
	#define _ODP_INLINE
#endif

_ODP_INLINE odp_time_t odp_time_local(void)
{
	return _odp_time_cur();
}

_ODP_INLINE odp_time_t odp_time_global(void)
{
	return _odp_time_cur();
}

/** @endcond */

#endif