timing: do not repeatedly do init()/start()/stop()
We should not be initializing/starting/stoping timing functions multiple times. So this changes how the timing functions are structured to allow only one initialization, only start when stopped, and only stop when started. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
e9ef078a11
commit
9be37553ee
13 changed files with 353 additions and 88 deletions
6
subsys/timing/CMakeLists.txt
Normal file
6
subsys/timing/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Copyright (c) 2020 Intel Corporation.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_library()
|
||||
|
||||
zephyr_library_sources(timing.c)
|
60
subsys/timing/timing.c
Normal file
60
subsys/timing/timing.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <kernel.h>
|
||||
#include <sys/atomic.h>
|
||||
#include <timing/timing.h>
|
||||
|
||||
static bool has_inited;
|
||||
static atomic_val_t started_ref;
|
||||
|
||||
void timing_init(void)
|
||||
{
|
||||
if (has_inited) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BOARD_HAS_TIMING_FUNCTIONS)
|
||||
board_timing_init();
|
||||
#elif defined(CONFIG_SOC_HAS_TIMING_FUNCTIONS)
|
||||
soc_timing_init();
|
||||
#else
|
||||
arch_timing_init();
|
||||
#endif
|
||||
|
||||
has_inited = true;
|
||||
}
|
||||
|
||||
void timing_start(void)
|
||||
{
|
||||
if (atomic_inc(&started_ref) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BOARD_HAS_TIMING_FUNCTIONS)
|
||||
board_timing_start();
|
||||
#elif defined(CONFIG_SOC_HAS_TIMING_FUNCTIONS)
|
||||
soc_timing_start();
|
||||
#else
|
||||
arch_timing_start();
|
||||
#endif
|
||||
}
|
||||
|
||||
void timing_stop(void)
|
||||
{
|
||||
if (atomic_dec(&started_ref) > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BOARD_HAS_TIMING_FUNCTIONS)
|
||||
board_timing_stop();
|
||||
#elif defined(CONFIG_SOC_HAS_TIMING_FUNCTIONS)
|
||||
soc_timing_stop();
|
||||
#else
|
||||
arch_timing_stop();
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue