From patchwork Mon Mar 29 18:25:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42798 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 E1D563861031; Mon, 29 Mar 2021 18:25:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1D563861031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617042328; bh=L0vXJoXYexsKYz2SzkD2dVuT1wu35/3ZXFjzOYizygg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Mqw09eJrUYdaPMxNVafu+AFM/tf/6ODW5a3TNUV/2gBCMLNicfiukQGXRPK/xpvIq 6S3aPyVLy6a/cJBJPHKuuTrB2Y/FCzVU30lZjC/99ooMg+OKpWRkkQFmfsAShd2wbw 3vKmkzdO7fuCHfb0wSRXx+jNe3/LuDXKLudUxhUQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by sourceware.org (Postfix) with ESMTPS id 41E0D3851C3E for ; Mon, 29 Mar 2021 18:25:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 41E0D3851C3E Received: by mail-qt1-x832.google.com with SMTP id x9so9980099qto.8 for ; Mon, 29 Mar 2021 11:25:26 -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:mime-version :content-transfer-encoding; bh=L0vXJoXYexsKYz2SzkD2dVuT1wu35/3ZXFjzOYizygg=; b=GzCoVVTwS33p5xt8ISvs/+ArtE2DaNA7COeSFKekVftzPNtBxTRgERF1rO3iciEHMs JLLT9GiqVOq0b/DWb8k7rt5TzbU3eEPcWOWwz1xxr7TUQV/hBBkBYqeATf0P3u+1WPhQ xGib6wfeR9uEGlvJJQ0b+mWZ9oq5nFid1MyQkk3G0DBdcbDV3GCsRwQP0NLOt+G3ge7t swqGn8TlQDp6CATCmlHkFJkAF4UZdoMDBiL83QDooEpEswZ2Ap9yTTp65GF4CLTHOGwf tQq0x5UBcH0JpNr7jVkBiLTa/Z6V57ZnpS9YbInOEgIYaTfjVm3mT39w62CeVQYpWsEc 9DXA== X-Gm-Message-State: AOAM531JDSTSWgumJcShLZ2ACD2tm/DtPBN2blD/qOgkz+Ae/tStPAzh 7ll2wj2FMw2KPbjejcgm6D2j5n8KmDAl2vvq X-Google-Smtp-Source: ABdhPJxO2rfP1Jj9jQ0VlVxnLYtABmEheaEDUKZsajvJCH7LmPDLv0Mmli7ENfxrzz44hgLeYSB4Sg== X-Received: by 2002:ac8:5716:: with SMTP id 22mr24518782qtw.212.1617042325350; Mon, 29 Mar 2021 11:25:25 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id o7sm14009565qkb.104.2021.03.29.11.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 11:25:24 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 1/4] Remove architecture specific sched_cpucount optimizations Date: Mon, 29 Mar 2021 15:25:17 -0300 Message-Id: <20210329182520.323665-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: crrodriguez@opensuse.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" And replace the generic algorithm with the Brian Kernighan’s one. GCC optimize it with popcnt if the architecture supports, so there is no need to add the extra POPCNT define to enable it. This is really a micro-optimization that only adds complexity: recent ABIs already support it (x86-64-v2 or power64le) and it simplifies the code for internal usage, since i686 does not allow an internal iFUNC call. Checked on x86_64-linux-gnu, aarch64-linux-gnu, and powerpc64le-linux-gnu. --- posix/sched_cpucount.c | 28 +++------------ sysdeps/i386/i686/multiarch/sched_cpucount.c | 1 - sysdeps/ia64/sched_cpucount.c | 20 ----------- sysdeps/powerpc/sched_cpucount.c | 22 ------------ sysdeps/x86_64/multiarch/sched_cpucount.c | 36 -------------------- sysdeps/x86_64/sched_cpucount.c | 25 -------------- 6 files changed, 4 insertions(+), 128 deletions(-) delete mode 100644 sysdeps/i386/i686/multiarch/sched_cpucount.c delete mode 100644 sysdeps/ia64/sched_cpucount.c delete mode 100644 sysdeps/powerpc/sched_cpucount.c delete mode 100644 sysdeps/x86_64/multiarch/sched_cpucount.c delete mode 100644 sysdeps/x86_64/sched_cpucount.c diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c index b0ca4ea7bc..529286e777 100644 --- a/posix/sched_cpucount.c +++ b/posix/sched_cpucount.c @@ -22,31 +22,11 @@ int __sched_cpucount (size_t setsize, const cpu_set_t *setp) { int s = 0; - const __cpu_mask *p = setp->__bits; - const __cpu_mask *end = &setp->__bits[setsize / sizeof (__cpu_mask)]; - - while (p < end) + for (int i = 0; i < setsize / sizeof (__cpu_mask); i++) { - __cpu_mask l = *p++; - -#ifdef POPCNT - s += POPCNT (l); -#else - if (l == 0) - continue; - - _Static_assert (sizeof (l) == sizeof (unsigned int) - || sizeof (l) == sizeof (unsigned long) - || sizeof (l) == sizeof (unsigned long long), - "sizeof (__cpu_mask"); - if (sizeof (__cpu_mask) == sizeof (unsigned int)) - s += __builtin_popcount (l); - else if (sizeof (__cpu_mask) == sizeof (unsigned long)) - s += __builtin_popcountl (l); - else - s += __builtin_popcountll (l); -#endif + __cpu_mask si = setp->__bits[i]; + /* Clear the least significant bit set. */ + for (; si != 0; si &= si - 1, s++); } - return s; } diff --git a/sysdeps/i386/i686/multiarch/sched_cpucount.c b/sysdeps/i386/i686/multiarch/sched_cpucount.c deleted file mode 100644 index 7db31b02f8..0000000000 --- a/sysdeps/i386/i686/multiarch/sched_cpucount.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/ia64/sched_cpucount.c b/sysdeps/ia64/sched_cpucount.c deleted file mode 100644 index 8440864b02..0000000000 --- a/sysdeps/ia64/sched_cpucount.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 2007-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#define POPCNT(l) __builtin_popcountl (l) - -#include diff --git a/sysdeps/powerpc/sched_cpucount.c b/sysdeps/powerpc/sched_cpucount.c deleted file mode 100644 index 8f00e3dbc8..0000000000 --- a/sysdeps/powerpc/sched_cpucount.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 2007-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifdef _ARCH_PWR5 -# define POPCNT(l) __builtin_popcountl (l) -#endif - -#include diff --git a/sysdeps/x86_64/multiarch/sched_cpucount.c b/sysdeps/x86_64/multiarch/sched_cpucount.c deleted file mode 100644 index 5180a11434..0000000000 --- a/sysdeps/x86_64/multiarch/sched_cpucount.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Count bits in CPU set. x86-64 multi-arch version. - This file is part of the GNU C Library. - Copyright (C) 2008-2021 Free Software Foundation, Inc. - Contributed by Ulrich Drepper . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include "init-arch.h" - -#define __sched_cpucount static generic_cpucount -#include -#undef __sched_cpucount - -#define POPCNT(l) \ - ({ __cpu_mask r; \ - asm ("popcnt %1, %0" : "=r" (r) : "0" (l));\ - r; }) -#define __sched_cpucount static popcount_cpucount -#include -#undef __sched_cpucount - -libc_ifunc (__sched_cpucount, - CPU_FEATURE_USABLE (POPCNT) ? popcount_cpucount : generic_cpucount); diff --git a/sysdeps/x86_64/sched_cpucount.c b/sysdeps/x86_64/sched_cpucount.c deleted file mode 100644 index 5a27336d6d..0000000000 --- a/sysdeps/x86_64/sched_cpucount.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2007-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifdef __amdfam10 -# define POPCNT(l) \ - ({ __cpu_mask r; \ - asm ("popcntq %1, %0" : "=r" (r) : "0" (l)); \ - r; }) -#endif - -#include From patchwork Mon Mar 29 18:25:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42800 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 74407385040B; Mon, 29 Mar 2021 18:25:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74407385040B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617042331; bh=RfADeB6Pm4BBCS55x4VMQfvm5sZMCATagT55FgPDJhk=; 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=rmwp1h2/577E9h4amiKQsv71BrJBpuYYikMgrmd85mcUaezEZWnDpZt5Q0W2/MvmD NDB0Zf3VLFX/WdDRZkMhToxuHGzANuVauvJWABR+ZxW8T9FH/VSOmsuHexq6S8OSsX jfoR1Yh/E/Ym3N4QiprF5n/hOPeCHjtoZsP1oaVk= 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 CA8C43860C34 for ; Mon, 29 Mar 2021 18:25:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CA8C43860C34 Received: by mail-qt1-x836.google.com with SMTP id l6so1805013qtq.2 for ; Mon, 29 Mar 2021 11:25:27 -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=RfADeB6Pm4BBCS55x4VMQfvm5sZMCATagT55FgPDJhk=; b=AKDQE4e0aW7TaX2SpQjREdPsRaE9wDQ1CBn0z1YiyYdLq0gN8XzfBLIOJfsIcvnmgk jMp3EfktDxed0dRHUpluQXCvjgfCkKzsO8C2Pt9x1DB+uMKuNV8+LeKa4nsfqW4lY6KG v9BZTsRrYnN0ivv8HCwdnHLEK/y5GzKe2MMqqeaRSK5IIZi7pfB74lRdibJTPtW7drAg ZTV7hadn0coqDpKXUVa49f9LZDp3VCCQ3nGatUGHKKU6sIn2bvHgiC4c/X9R8em3zRiK g8JOKdA7gd9xRAYzuBOdDmyLjykbcJEPtQ60phfLfg2ybxMg7A2a3IeQJyD1uachMw5G KCoA== X-Gm-Message-State: AOAM532Gg4olRdLc8TsbWuttrI6xak+wRcPAoTVtvUpKLAuTPBL0yEip ENaYKoU20W8bVe0uodCEnKvahrqg5zwst3f1 X-Google-Smtp-Source: ABdhPJw7SfB6lnTio1jKTAd0l6Hnc5l1mGVek81uG1F2/Up0de/moxCkBwdi3kWfqvX3U4vDJ4Yk+w== X-Received: by 2002:a05:622a:100c:: with SMTP id d12mr23525344qte.378.1617042326820; Mon, 29 Mar 2021 11:25:26 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id o7sm14009565qkb.104.2021.03.29.11.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 11:25:26 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/4] linux: Use sched_getaffinity for __get_nprocs (BZ #27645) Date: Mon, 29 Mar 2021 15:25:18 -0300 Message-Id: <20210329182520.323665-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210329182520.323665-1-adhemerval.zanella@linaro.org> References: <20210329182520.323665-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: crrodriguez@opensuse.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Both the sysfs and procfs parsing (through GET_NPROCS_PARSER) are removed in favor the syscall. The initial scratch buffer should fit to most of the common usage (1024 bytes with maps to 8192 CPUs). Checked on x86_64-linux-gnu and aarch64-linux-gnu. --- include/bits/cpu-set.h | 8 + posix/sched_cpucount.c | 1 + sysdeps/unix/sysv/linux/alpha/getsysstats.c | 19 -- sysdeps/unix/sysv/linux/getsysstats.c | 217 ++---------------- sysdeps/unix/sysv/linux/m68k/getsysstats.c | 37 --- .../unix/sysv/linux/microblaze/getsysstats.c | 34 --- sysdeps/unix/sysv/linux/mips/getsysstats.c | 36 --- sysdeps/unix/sysv/linux/sparc/getsysstats.c | 17 -- 8 files changed, 31 insertions(+), 338 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/m68k/getsysstats.c delete mode 100644 sysdeps/unix/sysv/linux/microblaze/getsysstats.c delete mode 100644 sysdeps/unix/sysv/linux/mips/getsysstats.c diff --git a/include/bits/cpu-set.h b/include/bits/cpu-set.h index 388f03cfbd..05aa0a8cf9 100644 --- a/include/bits/cpu-set.h +++ b/include/bits/cpu-set.h @@ -1 +1,9 @@ +#ifndef _BITS_CPU_SET_H #include + +#ifndef _ISOMAC +int __sched_cpucount (size_t __setsize, const cpu_set_t *__setp); +libc_hidden_proto (__sched_cpucount) +#endif + +#endif /* _BITS_CPU_SET_H */ diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c index 529286e777..8d853dcc2f 100644 --- a/posix/sched_cpucount.c +++ b/posix/sched_cpucount.c @@ -30,3 +30,4 @@ __sched_cpucount (size_t setsize, const cpu_set_t *setp) } return s; } +libc_hidden_def (__sched_cpucount) diff --git a/sysdeps/unix/sysv/linux/alpha/getsysstats.c b/sysdeps/unix/sysv/linux/alpha/getsysstats.c index bdf794703a..098575faef 100644 --- a/sysdeps/unix/sysv/linux/alpha/getsysstats.c +++ b/sysdeps/unix/sysv/linux/alpha/getsysstats.c @@ -18,25 +18,6 @@ . */ -/* We need to define a special parser for /proc/cpuinfo. */ -#define GET_NPROCS_PARSER(FD, BUFFER, CP, RE, BUFFER_END, RESULT) \ - do \ - { \ - /* Find the line that contains the information about the number of \ - active cpus. We don't have to fear extremely long lines since \ - the kernel will not generate them. 8192 bytes are really enough. \ - If there is no "CPUs ..." line then we are on a UP system. */ \ - char *l; \ - (RESULT) = 1; \ - while ((l = next_line (FD, BUFFER, &CP, &RE, BUFFER_END)) != NULL) \ - if ((sscanf (BUFFER, "cpus active : %d", &(RESULT)) == 1) \ - || (sscanf (BUFFER, "CPUs probed %*d active %d", \ - &(RESULT)) == 1)) \ - break; \ - } \ - while (0) - - /* On the Alpha we can distinguish between the number of configured and active cpus. */ #define GET_NPROCS_CONF_PARSER(FP, BUFFER, RESULT) \ diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c index 2c7f40998a..f8a4a31d1b 100644 --- a/sysdeps/unix/sysv/linux/getsysstats.c +++ b/sysdeps/unix/sysv/linux/getsysstats.c @@ -17,215 +17,42 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include #include -#include -#include -#include -#include +#include +#include #include #include -#include -#include -#include #include - -#include -#include - - -/* How we can determine the number of available processors depends on - the configuration. There is currently (as of version 2.0.21) no - system call to determine the number. It is planned for the 2.1.x - series to add this, though. - - One possibility to implement it for systems using Linux 2.0 is to - examine the pseudo file /proc/cpuinfo. Here we have one entry for - each processor. - - But not all systems have support for the /proc filesystem. If it - is not available we simply return 1 since there is no way. */ - - -/* Other architectures use different formats for /proc/cpuinfo. This - provides a hook for alternative parsers. */ -#ifndef GET_NPROCS_PARSER -# define GET_NPROCS_PARSER(FD, BUFFER, CP, RE, BUFFER_END, RESULT) \ - do \ - { \ - (RESULT) = 0; \ - /* Read all lines and count the lines starting with the string \ - "processor". We don't have to fear extremely long lines since \ - the kernel will not generate them. 8192 bytes are really \ - enough. */ \ - char *l; \ - while ((l = next_line (FD, BUFFER, &CP, &RE, BUFFER_END)) != NULL) \ - if (strncmp (l, "processor", 9) == 0) \ - ++(RESULT); \ - } \ - while (0) -#endif - - -static char * -next_line (int fd, char *const buffer, char **cp, char **re, - char *const buffer_end) -{ - char *res = *cp; - char *nl = memchr (*cp, '\n', *re - *cp); - if (nl == NULL) - { - if (*cp != buffer) - { - if (*re == buffer_end) - { - memmove (buffer, *cp, *re - *cp); - *re = buffer + (*re - *cp); - *cp = buffer; - - ssize_t n = __read_nocancel (fd, *re, buffer_end - *re); - if (n < 0) - return NULL; - - *re += n; - - nl = memchr (*cp, '\n', *re - *cp); - while (nl == NULL && *re == buffer_end) - { - /* Truncate too long lines. */ - *re = buffer + 3 * (buffer_end - buffer) / 4; - n = __read_nocancel (fd, *re, buffer_end - *re); - if (n < 0) - return NULL; - - nl = memchr (*re, '\n', n); - **re = '\n'; - *re += n; - } - } - else - nl = memchr (*cp, '\n', *re - *cp); - - res = *cp; - } - - if (nl == NULL) - nl = *re - 1; - } - - *cp = nl + 1; - assert (*cp <= *re); - - return res == *re ? NULL : res; -} - +#include int __get_nprocs (void) { - static int cached_result = -1; - static time_t timestamp; - - time_t now = time_now (); - time_t prev = timestamp; - atomic_read_barrier (); - if (now == prev && cached_result > -1) - return cached_result; - - /* XXX Here will come a test for the new system call. */ - - const size_t buffer_size = __libc_use_alloca (8192) ? 8192 : 512; - char *buffer = alloca (buffer_size); - char *buffer_end = buffer + buffer_size; - char *cp = buffer_end; - char *re = buffer_end; + struct scratch_buffer set; + scratch_buffer_init (&set); - const int flags = O_RDONLY | O_CLOEXEC; - /* This file contains comma-separated ranges. */ - int fd = __open_nocancel ("/sys/devices/system/cpu/online", flags); - char *l; - int result = 0; - if (fd != -1) + int r; + while (true) { - l = next_line (fd, buffer, &cp, &re, buffer_end); - if (l != NULL) - do - { - char *endp; - unsigned long int n = strtoul (l, &endp, 10); - if (l == endp) - { - result = 0; - break; - } - - unsigned long int m = n; - if (*endp == '-') - { - l = endp + 1; - m = strtoul (l, &endp, 10); - if (l == endp) - { - result = 0; - break; - } - } - - result += m - n + 1; - - l = endp; - if (l < re && *l == ',') - ++l; - } - while (l < re && *l != '\n'); - - __close_nocancel_nostatus (fd); - - if (result > 0) - goto out; + /* The possible error are EFAULT for an invalid buffer or ESRCH for + invalid pid, none could happen. */ + r = INTERNAL_SYSCALL_CALL (sched_getaffinity, 0, set.length, + set.data); + if (r > 0) + break; + + if (!scratch_buffer_grow (&set)) + /* Default to an SMP system in case we cannot obtain an accurate + number. */ + return 2; } - cp = buffer_end; - re = buffer_end; - - /* Default to an SMP system in case we cannot obtain an accurate - number. */ - result = 2; + /* The scratch_buffer is aligned to max_align_t. */ + r = __sched_cpucount (r, (const cpu_set_t *) set.data); - /* The /proc/stat format is more uniform, use it by default. */ - fd = __open_nocancel ("/proc/stat", flags); - if (fd != -1) - { - result = 0; - - while ((l = next_line (fd, buffer, &cp, &re, buffer_end)) != NULL) - /* The current format of /proc/stat has all the cpu* entries - at the front. We assume here that stays this way. */ - if (strncmp (l, "cpu", 3) != 0) - break; - else if (isdigit (l[3])) - ++result; + scratch_buffer_free (&set); - __close_nocancel_nostatus (fd); - } - else - { - fd = __open_nocancel ("/proc/cpuinfo", flags); - if (fd != -1) - { - GET_NPROCS_PARSER (fd, buffer, cp, re, buffer_end, result); - __close_nocancel_nostatus (fd); - } - } - - out: - cached_result = result; - atomic_write_barrier (); - timestamp = now; - - return result; + return r; } libc_hidden_def (__get_nprocs) weak_alias (__get_nprocs, get_nprocs) diff --git a/sysdeps/unix/sysv/linux/m68k/getsysstats.c b/sysdeps/unix/sysv/linux/m68k/getsysstats.c deleted file mode 100644 index 6915f6d721..0000000000 --- a/sysdeps/unix/sysv/linux/m68k/getsysstats.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Determine various system internal values, Linux/m68k version. - Copyright (C) 2003-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Andreas Schwab - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - - -/* We need to define a special parser for /proc/cpuinfo. */ -#define GET_NPROCS_PARSER(FD, BUFFER, CP, RE, BUFFER_END, RESULT) \ - do \ - { \ - (RESULT) = 0; \ - /* Read all lines and count the lines starting with the string \ - "CPU:". We don't have to fear extremely long lines since \ - the kernel will not generate them. 8192 bytes are really \ - enough. */ \ - char *l; \ - while ((l = next_line (FD, BUFFER, &CP, &RE, BUFFER_END)) != NULL) \ - if (strncmp (l, "CPU:", 4) == 0) \ - ++(RESULT); \ - } \ - while (0) - -#include diff --git a/sysdeps/unix/sysv/linux/microblaze/getsysstats.c b/sysdeps/unix/sysv/linux/microblaze/getsysstats.c deleted file mode 100644 index 46403e74a8..0000000000 --- a/sysdeps/unix/sysv/linux/microblaze/getsysstats.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 1997-2021 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* We need to define a special parser for /proc/cpuinfo. */ -#define GET_NPROCS_PARSER(FD, BUFFER, CP, RE, BUFFER_END, RESULT) \ - do \ - { \ - (RESULT) = 0; \ - /* Read all lines and count the lines starting with the string \ - "CPU-Family:". We don't have to fear extremely long lines since \ - the kernel will not generate them. 8192 bytes are really enough. */ \ - char *l; \ - while ((l = next_line (FD, BUFFER, &CP, &RE, BUFFER_END)) != NULL) \ - if (strncmp (l, "CPU-Family:", 11) == 0) \ - ++(RESULT); \ - } \ - while (0) - -#include diff --git a/sysdeps/unix/sysv/linux/mips/getsysstats.c b/sysdeps/unix/sysv/linux/mips/getsysstats.c deleted file mode 100644 index 34f352e963..0000000000 --- a/sysdeps/unix/sysv/linux/mips/getsysstats.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Determine various system internal values, Linux/MIPS version. - Copyright (C) 2001-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - - -/* We need to define a special parser for /proc/cpuinfo. */ -#define GET_NPROCS_PARSER(FD, BUFFER, CP, RE, BUFFER_END, RESULT) \ - do \ - { \ - (RESULT) = 0; \ - /* Read all lines and count the lines starting with the string \ - "cpu model". We don't have to fear extremely long lines since \ - the kernel will not generate them. 8192 bytes are really \ - enough. */ \ - char *l; \ - while ((l = next_line (FD, BUFFER, &CP, &RE, BUFFER_END)) != NULL) \ - if (strncmp (l, "cpu model", 9) == 0) \ - ++(RESULT); \ - } \ - while (0) - -#include diff --git a/sysdeps/unix/sysv/linux/sparc/getsysstats.c b/sysdeps/unix/sysv/linux/sparc/getsysstats.c index 8e1760802f..a8adba8321 100644 --- a/sysdeps/unix/sysv/linux/sparc/getsysstats.c +++ b/sysdeps/unix/sysv/linux/sparc/getsysstats.c @@ -19,23 +19,6 @@ . */ -/* We need to define a special parser for /proc/cpuinfo. */ -#define GET_NPROCS_PARSER(FD, BUFFER, CP, RE, BUFFER_END, RESULT) \ - do \ - { \ - (RESULT) = 0; \ - /* Find the line that contains the information about the number of \ - active cpus. We don't have to fear extremely long lines since \ - the kernel will not generate them. 8192 bytes are really \ - enough. */ \ - char *l; \ - while ((l = next_line (FD, BUFFER, &CP, &RE, BUFFER_END)) != NULL) \ - if (sscanf (l, "ncpus active : %d", &(RESULT)) == 1) \ - break; \ - } \ - while (0) - - /* On the Sparc we can distinguish between the number of configured and active cpus. */ #define GET_NPROCS_CONF_PARSER(FP, BUFFER, RESULT) \ From patchwork Mon Mar 29 18:25:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42799 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 E23E73850403; Mon, 29 Mar 2021 18:25:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E23E73850403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617042330; bh=a4LgcnWQEJ5nwvrv6nOt/lVY8gMV1Q6y8rTAW6WpPnw=; 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=JjeIkAqI1X6qth4alCMiJ2QEp3Pbu7gYEpYDP1aDae15CWJk1+ZNUMjxfJKq/g1dE MkIlIvMcHLSVryeCl9RqZtZS288YXgKW6UxEVzRblLDyIlNmF1FjfXUJovuN+gRBIa FJ4hNw8xfxybmnR67Sxy3E0Sp5VcRv4mw8MzsV+s= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by sourceware.org (Postfix) with ESMTPS id D37553861030 for ; Mon, 29 Mar 2021 18:25:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D37553861030 Received: by mail-qt1-x82c.google.com with SMTP id g24so10005856qts.6 for ; Mon, 29 Mar 2021 11:25:28 -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=a4LgcnWQEJ5nwvrv6nOt/lVY8gMV1Q6y8rTAW6WpPnw=; b=GA9f6r2au+QPn3ouJGbISOA9fToRriVn6f284YcGSeJARQv/aDFgxnuXEYwg8GAn/B u2hdsxNsmmTfvwF0D0jT1OswDwSDBVcZi7DXF1q2luh4jdDToi/S6genfcMj3+c8Tg+6 IKcIvEL9N5Z1Srrq9ll+B103KPhwnlGRQ44PWULyYZfB88fykQ8vFS54gq7jSFcOjMXG nUxC9S9qvMsgoWhPItIxzyPLmSINqtd1HoHq9ZpEL4t4ySt65mQglzNCslKExN0m94Zt 8vz/h1n8J2p7e16LC/jMRp7SbQppINl9POeEKuiqmcjE0fTnpK+tO/yK7/u8PBmcHJR4 2YmA== X-Gm-Message-State: AOAM5300kXQv8hnj566ViJcP+4erUeGoKALlWlyOxPsLreOfOWBdQ3of I3r7+2QYmqckEi4odvchPD/NgNw7WlQlrbk4 X-Google-Smtp-Source: ABdhPJwBFfNn6TOber8GI2mhYNCkOCG6BvWZufClSHJyX+iA1WTA8yP6AnoVrUyBh2Se24Td04KMIw== X-Received: by 2002:ac8:45d7:: with SMTP id e23mr23767748qto.107.1617042328282; Mon, 29 Mar 2021 11:25:28 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id o7sm14009565qkb.104.2021.03.29.11.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 11:25:28 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 3/4] linux: Use /sys/devices/system/cpu/possible on __get_nprocs_conf Date: Mon, 29 Mar 2021 15:25:19 -0300 Message-Id: <20210329182520.323665-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210329182520.323665-1-adhemerval.zanella@linaro.org> References: <20210329182520.323665-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: crrodriguez@opensuse.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Instead of iterate over all the cpu in the sysfs folder. It consumes slight less resources on large system (which might require extra getdents call) and memory (a limited stack buffer instead a large malloced one for opendir). Checked on x86_64-linux-gnu, aarch64-linux-gnu, and powerpc64le-linux-gnu. --- sysdeps/unix/sysv/linux/getsysstats.c | 51 +++++++++++++++------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c index f8a4a31d1b..5069951246 100644 --- a/sysdeps/unix/sysv/linux/getsysstats.c +++ b/sysdeps/unix/sysv/linux/getsysstats.c @@ -17,7 +17,8 @@ License along with the GNU C Library; if not, see . */ -#include +#include +#include #include #include #include @@ -63,33 +64,39 @@ weak_alias (__get_nprocs, get_nprocs) int __get_nprocs_conf (void) { - /* XXX Here will come a test for the new system call. */ + int result = 1; /* Try to use the sysfs filesystem. It has actual information about online processors. */ - DIR *dir = __opendir ("/sys/devices/system/cpu"); - if (dir != NULL) + int fd = __open64_nocancel ("/sys/devices/system/cpu/possible", O_RDONLY); + if (fd != -1) { - int count = 0; - struct dirent64 *d; - - while ((d = __readdir64 (dir)) != NULL) - /* NB: the sysfs has d_type support. */ - if (d->d_type == DT_DIR && strncmp (d->d_name, "cpu", 3) == 0) - { - char *endp; - unsigned long int nr = strtoul (d->d_name + 3, &endp, 10); - if (nr != ULONG_MAX && endp != d->d_name + 3 && *endp == '\0') - ++count; - } - - __closedir (dir); - - return count; + /* The entry is in the form of '[cpuX]-[cpuY]'. */ + char buf[2 * INT_STRLEN_BOUND (unsigned int) + 1]; + + ssize_t n = __read_nocancel (fd, buf, sizeof (buf)); + if (n > 0) + { + buf[n] = '\0'; + + /* Start on the right, to find highest node number. */ + int m = 1; + while (--n) + { + if ((buf[n] == ',') || (buf[n] == '-')) + break; + /* Ignore '\n' */ + if (! isdigit (buf[n])) + continue; + result += (buf[n] - '0') * m; + m *= 10; + } + } + + __close_nocancel (fd); + return result + 1; } - int result = 1; - #ifdef GET_NPROCS_CONF_PARSER /* If we haven't found an appropriate entry return 1. */ FILE *fp = fopen ("/proc/cpuinfo", "rce"); From patchwork Mon Mar 29 18:25:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42801 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 6D44E3850417; Mon, 29 Mar 2021 18:25:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D44E3850417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617042333; bh=KL/dXHClwAVCiQ1pWfB/SiGjuE6YzlT8ELYubyAFY5w=; 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=aGBY2jri2OTq9UR2uiPzTWVdqm/cqsAJ/eOFLiPnnSgc0Ncdu2JpHTQqMzFGa8DFh 2MlKWRNIluLvvcy4+/mb4HPP7eZ5giRdjMgGDXUN4gtcgWKnWCHONRGFGY4LHzAlZp gYaoMnl5zOh26fBLRmVfYoZHnz9GQTfDybEN5x0o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by sourceware.org (Postfix) with ESMTPS id 895A03860C34 for ; Mon, 29 Mar 2021 18:25:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 895A03860C34 Received: by mail-qv1-xf2b.google.com with SMTP id g8so6928988qvx.1 for ; Mon, 29 Mar 2021 11:25:30 -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=KL/dXHClwAVCiQ1pWfB/SiGjuE6YzlT8ELYubyAFY5w=; b=NnKolE2CKN42Fqfcw3C5/B9SvtsmrxjxFv+YZsfYcjV2HrmtqxPGO91QhjRUX2FPY4 +qTFaW3CTBn+a5mw6v41ezEBCDf0tL2HH8bztl0TNzTsqk/pcv0A0r7Ra4iXVXJESc3j OWDSPF2oa8VPZWA5mvXr4kgxS22Lg/7FN+8pQt8uj0g72/qSpYAdaI2FS+HRSYE7ojj1 bihFa7+CvCAf26Wsy+vbjNP8rbjGUtFtH4LatU+2hZhGz3quwKf1Go+1C8Z8mRftAz7T WcK4hEar9n4Xu62OSnrrP3Pwo88Wud3u7WNzFVfpJPAA+TGIsawxbnF50iBiZDgxoqgG eY2A== X-Gm-Message-State: AOAM532j7yU9AqFtevesaJYHDWC9t/3dIg4g/nr8gm5NNQ4gCcHy+ccn cJxNC9LLGd0lu/tRC5zwSQYhhS/0zl7XOdqr X-Google-Smtp-Source: ABdhPJy806Jui58z3I840V5SfwR0lqPOzYaHqw0OKetKjizDuAbt9XIUPV2WEv8/mNW25fyjlUgUYw== X-Received: by 2002:ad4:560f:: with SMTP id ca15mr26498643qvb.42.1617042329853; Mon, 29 Mar 2021 11:25:29 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id o7sm14009565qkb.104.2021.03.29.11.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 11:25:29 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 4/4] linux: Remove /proc/cpuinfo fallback on alpha and sparc Date: Mon, 29 Mar 2021 15:25:20 -0300 Message-Id: <20210329182520.323665-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210329182520.323665-1-adhemerval.zanella@linaro.org> References: <20210329182520.323665-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: crrodriguez@opensuse.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" There is no much gain in fallback to cpuinfo if sysfs is no present, usually on restricted environment neither will be present. It also simplifies the code and make all architecture use the sched_getaffinity as the sysfs fallback. Checked on sparc64-linux-gnu. --- sysdeps/unix/sysv/linux/alpha/getsysstats.c | 38 --------------------- sysdeps/unix/sysv/linux/getsysstats.c | 22 ++---------- sysdeps/unix/sysv/linux/sparc/getsysstats.c | 38 --------------------- 3 files changed, 3 insertions(+), 95 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/alpha/getsysstats.c delete mode 100644 sysdeps/unix/sysv/linux/sparc/getsysstats.c diff --git a/sysdeps/unix/sysv/linux/alpha/getsysstats.c b/sysdeps/unix/sysv/linux/alpha/getsysstats.c deleted file mode 100644 index 098575faef..0000000000 --- a/sysdeps/unix/sysv/linux/alpha/getsysstats.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Determine various system internal values, Linux/Alpha version. - Copyright (C) 1999-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Andreas Schwab - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - - -/* On the Alpha we can distinguish between the number of configured and - active cpus. */ -#define GET_NPROCS_CONF_PARSER(FP, BUFFER, RESULT) \ - do \ - { \ - /* Find the line that contains the information about the number of \ - probed cpus. We don't have to fear extremely long lines since \ - the kernel will not generate them. 8192 bytes are really enough. \ - If there is no "CPUs ..." line then we are on a UP system. */ \ - (RESULT) = 1; \ - while (__fgets_unlocked ((BUFFER), sizeof (BUFFER), (FP)) != NULL) \ - if ((sscanf (buffer, "cpus detected : %d", &(RESULT)) == 1) \ - || (sscanf (buffer, "CPUs probed %d", &(RESULT)) == 1)) \ - break; \ - } \ - while (0) - -#include diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c index 5069951246..0791399b8f 100644 --- a/sysdeps/unix/sysv/linux/getsysstats.c +++ b/sysdeps/unix/sysv/linux/getsysstats.c @@ -64,13 +64,13 @@ weak_alias (__get_nprocs, get_nprocs) int __get_nprocs_conf (void) { - int result = 1; - /* Try to use the sysfs filesystem. It has actual information about online processors. */ int fd = __open64_nocancel ("/sys/devices/system/cpu/possible", O_RDONLY); if (fd != -1) { + int result = 0; + /* The entry is in the form of '[cpuX]-[cpuY]'. */ char buf[2 * INT_STRLEN_BOUND (unsigned int) + 1]; @@ -97,23 +97,7 @@ __get_nprocs_conf (void) return result + 1; } -#ifdef GET_NPROCS_CONF_PARSER - /* If we haven't found an appropriate entry return 1. */ - FILE *fp = fopen ("/proc/cpuinfo", "rce"); - if (fp != NULL) - { - char buffer[8192]; - - /* No threads use this stream. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); - GET_NPROCS_CONF_PARSER (fp, buffer, result); - fclose (fp); - } -#else - result = __get_nprocs (); -#endif - - return result; + return __get_nprocs (); } libc_hidden_def (__get_nprocs_conf) weak_alias (__get_nprocs_conf, get_nprocs_conf) diff --git a/sysdeps/unix/sysv/linux/sparc/getsysstats.c b/sysdeps/unix/sysv/linux/sparc/getsysstats.c deleted file mode 100644 index a8adba8321..0000000000 --- a/sysdeps/unix/sysv/linux/sparc/getsysstats.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Determine various system internal values, Linux/Sparc version. - Copyright (C) 1999-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Andreas Schwab and - Jakub Jelinek - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - - -/* On the Sparc we can distinguish between the number of configured and - active cpus. */ -#define GET_NPROCS_CONF_PARSER(FP, BUFFER, RESULT) \ - do \ - { \ - (RESULT) = 0; \ - /* Find the line that contains the information about the number of \ - probed cpus. We don't have to fear extremely long lines since \ - the kernel will not generate them. 8192 bytes are really \ - enough. */ \ - while (__fgets_unlocked ((BUFFER), sizeof (BUFFER), (FP)) != NULL) \ - if (sscanf (buffer, "ncpus probed : %d", &(RESULT)) == 1) \ - break; \ - } \ - while (0) - -#include