glibc/malloc
Siddhesh Poyarekar 44330b6d32 tunables: Clean up hooks to get and set tunables
The TUNABLE_SET_VALUE and family of macros (and my later attempt to
add a TUNABLE_GET) never quite went together very well because the
overall interface was not clearly defined.  This patch is an attempt
to do just that.

This patch consolidates the API to two simple sets of macros,
TUNABLE_GET* and TUNABLE_SET*.  If TUNABLE_NAMESPACE is defined,
TUNABLE_GET takes just the tunable name, type and a (optionally NULL)
callback function to get the value of the tunable.  The callback
function, if non-NULL, is called if the tunable was externally set
(i.e. via GLIBC_TUNABLES or any future mechanism).  For example:

    val = TUNABLE_GET (check, int32_t, check_callback)

returns the value of the glibc.malloc.check tunable (assuming
TUNABLE_NAMESPACE is set to malloc) as an int32_t into VAL after
calling check_callback.

Likewise, TUNABLE_SET can be used to set the value of the tunable,
although this is currently possible only in the dynamic linker before
it relocates itself.  For example:

  TUNABLE_SET (check, int32_t, 2)

will set glibc.malloc.check to 2.  Of course, this is not possible
since we set (or read) glibc.malloc.check long after it is relocated.

To access or set a tunable outside of TUNABLE_NAMESPACE, use the
TUNABLE_GET_FULL and TUNABLE_SET_FULL macros, which have the following
prototype:

  TUNABLE_GET_FULL (glibc, tune, hwcap_mask, uint64_t, NULL)
  TUNABLE_SET_FULL (glibc, tune, hwcap_mask, uint64_t, 0xffff)

In future the tunable list may get split into mutable and immutable
tunables where mutable tunables can be modified by the library and
userspace after relocation as well and TUNABLE_SET will be more useful
than it currently is.  However whenever we actually do that split, we
will have to ensure that the mutable tunables are protected with
locks.

	* elf/Versions (__tunable_set_val): Rename to __tunable_get_val.
	* elf/dl-tunables.c: Likewise.
	(do_tunable_update_val): New function.
	(__tunable_set_val): New function.
	(__tunable_get_val): Call CB only if the tunable was externally
	initialized.
	(tunables_strtoul): Replace strval with initialized.
	* elf/dl-tunables.h (strval): Replace with a bool initialized.
	(TUNABLE_ENUM_NAME, TUNABLE_ENUM_NAME1): Adjust names to
	prevent collision.
	(__tunable_set_val): New function.
	(TUNABLE_GET, TUNABLE_GET_FULL): New macros.
	(TUNABLE_SET, TUNABLE_SET_FULL): Likewise.
	(TUNABLE_SET_VAL): Remove.
	(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
	* README.tunables: Document the new macros.
	* malloc/arena.c (ptmalloc_init): Adjust.
2017-06-07 11:11:36 +05:30
..
Depend Update. 1999-10-04 22:59:43 +00:00
Makefile Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
Versions Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
arena.c tunables: Clean up hooks to get and set tunables 2017-06-07 11:11:36 +05:30
dynarray-skeleton.c Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
dynarray.h Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
dynarray_at_failure.c Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
dynarray_emplace_enlarge.c Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
dynarray_finalize.c Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
dynarray_resize.c Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
dynarray_resize_clear.c Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
hooks.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
malloc-hooks.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
malloc-internal.h Add reallocarray function 2017-05-30 18:27:57 -03:00
malloc.c Tweak realloc/MREMAP comment to be more accurate. 2017-05-03 16:28:01 -04:00
malloc.h Add reallocarray function 2017-05-30 18:27:57 -03:00
mallocbug.c Reformat malloc to gnu style. 2014-01-02 09:40:10 +01:00
mcheck-init.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
mcheck.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
mcheck.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
memusage.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
memusage.sh Update copyright dates not handled by scripts/update-copyrights. 2017-01-01 00:26:24 +00:00
memusagestat.c Update copyright dates not handled by scripts/update-copyrights. 2017-01-01 00:26:24 +00:00
morecore.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
mtrace.c Assume that O_CLOEXEC is always defined and works 2017-04-18 14:56:51 +02:00
mtrace.pl Update copyright dates not handled by scripts/update-copyrights. 2017-01-01 00:26:24 +00:00
obstack.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
obstack.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
reallocarray.c Add reallocarray function 2017-05-30 18:27:57 -03:00
scratch_buffer_grow.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
scratch_buffer_grow_preserve.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
scratch_buffer_set_array_size.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
set-freeres.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
thread-freeres.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-calloc.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-dynarray-at-fail.c Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
tst-dynarray-fail.c Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
tst-dynarray-shared.h Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
tst-dynarray.c Add internal facility for dynamic array handling 2017-06-02 11:59:28 +02:00
tst-interpose-aux-nothread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-aux-thread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-aux.c Fix failing test malloc/tst-interpose-nothread with GCC 7. 2017-03-21 16:41:56 +01:00
tst-interpose-aux.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-nothread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-skeleton.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-static-nothread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-static-thread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-thread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-malloc-backtrace.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-malloc-fork-deadlock.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-malloc-thread-exit.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-malloc-thread-fail.c Increase some test timeouts. 2017-01-05 17:39:38 +00:00
tst-malloc-usable-static-tunables.c Initialize tunable list with the GLIBC_TUNABLES environment variable 2016-12-31 23:49:24 +05:30
tst-malloc-usable-static.c Add framework for tunables 2016-12-31 23:49:24 +05:30
tst-malloc-usable-tunables.c Initialize tunable list with the GLIBC_TUNABLES environment variable 2016-12-31 23:49:24 +05:30
tst-malloc-usable.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-malloc.c Split DIAG_* macros to new header libc-diag.h. 2017-02-25 09:59:46 -05:00
tst-mallocfork.c * malloc/tst-mallocfork.c (do_test): Make sure sa_flags is 2005-12-06 00:50:15 +00:00
tst-mallocfork2.c Increase some test timeouts. 2017-01-05 17:39:38 +00:00
tst-mallocstate.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-mallopt.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-mcheck.c Split DIAG_* macros to new header libc-diag.h. 2017-02-25 09:59:46 -05:00
tst-memalign.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-mtrace.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-mtrace.sh Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-obstack.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-posix_memalign.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-pvalloc.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-realloc.c Split DIAG_* macros to new header libc-diag.h. 2017-02-25 09:59:46 -05:00
tst-reallocarray.c Add reallocarray function 2017-05-30 18:27:57 -03:00
tst-scratch_buffer.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-trim1.c * malloc/tst-trim1.c: New file. 2007-12-16 22:57:57 +00:00
tst-valloc.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00