timing: introduce timing functions as a generic feature
Add timing functions and APIs. This is now used with some of the tests we have for performance and metrics and will be used whereever timing informations are needed, for example for tracing, profiling and other operations where timing info is critical. Signed-off-by: Daniel Leung <daniel.leung@intel.com> Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
80fb6538b3
commit
0ffcfa9633
|
@ -522,6 +522,7 @@
|
|||
/subsys/stats/ @nvlsianpu
|
||||
/subsys/storage/ @nvlsianpu
|
||||
/subsys/testsuite/ @nashif
|
||||
/subsys/timing/ @nashif @dcpleung
|
||||
/subsys/usb/ @jfischer-phytec-iot @finikorg
|
||||
/tests/ @nashif
|
||||
/tests/application_development/libcxx/ @pabigot
|
||||
|
|
|
@ -47,3 +47,9 @@ config QEMU_ICOUNT_SHIFT
|
|||
# There might not be any board options, hence the optional source
|
||||
osource "$(BOARD_DIR)/Kconfig"
|
||||
endmenu
|
||||
|
||||
config BOARD_HAS_TIMING_FUNCTIONS
|
||||
bool
|
||||
help
|
||||
Should be selected if board provides custom method for retrieving
|
||||
timestamps and cycle count.
|
||||
|
|
92
include/timing/timing.h
Normal file
92
include/timing/timing.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_TIMING_TIMING_H_
|
||||
#define ZEPHYR_INCLUDE_TIMING_TIMING_H_
|
||||
|
||||
#include <kernel.h>
|
||||
|
||||
|
||||
/**
|
||||
* @brief Timing Measurement APIs
|
||||
* @defgroup timing_api Timing APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
typedef uint64_t timing_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the timing subsystem.
|
||||
*
|
||||
* Perform the necessary steps to initialize the timing subsystem.
|
||||
*/
|
||||
void timing_init(void);
|
||||
|
||||
/**
|
||||
* @brief Signal the start of the timing information gathering.
|
||||
*
|
||||
* Signal to the timing subsystem that timing information
|
||||
* will be gathered from this point forward.
|
||||
*/
|
||||
void timing_start(void);
|
||||
|
||||
/**
|
||||
* @brief Signal the end of the timing information gathering.
|
||||
*
|
||||
* Signal to the timing subsystem that timing information
|
||||
* is no longer being gathered from this point forward.
|
||||
*/
|
||||
void timing_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Return timing counter.
|
||||
*
|
||||
* @return Timing counter.
|
||||
*/
|
||||
timing_t timing_counter_get(void);
|
||||
|
||||
/**
|
||||
* @brief Get number of cycles between @p start and @p end.
|
||||
*
|
||||
* For some architectures or SoCs, the raw numbers from counter
|
||||
* need to be scaled to obtain actual number of cycles.
|
||||
*
|
||||
* @param start Pointer to counter at start of a measured execution.
|
||||
* @param end Pointer to counter at stop of a measured execution.
|
||||
* @return Number of cycles between start and end.
|
||||
*/
|
||||
uint64_t timing_cycles_get(volatile timing_t *const start,
|
||||
volatile timing_t *const end);
|
||||
|
||||
/**
|
||||
* @brief Get frequency of counter used (in Hz).
|
||||
*
|
||||
* @return Frequency of counter used for timing in Hz.
|
||||
*/
|
||||
uint64_t timing_freq_get(void);
|
||||
|
||||
/**
|
||||
* @brief Convert number of @p cycles into nanoseconds.
|
||||
*
|
||||
* @param cycles Number of cycles
|
||||
* @return Converted time value
|
||||
*/
|
||||
uint64_t timing_cycles_to_ns(uint64_t cycles);
|
||||
|
||||
uint64_t timing_cycles_to_ns_avg(uint64_t cycles, uint32_t count);
|
||||
|
||||
/**
|
||||
* @brief Get frequency of counter used (in MHz).
|
||||
*
|
||||
* @return Frequency of counter used for timing in MHz.
|
||||
*/
|
||||
uint32_t timing_freq_get_mhz(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* ZEPHYR_INCLUDE_TIMING_TIMING_H_ */
|
|
@ -316,6 +316,7 @@ config BOOT_DELAY
|
|||
|
||||
config EXECUTION_BENCHMARKING
|
||||
bool "Timing metrics"
|
||||
select TIMING_FUNCTIONS
|
||||
help
|
||||
This option enables the tracking of various times inside the kernel
|
||||
the exact set of metrics being tracked is board-dependent.
|
||||
|
|
|
@ -41,3 +41,9 @@ config SOC_DEPRECATED_RELEASE
|
|||
the Zephyr release that the SoC configuration will be removed.
|
||||
When set, any build for that SoC will generate a clearly visible
|
||||
deprecation warning.
|
||||
|
||||
config SOC_HAS_TIMING_FUNCTIONS
|
||||
bool
|
||||
help
|
||||
Should be selected if SoC provides custom method for retrieving
|
||||
timestamps and cycle count.
|
||||
|
|
|
@ -49,6 +49,8 @@ source "subsys/settings/Kconfig"
|
|||
|
||||
source "subsys/testsuite/Kconfig"
|
||||
|
||||
source "subsys/timing/Kconfig"
|
||||
|
||||
source "subsys/tracing/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
|
9
subsys/timing/Kconfig
Normal file
9
subsys/timing/Kconfig
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config TIMING_FUNCTIONS
|
||||
bool "Timing Functions"
|
||||
help
|
||||
When enabled, timing related functions are compiled. This is
|
||||
useful for gathering timing on code execution.
|
Loading…
Reference in a new issue