arch: default timings for all architectures

Use default if architecture does not have a custom timing
implementation.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2020-08-27 23:07:01 -04:00 committed by Maureen Helm
commit 5dec235196
3 changed files with 63 additions and 0 deletions

View file

@ -45,6 +45,7 @@ config X86
select CPU_HAS_MMU
select ARCH_MEM_DOMAIN_SYNCHRONOUS_API if USERSPACE
select ARCH_HAS_GDBSTUB if !X86_64
select ARCH_HAS_TIMING_FUNCTIONS
help
x86 architecture
@ -385,6 +386,9 @@ endmenu
# Architecture Capabilities
#
config ARCH_HAS_TIMING_FUNCTIONS
bool
config ARCH_HAS_TRUSTED_EXECUTION
bool

View file

@ -14,6 +14,12 @@ if(CONFIG_GEN_ISR_TABLES OR CONFIG_EXECUTION_BENCHMARKING)
)
endif()
if(NOT CONFIG_ARCH_HAS_TIMING_FUNCTIONS AND
NOT CONFIG_SOC_HAS_TIMING_FUNCTIONS AND
NOT CONFIG_BOARD_HAS_TIMING_FUNCTIONS)
zephyr_library_sources_ifdef(CONFIG_TIMING_FUNCTIONS timing.c)
endif()
# Put functions and data in their own binary sections so that ld can
# garbage collect them
zephyr_cc_option(-ffunction-sections -fdata-sections)

53
arch/common/timing.c Normal file
View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2020 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <sys_clock.h>
#include <timing/timing.h>
void timing_init(void)
{
}
void timing_start(void)
{
}
void timing_stop(void)
{
}
timing_t timing_counter_get(void)
{
return k_cycle_get_32();
}
uint64_t timing_cycles_get(volatile timing_t *const start,
volatile timing_t *const end)
{
return (*end - *start);
}
uint64_t timing_freq_get(void)
{
return sys_clock_hw_cycles_per_sec();
}
uint64_t timing_cycles_to_ns(uint64_t cycles)
{
return k_cyc_to_ns_floor64(cycles);
}
uint64_t timing_cycles_to_ns_avg(uint64_t cycles, uint32_t count)
{
return timing_cycles_to_ns(cycles) / count;
}
uint32_t timing_freq_get_mhz(void)
{
return (uint32_t)(timing_freq_get() / 1000000);
}