Skip to content

Commit 5dec235

Browse files
nashifMaureenHelm
authored andcommitted
arch: default timings for all architectures
Use default if architecture does not have a custom timing implementation. Signed-off-by: Anas Nashif <[email protected]>
1 parent 0ffcfa9 commit 5dec235

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

arch/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ config X86
4545
select CPU_HAS_MMU
4646
select ARCH_MEM_DOMAIN_SYNCHRONOUS_API if USERSPACE
4747
select ARCH_HAS_GDBSTUB if !X86_64
48+
select ARCH_HAS_TIMING_FUNCTIONS
4849
help
4950
x86 architecture
5051

@@ -385,6 +386,9 @@ endmenu
385386
# Architecture Capabilities
386387
#
387388

389+
config ARCH_HAS_TIMING_FUNCTIONS
390+
bool
391+
388392
config ARCH_HAS_TRUSTED_EXECUTION
389393
bool
390394

arch/common/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ if(CONFIG_GEN_ISR_TABLES OR CONFIG_EXECUTION_BENCHMARKING)
1414
)
1515
endif()
1616

17+
if(NOT CONFIG_ARCH_HAS_TIMING_FUNCTIONS AND
18+
NOT CONFIG_SOC_HAS_TIMING_FUNCTIONS AND
19+
NOT CONFIG_BOARD_HAS_TIMING_FUNCTIONS)
20+
zephyr_library_sources_ifdef(CONFIG_TIMING_FUNCTIONS timing.c)
21+
endif()
22+
1723
# Put functions and data in their own binary sections so that ld can
1824
# garbage collect them
1925
zephyr_cc_option(-ffunction-sections -fdata-sections)

arch/common/timing.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2020 Intel Corporation.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <kernel.h>
8+
#include <sys_clock.h>
9+
#include <timing/timing.h>
10+
11+
void timing_init(void)
12+
{
13+
}
14+
15+
void timing_start(void)
16+
{
17+
}
18+
19+
void timing_stop(void)
20+
{
21+
}
22+
23+
timing_t timing_counter_get(void)
24+
{
25+
return k_cycle_get_32();
26+
}
27+
28+
uint64_t timing_cycles_get(volatile timing_t *const start,
29+
volatile timing_t *const end)
30+
{
31+
return (*end - *start);
32+
}
33+
34+
35+
uint64_t timing_freq_get(void)
36+
{
37+
return sys_clock_hw_cycles_per_sec();
38+
}
39+
40+
uint64_t timing_cycles_to_ns(uint64_t cycles)
41+
{
42+
return k_cyc_to_ns_floor64(cycles);
43+
}
44+
45+
uint64_t timing_cycles_to_ns_avg(uint64_t cycles, uint32_t count)
46+
{
47+
return timing_cycles_to_ns(cycles) / count;
48+
}
49+
50+
uint32_t timing_freq_get_mhz(void)
51+
{
52+
return (uint32_t)(timing_freq_get() / 1000000);
53+
}

0 commit comments

Comments
 (0)