2011-09-16 23:15:02 -03:00
|
|
|
/*
|
|
|
|
test CPU speed
|
|
|
|
Andrew Tridgell September 2011
|
|
|
|
*/
|
|
|
|
|
2019-02-13 03:41:33 -04:00
|
|
|
#define ALLOW_DOUBLE_MATH_FUNCTIONS
|
|
|
|
|
2016-03-31 18:43:36 -03:00
|
|
|
#include <cmath>
|
2015-10-20 09:57:50 -03:00
|
|
|
|
2015-08-11 03:28:41 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Common/AP_Common.h>
|
2019-02-24 16:58:27 -04:00
|
|
|
#include <AP_Math/AP_Math.h>
|
2022-02-04 13:53:42 -04:00
|
|
|
#include <AP_ESC_Telem/AP_ESC_Telem.h>
|
2019-03-01 07:05:53 -04:00
|
|
|
#include "EKF_Maths.h"
|
2012-12-14 21:52:21 -04:00
|
|
|
|
2022-02-21 17:05:49 -04:00
|
|
|
#if HAL_WITH_DSP && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
|
|
|
|
#include <arm_math.h>
|
|
|
|
#endif
|
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
void setup();
|
|
|
|
void loop();
|
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
2011-09-16 23:15:02 -03:00
|
|
|
|
2022-02-04 13:53:42 -04:00
|
|
|
#if CONFIG_HAL_BOARD != HAL_BOARD_LINUX
|
|
|
|
|
|
|
|
// On H750 we want to measure external flash to ram performance
|
2023-04-10 01:45:07 -03:00
|
|
|
#if defined(EXT_FLASH_SIZE_MB) && EXT_FLASH_SIZE_MB>0 && defined(STM32H7)
|
2022-09-01 13:09:33 -03:00
|
|
|
#include "ch.h"
|
2022-02-04 13:53:42 -04:00
|
|
|
#define DISABLE_CACHES
|
|
|
|
#endif
|
|
|
|
|
2019-02-13 03:41:33 -04:00
|
|
|
#ifdef STM32_SYS_CK
|
|
|
|
static uint32_t sysclk = STM32_SYS_CK;
|
|
|
|
#elif defined(STM32_SYSCLK)
|
|
|
|
static uint32_t sysclk = STM32_SYSCLK;
|
|
|
|
#else
|
|
|
|
static uint32_t sysclk = 0;
|
|
|
|
#endif
|
|
|
|
|
2019-03-01 07:05:53 -04:00
|
|
|
static EKF_Maths ekf;
|
|
|
|
|
2020-01-18 00:53:36 -04:00
|
|
|
HAL_Semaphore sem;
|
2022-02-04 13:53:42 -04:00
|
|
|
AP_ESC_Telem telem;
|
2019-03-01 07:05:53 -04:00
|
|
|
|
2011-09-16 23:15:02 -03:00
|
|
|
void setup() {
|
2022-02-04 13:53:42 -04:00
|
|
|
#ifdef DISABLE_CACHES
|
2023-04-23 13:28:57 -03:00
|
|
|
#if !HAL_XIP_ENABLED // can't disable DCache in memory-mapped mode
|
2022-02-04 13:53:42 -04:00
|
|
|
SCB_DisableDCache();
|
2022-09-01 13:09:33 -03:00
|
|
|
#endif
|
2022-02-04 13:53:42 -04:00
|
|
|
SCB_DisableICache();
|
|
|
|
#endif
|
2019-03-01 07:05:53 -04:00
|
|
|
ekf.init();
|
2011-09-16 23:15:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void show_sizes(void)
|
|
|
|
{
|
2019-02-13 03:41:33 -04:00
|
|
|
hal.console->printf("SYSCLK %uMHz\n", unsigned(sysclk/1000000U));
|
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
hal.console->printf("Type sizes:\n");
|
|
|
|
hal.console->printf("char : %lu\n", (unsigned long)sizeof(char));
|
|
|
|
hal.console->printf("short : %lu\n", (unsigned long)sizeof(short));
|
|
|
|
hal.console->printf("int : %lu\n", (unsigned long)sizeof(int));
|
|
|
|
hal.console->printf("long : %lu\n", (unsigned long)sizeof(long));
|
|
|
|
hal.console->printf("long long : %lu\n", (unsigned long)sizeof(long long));
|
|
|
|
hal.console->printf("bool : %lu\n", (unsigned long)sizeof(bool));
|
|
|
|
hal.console->printf("void* : %lu\n", (unsigned long)sizeof(void *));
|
|
|
|
|
|
|
|
hal.console->printf("printing NaN: %f\n", (double)sqrtf(-1.0f));
|
|
|
|
hal.console->printf("printing +Inf: %f\n", (double)(1.0f/0.0f));
|
|
|
|
hal.console->printf("printing -Inf: %f\n", (double)(-1.0f/0.0f));
|
2011-09-16 23:15:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define TENTIMES(x) do { x; x; x; x; x; x; x; x; x; x; } while (0)
|
|
|
|
#define FIFTYTIMES(x) do { TENTIMES(x); TENTIMES(x); TENTIMES(x); TENTIMES(x); TENTIMES(x); } while (0)
|
|
|
|
|
|
|
|
#define TIMEIT(name, op, count) do { \
|
2021-10-02 03:47:21 -03:00
|
|
|
uint16_t us_end, us_start; \
|
|
|
|
us_start = AP_HAL::micros16(); \
|
2017-04-13 08:34:26 -03:00
|
|
|
for (uint8_t i = 0; i < count; i++) { \
|
|
|
|
FIFTYTIMES(op); \
|
|
|
|
} \
|
2021-10-02 03:47:21 -03:00
|
|
|
us_end = AP_HAL::micros16(); \
|
|
|
|
uint16_t dt_us = us_end - us_start; \
|
|
|
|
hal.console->printf("%-10s %7.4f usec/call\n", name, double(dt_us) / double(count * 50.0)); \
|
2019-02-13 03:41:33 -04:00
|
|
|
hal.scheduler->delay(10); \
|
2011-09-16 23:15:02 -03:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
volatile float v_f = 1.0;
|
|
|
|
volatile float v_out;
|
|
|
|
volatile double v_d = 1.0;
|
|
|
|
volatile double v_out_d;
|
|
|
|
volatile uint32_t v_32 = 1;
|
|
|
|
volatile uint32_t v_out_32 = 1;
|
|
|
|
volatile uint16_t v_16 = 1;
|
|
|
|
volatile uint16_t v_out_16 = 1;
|
|
|
|
volatile uint8_t v_8 = 1;
|
|
|
|
volatile uint8_t v_out_8 = 1;
|
|
|
|
volatile uint8_t mbuf1[128], mbuf2[128];
|
2011-12-19 03:52:00 -04:00
|
|
|
volatile uint64_t v_64 = 1;
|
|
|
|
volatile uint64_t v_out_64 = 1;
|
2011-09-16 23:15:02 -03:00
|
|
|
|
2022-09-01 13:09:33 -03:00
|
|
|
#pragma GCC diagnostic error "-Wframe-larger-than=2000"
|
2011-09-16 23:15:02 -03:00
|
|
|
static void show_timings(void)
|
|
|
|
{
|
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
v_f = 1+(AP_HAL::micros() % 5);
|
|
|
|
v_out = 1+(AP_HAL::micros() % 3);
|
2011-09-16 23:15:02 -03:00
|
|
|
|
2022-02-04 13:53:42 -04:00
|
|
|
v_32 = AP_HAL::millis();
|
2017-04-13 08:34:26 -03:00
|
|
|
v_32 = 1+(AP_HAL::micros() % 5);
|
|
|
|
v_out_32 = 1+(AP_HAL::micros() % 3);
|
2011-09-16 23:15:02 -03:00
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
v_16 = 1+(AP_HAL::micros() % 5);
|
|
|
|
v_out_16 = 1+(AP_HAL::micros() % 3);
|
2011-09-16 23:15:02 -03:00
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
v_8 = 1+(AP_HAL::micros() % 5);
|
|
|
|
v_out_8 = 1+(AP_HAL::micros() % 3);
|
2011-09-16 23:15:02 -03:00
|
|
|
|
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
hal.console->printf("Operation timings:\n");
|
|
|
|
hal.console->printf("Note: timings for some operations are very data dependent\n");
|
2011-09-16 23:15:02 -03:00
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
TIMEIT("nop", asm volatile("nop"::), 255);
|
2011-09-16 23:15:02 -03:00
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
TIMEIT("micros()", AP_HAL::micros(), 200);
|
2021-10-02 03:47:21 -03:00
|
|
|
TIMEIT("micros16()", AP_HAL::micros16(), 200);
|
2017-04-13 08:34:26 -03:00
|
|
|
TIMEIT("millis()", AP_HAL::millis(), 200);
|
2021-10-02 03:47:21 -03:00
|
|
|
TIMEIT("millis16()", AP_HAL::millis16(), 200);
|
2019-12-08 20:24:16 -04:00
|
|
|
TIMEIT("micros64()", AP_HAL::micros64(), 200);
|
2011-09-16 23:15:02 -03:00
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
TIMEIT("fadd", v_out += v_f, 100);
|
|
|
|
TIMEIT("fsub", v_out -= v_f, 100);
|
|
|
|
TIMEIT("fmul", v_out *= v_f, 100);
|
|
|
|
TIMEIT("fdiv /=", v_out /= v_f, 100);
|
2013-07-18 11:08:13 -03:00
|
|
|
TIMEIT("fdiv 2/x", v_out = 2.0f/v_f, 100);
|
2011-09-16 23:15:02 -03:00
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
TIMEIT("dadd", v_out_d += v_d, 100);
|
|
|
|
TIMEIT("dsub", v_out_d -= v_d, 100);
|
|
|
|
TIMEIT("dmul", v_out_d *= v_d, 100);
|
|
|
|
TIMEIT("ddiv", v_out_d /= v_d, 100);
|
|
|
|
|
2022-02-21 17:05:49 -04:00
|
|
|
TIMEIT("sinf()", v_out = sinf(v_f), 100);
|
|
|
|
TIMEIT("cosf()", v_out = cosf(v_f), 100);
|
|
|
|
#if HAL_WITH_DSP && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
|
|
|
|
TIMEIT("arm_sin_f32()", v_out = arm_sin_f32(v_f), 100);
|
|
|
|
TIMEIT("arm_cos_f32()", v_out = arm_cos_f32(v_f), 100);
|
|
|
|
#endif
|
|
|
|
TIMEIT("tanf()", v_out = tanf(v_f), 100);
|
|
|
|
TIMEIT("acosf()", v_out = acosf(v_f * 0.2), 100);
|
|
|
|
TIMEIT("asinf()", v_out = asinf(v_f * 0.2), 100);
|
|
|
|
TIMEIT("atan2f()", v_out = atan2f(v_f * 0.2, v_f * 0.3), 100);
|
|
|
|
TIMEIT("sqrtf()",v_out = sqrtf(v_f), 100);
|
|
|
|
|
|
|
|
TIMEIT("sin()", v_out = sin(v_f), 100);
|
|
|
|
TIMEIT("cos()", v_out = cos(v_f), 100);
|
|
|
|
TIMEIT("tan()", v_out = tan(v_f), 100);
|
|
|
|
TIMEIT("acos()", v_out = acos(v_f * 0.2), 100);
|
|
|
|
TIMEIT("asin()", v_out = asin(v_f * 0.2), 100);
|
|
|
|
TIMEIT("atan2()", v_out = atan2(v_f * 0.2, v_f * 0.3), 100);
|
|
|
|
TIMEIT("sqrt()",v_out = sqrt(v_f), 100);
|
|
|
|
#if HAL_WITH_DSP && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
|
|
|
|
TIMEIT("arm_sqrt_f32()", arm_sqrt_f32(v_f, (float32_t*)&v_out), 100);
|
|
|
|
#endif
|
|
|
|
TIMEIT("sq()",v_out = sq(v_f), 100);
|
|
|
|
TIMEIT("powf(v,2)",v_out = powf(v_f, 2), 100);
|
|
|
|
TIMEIT("powf(v,3.1)",v_out = powf(v_f, 3.1), 100);
|
2019-03-01 07:05:53 -04:00
|
|
|
TIMEIT("EKF",v_out = ekf.test(), 5);
|
2019-02-24 16:58:27 -04:00
|
|
|
|
2017-04-13 08:34:26 -03:00
|
|
|
TIMEIT("iadd8", v_out_8 += v_8, 100);
|
|
|
|
TIMEIT("isub8", v_out_8 -= v_8, 100);
|
|
|
|
TIMEIT("imul8", v_out_8 *= v_8, 100);
|
|
|
|
TIMEIT("idiv8", v_out_8 /= v_8, 100);
|
|
|
|
|
|
|
|
TIMEIT("iadd16", v_out_16 += v_16, 100);
|
|
|
|
TIMEIT("isub16", v_out_16 -= v_16, 100);
|
|
|
|
TIMEIT("imul16", v_out_16 *= v_16, 100);
|
|
|
|
TIMEIT("idiv16", v_out_16 /= v_16, 100);
|
|
|
|
|
|
|
|
TIMEIT("iadd32", v_out_32 += v_32, 100);
|
|
|
|
TIMEIT("isub32", v_out_32 -= v_32, 100);
|
|
|
|
TIMEIT("imul32", v_out_32 *= v_32, 100);
|
|
|
|
TIMEIT("idiv32", v_out_32 /= v_32, 100);
|
|
|
|
|
|
|
|
TIMEIT("iadd64", v_out_64 += v_64, 100);
|
|
|
|
TIMEIT("isub64", v_out_64 -= v_64, 100);
|
|
|
|
TIMEIT("imul64", v_out_64 *= v_64, 100);
|
|
|
|
TIMEIT("idiv64", v_out_64 /= v_64, 100);
|
|
|
|
|
2019-02-13 03:41:33 -04:00
|
|
|
TIMEIT("memcpy128", memcpy((void*)mbuf1, (const void *)mbuf2, sizeof(mbuf1)); v_out_8 += mbuf1[0], 200);
|
|
|
|
TIMEIT("memset128", memset((void*)mbuf1, 1, sizeof(mbuf1)); v_out_8 += mbuf1[0], 200);
|
2017-04-13 08:34:26 -03:00
|
|
|
TIMEIT("delay(1)", hal.scheduler->delay(1), 5);
|
2020-01-18 00:53:36 -04:00
|
|
|
|
|
|
|
TIMEIT("SEM", { WITH_SEMAPHORE(sem); v_out_32 += v_32;}, 100);
|
2011-09-16 23:15:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2017-04-13 08:34:26 -03:00
|
|
|
show_sizes();
|
|
|
|
hal.console->printf("\n");
|
|
|
|
show_timings();
|
|
|
|
hal.console->printf("\n");
|
|
|
|
hal.scheduler->delay(3000);
|
2011-09-16 23:15:02 -03:00
|
|
|
}
|
2012-12-14 21:52:21 -04:00
|
|
|
|
2022-02-04 13:53:42 -04:00
|
|
|
#else
|
|
|
|
void loop() {}
|
|
|
|
void setup() {}
|
|
|
|
#endif
|
|
|
|
|
2012-12-14 21:52:21 -04:00
|
|
|
AP_HAL_MAIN();
|