This commit is contained in:
Matthew Kennedy 2019-11-21 20:45:16 -08:00 committed by rusefi
parent 9597215ad9
commit 1ad5b55dbb
2 changed files with 15 additions and 7 deletions

View File

@ -487,7 +487,9 @@ static bool isKnownCommand(char command) {
|| command == TS_GET_LOGGER_BUFFER
|| command == TS_GET_TEXT
|| command == TS_CRC_CHECK_COMMAND
|| command == TS_GET_FIRMWARE_VERSION;
|| command == TS_GET_FIRMWARE_VERSION
|| command == TS_PERF_TRACE_BEGIN
|| command == TS_PERF_TRACE_GET_BUFFER;
}
// this function runs indefinitely
@ -855,6 +857,8 @@ int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomin
case TS_PERF_TRACE_BEGIN:
#if ENABLE_PERF_TRACE
perfTraceEnable();
sendOkResponse(tsChannel, TS_CRC);
#endif /* ENABLE_PERF_TRACE */
break;
case TS_PERF_TRACE_GET_BUFFER:

View File

@ -47,13 +47,19 @@ void perfEventImpl(PE event, EPhase phase, uint8_t data)
return;
}
uint32_t timestamp = getTimeNowLowerNt();
// todo: why doesn't getTimeNowLowerNt() work here?
// It returns 0 like we're in a unit test
uint32_t timestamp = port_rt_get_counter_value();
size_t idx;
// Critical section: reserve index under lock
// Critical section: disable interrupts to reserve an index.
// We could lock, but this gets called a LOT - so locks could
// significantly alter the results of the measurement.
// In addition, if we want to trace lock/unlock events, we can't
// be locking ourselves from the trace functionality.
{
bool wasLocked = lockAnyContext();
__disable_irq();
idx = s_nextIdx++;
if (s_nextIdx >= TRACE_BUFFER_LENGTH) {
@ -61,9 +67,7 @@ void perfEventImpl(PE event, EPhase phase, uint8_t data)
s_isTracing = false;
}
if (!wasLocked) {
unlockAnyContext();
}
__enable_irq();
}
// We can safely write data out of the lock, our spot is reserved