2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file rfi_perftest.cpp
|
|
|
|
*
|
2020-10-12 06:18:36 -07:00
|
|
|
* Method execution time micro test.
|
|
|
|
*
|
2015-07-10 06:01:56 -07:00
|
|
|
* @date Nov 30, 2012
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "rfi_perftest.h"
|
|
|
|
#include "fuel_math.h"
|
|
|
|
|
|
|
|
#include "eficonsole.h"
|
|
|
|
#include "time.h"
|
2019-03-31 14:44:34 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "console_io.h"
|
|
|
|
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_PERF_METRICS
|
2016-01-11 19:01:29 -08:00
|
|
|
#include "test.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
static void testSystemCalls(const int count) {
|
|
|
|
time_t start, time;
|
|
|
|
long result = 0;
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
for (int i = 0; i < count / 2; i++) {
|
|
|
|
// setPinValue(&testOutput, 0);
|
|
|
|
// setPinValue(&testOutput, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
// Finished 100000 iterations of 'setPinValue()' in 120ms
|
|
|
|
// prin("Finished %d iterations of 'setPinValue()' in %dms\r\n", count, time);
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
result += chTimeNow();
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (result != 0) {
|
|
|
|
// Finished 100000 iterations of 'chTimeNow()' in 33ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of 'chTimeNow()' in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
chSysLock()
|
|
|
|
;
|
|
|
|
result += chTimeNow();
|
|
|
|
chSysUnlock()
|
|
|
|
;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (result != 0) {
|
|
|
|
// Finished 100000 iterations of 'chTimeNow()' with chSysLock in 144ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of 'chTimeNow()' with chSysLock in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
result += currentTimeMillis();
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (result != 0)
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of 'currentTimeMillis' in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Engine testEngine;
|
|
|
|
|
|
|
|
static void testRusefiMethods(const int count) {
|
|
|
|
time_t start, time;
|
|
|
|
int tempi = 1;
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempi != 0)
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of getBaseFuel in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
// start = currentTimeMillis();
|
|
|
|
// for (int i = 0; i < count; i++)
|
2016-08-26 15:02:39 -07:00
|
|
|
// tempi += getInjectionDuration(1200, NULL); // todo
|
2015-07-10 06:01:56 -07:00
|
|
|
// time = currentTimeMillis() - start;
|
|
|
|
// if (tempi != 0)
|
2021-04-21 09:53:13 -07:00
|
|
|
// efiPrintf("Finished %d iterations of getFuelMs in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
testEngine.updateSlowSensors();
|
|
|
|
tempi += testEngine.engineState.clt;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempi != 0)
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of updateSlowSensors in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void testMath(const int count) {
|
|
|
|
time_t start, time;
|
|
|
|
|
|
|
|
int64_t temp64 = 0;
|
|
|
|
start = currentTimeMillis();
|
|
|
|
for (int64_t i = 0; i < count; i++) {
|
|
|
|
temp64 += i;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (temp64 != 0) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of int64_t summation in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
temp64 = 1;
|
|
|
|
start = currentTimeMillis();
|
|
|
|
for (int64_t i = 0; i < count; i++) {
|
|
|
|
temp64 *= i;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (temp64 == 0) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of int64_t multiplication in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
;
|
|
|
|
time = currentTimeMillis() - start;
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of empty loop in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
uint32_t tempi = 1;
|
|
|
|
start = currentTimeMillis();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
tempi += tempi;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempi == 0) {
|
|
|
|
// 11ms is 1848000 ticks
|
|
|
|
// 18.48 ticks per iteration
|
|
|
|
// Finished 100000 iterations of uint32_t summation in 11ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of uint32_t summation in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
tempi = 1;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
tempi += (tempi + 100) / 130;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempi != 0) {
|
|
|
|
// Finished 100000 iterations of uint32_t division in 16ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of uint32_t division in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
temp64 = 1;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
temp64 += temp64;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (temp64 == 0) {
|
|
|
|
// Finished 100000 iterations of int64_t summation in 21ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of int64_t summation in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
temp64 = 1;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
temp64 += (temp64 + 100) / 130;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (temp64 != 0) {
|
|
|
|
// Finished 100000 iterations of int64_t division in 181ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of int64_t division in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
float tempf = 1;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
tempf += tempf;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempf != 0) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of float summation in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
tempf = 1;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
tempf += tempf * 130.0f;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempf != 0) {
|
|
|
|
// ms = ticks
|
|
|
|
// ticks per iteration
|
|
|
|
// Finished 100000 iterations of float division in ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of float multiplication in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
tempf = 1;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
tempf += (tempf + 100) / 130.0;
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempf != 0) {
|
|
|
|
// 65 ms = 10920000 ticks
|
|
|
|
// 109.2 ticks per iteration
|
|
|
|
// Finished 100000 iterations of float division in 65ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of float division in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
tempf = 1;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
tempf += logf(tempf);
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempf != 0) {
|
|
|
|
// Finished 100000 iterations of float log in 191ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of float log in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
double tempd = 1;
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
tempd += tempd / 2;
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempd != 0) {
|
|
|
|
// Finished 100000 iterations of double summation in 80ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of double summation in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
tempd = 1;
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
tempd += (tempd + 100) / 130.0;
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempd != 0) {
|
|
|
|
// Finished 100000 iterations of double division in 497ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of double division in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
start = currentTimeMillis();
|
|
|
|
tempd = 1;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
tempd += log(tempd);
|
|
|
|
}
|
|
|
|
time = currentTimeMillis() - start;
|
|
|
|
if (tempd != 0) {
|
|
|
|
// Finished 100000 iterations of double log in 242ms
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Finished %d iterations of double log in %dms", count, time);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void runTests(const int count) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Running tests: %d", count);
|
2015-07-10 06:01:56 -07:00
|
|
|
testRusefiMethods(count / 10);
|
|
|
|
testSystemCalls(count);
|
|
|
|
testMath(count);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern Overflow64Counter halTime;
|
|
|
|
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_RTC
|
2015-07-10 06:01:56 -07:00
|
|
|
static int rtcStartTime;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "chrtclib.h"
|
|
|
|
|
2021-11-15 04:02:34 -08:00
|
|
|
static void timeInfo() {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("chTimeNow as seconds = %d", getTimeNowSeconds());
|
|
|
|
efiPrintf("hal seconds = %d", halTime.get() / (long)CORE_CLOCK);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_RTC
|
2015-07-10 06:01:56 -07:00
|
|
|
int unix = rtcGetTimeUnixSec(&RTCD1) - rtcStartTime;
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("unix seconds = %d", unix);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-11-15 04:02:34 -08:00
|
|
|
static void runChibioTest() {
|
2015-07-10 06:01:56 -07:00
|
|
|
print("EFI_SHAFT_POSITION_INPUT=%d\r\n", EFI_SHAFT_POSITION_INPUT);
|
|
|
|
print("EFI_EMULATE_POSITION_SENSORS=%d\r\n", EFI_EMULATE_POSITION_SENSORS);
|
|
|
|
print("EFI_ANALOG_SENSORS=%d\r\n", EFI_ANALOG_SENSORS);
|
|
|
|
print("EFI_INTERNAL_ADC=%d\r\n", EFI_INTERNAL_ADC);
|
|
|
|
print("EFI_HD44780_LCD=%d\r\n", EFI_HD44780_LCD);
|
|
|
|
print("EFI_MAP_AVERAGING=%d\r\n", EFI_MAP_AVERAGING);
|
2019-12-03 22:11:10 -08:00
|
|
|
print("EFI_LOGIC_ANALYZER=%d\r\n", EFI_LOGIC_ANALYZER);
|
2015-07-15 18:01:45 -07:00
|
|
|
print("EFI_ENGINE_SNIFFER=%d\r\n", EFI_ENGINE_SNIFFER);
|
2015-09-13 09:01:42 -07:00
|
|
|
print("EFI_SENSOR_CHART=%d\r\n", EFI_SENSOR_CHART);
|
2015-07-10 06:01:56 -07:00
|
|
|
print("EFI_SHAFT_POSITION_INPUT=%d\r\n", EFI_SHAFT_POSITION_INPUT);
|
|
|
|
print("EFI_ENGINE_CONTROL=%d\r\n", EFI_ENGINE_CONTROL);
|
|
|
|
print("CH_DBG_SYSTEM_STATE_CHECK=%d\r\n", CH_DBG_SYSTEM_STATE_CHECK);
|
|
|
|
print("CH_DBG_ENABLE_CHECKS=%d\r\n", CH_DBG_ENABLE_CHECKS);
|
|
|
|
print("CH_DBG_ENABLE_ASSERTS=%d\r\n", CH_DBG_ENABLE_ASSERTS);
|
|
|
|
print("CH_DBG_ENABLE_STACK_CHECK=%d\r\n", CH_DBG_ENABLE_STACK_CHECK);
|
|
|
|
print("CH_DBG_THREADS_PROFILING=%d\r\n", CH_DBG_THREADS_PROFILING);
|
|
|
|
TestThread(getConsoleChannel());
|
|
|
|
}
|
|
|
|
|
2021-04-21 11:28:48 -07:00
|
|
|
void initTimePerfActions() {
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_RTC
|
2015-07-10 06:01:56 -07:00
|
|
|
rtcStartTime = rtcGetTimeUnixSec(&RTCD1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
addConsoleActionI("perftest", runTests);
|
|
|
|
|
|
|
|
addConsoleAction("timeinfo", timeInfo);
|
|
|
|
addConsoleAction("chtest", runChibioTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* EFI_PERF_METRICS */
|