auto-sync

This commit is contained in:
rusEfi 2015-01-14 17:04:00 -06:00
parent 86ccbfd756
commit 3c3aa929c6
11 changed files with 61 additions and 76 deletions

View File

@ -231,7 +231,7 @@ void startConsole(void (*console_line_callback_p)(char *)) {
bool lockAnyContext(void) { bool lockAnyContext(void) {
int alreadyLocked = isLocked(); int alreadyLocked = isLocked();
if (alreadyLocked) if (alreadyLocked)
return TRUE; return true;
if (isIsrContext()) { if (isIsrContext()) {
chSysLockFromIsr() chSysLockFromIsr()
; ;

View File

@ -308,7 +308,7 @@ static void setFloat(const char *offsetStr, const char *valueStr) {
scheduleMsg(&logger, "setting float @%d to %f", offset, value); scheduleMsg(&logger, "setting float @%d to %f", offset, value);
} }
void initEngineContoller(Engine *engine) { void initEngineContoller(Logging *sharedLogger, Engine *engine) {
if (hasFirmwareError()) { if (hasFirmwareError()) {
return; return;
} }
@ -326,7 +326,7 @@ void initEngineContoller(Engine *engine) {
#if EFI_WAVE_ANALYZER #if EFI_WAVE_ANALYZER
if (engineConfiguration->isWaveAnalyzerEnabled) { if (engineConfiguration->isWaveAnalyzerEnabled) {
initWaveAnalyzer(); initWaveAnalyzer(sharedLogger);
} }
#endif /* EFI_WAVE_ANALYZER */ #endif /* EFI_WAVE_ANALYZER */

View File

@ -15,6 +15,6 @@
#include "engine.h" #include "engine.h"
char * getPinNameByAdcChannel(adc_channel_e hwChannel, char *buffer); char * getPinNameByAdcChannel(adc_channel_e hwChannel, char *buffer);
void initEngineContoller(Engine *engine); void initEngineContoller(Logging *sharedLogger, Engine *engine);
#endif /* ENGINE_STATUS_H_ */ #endif /* ENGINE_STATUS_H_ */

View File

@ -189,5 +189,5 @@ void initThermistors(Engine *engine) {
engine->engineConfiguration->cltAdcChannel); engine->engineConfiguration->cltAdcChannel);
initThermistorCurve(&engine->iat, &engine->engineConfiguration->iatThermistorConf, initThermistorCurve(&engine->iat, &engine->engineConfiguration->iatThermistorConf,
engine->engineConfiguration->iatAdcChannel); engine->engineConfiguration->iatAdcChannel);
initialized = TRUE; initialized = true;
} }

View File

@ -20,7 +20,7 @@
#if EFI_PERF_METRICS || defined(__DOXYGEN__) #if EFI_PERF_METRICS || defined(__DOXYGEN__)
static LoggingWithStorage logger; static Logging* logger;
static void testSystemCalls(const int count) { static void testSystemCalls(const int count) {
time_t start, time; time_t start, time;
@ -42,7 +42,7 @@ static void testSystemCalls(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (result != 0) { if (result != 0) {
// Finished 100000 iterations of 'chTimeNow()' in 33ms // Finished 100000 iterations of 'chTimeNow()' in 33ms
scheduleMsg(&logger, "Finished %d iterations of 'chTimeNow()' in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of 'chTimeNow()' in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -56,7 +56,7 @@ static void testSystemCalls(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (result != 0) { if (result != 0) {
// Finished 100000 iterations of 'chTimeNow()' with chSysLock in 144ms // Finished 100000 iterations of 'chTimeNow()' with chSysLock in 144ms
scheduleMsg(&logger, "Finished %d iterations of 'chTimeNow()' with chSysLock in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of 'chTimeNow()' with chSysLock in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -64,7 +64,7 @@ static void testSystemCalls(const int count) {
result += currentTimeMillis(); result += currentTimeMillis();
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (result != 0) if (result != 0)
scheduleMsg(&logger, "Finished %d iterations of 'currentTimeMillis' in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of 'currentTimeMillis' in %dms", count, time);
} }
static Engine testEngine; static Engine testEngine;
@ -79,14 +79,14 @@ static void testRusefiMethods(const int count) {
tempi += getBaseTableFuel(testEngine.engineConfiguration, 4020, 2.21111); tempi += getBaseTableFuel(testEngine.engineConfiguration, 4020, 2.21111);
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (tempi != 0) if (tempi != 0)
scheduleMsg(&logger, "Finished %d iterations of getBaseFuel in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of getBaseFuel in %dms", count, time);
// start = currentTimeMillis(); // start = currentTimeMillis();
// for (int i = 0; i < count; i++) // for (int i = 0; i < count; i++)
// tempi += getFuelMs(1200, NULL); // todo // tempi += getFuelMs(1200, NULL); // todo
// time = currentTimeMillis() - start; // time = currentTimeMillis() - start;
// if (tempi != 0) // if (tempi != 0)
// scheduleMsg(&logger, "Finished %d iterations of getFuelMs in %dms", count, time); // scheduleMsg(logger, "Finished %d iterations of getFuelMs in %dms", count, time);
start = currentTimeMillis(); start = currentTimeMillis();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@ -95,7 +95,7 @@ static void testRusefiMethods(const int count) {
} }
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (tempi != 0) if (tempi != 0)
scheduleMsg(&logger, "Finished %d iterations of updateSlowSensors in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of updateSlowSensors in %dms", count, time);
} }
static void testMath(const int count) { static void testMath(const int count) {
@ -108,7 +108,7 @@ static void testMath(const int count) {
} }
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (temp64 != 0) { if (temp64 != 0) {
scheduleMsg(&logger, "Finished %d iterations of int64_t summation in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of int64_t summation in %dms", count, time);
} }
temp64 = 1; temp64 = 1;
@ -118,14 +118,14 @@ static void testMath(const int count) {
} }
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (temp64 == 0) { if (temp64 == 0) {
scheduleMsg(&logger, "Finished %d iterations of int64_t multiplication in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of int64_t multiplication in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
; ;
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
scheduleMsg(&logger, "Finished %d iterations of empty loop in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of empty loop in %dms", count, time);
uint32_t tempi = 1; uint32_t tempi = 1;
start = currentTimeMillis(); start = currentTimeMillis();
@ -135,7 +135,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (tempi == 0) { if (tempi == 0) {
// Finished 100000 iterations of uint32_t summation in 11ms // Finished 100000 iterations of uint32_t summation in 11ms
scheduleMsg(&logger, "Finished %d iterations of uint32_t summation in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of uint32_t summation in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -146,7 +146,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (tempi != 0) { if (tempi != 0) {
// Finished 100000 iterations of uint32_t division in 16ms // Finished 100000 iterations of uint32_t division in 16ms
scheduleMsg(&logger, "Finished %d iterations of uint32_t division in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of uint32_t division in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -157,7 +157,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (temp64 == 0) { if (temp64 == 0) {
// Finished 100000 iterations of int64_t summation in 21ms // Finished 100000 iterations of int64_t summation in 21ms
scheduleMsg(&logger, "Finished %d iterations of int64_t summation in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of int64_t summation in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -168,7 +168,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (temp64 != 0) { if (temp64 != 0) {
// Finished 100000 iterations of int64_t division in 181ms // Finished 100000 iterations of int64_t division in 181ms
scheduleMsg(&logger, "Finished %d iterations of int64_t division in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of int64_t division in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -178,7 +178,7 @@ static void testMath(const int count) {
} }
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (tempf != 0) { if (tempf != 0) {
scheduleMsg(&logger, "Finished %d iterations of float summation in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of float summation in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -189,7 +189,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (tempf != 0) { if (tempf != 0) {
// Finished 100000 iterations of float division in 65ms // Finished 100000 iterations of float division in 65ms
scheduleMsg(&logger, "Finished %d iterations of float division in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of float division in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -200,7 +200,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (tempf != 0) { if (tempf != 0) {
// Finished 100000 iterations of float log in 191ms // Finished 100000 iterations of float log in 191ms
scheduleMsg(&logger, "Finished %d iterations of float log in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of float log in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -210,7 +210,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (tempd != 0) { if (tempd != 0) {
// Finished 100000 iterations of double summation in 80ms // Finished 100000 iterations of double summation in 80ms
scheduleMsg(&logger, "Finished %d iterations of double summation in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of double summation in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -220,7 +220,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (tempd != 0) { if (tempd != 0) {
// Finished 100000 iterations of double division in 497ms // Finished 100000 iterations of double division in 497ms
scheduleMsg(&logger, "Finished %d iterations of double division in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of double division in %dms", count, time);
} }
start = currentTimeMillis(); start = currentTimeMillis();
@ -231,12 +231,12 @@ static void testMath(const int count) {
time = currentTimeMillis() - start; time = currentTimeMillis() - start;
if (tempd != 0) { if (tempd != 0) {
// Finished 100000 iterations of double log in 242ms // Finished 100000 iterations of double log in 242ms
scheduleMsg(&logger, "Finished %d iterations of double log in %dms", count, time); scheduleMsg(logger, "Finished %d iterations of double log in %dms", count, time);
} }
} }
static void runTests(const int count) { static void runTests(const int count) {
scheduleMsg(&logger, "Running tests: %d", count); scheduleMsg(logger, "Running tests: %d", count);
testRusefiMethods(count / 10); testRusefiMethods(count / 10);
testSystemCalls(count); testSystemCalls(count);
testMath(count); testMath(count);
@ -251,12 +251,12 @@ static int rtcStartTime;
#include "chrtclib.h" #include "chrtclib.h"
static void timeInfo(void) { static void timeInfo(void) {
scheduleMsg(&logger, "chTimeNow as seconds = %d", getTimeNowSeconds()); scheduleMsg(logger, "chTimeNow as seconds = %d", getTimeNowSeconds());
scheduleMsg(&logger, "hal seconds = %d", halTime.get() / 168000000LL); scheduleMsg(logger, "hal seconds = %d", halTime.get() / 168000000LL);
#if EFI_RTC #if EFI_RTC
int unix = rtcGetTimeUnixSec(&RTCD1) - rtcStartTime; int unix = rtcGetTimeUnixSec(&RTCD1) - rtcStartTime;
scheduleMsg(&logger, "unix seconds = %d", unix); scheduleMsg(logger, "unix seconds = %d", unix);
#endif #endif
} }
@ -280,13 +280,14 @@ static void runChibioTest(void) {
TestThread(getConsoleChannel()); TestThread(getConsoleChannel());
} }
void initTimePerfActions() { void initTimePerfActions(Logging *sharedLogger) {
logger = sharedLogger;
#if EFI_RTC #if EFI_RTC
rtcStartTime = rtcGetTimeUnixSec(&RTCD1); rtcStartTime = rtcGetTimeUnixSec(&RTCD1);
#endif #endif
initLogging(&logger, "perftest");
// initOutputPin("test pad", &testOutput, TEST_PORT, TEST_PIN); // initOutputPin("test pad", &testOutput, TEST_PORT, TEST_PIN);
addConsoleActionI("perftest", runTests); addConsoleActionI("perftest", runTests);

View File

@ -8,17 +8,8 @@
#ifndef RFI_PERFTEST_H_ #ifndef RFI_PERFTEST_H_
#define RFI_PERFTEST_H_ #define RFI_PERFTEST_H_
#ifdef __cplusplus #include "global.h"
extern "C"
{
#endif /* __cplusplus */
//void testMath(int count); void initTimePerfActions(Logging *sharedLogger);
//void testSystemCalls(int count);
void initTimePerfActions(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* RFI_PERFTEST_H_ */ #endif /* RFI_PERFTEST_H_ */

View File

@ -45,7 +45,7 @@ static int waveReaderCount = 0;
static WaveReader readers[MAX_ICU_COUNT]; static WaveReader readers[MAX_ICU_COUNT];
static THD_WORKING_AREA(waThreadStack, UTILITY_THREAD_STACK_SIZE); static THD_WORKING_AREA(waThreadStack, UTILITY_THREAD_STACK_SIZE);
static LoggingWithStorage logger; static Logging * logger;
static void ensureInitialized(WaveReader *reader) { static void ensureInitialized(WaveReader *reader) {
efiAssertVoid(reader->hw.started, "wave analyzer NOT INITIALIZED"); efiAssertVoid(reader->hw.started, "wave analyzer NOT INITIALIZED");
@ -238,10 +238,9 @@ void printWave(Logging *logging) {
reportWave(logging, 1); reportWave(logging, 1);
} }
void initWaveAnalyzer(void) { void initWaveAnalyzer(Logging *sharedLogger) {
logger = sharedLogger;
#if EFI_WAVE_ANALYZER || defined(__DOXYGEN__) #if EFI_WAVE_ANALYZER || defined(__DOXYGEN__)
initLogging(&logger, "wave");
initWave(WA_CHANNEL_1, 0); initWave(WA_CHANNEL_1, 0);
initWave(WA_CHANNEL_2, 1); initWave(WA_CHANNEL_2, 1);

View File

@ -57,7 +57,7 @@ public:
volatile uint64_t last_wave_high_widthUs; // time period in systimer ticks volatile uint64_t last_wave_high_widthUs; // time period in systimer ticks
}; };
void initWaveAnalyzer(void); void initWaveAnalyzer(Logging *sharedLogger);
void printWave(Logging *logging); void printWave(Logging *logging);
#endif #endif

View File

@ -101,11 +101,8 @@
#include "efiGpio.h" #include "efiGpio.h"
#include "global.h" #include "global.h"
extern "C" {
#include "rfi_perftest.h" #include "rfi_perftest.h"
#include "rusefi.h" #include "rusefi.h"
}
#include "memstreams.h" #include "memstreams.h"
#include "eficonsole.h" #include "eficonsole.h"
@ -120,7 +117,7 @@ extern "C" {
#include "engine_emulator.h" #include "engine_emulator.h"
#endif /* EFI_ENGINE_EMULATOR */ #endif /* EFI_ENGINE_EMULATOR */
static LoggingWithStorage logging; static LoggingWithStorage sharedLogger;
int main_loop_started = FALSE; int main_loop_started = FALSE;
@ -155,7 +152,7 @@ void runRusEfi(void) {
* Next we should initialize serial port console, it's important to know what's going on * Next we should initialize serial port console, it's important to know what's going on
*/ */
initializeConsole(); initializeConsole();
initLogging(&logging, "main"); initLogging(&sharedLogger, "main");
engine->init(); engine->init();
@ -164,17 +161,17 @@ void runRusEfi(void) {
/** /**
* Initialize hardware drivers * Initialize hardware drivers
*/ */
initHardware(&logging, engine); initHardware(&sharedLogger, engine);
initStatusLoop(engine); initStatusLoop(engine);
/** /**
* Now let's initialize actual engine control logic * Now let's initialize actual engine control logic
* todo: should we initialize some? most? controllers before hardware? * todo: should we initialize some? most? controllers before hardware?
*/ */
initEngineContoller(engine); initEngineContoller(&sharedLogger, engine);
#if EFI_PERF_METRICS || defined(__DOXYGEN__) #if EFI_PERF_METRICS || defined(__DOXYGEN__)
initTimePerfActions(); initTimePerfActions(&sharedLogger);
#endif #endif
#if EFI_ENGINE_EMULATOR || defined(__DOXYGEN__) #if EFI_ENGINE_EMULATOR || defined(__DOXYGEN__)
@ -211,7 +208,7 @@ static void rebootNow(void) {
* Once day we will write graceful shutdown, but that would be one day. * Once day we will write graceful shutdown, but that would be one day.
*/ */
void scheduleReset(void) { void scheduleReset(void) {
scheduleMsg(&logging, "Rebooting in 5 seconds..."); scheduleMsg(&sharedLogger, "Rebooting in 5 seconds...");
lockAnyContext(); lockAnyContext();
chVTSetI(&resetTimer, 5 * CH_FREQUENCY, (vtfunc_t) rebootNow, NULL); chVTSetI(&resetTimer, 5 * CH_FREQUENCY, (vtfunc_t) rebootNow, NULL);
unlockAnyContext(); unlockAnyContext();

View File

@ -138,30 +138,19 @@ static void vappendPrintfI(Logging *logging, const char *fmt, va_list arg) {
append(logging, (char *) intermediateLoggingBufferData); append(logging, (char *) intermediateLoggingBufferData);
} }
/**
* this method acquires system lock to guard the shared intermediateLoggingBuffer memory stream
*/
void vappendPrintf(Logging *logging, const char *fmt, va_list arg) { void vappendPrintf(Logging *logging, const char *fmt, va_list arg) {
efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#5b"); efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#5b");
if (!intermediateLoggingBufferInited) { if (!intermediateLoggingBufferInited) {
firmwareError("intermediateLoggingBufferInited not inited!"); firmwareError("intermediateLoggingBufferInited not inited!");
return; return;
} }
int is_locked = isLocked(); int wasLocked = lockAnyContext();
int icsr_vectactive = isIsrContext();
if (is_locked) {
vappendPrintfI(logging, fmt, arg); vappendPrintfI(logging, fmt, arg);
} else { if (wasLocked) {
if (icsr_vectactive == 0) { unlockAnyContext();
chSysLock()
;
vappendPrintfI(logging, fmt, arg);
chSysUnlock()
;
} else {
chSysLockFromIsr()
;
vappendPrintfI(logging, fmt, arg);
chSysUnlockFromIsr()
;
}
} }
} }
@ -274,7 +263,7 @@ void printLine(Logging *logging) {
} }
void appendMsgPrefix(Logging *logging) { void appendMsgPrefix(Logging *logging) {
appendPrintf(logging, "msg%s", DELIMETER); append(logging, "msg" DELIMETER);
} }
void appendMsgPostfix(Logging *logging) { void appendMsgPostfix(Logging *logging) {
@ -309,7 +298,12 @@ void printMsg(Logging *logger, const char *fmt, ...) {
printLine(logger); printLine(logger);
} }
/**
* this whole method is executed under syslock so that we can have multiple threads use the same shared buffer
* in order to reduce memory usage
*/
void scheduleMsg(Logging *logging, const char *fmt, ...) { void scheduleMsg(Logging *logging, const char *fmt, ...) {
int wasLocked = lockAnyContext();
resetLogging(logging); // todo: is 'reset' really needed here? resetLogging(logging); // todo: is 'reset' really needed here?
appendMsgPrefix(logging); appendMsgPrefix(logging);
@ -320,6 +314,9 @@ void scheduleMsg(Logging *logging, const char *fmt, ...) {
appendMsgPostfix(logging); appendMsgPostfix(logging);
scheduleLogging(logging); scheduleLogging(logging);
if (wasLocked) {
unlockAnyContext();
}
} }
void scheduleLogging(Logging *logging) { void scheduleLogging(Logging *logging) {

View File

@ -16,7 +16,7 @@ void IntListenerArray::registerCallback(IntListener handler, void *arg) {
} }
void IntListenerArray::registerCallback(Void listener) { void IntListenerArray::registerCallback(Void listener) {
registerCallback((IntListener)listener, NULL);
} }
void invokeCallbacks(IntListenerArray *array, int value) { void invokeCallbacks(IntListenerArray *array, int value) {