Go to file
Tom Cherry c581886eea logd: single std::mutex for locking log buffers and tracking readers
There are only three places where the log buffer lock is not already
held when the reader lock is taken:
1) In LogReader, when a new reader connects
2) In LogReader, when a misbehaving reader disconnects
3) LogReaderThread::ThreadFunction()

1) and 2) happen sufficiently rarely that there's no impact if they
additionally held a global lock.
3) is refactored in this CL.  Previously, it would do the below in a loop
  1) Lock the reader lock then wait on a condition variable
  2) Unlock the reader lock
  3) Lock the log buffer lock in LogBuffer::FlushTo()
  4) In each iteration in the LogBuffer::FlushTo() loop
    1) Lock then unlock the reader lock in FilterSecondPass()
    2) Unlock the log buffer lock to send the message, then re-lock it
  5) Unlock the log buffer lock when leaving LogBuffer::FlushTo()
If these locks are collapsed into a single lock, then this simplifies to:
  1) Lock the single lock then wait on a condition variable
  2) In each iteration in the LogBuffer::FlushTo() loop
    1) Unlock the single lock to send the message, then re-lock it

Collapsing both these locks into a single lock simplifes the code and
removes the overhead of acquiring the second lock, in the majority of
use cases where the first lock is already held.

Secondly, this lock will be a plain std::mutex instead of a RwLock.
RwLock's are appropriate when there is a substantial imbalance between
readers and writers and high contention, neither are true for logd.

