remove virtual calls from hot path (#1857)

* const ref-ify

* no virtual 

* even more const

* tests

* fix tests
This commit is contained in:
Matthew Kennedy 2020-10-05 13:42:50 -07:00 committed by GitHub
parent 5925a5f4bd
commit c9fdde4472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 32 deletions

View File

@ -96,6 +96,10 @@ void Engine::initializeTriggerWaveform(Logging *logger DECLARE_ENGINE_PARAMETER_
static TriggerState initState;
INJECT_ENGINE_REFERENCE(&initState);
// Re-read config in case it's changed
primaryTriggerConfiguration.update();
vvtTriggerConfiguration.update();
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
// we have a confusing threading model so some synchronization would not hurt
bool alreadyLocked = lockAnyContext();
@ -164,7 +168,11 @@ static void assertCloseTo(const char * msg, float actual, float expected) {
void Engine::periodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
ScopePerf perf(PE::EnginePeriodicSlowCallback);
// Re-read config in case it's changed
primaryTriggerConfiguration.update();
vvtTriggerConfiguration.update();
watchdog();
updateSlowSensors(PASS_ENGINE_PARAMETER_SIGNATURE);
checkShutdown(PASS_ENGINE_PARAMETER_SIGNATURE);
@ -401,6 +409,9 @@ void Engine::injectEngineReferences() {
INJECT_ENGINE_REFERENCE(&primaryTriggerConfiguration);
INJECT_ENGINE_REFERENCE(&vvtTriggerConfiguration);
primaryTriggerConfiguration.update();
vvtTriggerConfiguration.update();
triggerCentral.init(PASS_ENGINE_PARAMETER_SIGNATURE);
}

View File

@ -56,20 +56,22 @@ class IInjectorModel;
class PrimaryTriggerConfiguration final : public TriggerConfiguration {
public:
bool isUseOnlyRisingEdgeForTrigger() const;
const char * getPrintPrefix() const;
bool isVerboseTriggerSynchDetails() const;
debug_mode_e getDebugMode() const;
trigger_type_e getType() const;
PrimaryTriggerConfiguration() : TriggerConfiguration("TRG ") {}
protected:
bool isUseOnlyRisingEdgeForTrigger() const override;
bool isVerboseTriggerSynchDetails() const override;
trigger_type_e getType() const override;
};
class VvtTriggerConfiguration final : public TriggerConfiguration {
public:
bool isUseOnlyRisingEdgeForTrigger() const;
const char * getPrintPrefix() const;
bool isVerboseTriggerSynchDetails() const;
debug_mode_e getDebugMode() const;
trigger_type_e getType() const;
VvtTriggerConfiguration() : TriggerConfiguration("TRG ") {}
protected:
bool isUseOnlyRisingEdgeForTrigger() const override;
bool isVerboseTriggerSynchDetails() const override;
trigger_type_e getType() const override;
};
class Engine final : public TriggerStateListener {

View File

@ -251,6 +251,12 @@ void printCurrentState(Logging *logging, int seconds, const char *engineTypeName
DELIMETER);
}
void TriggerConfiguration::update() {
UseOnlyRisingEdgeForTrigger = isUseOnlyRisingEdgeForTrigger();
VerboseTriggerSynchDetails = isVerboseTriggerSynchDetails();
TriggerType = getType();
}
bool PrimaryTriggerConfiguration::isUseOnlyRisingEdgeForTrigger() const {
return CONFIG(useOnlyRisingEdgeForTrigger);
}
@ -259,10 +265,6 @@ trigger_type_e PrimaryTriggerConfiguration::getType() const {
return CONFIG(trigger.type);
}
const char * PrimaryTriggerConfiguration::getPrintPrefix() const {
return "TRG ";
}
bool PrimaryTriggerConfiguration::isVerboseTriggerSynchDetails() const {
return CONFIG(verboseTriggerSynchDetails);
}
@ -271,10 +273,6 @@ bool VvtTriggerConfiguration::isUseOnlyRisingEdgeForTrigger() const {
return CONFIG(vvtCamSensorUseRise);
}
const char * VvtTriggerConfiguration::getPrintPrefix() const {
return "VVT ";
}
trigger_type_e VvtTriggerConfiguration::getType() const {
return engine->triggerCentral.vvtTriggerType;
}

View File

@ -318,7 +318,7 @@ static trigger_value_e eventType[6] = { TV_FALL, TV_RISE, TV_FALL, TV_RISE, TV_F
/* odd event - start accumulation */ \
currentCycle.timeOfPreviousEventNt[triggerWheel] = nowNt; \
} \
if (triggerConfiguration.isUseOnlyRisingEdgeForTrigger()) {currentCycle.current_index++;} \
if (triggerConfiguration.UseOnlyRisingEdgeForTrigger) {currentCycle.current_index++;} \
currentCycle.current_index++; \
PRINT_INC_INDEX; \
}
@ -423,9 +423,7 @@ void TriggerState::decodeTriggerEvent(
}
previousShaftEventTimeNt = nowNt;
bool useOnlyRisingEdgeForTrigger = triggerConfiguration.isUseOnlyRisingEdgeForTrigger();
bool useOnlyRisingEdgeForTrigger = triggerConfiguration.UseOnlyRisingEdgeForTrigger;
efiAssertVoid(CUSTOM_TRIGGER_UNEXPECTED, signal <= SHAFT_3RD_RISING, "unexpected signal");
@ -458,7 +456,7 @@ void TriggerState::decodeTriggerEvent(
#if EFI_UNIT_TEST
if (printTriggerTrace) {
printf("%s isLessImportant %s now=%d index=%d\r\n",
getTrigger_type_e(triggerConfiguration.getType()),
getTrigger_type_e(triggerConfiguration.TriggerType),
getTrigger_event_e(signal),
(int)nowNt,
currentCycle.current_index);
@ -474,7 +472,7 @@ void TriggerState::decodeTriggerEvent(
#if !EFI_PROD_CODE
if (printTriggerTrace) {
printf("%s event %s %d\r\n",
getTrigger_type_e(triggerConfiguration.getType()),
getTrigger_type_e(triggerConfiguration.TriggerType),
getTrigger_event_e(signal),
nowNt);
printf("decodeTriggerEvent ratio %.2f: current=%d previous=%d\r\n", 1.0 * toothDurations[0] / toothDurations[1],
@ -547,7 +545,7 @@ void TriggerState::decodeTriggerEvent(
#endif /* EFI_UNIT_TEST */
#if EFI_PROD_CODE || EFI_SIMULATOR
if (triggerConfiguration.isVerboseTriggerSynchDetails() || (someSortOfTriggerError && !silentTriggerError)) {
if (triggerConfiguration.VerboseTriggerSynchDetails || (someSortOfTriggerError && !silentTriggerError)) {
for (int i = 0;i<triggerShape.gapTrackingLength;i++) {
float ratioFrom = triggerShape.syncronizationRatioFrom[i];
if (cisnan(ratioFrom)) {
@ -561,7 +559,7 @@ void TriggerState::decodeTriggerEvent(
i);
} else {
scheduleMsg(logger, "%s rpm=%d time=%d index=%d: gap=%.3f expected from %.3f to %.3f error=%s",
triggerConfiguration.getPrintPrefix(),
triggerConfiguration.PrintPrefix,
GET_RPM(),
/* cast is needed to make sure we do not put 64 bit value to stack*/ (int)getTimeNowSeconds(),
i,
@ -594,7 +592,7 @@ void TriggerState::decodeTriggerEvent(
* in case of noise the counter could be above the expected number of events, that's why 'more or equals' and not just 'equals'
*/
unsigned int endOfCycleIndex = triggerShape.getSize() - (triggerConfiguration.isUseOnlyRisingEdgeForTrigger() ? 2 : 1);
unsigned int endOfCycleIndex = triggerShape.getSize() - (triggerConfiguration.UseOnlyRisingEdgeForTrigger ? 2 : 1);
isSynchronizationPoint = !shaft_is_synchronized || (currentCycle.current_index >= endOfCycleIndex);
@ -611,7 +609,7 @@ void TriggerState::decodeTriggerEvent(
#if EFI_UNIT_TEST
if (printTriggerTrace) {
printf("decodeTriggerEvent %s isSynchronizationPoint=%d index=%d %s\r\n",
getTrigger_type_e(triggerConfiguration.getType()),
getTrigger_type_e(triggerConfiguration.TriggerType),
isSynchronizationPoint, currentCycle.current_index,
getTrigger_event_e(signal));
}

View File

@ -27,9 +27,17 @@ class TriggerConfiguration {
public:
DECLARE_ENGINE_PTR;
explicit TriggerConfiguration(const char* printPrefix) : PrintPrefix(printPrefix) {}
void update();
const char* const PrintPrefix;
bool UseOnlyRisingEdgeForTrigger;
bool VerboseTriggerSynchDetails;
trigger_type_e TriggerType;
protected:
virtual bool isUseOnlyRisingEdgeForTrigger() const = 0;
virtual bool isVerboseTriggerSynchDetails() const = 0;
virtual const char * getPrintPrefix() const = 0;
virtual trigger_type_e getType() const = 0;
};

View File

@ -22,7 +22,7 @@ static const bool isRisingEdge[HW_EVENT_TYPES] = { false, true, false, true, fal
* @return true if front should be decoded further, false if we are not interested
*/
bool isUsefulSignal(trigger_event_e signal, const TriggerConfiguration& triggerConfiguration) {
return !triggerConfiguration.isUseOnlyRisingEdgeForTrigger() || isRisingEdge[(int) signal];
return !triggerConfiguration.UseOnlyRisingEdgeForTrigger || isRisingEdge[(int) signal];
}
#if EFI_UNIT_TEST
@ -122,7 +122,7 @@ void TriggerStimulatorHelper::assertSyncPositionAndSetDutyCycle(
}
int revolutionCounter = state.getTotalRevolutionCounter();
if (revolutionCounter != GAP_TRACKING_LENGTH + 1) {
warning(CUSTOM_OBD_TRIGGER_WAVEFORM, "sync failed/wrong gap parameters trigger=%s rc=%d", getTrigger_type_e(triggerConfiguration.getType()), revolutionCounter);
warning(CUSTOM_OBD_TRIGGER_WAVEFORM, "sync failed/wrong gap parameters trigger=%s rc=%d", getTrigger_type_e(triggerConfiguration.TriggerType), revolutionCounter);
shape.setShapeDefinitionError(true);
return;
}