glibc/sysdeps/pthread
Szabolcs Nagy d2e0491883 Single threaded stdio optimization
Locking overhead can be significant in some stdio operations
that are common in single threaded applications.

This patch adds the _IO_FLAGS2_NEED_LOCK flag to indicate if
an _IO_FILE object needs to be locked and some of the stdio
functions just jump to their _unlocked variant when not.  The
flag is set on all _IO_FILE objects when the first thread is
created.  A new GLIBC_PRIVATE libc symbol, _IO_enable_locks,
was added to do this from libpthread.

The optimization can be applied to more stdio functions,
currently it is only applied to single flag check or single
non-wide-char standard operations.  The flag should probably
be never set for files with _IO_USER_LOCK, but that's just a
further optimization, not a correctness requirement.

The optimization is valid in a single thread because stdio
operations are non-as-safe (so lock state is not observable
from a signal handler) and stdio locks are recursive (so lock
state is not observable via deadlock).  The optimization is not
valid if a thread may be created while an stdio lock is taken
and thus it should be disabled if any user code may run during
an stdio operation (interposed malloc, printf hooks, etc).
This makes the optimization more complicated for some stdio
operations (e.g. printf), but those are bigger and thus less
important to optimize so this patch does not try to do that.

	* libio/libio.h (_IO_FLAGS2_NEED_LOCK, _IO_need_lock): Define.
	* libio/libioP.h (_IO_enable_locks): Declare.
	* libio/Versions (_IO_enable_locks): New symbol.
	* libio/genops.c (_IO_enable_locks): Define.
	(_IO_old_init): Initialize flags2.
	* libio/feof.c.c (_IO_feof): Avoid locking when not needed.
	* libio/ferror.c (_IO_ferror): Likewise.
	* libio/fputc.c (fputc): Likewise.
	* libio/putc.c (_IO_putc): Likewise.
	* libio/getc.c (_IO_getc): Likewise.
	* libio/getchar.c (getchar): Likewise.
	* libio/ioungetc.c (_IO_ungetc): Likewise.
	* nptl/pthread_create.c (__pthread_create_2_1): Enable stdio locks.
	* libio/iofopncook.c (_IO_fopencookie): Enable locking for the file.
	* sysdeps/pthread/flockfile.c (__flockfile): Likewise.
2017-07-04 16:05:12 +01:00
..
bits Remove __need macros from signal.h. 2017-05-20 19:04:43 -04:00
aio_cancel.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
aio_error.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
aio_fsync.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
aio_misc.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
aio_misc.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
aio_notify.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
aio_read64.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
aio_read.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
aio_suspend.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
aio_write64.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
aio_write.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
allocalim.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
flockfile.c Single threaded stdio optimization 2017-07-04 16:05:12 +01:00
ftrylockfile.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
funlockfile.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
lio_listio64.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
lio_listio.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
Makeconfig
Makefile Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
posix-timer.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
semaphore.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
timer_create.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
timer_delete.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
timer_getoverr.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
timer_gettime.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
timer_routines.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
timer_settime.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-timer.c Add missing header files throughout the testsuite. 2017-02-16 17:33:18 -05:00
Versions