blob: fa59f5a1595cf43098cdf53619833ffe456346ed (
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
|
/* Copyright (c) 2015-2018, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <odp_posix_extensions.h>
#include <time.h>
#include <odp_debug_internal.h>
#include <odp/api/abi/cpu_time.h>
#include <odp/visibility_begin.h>
uint64_t _odp_cpu_global_time(void)
{
uint64_t cntvct;
/*
* To be consistent with other architectures, do not issue a
* serializing instruction, e.g. ISB, before reading this
* sys reg.
*/
/* Memory clobber to minimize optimization around load from sys reg. */
__asm__ volatile("mrs %0, cntvct_el0" : "=r"(cntvct) : : "memory");
return cntvct;
}
#include <odp/visibility_end.h>
int _odp_cpu_has_global_time(void)
{
uint64_t hz = _odp_cpu_global_time_freq();
/*
* The system counter portion of the architected timer must
* provide a uniform view of system time to all processing
* elements in the system. This should hold true even for
* heterogeneous SoCs.
*
* Determine whether the system has 'global time' by checking
* whether a read of the architected timer frequency sys reg
* returns a sane value. Sane is considered to be within
* 1MHz and 6GHz (1us and .1667ns period).
*/
return hz >= 1000000 && hz <= 6000000000;
}
uint64_t _odp_cpu_global_time_freq(void)
{
uint64_t cntfrq;
__asm__ volatile("mrs %0, cntfrq_el0" : "=r"(cntfrq) : : );
return cntfrq;
}
|