diff options
author | Elliott Hughes <enh@google.com> | 2017-10-17 15:34:41 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2017-10-25 14:28:42 -0700 |
commit | 8aecba7aa6b7f7b92f69c0d3febef59fdb135f87 (patch) | |
tree | fd3d9743a0e282dcbb2a8b2b51906f7da3a84468 /libc/async_safe/async_safe_log.cpp | |
parent | 435e6384de8f9e35b8878b1ccda5bb5686c15207 (diff) |
Implement pthread_attr_getinheritsched/pthread_attr_setinheritsched.
Historically, Android defaulted to EXPLICIT but with a special case
because SCHED_NORMAL/priority 0 was awkward. Because the code couldn't
actually tell whether SCHED_NORMAL/priority 0 was a genuine attempt to
explicitly set those attributes (because the parent thread is SCHED_FIFO,
say) or just because the pthread_attr_t was left at its defaults.
Now we support INHERIT, we could call sched_getscheduler to see whether
we actually need to call sched_setscheduler, but since the major cost
is the fixed syscall overhead, we may as well just conservatively
call sched_setscheduler and let the kernel decide whether it's a
no-op. (Especially because we'd then have to add both sched_getscheduler
and sched_setscheduler to any seccomp filter.)
Platform code (or app code that only needs to support >= P) can actually
add a call to pthread_attr_setinheritsched to say that they just want
to inherit (if they know that none of their threads actually mess with
scheduler attributes at all), which will save them a sched_setscheduler
call except in the doubly-special case of SCHED_RESET_ON_FORK (which we
do handle).
An alternative would be "make pthread_attr_setschedparams and
pthread_attr_setschedprio set EXPLICIT and change the platform default
to INHERIT", but even though I can only think of weird pathological
examples where anyone would notice that change, that behavior -- of
pthread_attr_setschedparams/pthread_attr_setschedprio overriding an
earlier call to pthread_attr_setinheritsched -- isn't allowed by POSIX
(whereas defaulting to EXPLICIT is).
If we have a lot of trouble with this change in the app compatibility
testing phase, though, we'll want to reconsider this decision!
-*-
This change also removes a comment about setting the scheduler attributes
in main_thread because we'd have to actually keep them up to date,
and it's not clear that doing so would be worth the trouble.
Also make async_safe_format_log preserve errno so we don't have to be
so careful around it.
Bug: http://b/67471710
Test: ran tests
Change-Id: Idd026c4ce78a536656adcb57aa2e7b2c616eeddf
Diffstat (limited to 'libc/async_safe/async_safe_log.cpp')
-rw-r--r-- | libc/async_safe/async_safe_log.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/libc/async_safe/async_safe_log.cpp b/libc/async_safe/async_safe_log.cpp index 78f62bdba..d5aad16d6 100644 --- a/libc/async_safe/async_safe_log.cpp +++ b/libc/async_safe/async_safe_log.cpp @@ -47,6 +47,7 @@ #include <async_safe/log.h> #include "private/CachedProperty.h" +#include "private/ErrnoRestorer.h" #include "private/ScopedPthreadMutexLocker.h" // Must be kept in sync with frameworks/base/core/java/android/util/EventLog.java. @@ -508,6 +509,7 @@ int async_safe_write_log(int priority, const char* tag, const char* msg) { } int async_safe_format_log_va_list(int priority, const char* tag, const char* format, va_list args) { + ErrnoRestorer errno_restorer; char buffer[1024]; BufferOutputStream os(buffer, sizeof(buffer)); out_vformat(os, format, args); |