From patchwork Fri Sep 18 16:07:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1367034 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=DIxfvX3L; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BtJdK5VSyz9sRf for ; Sat, 19 Sep 2020 02:07:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08001397242C; Fri, 18 Sep 2020 16:07:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08001397242C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1600445238; bh=4bvfwzCgjWK8XD7Iauj/eBQb5YBQR8RPJ419pIA0e+s=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=DIxfvX3L1Y7KQHbEN+KjkfVGQNY0ZUFKjctHEneeSfonPiy0c+Qkm5ReEehU2+z6v 8qBT9toQ4D/jdpOw+2bvT6Nq8V/j/3HlYT8Rky9UaQs8hBmM5O1CJ3wShBky+G6Sm3 ZDMMDXkzEtl3aZZGTCvqY3ZtiQ8Ny27kSeM2vLg8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by sourceware.org (Postfix) with ESMTPS id 21433396EC8D for ; Fri, 18 Sep 2020 16:07:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 21433396EC8D Received: by mail-pg1-x543.google.com with SMTP id 7so3719909pgm.11 for ; Fri, 18 Sep 2020 09:07:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4bvfwzCgjWK8XD7Iauj/eBQb5YBQR8RPJ419pIA0e+s=; b=UTPfhpv5oiB1OzXp5aSMrXFR1UXqUkemY5A2ACXDDhEnHMxP5gKCxsTnsQALvNmOS4 LEMUPHqeWsuSd2+auCNlqAZBlxJyNq475bHu4mid29RfF5WtbYhrYvTVX5lGG9n1gyOj Lf2IqYIiKGX6tZzSnnv7FnDuhc0WhDKfdnOt6LMqIxqyhjAS233+jlJzAx8esmE0ekAY qu2h43qlcaFwVH10cdcfoY4ctH3XuJ387BUTi6ISO/rNgcFJ03o35WjYYIqN6+hXtwzT WZ3n6SoyqM1Evw3DloxzLil+eHvX8BjzNrUiQP/4uV4X0I4s+tuDcXEJP3+5b8LzrHA5 TOTQ== X-Gm-Message-State: AOAM532CsC0pzaTmo5l8kVQLSLus5EAnUpq/RnmWPOsWVXNkZ5e5ZRzQ P85a5UEkLeMYwlx4ddWqMMX35l4wJG0= X-Google-Smtp-Source: ABdhPJwD4bVkmOA6sYafWv5i4gugAzgjqV+lWaP/uDuYZNKb5HW0DvrAQ0ISATZPJFJGdinG035Ftg== X-Received: by 2002:a62:19c4:0:b029:13e:d13d:a0fd with SMTP id 187-20020a6219c40000b029013ed13da0fdmr32440707pfz.25.1600445233153; Fri, 18 Sep 2020 09:07:13 -0700 (PDT) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id r206sm3850298pfr.91.2020.09.18.09.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 09:07:11 -0700 (PDT) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id EE9641A0410; Fri, 18 Sep 2020 09:07:09 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 4/4] ld.so: Add --list-tunables to print tunable values Date: Fri, 18 Sep 2020 09:07:09 -0700 Message-Id: <20200918160709.949608-5-hjl.tools@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200918160709.949608-1-hjl.tools@gmail.com> References: <20200918160709.949608-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Pass --list-tunables to ld.so to print tunables with min and max values. --- NEWS | 2 ++ elf/Makefile | 8 ++++++++ elf/dl-tunables.c | 36 ++++++++++++++++++++++++++++++++++++ elf/dl-tunables.h | 2 ++ elf/rtld.c | 31 +++++++++++++++++++++++++++++-- manual/tunables.texi | 37 +++++++++++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index fc8dd15439..f47516a02f 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ Version 2.33 Major new features: +* Pass --list-tunables to ld.so to print tunable values. + * The mallinfo2 function is added to report statistics as per mallinfo, but with larger field widths to accurately report values that are larger than fit in an integer. diff --git a/elf/Makefile b/elf/Makefile index 0b78721848..11e90c9d17 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -44,6 +44,10 @@ dl-routines += dl-tunables tunables-type = $(addprefix TUNABLES_FRONTEND_,$(have-tunables)) CPPFLAGS-dl-tunables.c += -DTUNABLES_FRONTEND=$(tunables-type) +ifeq (yesyes,$(build-shared)$(run-built-tests)) +tests-special += $(objpfx)list-tunables.out +endif + # Make sure that the compiler does not insert any library calls in tunables # code paths. ifeq (yes,$(have-loop-to-function)) @@ -1796,3 +1800,7 @@ $(objpfx)tst-tls-ie-dlmopen.out: \ $(objpfx)tst-tls-ie-mod6.so $(objpfx)tst-tls-surplus: $(libdl) + +$(objpfx)list-tunables.out: $(objpfx)ld.so + $(objpfx)ld.so --list-tunables > $@; \ + $(evaluate-test) diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c index b44174fe71..53226ef258 100644 --- a/elf/dl-tunables.c +++ b/elf/dl-tunables.c @@ -368,6 +368,42 @@ __tunables_init (char **envp) } } +void +__tunables_print (void) +{ + for (int i = 0; i < sizeof (tunable_list) / sizeof (tunable_t); i++) + { + tunable_t *cur = &tunable_list[i]; + _dl_printf ("%s: ", cur->name); + switch (cur->type.type_code) + { + case TUNABLE_TYPE_INT_32: + _dl_printf ("%d (min: %d, max: %d)\n", + (int) cur->val.numval, + (int) cur->type.min, + (int) cur->type.max); + break; + case TUNABLE_TYPE_UINT_64: + _dl_printf ("0x%lx (min: 0x%lx, max: 0x%lx)\n", + (long int) cur->val.numval, + (long int) cur->type.min, + (long int) cur->type.max); + break; + case TUNABLE_TYPE_SIZE_T: + _dl_printf ("0x%Zx (min: 0x%Zx, max: 0x%Zx)\n", + (size_t) cur->val.numval, + (size_t) cur->type.min, + (size_t) cur->type.max); + break; + case TUNABLE_TYPE_STRING: + _dl_printf ("%s\n", cur->val.strval ? cur->val.strval : ""); + break; + default: + __builtin_unreachable (); + } + } +} + /* Set the tunable value. This is called by the module that the tunable exists in. */ void diff --git a/elf/dl-tunables.h b/elf/dl-tunables.h index b1add3184f..a2c728f0dd 100644 --- a/elf/dl-tunables.h +++ b/elf/dl-tunables.h @@ -69,9 +69,11 @@ typedef struct _tunable tunable_t; # include "dl-tunable-list.h" extern void __tunables_init (char **); +extern void __tunables_print (void); extern void __tunable_get_val (tunable_id_t, void *, tunable_callback_t); extern void __tunable_set_val (tunable_id_t, void *, void *, void *); rtld_hidden_proto (__tunables_init) +rtld_hidden_proto (__tunables_print) rtld_hidden_proto (__tunable_get_val) rtld_hidden_proto (__tunable_set_val) diff --git a/elf/rtld.c b/elf/rtld.c index 5b882163fa..f76b9b0265 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -48,6 +48,10 @@ #include #include +#if HAVE_TUNABLES +# include +#endif + #include /* Only enables rtld profiling for architectures which provides non generic @@ -168,7 +172,7 @@ static void audit_list_add_dynamic_tag (struct audit_list *, static const char *audit_list_next (struct audit_list *); /* This is a list of all the modes the dynamic loader can be in. */ -enum mode { normal, list, verify, trace }; +enum mode { normal, list, verify, trace, list_tunables }; /* Process all environments variables the dynamic linker must recognize. Since all of them start with `LD_' we are a bit smarter while finding @@ -1263,9 +1267,27 @@ dl_main (const ElfW(Phdr) *phdr, _dl_argc -= 2; _dl_argv += 2; } +#if HAVE_TUNABLES + else if (! strcmp (_dl_argv[1], "--list-tunables")) + { + mode = list_tunables; + + ++_dl_skip_args; + --_dl_argc; + ++_dl_argv; + } +#endif else break; +#if HAVE_TUNABLES + if (__builtin_expect (mode, normal) == list_tunables) + { + __tunables_print (); + _exit (0); + } +#endif + /* If we have no further argument the program was called incorrectly. Grant the user some education. */ if (_dl_argc < 2) @@ -1292,7 +1314,12 @@ of this helper program; chances are you did not intend to run this program.\n\ --inhibit-rpath LIST ignore RUNPATH and RPATH information in object names\n\ in LIST\n\ --audit LIST use objects named in LIST as auditors\n\ - --preload LIST preload objects named in LIST\n"); + --preload LIST preload objects named in LIST\n" +#if HAVE_TUNABLES +"\ + --list-tunables list all tunables with minimum and maximum values\n" +#endif + ); ++_dl_skip_args; --_dl_argc; diff --git a/manual/tunables.texi b/manual/tunables.texi index 23ef0d40e7..38c8578229 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -28,6 +28,43 @@ Finally, the set of tunables available may vary between distributions as the tunables feature allows distributions to add their own tunables under their own namespace. +Passing @option{--list-tunables} to the dynamic loader to print all +tunables with minimum and maximum values: + +@example +$ /lib64/ld-linux-x86-64.so.2 --list-tunables +glibc.rtld.nns: 0x4 (min: 0x1, max: 0x10) +glibc.elision.skip_lock_after_retries: 3 (min: -2147483648, max: 2147483647) +glibc.malloc.trim_threshold: 0x0 (min: 0x0, max: 0xffffffffffffffff) +glibc.malloc.perturb: 0 (min: 0, max: 255) +glibc.cpu.x86_shared_cache_size: 0x100000 (min: 0x0, max: 0xffffffffffffffff) +glibc.elision.tries: 3 (min: -2147483648, max: 2147483647) +glibc.elision.enable: 0 (min: 0, max: 1) +glibc.cpu.x86_rep_movsb_threshold: 0x800 (min: 0x100, max: 0xffffffffffffffff) +glibc.malloc.mxfast: 0x0 (min: 0x0, max: 0xffffffffffffffff) +glibc.elision.skip_lock_busy: 3 (min: -2147483648, max: 2147483647) +glibc.malloc.top_pad: 0x0 (min: 0x0, max: 0xffffffffffffffff) +glibc.cpu.x86_rep_stosb_threshold: 0x800 (min: 0x1, max: 0xffffffffffffffff) +glibc.cpu.x86_non_temporal_threshold: 0x600000 (min: 0x0, max: 0xffffffffffffffff) +glibc.cpu.x86_shstk: +glibc.cpu.hwcap_mask: 0x6 (min: 0x0, max: 0xffffffffffffffff) +glibc.malloc.mmap_max: 0 (min: -2147483648, max: 2147483647) +glibc.elision.skip_trylock_internal_abort: 3 (min: -2147483648, max: 2147483647) +glibc.malloc.tcache_unsorted_limit: 0x0 (min: 0x0, max: 0xffffffffffffffff) +glibc.cpu.x86_ibt: +glibc.cpu.hwcaps: +glibc.elision.skip_lock_internal_abort: 3 (min: -2147483648, max: 2147483647) +glibc.malloc.arena_max: 0x0 (min: 0x1, max: 0xffffffffffffffff) +glibc.malloc.mmap_threshold: 0x0 (min: 0x0, max: 0xffffffffffffffff) +glibc.cpu.x86_data_cache_size: 0x8000 (min: 0x0, max: 0xffffffffffffffff) +glibc.malloc.tcache_count: 0x0 (min: 0x0, max: 0xffffffffffffffff) +glibc.malloc.arena_test: 0x0 (min: 0x1, max: 0xffffffffffffffff) +glibc.pthread.mutex_spin_count: 100 (min: 0, max: 32767) +glibc.rtld.optional_static_tls: 0x200 (min: 0x0, max: 0xffffffffffffffff) +glibc.malloc.tcache_max: 0x0 (min: 0x0, max: 0xffffffffffffffff) +glibc.malloc.check: 0 (min: 0, max: 3) +@end example + @menu * Tunable names:: The structure of a tunable name * Memory Allocation Tunables:: Tunables in the memory allocation subsystem