logd: don't poll() before recvmsg()
LogListener uses the libsysutils SocketListener class to read incoming log messages, which means that it poll()'s to wait for new data then calls recvmsg() when this data is available. That is unnecessary, since this is a blocking socket, it already has a dedicated thread, and we're not using any other SocketListner features, so a tight loop of recvmsg() is sufficient. Below are the stats from simpleperf during a framework restart. To get an apples to apples comparison, these stats calculate the overhead of receiving the message as 1 - (<number of perf events dispatching the logs in logd>/<total number of perf events for the listener thread>). With SocketListener / poll() 378563153 total events for the listener thread - SocketListener::runListener() 245799364 events for reading and dispatching logs + recvmsg() - LogListener::onDataAvailable() 67622952 events for recvmsg() inside LogListener::onDataAvailable() => (378563153 - 245799364) = 132763789 SocketListener + poll() overhead => (132763789 + 67622952) = 200386741 total overhead to for recvmsg() + poll() + SocketListener => (200386741 / 378563153) = 52.9% overhead to read each log message. Without SocketListener / poll() 324802401 total events for the new listener thread - LogListener::ThreadFunction() 133208105 events for recvmsg() => (133208105 / 324802401) = 41% overhead to read each log message. This shows a 22.5% = (41 - 52.9)/52.9 reduction in cost spent for each log message. Test: logging unit tests Test: simpleperf Change-Id: I1f93b7a06fac6adce8e64e727bf6d8c5935c77c9
Loading
Please register or sign in to comment