rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Namespaces | Typedefs | Functions | Variables
loggingcentral.cpp File Reference

Detailed Description

This file implements text logging.

Uses a queue of buffers so that the expensive printf operation doesn't require exclusive access (ie, global system lock) to log. In the past there have been serious performance problems caused by heavy logging on a low priority thread that blocks the rest of the system running (trigger errors, etc).

Uses ChibiOS message queues to maintain one queue of free buffers, and one queue of used buffers. When a thread wants to write, it acquires a free buffer, prints to it, and pushes it in to the used queue. A dedicated thread then dequeues and writes lines from the used buffer in to the large output buffer.

Later, the binary TS thread will request access to the output log buffer for reading, so a lock is taken, buffers, swapped, and the back buffer returned. This blocks neither output nor logging in any case, as each operation operates on a different buffer.

Date
Mar 8, 2015, heavily revised April 2021
Author
Andrey Belomutskiy, (c) 2012-2021
Matthew Kennedy

Definition in file loggingcentral.cpp.

Namespaces

namespace  priv
 

Typedefs

using LB = LogBuffer< DL_OUTPUT_BUFFER >
 

Functions

const charswapOutputBuffers (size_t *actualOutputBufferSize)
 
void startLoggingProcessor ()
 
void priv::efiPrintfInternal (const char *format,...)
 
void scheduleLogging (Logging *logging)
 

Variables

chibios_rt::Mutex logBufferMutex
 
LB buffers [2]
 
LBwriteBuffer = &buffers[0]
 
LBreadBuffer = &buffers[1]
 
constexpr size_t lineBufferCount = 24
 
static LogLineBuffer lineBuffers [lineBufferCount]
 
static chibios_rt::Mailbox< LogLineBuffer *, lineBufferCountfreeBuffers
 
static chibios_rt::Mailbox< LogLineBuffer *, lineBufferCountfilledBuffers
 
static LoggingBufferFlusher lbf
 
bool verboseMode
 

Typedef Documentation

◆ LB

using LB = LogBuffer<DL_OUTPUT_BUFFER>

Definition at line 83 of file loggingcentral.cpp.

Function Documentation

◆ scheduleLogging()

void scheduleLogging ( Logging logging)

This method appends the content of specified thread-local logger into the global buffer of logging content.

This is a legacy function, most normal logging should use efiPrintf

Definition at line 237 of file loggingcentral.cpp.

237 {
238#if (EFI_PROD_CODE || EFI_SIMULATOR) && EFI_TEXT_LOGGING
239 // Lock the buffer mutex - inhibit buffer swaps while writing
240 {
241 chibios_rt::MutexLocker lock(logBufferMutex);
242
243 writeBuffer->writeLogger(logging);
244 }
245
246 // Reset the logging now that it's been written out
247 logging->reset();
248#endif
249}
void writeLogger(Logging *logging)
void reset()
chibios_rt::Mutex logBufferMutex
LB * writeBuffer

Referenced by printHistogram(), WaveChart::publish(), and updateDevConsoleState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startLoggingProcessor()

void startLoggingProcessor ( )

Definition at line 159 of file loggingcentral.cpp.

159 {
160 // Push all buffers in to the free queue
161 for (size_t i = 0; i < lineBufferCount; i++) {
162 freeBuffers.post(&lineBuffers[i], TIME_INFINITE);
163 }
164
165 // Start processing used buffers
166 lbf.start();
167}
static LogLineBuffer lineBuffers[lineBufferCount]
constexpr size_t lineBufferCount
static LoggingBufferFlusher lbf
static chibios_rt::Mailbox< LogLineBuffer *, lineBufferCount > freeBuffers

Referenced by runRusEfi().

Here is the caller graph for this function:

◆ swapOutputBuffers()

const char * swapOutputBuffers ( size_t actualOutputBufferSize)

Actual communication layer invokes this method when it's ready to send some data out

Returns
pointer to the buffer which should be print to console

Definition at line 93 of file loggingcentral.cpp.

93 {
94 {
95 chibios_rt::MutexLocker lock(logBufferMutex);
96
97 // Swap buffers under lock
98 auto temp = writeBuffer;
100 readBuffer = temp;
101
102 // Reset the front buffer - it's now empty
104 }
105
106 *actualOutputBufferSize = readBuffer->length();
107#if EFI_ENABLE_ASSERTS
108 size_t expectedOutputSize = std::strlen(readBuffer->get());
109
110 // Check that the actual length of the buffer matches the expected length of how much we thought we wrote
111 if (*actualOutputBufferSize != expectedOutputSize) {
112 firmwareError(ObdCode::ERROR_LOGGING_SIZE_CALC, "lsize mismatch %d vs strlen %d", *actualOutputBufferSize, expectedOutputSize);
113
114 return nullptr;
115 }
116#endif /* EFI_ENABLE_ASSERTS */
117 return readBuffer->get();
118}
size_t length() const
const char * get() const
void firmwareError(ObdCode code, const char *fmt,...)
LB * readBuffer
@ ERROR_LOGGING_SIZE_CALC

Referenced by handleGetText().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ buffers

LB buffers[2]

Definition at line 84 of file loggingcentral.cpp.

◆ filledBuffers

chibios_rt::Mailbox<LogLineBuffer*, lineBufferCount> filledBuffers
static

Definition at line 127 of file loggingcentral.cpp.

Referenced by priv::efiPrintfInternal().

◆ freeBuffers

chibios_rt::Mailbox<LogLineBuffer*, lineBufferCount> freeBuffers
static

Definition at line 125 of file loggingcentral.cpp.

Referenced by priv::efiPrintfInternal(), and startLoggingProcessor().

◆ lbf

LoggingBufferFlusher lbf
static

Definition at line 157 of file loggingcentral.cpp.

Referenced by startLoggingProcessor().

◆ lineBufferCount

constexpr size_t lineBufferCount = 24
constexpr

Definition at line 121 of file loggingcentral.cpp.

Referenced by startLoggingProcessor().

◆ lineBuffers

LogLineBuffer lineBuffers[lineBufferCount]
static

Definition at line 122 of file loggingcentral.cpp.

Referenced by startLoggingProcessor().

◆ logBufferMutex

chibios_rt::Mutex logBufferMutex

Definition at line 78 of file loggingcentral.cpp.

Referenced by scheduleLogging(), and swapOutputBuffers().

◆ readBuffer

LB* readBuffer = &buffers[1]

Definition at line 86 of file loggingcentral.cpp.

Referenced by swapOutputBuffers().

◆ verboseMode

bool verboseMode
extern

Referenced by priv::efiPrintfInternal().

◆ writeBuffer

LB* writeBuffer = &buffers[0]

Definition at line 85 of file loggingcentral.cpp.

Referenced by scheduleLogging(), and swapOutputBuffers().

Go to the source code of this file.