From patchwork Fri Sep 18 16:07:07 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: 40440 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B75D3972418; Fri, 18 Sep 2020 16:07:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B75D3972418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1600445237; bh=ivspl6J/li+9KTR5gu1ejqF3HRxW4jqLW3uJXlVXWpA=; 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=dEfR7i/+48/YyarNCQqBvX9ZIKLSIj0Vb310ehVCxD8Nne1ZFvrsZOZuO++upYviQ E/zPIlPvaVfVDgXiTWQ3YTddT88pk15+Af/JcRqKRNA1iUMtFTh2ZPvienJETFbfx3 MN7uZHP4v9c9iwMsy6ube5LFwM961Fy3zQgOLEqk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by sourceware.org (Postfix) with ESMTPS id 1EE463954C0B for ; Fri, 18 Sep 2020 16:07:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1EE463954C0B Received: by mail-pj1-x1044.google.com with SMTP id mm21so3410646pjb.4 for ; Fri, 18 Sep 2020 09:07:13 -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=ivspl6J/li+9KTR5gu1ejqF3HRxW4jqLW3uJXlVXWpA=; b=Qh0Jk1uST2kaNJVQ0P69FuJhuKMwEF7b8wlCS1YAa6NiuLFLnt6mCgaY9q4iSpA554 XHdLfvn5ygOsQPHEMtKflZuwZ+4Cj59jNMlb/iRscgR0jZ5b0RGBAqoo5wdAdybpQ1U6 zCcF6GSylnsNYKY258AHN2OI7vD9QaW7seezJR4rJgHNIm1NTS75IPbJJAjB1YXzlGBp biN5zc3PS2iMuphsNxwpL+of3JqBWrOSpYySALfjFSs5QBnnMiJ3GxBCnDG/fsg16Qe6 44xj7ghaeo6MIUzImNhNDTSegWCJJFOhVBLP+tK/kB2eSVVCWUHQWC+pHQG0186pMFzW abbA== X-Gm-Message-State: AOAM532KBOuYAiNIB4SIT5AUF5V3muCPYixMaWHJ9E4Od5YqLjunPQdJ sY2WQHVYvl1ViHHnG+V+Mv0= X-Google-Smtp-Source: ABdhPJw5nBQ+SwgsFGl0yOV1gH3taHVNzetrng5J+JFQR6XcaXdMRHvWZFGYyLwGXSmgUtKKEX74Ug== X-Received: by 2002:a17:902:465:b029:d0:89f1:9e2a with SMTP id 92-20020a1709020465b02900d089f19e2amr33299271ple.6.1600445232213; Fri, 18 Sep 2020 09:07:12 -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 t24sm3914908pfq.37.2020.09.18.09.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 09:07:10 -0700 (PDT) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id DD9981A03E7; Fri, 18 Sep 2020 09:07:09 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/4] Set tunable value as well as min/max values Date: Fri, 18 Sep 2020 09:07:07 -0700 Message-Id: <20200918160709.949608-3-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" Some tunable values and their minimum/maximum values must be determinted at run-time. Add TUNABLE_SET_ALL and TUNABLE_SET_ALL_FULL to update tunable value together with minimum and maximum values. __tunable_set_val is updated to set tunable value as well as min/max values. --- elf/dl-tunables.c | 17 ++++++++++++----- elf/dl-tunables.h | 18 ++++++++++++++++-- manual/README.tunables | 24 ++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c index 26e6e26612..b44174fe71 100644 --- a/elf/dl-tunables.c +++ b/elf/dl-tunables.c @@ -101,12 +101,19 @@ get_next_env (char **envp, char **name, size_t *namelen, char **val, }) static void -do_tunable_update_val (tunable_t *cur, const void *valp) +do_tunable_update_val (tunable_t *cur, const void *valp, + const void *minp, const void *maxp) { uint64_t val; if (cur->type.type_code != TUNABLE_TYPE_STRING) - val = *((int64_t *) valp); + { + val = *((int64_t *) valp); + if (minp) + cur->type.min = *((int64_t *) minp); + if (maxp) + cur->type.max = *((int64_t *) maxp); + } switch (cur->type.type_code) { @@ -153,15 +160,15 @@ tunable_initialize (tunable_t *cur, const char *strval) cur->initialized = true; valp = strval; } - do_tunable_update_val (cur, valp); + do_tunable_update_val (cur, valp, NULL, NULL); } void -__tunable_set_val (tunable_id_t id, void *valp) +__tunable_set_val (tunable_id_t id, void *valp, void *minp, void *maxp) { tunable_t *cur = &tunable_list[id]; - do_tunable_update_val (cur, valp); + do_tunable_update_val (cur, valp, minp, maxp); } #if TUNABLES_FRONTEND == TUNABLES_FRONTEND_valstring diff --git a/elf/dl-tunables.h b/elf/dl-tunables.h index f05eb50c2f..b1add3184f 100644 --- a/elf/dl-tunables.h +++ b/elf/dl-tunables.h @@ -70,9 +70,10 @@ typedef struct _tunable tunable_t; extern void __tunables_init (char **); extern void __tunable_get_val (tunable_id_t, void *, tunable_callback_t); -extern void __tunable_set_val (tunable_id_t, void *); +extern void __tunable_set_val (tunable_id_t, void *, void *, void *); rtld_hidden_proto (__tunables_init) rtld_hidden_proto (__tunable_get_val) +rtld_hidden_proto (__tunable_set_val) /* Define TUNABLE_GET and TUNABLE_SET in short form if TOP_NAMESPACE and TUNABLE_NAMESPACE are defined. This is useful shorthand to get and set @@ -82,11 +83,16 @@ rtld_hidden_proto (__tunable_get_val) TUNABLE_GET_FULL (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id, __type, __cb) # define TUNABLE_SET(__id, __type, __val) \ TUNABLE_SET_FULL (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id, __type, __val) +# define TUNABLE_SET_ALL(__id, __type, __val, __min, __max) \ + TUNABLE_SET_ALL_FULL (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id, __type, \ + __val, __min, __max) #else # define TUNABLE_GET(__top, __ns, __id, __type, __cb) \ TUNABLE_GET_FULL (__top, __ns, __id, __type, __cb) # define TUNABLE_SET(__top, __ns, __id, __type, __val) \ TUNABLE_SET_FULL (__top, __ns, __id, __type, __val) +# define TUNABLE_SET_ALL(__top, __ns, __id, __type, __val, __min, __max) \ + TUNABLE_SET_ALL_FULL (__top, __ns, __id, __type, __val, __min, __max) #endif /* Get and return a tunable value. If the tunable was set externally and __CB @@ -103,7 +109,15 @@ rtld_hidden_proto (__tunable_get_val) # define TUNABLE_SET_FULL(__top, __ns, __id, __type, __val) \ ({ \ __tunable_set_val (TUNABLE_ENUM_NAME (__top, __ns, __id), \ - & (__type) {__val}); \ + & (__type) {__val}, NULL, NULL); \ +}) + +/* Set a tunable value together with min/max values. */ +# define TUNABLE_SET_ALL_FULL(__top, __ns, __id, __type, __val, __min, __max) \ +({ \ + __tunable_set_val (TUNABLE_ENUM_NAME (__top, __ns, __id), \ + & (__type) {__val}, & (__type) {__min}, \ + & (__type) {__max}); \ }) /* Namespace sanity for callback functions. Use this macro to keep the diff --git a/manual/README.tunables b/manual/README.tunables index f87a31a65e..db6f6bae8d 100644 --- a/manual/README.tunables +++ b/manual/README.tunables @@ -67,7 +67,7 @@ The list of allowed attributes are: non-AT_SECURE subprocesses. NONE: Read all the time. -2. Use TUNABLE_GET/TUNABLE_SET to get and set tunables. +2. Use TUNABLE_GET/TUNABLE_SET/TUNABLE_SET_ALL to get and set tunables. 3. OPTIONAL: If tunables in a namespace are being used multiple times within a specific module, set the TUNABLE_NAMESPACE macro to reduce the amount of @@ -112,9 +112,29 @@ form of the macros as follows: where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the remaining arguments are the same as the short form macros. +The minimum and maximum values can updated together with the tunable value +using: + + TUNABLE_SET_ALL (check, int32_t, val, min, max) + +where 'check' is the tunable name, 'int32_t' is the C type of the tunable, +'val' is a value of same type, 'min' and 'max' are the minimum and maximum +values of the tunable. + +To set the minimum and maximum values of tunables in a different namespace +from that module, use the full form of the macros as follows: + + val = TUNABLE_GET_FULL (glibc, cpu, hwcap_mask, uint64_t, NULL) + + TUNABLE_SET_ALL_FULL (glibc, cpu, hwcap_mask, uint64_t, val, min, max) + +where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the +remaining arguments are the same as the short form macros. + When TUNABLE_NAMESPACE is not defined in a module, TUNABLE_GET is equivalent to TUNABLE_GET_FULL, so you will need to provide full namespace information for -both macros. Likewise for TUNABLE_SET and TUNABLE_SET_FULL. +both macros. Likewise for TUNABLE_SET, TUNABLE_SET_FULL, TUNABLE_SET_ALL +and TUNABLE_SET_ALL_FULL. ** IMPORTANT NOTE **