From patchwork Tue Sep 7 12:22:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44882 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 B42BA385E82E for ; Tue, 7 Sep 2021 12:24:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B42BA385E82E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631017447; bh=liG1REC4YvqfZ9ESnrmJuIPu3gPIKaCLtiJKJBq6fCs=; 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=QqKJxleNGZ1REw5C8/X3wNJQAxNvUbMZ3ZfDLVTLP/LKLsNvmhsVQWZKHRIF0xRs/ esiuFMlEHSyv8dJ7XF65BAFRdBIJp5vZl/8jl8TQIQv7E10MAjNRnVx94chiDYUIl8 rT0gUc6CHmIjRi0SBEfmaFkHNZL2CrIngoxWxyLk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by sourceware.org (Postfix) with ESMTPS id A461E3858003 for ; Tue, 7 Sep 2021 12:23:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A461E3858003 Received: by mail-qt1-x836.google.com with SMTP id r21so7703489qtw.11 for ; Tue, 07 Sep 2021 05:23:04 -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=liG1REC4YvqfZ9ESnrmJuIPu3gPIKaCLtiJKJBq6fCs=; b=R/DEzt9daxlAkDqP9CmGW6r2TUXPMWCRQ7wm7couqkYnSSAUnRdZbxogCBPuQeZ/gA 6TkaDGhX95JDFQrgdXVXslUEN3hthNrKdnu2/4oE6ASCykGosA9fPFIv4No7jqx/exH4 FhterKBH5/Vo74GTwCE+YXxkYt4ixUW6DP+7cZUnUZ2c4Lcc8elQWgEqPiZ8SCLX2cDG Bm3dQiN7mbLJ/iSGIINNxL4Pu99nJlJf+TK4ly3mPIs3OrMLJu1Q6O6IsvzysL8ynKVh p8sdYk/v2Dz1/PfcDyR8GO3SRopRCsYHy/8T0skZ8hhmJZO8CxrQ4D3bvNqYbD1Ux8UJ 6OOg== X-Gm-Message-State: AOAM531DtpubmLP2oIhYSCvrZkzfhKJ6kINiOSBQFDBVbWS95Gb0Q1F3 BEIZujrhXMhEfx0ncldQzeOkmOljPqiQvg== X-Google-Smtp-Source: ABdhPJywAD25WXTf6gm4a7t/EiHwYeTKHcqc5Iktmny0JzXtlHGNFjaKA7y5Shiy+3lIoLic+nmicQ== X-Received: by 2002:a05:622a:1908:: with SMTP id w8mr15320505qtc.269.1631017384143; Tue, 07 Sep 2021 05:23:04 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:733d:f360:5bf3:9813:d8f5]) by smtp.gmail.com with ESMTPSA id r18sm6902148qtm.96.2021.09.07.05.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 05:23:03 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 1/3] misc: Add __get_nprocs_sched Date: Tue, 7 Sep 2021 09:22:57 -0300 Message-Id: <20210907122259.79800-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210907122259.79800-1-adhemerval.zanella@linaro.org> References: <20210907122259.79800-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Cc: Florian Weimer , Nicolas Saenz Julienne Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This is an internal function meant to return the number of avaliable processor where the process can scheduled, different than the __get_nprocs which returns a the system available online CPU. The Linux implementation currently only calls __get_nprocs(), which in tuns calls sched_getaffinity. Reviewed-by: Florian Weimer --- include/sys/sysinfo.h | 7 ++++++- malloc/arena.c | 2 +- misc/getsysstats.c | 6 ++++++ sysdeps/mach/getsysstats.c | 6 ++++++ sysdeps/unix/sysv/linux/getsysstats.c | 6 ++++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/sys/sysinfo.h b/include/sys/sysinfo.h index 7388356a19..c490561581 100644 --- a/include/sys/sysinfo.h +++ b/include/sys/sysinfo.h @@ -9,10 +9,15 @@ extern int __get_nprocs_conf (void); libc_hidden_proto (__get_nprocs_conf) -/* Return number of available processors. */ +/* Return number of available processors (not all of them will be + available to the caller process). */ extern int __get_nprocs (void); libc_hidden_proto (__get_nprocs) +/* Return the number of available processors which the process can + be scheduled. */ +extern int __get_nprocs_sched (void) attribute_hidden; + /* Return number of physical pages of memory in the system. */ extern long int __get_phys_pages (void); libc_hidden_proto (__get_phys_pages) diff --git a/malloc/arena.c b/malloc/arena.c index 4c398753ae..78ef4cf18c 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -878,7 +878,7 @@ arena_get2 (size_t size, mstate avoid_arena) narenas_limit = mp_.arena_max; else if (narenas > mp_.arena_test) { - int n = __get_nprocs (); + int n = __get_nprocs_sched (); if (n >= 1) narenas_limit = NARENAS_FROM_NCORES (n); diff --git a/misc/getsysstats.c b/misc/getsysstats.c index 2986d62247..5cbba0f9bd 100644 --- a/misc/getsysstats.c +++ b/misc/getsysstats.c @@ -44,6 +44,12 @@ weak_alias (__get_nprocs, get_nprocs) link_warning (get_nprocs, "warning: get_nprocs will always return 1") +int +__get_nprocs_sched (void) +{ + return 1; +} + long int __get_phys_pages (void) { diff --git a/sysdeps/mach/getsysstats.c b/sysdeps/mach/getsysstats.c index 1267f39da2..cc8023f979 100644 --- a/sysdeps/mach/getsysstats.c +++ b/sysdeps/mach/getsysstats.c @@ -62,6 +62,12 @@ __get_nprocs (void) libc_hidden_def (__get_nprocs) weak_alias (__get_nprocs, get_nprocs) +int +__get_nprocs_sched (void) +{ + return __get_nprocs (); +} + /* Return the number of physical pages on the system. */ long int __get_phys_pages (void) diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c index 8a5d342f0c..e9c0dc4d83 100644 --- a/sysdeps/unix/sysv/linux/getsysstats.c +++ b/sysdeps/unix/sysv/linux/getsysstats.c @@ -87,6 +87,12 @@ __get_nprocs (void) libc_hidden_def (__get_nprocs) weak_alias (__get_nprocs, get_nprocs) +int +__get_nprocs_sched (void) +{ + return __get_nprocs (); +} + /* On some architectures it is possible to distinguish between configured and active cpus. */