2019-12-09 19:45:19 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Stephanos Ioannidis <root@stephanos.io>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZEPHYR_BENCHMARK_CMSIS_DSP_COMMON_BENCHMARK_COMMON_H_
|
|
|
|
#define ZEPHYR_BENCHMARK_CMSIS_DSP_COMMON_BENCHMARK_COMMON_H_
|
|
|
|
|
2022-07-19 22:16:24 +08:00
|
|
|
#include <zephyr/ztest.h>
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 15:58:46 +08:00
|
|
|
#include <zephyr/kernel.h>
|
2019-12-09 19:45:19 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_CPU_CORTEX_M_HAS_DWT)
|
|
|
|
/* Use cycle counting on the Cortex-M devices that support DWT */
|
|
|
|
|
2023-06-30 00:22:37 +08:00
|
|
|
#include <cmsis_core.h>
|
2019-12-09 19:45:19 +08:00
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
static ALWAYS_INLINE void benchmark_begin(uint32_t *irq_key, uint32_t *timestamp)
|
2019-12-09 19:45:19 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(timestamp);
|
|
|
|
|
|
|
|
/* Lock interrupts to prevent preemption */
|
|
|
|
*irq_key = irq_lock();
|
|
|
|
|
|
|
|
/* Start DWT cycle counter */
|
|
|
|
DWT->CYCCNT = 0;
|
|
|
|
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
static ALWAYS_INLINE uint32_t benchmark_end(uint32_t irq_key, uint32_t timestamp)
|
2019-12-09 19:45:19 +08:00
|
|
|
{
|
|
|
|
/* Stop DWT cycle counter */
|
|
|
|
DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk;
|
|
|
|
|
|
|
|
/* Unlock interrupts */
|
|
|
|
irq_unlock(irq_key);
|
|
|
|
|
|
|
|
/* Return DWT cycle counter value */
|
|
|
|
return DWT->CYCCNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BENCHMARK_TYPE "Processor Cycles"
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* Use system timer clock on other systems */
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
static ALWAYS_INLINE void benchmark_begin(uint32_t *irq_key, uint32_t *timestamp)
|
2019-12-09 19:45:19 +08:00
|
|
|
{
|
2020-05-28 00:26:57 +08:00
|
|
|
volatile uint32_t now;
|
2019-12-09 19:45:19 +08:00
|
|
|
|
|
|
|
/* Lock interrupts to prevent preemption */
|
|
|
|
*irq_key = irq_lock();
|
|
|
|
|
|
|
|
/* Read timestamp for the beginning of benchmark */
|
|
|
|
now = k_cycle_get_32();
|
|
|
|
|
|
|
|
/* Store timestamp */
|
|
|
|
*timestamp = now;
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
static ALWAYS_INLINE uint32_t benchmark_end(uint32_t irq_key, uint32_t timestamp)
|
2019-12-09 19:45:19 +08:00
|
|
|
{
|
2020-05-28 00:26:57 +08:00
|
|
|
volatile uint32_t now;
|
2019-12-09 19:45:19 +08:00
|
|
|
|
|
|
|
/* Read timestamp for the end of benchmark */
|
|
|
|
now = k_cycle_get_32();
|
|
|
|
|
|
|
|
/* Unlock interrupts */
|
|
|
|
irq_unlock(irq_key);
|
|
|
|
|
|
|
|
/* Return timespan between the beginning and the end of benchmark */
|
|
|
|
return now - timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BENCHMARK_TYPE "System Timer Cycles"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ZEPHYR_BENCHMARK_CMSIS_DSP_COMMON_BENCHMARK_COMMON_H_ */
|