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) {
int alreadyLocked = isLocked();
if (alreadyLocked)
return TRUE;
return true;
if (isIsrContext()) {
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);
}
void initEngineContoller(Engine *engine) {
void initEngineContoller(Logging *sharedLogger, Engine *engine) {
if (hasFirmwareError()) {
return;
}
@ -326,7 +326,7 @@ void initEngineContoller(Engine *engine) {
#if EFI_WAVE_ANALYZER
if (engineConfiguration->isWaveAnalyzerEnabled) {
initWaveAnalyzer();
initWaveAnalyzer(sharedLogger);
}
#endif /* EFI_WAVE_ANALYZER */

View File

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

View File

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

View File

@ -20,7 +20,7 @@
#if EFI_PERF_METRICS || defined(__DOXYGEN__)
static LoggingWithStorage logger;
static Logging* logger;
static void testSystemCalls(const int count) {
time_t start, time;
@ -42,7 +42,7 @@ static void testSystemCalls(const int count) {
time = currentTimeMillis() - start;
if (result != 0) {
// 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();
@ -56,7 +56,7 @@ static void testSystemCalls(const int count) {
time = currentTimeMillis() - start;
if (result != 0) {
// 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();
@ -64,7 +64,7 @@ static void testSystemCalls(const int count) {
result += currentTimeMillis();
time = currentTimeMillis() - start;
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;
@ -79,14 +79,14 @@ static void testRusefiMethods(const int count) {
tempi += getBaseTableFuel(testEngine.engineConfiguration, 4020, 2.21111);
time = currentTimeMillis() - start;
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();
// for (int i = 0; i < count; i++)
// tempi += getFuelMs(1200, NULL); // todo
// time = currentTimeMillis() - start;
// 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();
for (int i = 0; i < count; i++) {
@ -95,7 +95,7 @@ static void testRusefiMethods(const int count) {
}
time = currentTimeMillis() - start;
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) {
@ -108,7 +108,7 @@ static void testMath(const int count) {
}
time = currentTimeMillis() - start;
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;
@ -118,14 +118,14 @@ static void testMath(const int count) {
}
time = currentTimeMillis() - start;
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();
for (int i = 0; i < count; i++)
;
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;
start = currentTimeMillis();
@ -135,7 +135,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start;
if (tempi == 0) {
// 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();
@ -146,7 +146,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start;
if (tempi != 0) {
// 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();
@ -157,7 +157,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start;
if (temp64 == 0) {
// 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();
@ -168,7 +168,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start;
if (temp64 != 0) {
// 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();
@ -178,7 +178,7 @@ static void testMath(const int count) {
}
time = currentTimeMillis() - start;
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();
@ -189,7 +189,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start;
if (tempf != 0) {
// 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();
@ -200,7 +200,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start;
if (tempf != 0) {
// 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();
@ -210,7 +210,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start;
if (tempd != 0) {
// 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();
@ -220,7 +220,7 @@ static void testMath(const int count) {
time = currentTimeMillis() - start;
if (tempd != 0) {
// 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();
@ -231,12 +231,12 @@ static void testMath(const int count) {
time = currentTimeMillis() - start;
if (tempd != 0) {
// 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) {
scheduleMsg(&logger, "Running tests: %d", count);
scheduleMsg(logger, "Running tests: %d", count);
testRusefiMethods(count / 10);
testSystemCalls(count);
testMath(count);
@ -251,12 +251,12 @@ static int rtcStartTime;
#include "chrtclib.h"
static void timeInfo(void) {
scheduleMsg(&logger, "chTimeNow as seconds = %d", getTimeNowSeconds());
scheduleMsg(&logger, "hal seconds = %d", halTime.get() / 168000000LL);
scheduleMsg(logger, "chTimeNow as seconds = %d", getTimeNowSeconds());
scheduleMsg(logger, "hal seconds = %d", halTime.get() / 168000000LL);
#if EFI_RTC
int unix = rtcGetTimeUnixSec(&RTCD1) - rtcStartTime;
scheduleMsg(&logger, "unix seconds = %d", unix);
scheduleMsg(logger, "unix seconds = %d", unix);
#endif
}
@ -280,13 +280,14 @@ static void runChibioTest(void) {
TestThread(getConsoleChannel());
}
void initTimePerfActions() {
void initTimePerfActions(Logging *sharedLogger) {
logger = sharedLogger;
#if EFI_RTC
rtcStartTime = rtcGetTimeUnixSec(&RTCD1);
#endif
initLogging(&logger, "perftest");
// initOutputPin("test pad", &testOutput, TEST_PORT, TEST_PIN);
addConsoleActionI("perftest", runTests);

View File

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

View File

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

View File

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

View File

@ -101,11 +101,8 @@
#include "efiGpio.h"
#include "global.h"
extern "C" {
#include "rfi_perftest.h"
#include "rusefi.h"
}
#include "memstreams.h"
#include "eficonsole.h"
@ -120,7 +117,7 @@ extern "C" {
#include "engine_emulator.h"
#endif /* EFI_ENGINE_EMULATOR */
static LoggingWithStorage logging;
static LoggingWithStorage sharedLogger;
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
*/
initializeConsole();
initLogging(&logging, "main");
initLogging(&sharedLogger, "main");
engine->init();
@ -164,17 +161,17 @@ void runRusEfi(void) {
/**
* Initialize hardware drivers
*/
initHardware(&logging, engine);
initHardware(&sharedLogger, engine);
initStatusLoop(engine);
/**
* Now let's initialize actual engine control logic
* todo: should we initialize some? most? controllers before hardware?
*/
initEngineContoller(engine);
initEngineContoller(&sharedLogger, engine);
#if EFI_PERF_METRICS || defined(__DOXYGEN__)
initTimePerfActions();
initTimePerfActions(&sharedLogger);
#endif
#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.
*/
void scheduleReset(void) {
scheduleMsg(&logging, "Rebooting in 5 seconds...");
scheduleMsg(&sharedLogger, "Rebooting in 5 seconds...");
lockAnyContext();
chVTSetI(&resetTimer, 5 * CH_FREQUENCY, (vtfunc_t) rebootNow, NULL);
unlockAnyContext();

View File

@ -138,30 +138,19 @@ static void vappendPrintfI(Logging *logging, const char *fmt, va_list arg) {
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) {
efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#5b");
if (!intermediateLoggingBufferInited) {
firmwareError("intermediateLoggingBufferInited not inited!");
return;
}
int is_locked = isLocked();
int icsr_vectactive = isIsrContext();
if (is_locked) {
int wasLocked = lockAnyContext();
vappendPrintfI(logging, fmt, arg);
} else {
if (icsr_vectactive == 0) {
chSysLock()
;
vappendPrintfI(logging, fmt, arg);
chSysUnlock()
;
} else {
chSysLockFromIsr()
;
vappendPrintfI(logging, fmt, arg);
chSysUnlockFromIsr()
;
}
if (wasLocked) {
unlockAnyContext();
}
}
@ -274,7 +263,7 @@ void printLine(Logging *logging) {
}
void appendMsgPrefix(Logging *logging) {
appendPrintf(logging, "msg%s", DELIMETER);
append(logging, "msg" DELIMETER);
}
void appendMsgPostfix(Logging *logging) {
@ -309,7 +298,12 @@ void printMsg(Logging *logger, const char *fmt, ...) {
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, ...) {
int wasLocked = lockAnyContext();
resetLogging(logging); // todo: is 'reset' really needed here?
appendMsgPrefix(logging);
@ -320,6 +314,9 @@ void scheduleMsg(Logging *logging, const char *fmt, ...) {
appendMsgPostfix(logging);
scheduleLogging(logging);
if (wasLocked) {
unlockAnyContext();
}
}
void scheduleLogging(Logging *logging) {

View File

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