platform_bionic/libc/include
Elliott Hughes 8aecba7aa6 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
2017-10-25 14:28:42 -07:00
..
android Fix "Add a legacy inline for mmap64". 2017-10-06 16:01:36 -07:00
arpa Name function arguments in libc headers for Studio. 2017-08-21 14:51:59 -07:00
bits Implement pthread_attr_getinheritsched/pthread_attr_setinheritsched. 2017-10-25 14:28:42 -07:00
net Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
netinet Name function arguments in libc headers for Studio. 2017-08-11 17:45:59 -07:00
netpacket auto import from //depot/cupcake/@135843 2009-03-03 19:28:35 -08:00
sys Fix "Add a legacy inline for mmap64". 2017-10-06 16:01:36 -07:00
alloca.h Always include <sys/cdefs.h>. 2016-07-22 17:01:54 -07:00
ar.h Always include <sys/cdefs.h>. 2016-07-22 17:01:54 -07:00
assert.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
byteswap.h Always include <sys/cdefs.h>. 2016-07-22 17:01:54 -07:00
complex.h Use __RENAME for long double functions. 2017-09-14 16:10:43 -07:00
cpio.h Add two missing POSIX constant-only headers. 2016-08-12 09:28:17 -07:00
ctype.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
dirent.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
dlfcn.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
elf.h Restore ELF32_ST_INFO/ELF64_ST_INFO. 2017-04-30 22:56:10 -07:00
endian.h Always include <sys/cdefs.h>. 2016-07-22 17:01:54 -07:00
err.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
errno.h Remove volatile from the __errno declaration. 2017-06-13 16:02:07 -07:00
error.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
fcntl.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
features.h Move the meat of <features.h> into <sys/cdefs.h>. 2014-08-19 11:18:20 -07:00
fenv.h Unified sysroot: kill arch-specific include dirs. 2017-10-12 13:19:51 -07:00
fnmatch.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
fts.h Pretend the <fts.h> functions didn't appear until 21. 2017-08-25 15:18:33 -07:00
ftw.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
getopt.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
glob.h Add <glob.h>. 2017-09-26 18:46:09 -07:00
grp.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
iconv.h Implement <iconv.h>. 2017-08-25 08:47:41 -07:00
ifaddrs.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
inttypes.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
langinfo.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
lastlog.h Fix various empty .h files in bionic. 2016-04-29 22:30:19 -07:00
libgen.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
limits.h POSIX clock cleanup. 2017-10-05 10:33:18 -07:00
link.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
locale.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
malloc.h Name function arguments in libc headers for Studio. 2017-08-11 17:45:59 -07:00
math.h Make <math.h> renames compatible with GCC. 2017-09-18 16:22:32 -07:00
memory.h Fix <memory.h> to be a synonym for <string.h> like in glibc. 2013-02-22 11:11:48 -08:00
mntent.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
netdb.h Complete <netdb.h>. 2017-10-15 10:37:51 -07:00
nl_types.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
paths.h libc: Add support to allow library calls to find appropriate shell executable for a process 2017-08-22 10:17:28 -07:00
poll.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
pthread.h Implement pthread_attr_getinheritsched/pthread_attr_setinheritsched. 2017-10-25 14:28:42 -07:00
pty.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
pwd.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
regex.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
resolv.h Name function arguments in libc headers for Studio. 2017-08-21 14:51:59 -07:00
sched.h Name function arguments in libc headers for Studio. 2017-08-11 17:45:59 -07:00
search.h Finish <search.h>. 2017-08-31 17:38:51 -07:00
semaphore.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
setjmp.h Unified sysroot: kill arch-specific include dirs. 2017-10-12 13:19:51 -07:00
signal.h Name function arguments in libc headers for Studio. 2017-08-11 17:45:59 -07:00
spawn.h Implement <spawn.h>. 2017-10-11 14:57:49 -07:00
stdatomic.h Guard include of uchar.h in stdatomic.h 2016-08-04 18:22:12 +00:00
stdint.h Fix instances of '#if __LP64__'. 2016-09-15 14:21:28 -07:00
stdio.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
stdio_ext.h Name function arguments in libc headers for Studio. 2017-08-11 17:45:59 -07:00
stdlib.h Rename _Exit in a way that works with libandroid_support. 2017-09-19 18:34:40 +00:00
string.h Add more const-correct C++ overloads. 2017-08-23 14:34:40 -07:00
strings.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
syscall.h Add all the glibc one-line "synonym" header files. 2015-07-17 13:59:36 -07:00
sysexits.h Always include <sys/cdefs.h>. 2016-07-22 17:01:54 -07:00
syslog.h Name function arguments in libc headers for Studio. 2017-08-11 17:45:59 -07:00
tar.h Add two missing POSIX constant-only headers. 2016-08-12 09:28:17 -07:00
termio.h Always include <sys/cdefs.h>. 2016-07-22 17:01:54 -07:00
termios.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
time.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
time64.h Remove the non-standard time64 stuff for LP64. 2014-05-05 17:14:02 -07:00
uchar.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
ucontext.h Always include <sys/cdefs.h>. 2016-07-22 17:01:54 -07:00
unistd.h Improve names for function arguments in <unistd.h> for Studio. 2017-08-25 15:07:05 -07:00
utime.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
utmp.h Name function arguments in libc headers for Studio. 2017-08-11 17:45:59 -07:00
wait.h Add all the glibc one-line "synonym" header files. 2015-07-17 13:59:36 -07:00
wchar.h Use __RENAME for long double functions. 2017-09-14 16:10:43 -07:00
wctype.h Re-submit "Name function arguments in libc headers for Studio." 2017-08-18 00:00:38 +00:00
xlocale.h Always include <sys/cdefs.h>. 2016-07-22 17:01:54 -07:00