zephyr/tests/benchmarks/cmsis_dsp/common/benchmark_common.h
Gerard Marull-Paretas 79e6b0e0f6 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-09-05 16:31:47 +02:00

80 lines
1.8 KiB
C

/*
* 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_
#include <zephyr/ztest.h>
#include <zephyr/kernel.h>
#if defined(CONFIG_CPU_CORTEX_M_HAS_DWT)
/* Use cycle counting on the Cortex-M devices that support DWT */
#include <zephyr/arch/arm/aarch32/cortex_m/cmsis.h>
static ALWAYS_INLINE void benchmark_begin(uint32_t *irq_key, uint32_t *timestamp)
{
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;
}
static ALWAYS_INLINE uint32_t benchmark_end(uint32_t irq_key, uint32_t timestamp)
{
/* 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 */
static ALWAYS_INLINE void benchmark_begin(uint32_t *irq_key, uint32_t *timestamp)
{
volatile uint32_t now;
/* 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;
}
static ALWAYS_INLINE uint32_t benchmark_end(uint32_t irq_key, uint32_t timestamp)
{
volatile uint32_t now;
/* 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_ */