logd: yield in FlushTo() if a write is pending
In bug 164973960, we see a situation where a log reader thread spends
over a second sending logs to a new client, preventing the log writer
thread from handling new logs. This eventually causes the logging
socket to back up and log messages to block until the reader thread
finishes.
logd.reader.per threads may hold the logd_lock for a significant
amount of time. For example, when doing a 'tail' operation,
SerializedLogBuffer::FlushTo() will loop through every log message in
the log buffer with the lock held. This can be 100000+ logs and
involve multiple compressions and decompressions.
This change adds a pending_write_ variable that
SerializedLogBuffer::Log() sets before attempting to acquire logd
lock. During each loop in SerializedLogBuffer::FlushTo(), if this
variable is set, then we release logd_lock and wait on this variable
before attempting to reacquire it. This ensures that logd.reader.per
threads will not block log writer threads.
Bug: 164973960
Test: logging unit tests
Test: view chromium-trace output showing logd.writer getting cycles
while a logd.reader.per thread is running a 'tail' operation.
Change-Id: I940d14bb7e8cb2313a96b2a16cdea918ade8a37f
3 files changed