[PATCH v2] Single threaded stdio optimization
Szabolcs Nagy
szabolcs.nagy@arm.com
Wed Jun 21 16:37:00 GMT 2017
Locking overhead can be significant in some stdio operations
that are common in single threaded applications. I'd like
to address it in this release as it causes performance problems
to aarch64 users. I prefer this high-level approach to be
reviewed, if that does not work then the aarch64 specific
low-level approach will be taken.
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 libc abi symbol, _IO_enable_locks, does this.
(The abilist files will have to be updated in a separate patch).
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 not valid if user code may run during
an stdio operation (interposed malloc, printf hooks, etc)
because the user code may create threads. To handle those cases
the flag has to be set when callbacks are registered etc which
is more involved and those cases are less important to optimize
hence _IO_flockfile is not modified.
2017-06-21 Szabolcs Nagy <szabolcs.nagy@arm.com>
* 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stdio.diff
Type: text/x-patch
Size: 6656 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20170621/7b2ddca8/attachment.bin>
More information about the Libc-alpha
mailing list