Bug: 169736426
Test: logging unit tests
Change-Id: Ia511506f2d0935a5321c1b2f65569066f91ecb06
2020-10-07 15:00:49 -07:00
adb Clarify `adb bugreport` failures on pre-N devices. 2020-10-06 13:53:38 -07:00
bootstat Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709) 2020-08-29 01:42:13 -07:00
cli-test cli-test: support checking exit status. 2020-09-25 16:43:35 -07:00
code_coverage extend syscall minijail for clang code coverage 2020-07-13 13:39:05 -07:00
cpio Remove EXCLUDE_FS_CONFIG_STRUCTURES 2020-03-04 15:34:09 -08:00
debuggerd Start tombstoned early in post-fs-data. 2020-10-01 14:25:36 -07:00
deprecated-adf remove deprecated bp 'subdirs' 2020-01-14 12:18:40 -08:00
diagnose_usb Make the udev vs plugdev distinction a bit clearer. 2020-07-31 15:09:35 -07:00
fastboot Merge "fastboot: add new oem command for post wipe userdata" 2020-10-05 02:34:52 +00:00
fs_mgr Remove vts10 related configs 2020-10-06 13:52:44 -07:00
gatekeeperd Chanage uid to userId where it denotes an Android user id. 2020-09-23 18:01:37 -07:00
healthd Assume UNSUPPORTED if the battery capacity level sysfs node does 2020-08-13 14:31:02 -07:00
include Reland: "Remove logging symlinks from system/core/include" 2020-10-06 10:45:11 -07:00
init Remove vts10 related configs 2020-10-06 13:52:44 -07:00
janitors Add the two best build system janitors. 2019-03-25 10:25:13 -07:00
libappfuse Fix Deadlock Issue On AppFuseBridge 2020-02-18 04:33:06 +00:00
libasyncio Revert "Revert "Set apex_available property"" 2020-03-26 00:23:56 +00:00
libbacktrace Add arch member into Unwinder object. 2020-09-24 18:46:23 -07:00
libbinderwrapper Make libbinderwrapper available in /vendor partition 2018-04-06 08:41:21 +09:00
libcrypto_utils libcrypto_utils: switch to C++. 2020-08-21 10:34:56 -07:00
libcutils Delete include/private/android_filesystem_config.h 2020-10-05 15:26:24 +00:00
libdiskconfig Rename target.linux[_x86[_64]] to target.linux_glibc[_x86[_64]] 2017-10-02 10:44:29 -07:00
libgrallocusage gralloc: Set min_sdk_version 2020-04-23 23:50:08 +09:00
libkeyutils Update language to comply with Android's inclusive language guidance 2020-07-31 16:36:06 -06:00
liblog Remove vts10 related configs 2020-10-06 13:52:44 -07:00
libmodprobe libmodprobe: remove SetMinimumLogSeverity() from constructor 2020-08-04 08:28:36 -07:00
libnetutils Add a libipchecksum that contains the C IP checksum code. 2020-07-09 16:35:47 +09:00
libpackagelistparser Add require_root to adbd_test and libpackagelistparser_test 2019-09-24 09:13:32 -07:00
libprocessgroup Remove vts10 related configs 2020-10-06 13:52:44 -07:00
libprocinfo Make libbacktrace buildable for native_bridge 2020-06-18 22:02:46 +02:00
libqtaguid Redirect qtaguid native call to netd fwmark client 2017-11-09 18:02:22 -08:00
libsparse Make libsparse vendor_available 2020-09-03 08:43:46 -07:00
libstats Use libcutils_headers for android_filesystem_config.h 2020-09-18 22:48:42 +00:00
libsuspend Remove libsuspend from VNDK. 2018-08-14 13:39:55 -07:00
libsync Make libsync a stubs library 2020-06-05 17:13:57 +09:00
libsystem Set min_sdk_version to be part of mainline modules 2020-05-13 08:18:06 +09:00
libsysutils SocketClient: don't ignore SIGPIPE 2020-07-31 15:53:18 -07:00
libunwindstack libunwindstack: Support signal frame CIEs. 2020-10-02 16:34:14 -07:00
libusbhost Prevent infinite loop on zero length USB descriptors 2020-02-21 11:11:02 -08:00
libutils DO NOT MERGE - Merge RP1A.201005.006 2020-10-06 04:30:21 +00:00
libvndksupport remove deprecated bp 'subdirs' 2020-01-14 12:18:40 -08:00
llkd llkd: Use more inclusive language 2020-06-16 10:28:14 -07:00
logcat logcat: fix tests broken from new formatting 2020-09-01 21:33:34 +00:00
logd logd: single std::mutex for locking log buffers and tracking readers 2020-10-07 15:00:49 -07:00
logwrapper logwrap: add missing O_CLOEXEC 2020-02-26 10:29:04 -08:00
property_service Cleanup for #inclusivefixit. 2020-07-27 11:37:19 -07:00
qemu_pipe Use more inclusive language for #inclusivefixit 2020-07-28 00:22:59 +00:00
reboot adb: replace reboot service with exec of /system/bin/reboot. 2019-10-23 14:33:36 -07:00
rootdir Merge "Activate encryption for /data/app-staging folder" 2020-10-05 16:01:59 +00:00
run-as Use libcutils_headers for android_filesystem_config.h 2020-09-18 22:48:42 +00:00
sdcard Move layout_version to /data/misc/installd 2019-08-21 10:12:18 -07:00
set-verity-state set-verity-state: Link to libfs_mgr_binder. 2019-12-30 13:42:57 -08:00
shell_and_utilities Add the rough toybox version numbers to the docs. 2020-08-06 10:15:25 -07:00
storaged storaged: ignore SIGPIPE 2020-03-17 09:31:01 -07:00
toolbox Merge "toolbox: make all janitors the owners." am: 5f33339b2f am: 459b5d6350 2020-07-13 18:10:13 +00:00
trusty Merge "trusty: keymaster: set_attestation_key: Change wrapped key" 2020-10-06 23:31:38 +00:00
usbd Remove libhwbinder/libhidltransport deps 2019-09-05 14:17:42 -07:00
watchdogd Move watchdogd out of init 2018-08-02 12:25:58 -07:00
.clang-format Add a 2 width option of clang format. 2017-03-10 13:01:39 -08:00
.clang-format-2 Move clang-formats to build. 2019-01-18 14:26:33 -08:00
.clang-format-4 Move clang-formats to build. 2019-01-18 14:26:33 -08:00
.gitignore Ignore adb/*.pyc files 2015-08-11 12:59:58 -07:00
CleanSpec.mk snapshotctl don't auto-merge. 2020-03-03 13:19:49 -08:00
METADATA Add METADATA to system/core: Apache2+BSD=NOTICE 2020-04-29 13:16:41 -07:00
MODULE_LICENSE_APACHE2 auto import from //depot/cupcake/@135843 2013-07-30 13:56:49 -07:00
NOTICE Fix omission in NOTICE file. 2013-07-30 13:56:55 -07:00
OWNERS Move per-file OWNERS directives to their directories. 2018-06-06 11:49:40 +09:00
PREUPLOAD.cfg Add AOSP preupload hook. 2020-04-23 11:02:00 -07:00
TEST_MAPPING Run liblog and logd CTS tests in presubmit 2020-07-29 08:02:52 -07:00
base Migrate system/core/base to system/libbase. 2020-05-19 21:32:42 +00:00