forked from shenango/caladan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhw_timestamp.h
55 lines (43 loc) · 1.02 KB
/
hw_timestamp.h
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
/*
* hw_timestamp.h - methods for tracking hardware timestamps in MLX5
*/
#ifdef MLX5
#include <infiniband/mlx5dv.h>
#include <util/mmio.h>
#include "defs.h"
extern double device_us_per_cycle;
extern uint32_t curr_hw_time;
extern void *hca_core_clock;
static inline bool is_hw_timestamp_enabled()
{
return !cfg.no_hw_qdel;
}
static inline void hw_timestamp_update(void)
{
if (cfg.no_hw_qdel)
return;
/* read the low 32 bits of the hardware counter */
curr_hw_time = be32toh(mmio_read32_be(hca_core_clock + 4));
}
static inline uint64_t hw_timestamp_delay_us(struct mlx5_cqe64 *cqe)
{
double us;
uint32_t hwstamp = (uint32_t)be64toh(ACCESS_ONCE(cqe->timestamp));
if (wraps_lte(hwstamp, curr_hw_time)) {
us = (double)(curr_hw_time - hwstamp) * device_us_per_cycle;
return us;
}
return 0;
}
#else
struct mlx5_cqe64;
static inline bool is_hw_timestamp_enabled()
{
return false;
}
static inline void hw_timestamp_update(void) {}
static inline uint64_t hw_timestamp_delay_us(struct mlx5_cqe64 *cqe)
{
return 0;
}
#endif