From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 2AB7F393BC16 for ; Fri, 7 May 2021 12:43:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2AB7F393BC16 Received: by mail-qt1-x836.google.com with SMTP id j11so6429962qtn.12 for ; Fri, 07 May 2021 05:43:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Ljna4orTPMVbzQrym/8i1q+pjJyM0R8Sc30Yw/lNQE8=; b=HJGhkd0iH6AjvSDdqTlcNHs5wku+SSDYh6H3Y8iyyTlrp3MgFKJMlOc5RhGOQ2i14C V60p/DfoNXfJv6SNS2GN4PA9LewK8vW6ZjcsXejwG0o5sayMaA7Z/Fl3QHwx8NXJI8oC STE3D1R8JSuPhqMOuTbexyOYy8WIjS9nPw/QldpEPih2AE7aZcrVeflTl/sOecdXXCt/ 3hrSKIgt8GznaUFQWmgE0ZQlIFBukKmbem/92/9EbyYHlkaVHHz3ZC+6ZmYQ1HtaFLjc 7bOrOykmLoGEHyGjGuMW0xHsPgXzuEGHUuUuKYa58Dz4cWN4eOOpwbta1qrQlHF3SMVN EhRA== X-Gm-Message-State: AOAM531QX+zgsL1HAtBH/U9HuSqKlauuYGAMsc8k0jv1aEZe+Ni49mTf cqeqMpLYMO4KbkBgJ11d8V6dIp27fDbSoQ== X-Google-Smtp-Source: ABdhPJwPQcTO6ZRYxLDDejw5KOogchHAX2MxBrpuah5SKzh/Bdk+ITT23pw55n/jQWyyklWj3r1Qiw== X-Received: by 2002:ac8:d02:: with SMTP id q2mr8983191qti.110.1620391429582; Fri, 07 May 2021 05:43:49 -0700 (PDT) Received: from [192.168.1.4] ([177.194.37.86]) by smtp.gmail.com with ESMTPSA id o189sm4437734qkd.60.2021.05.07.05.43.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 May 2021 05:43:49 -0700 (PDT) Subject: Re: [PATCH 3/4] linux: Use /sys/devices/system/cpu/possible on __get_nprocs_conf To: Florian Weimer , Adhemerval Zanella via Libc-alpha Cc: crrodriguez@opensuse.org References: <20210329182520.323665-1-adhemerval.zanella@linaro.org> <20210329182520.323665-3-adhemerval.zanella@linaro.org> <871ralcbha.fsf@oldenburg.str.redhat.com> <87sg31awd8.fsf@oldenburg.str.redhat.com> <87h7jggec3.fsf@oldenburg.str.redhat.com> <0b31aafd-b73b-fa82-ac1b-da04f8c68698@linaro.org> <874kfeer8x.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Message-ID: Date: Fri, 7 May 2021 09:43:46 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <874kfeer8x.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, 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-List-Received-Date: Fri, 07 May 2021 12:43:51 -0000 On 07/05/2021 08:07, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> On 06/05/2021 10:51, Florian Weimer wrote: >>> * Adhemerval Zanella via Libc-alpha: >>> >>>> On 05/05/2021 15:06, Florian Weimer wrote: >>>>> * Florian Weimer: >>>>> >>>>>> * Adhemerval Zanella via Libc-alpha: >>>>>> >>>>>>> + /* 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; >>>>>>> } >>>>>> >>>>>> I think the /online and /possible files have the same layout, so you >>>>>> could use both. >>>>> >>>>> Sorry, I meant to write: “so you could use *one parser for* both” >>>> >>>> I am not following, the second patch in this set *removed* the >>>> /sys/devices/system/cpu/online parsing in favor of the sched_getaffinity. >>>> So now it only parses /sys/devices/system/cpu/possible and fallbacks >>>> to sched_getaffinity. >>> >>> Oh, right. So you removed the old implementation and bring bug a >>> slightly different new one. Got it. >> >> Right, are you ok with the patch then? > > The new parser cannot handle gaps or ranges that do not start at 0, I > think. The old parser could cope with that. The kernel data structures > support gaps in the possible CPU mask. I don't know if they occur in > practice, but firmware quirks in this area aren't exactly rare (e.g., > single-socket systems which report hundreds of hot-pluggable CPU cores). Indeed I did not take this in consideration and it seems that using /possible is more complicated than just opendir the directory. And we will need to handle the possible unlikely issue of a truncated value from kernel, since the buffer is limited to PAGE_SIZE. I will drop this patch.