Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp26967pxb; Tue, 21 Sep 2021 17:46:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxggQYM8fHTOmnljX4n4WuoF8BL/0n9VxaMGM1XDhyO9u3rMI87/+b1Y2kIHe4sy+bnsT4+ X-Received: by 2002:a05:6402:cbb:: with SMTP id cn27mr39871749edb.5.1632271605515; Tue, 21 Sep 2021 17:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632271605; cv=none; d=google.com; s=arc-20160816; b=Od0BC8rBt2rOxScgCeNJMbIZd6rdN2RFW2W6yZrFQiugK3NPi7mNBU6LHZZ5beBH4H arGGlAOIVrpYTDFTJ5AhVqKOq/9TviqX0X2WdJ5B9Nw+R6e27zEbIcI12wN0UvGyUMJ7 C/+nJWUMwHggjRGRJhuLLPSIulC94NmOLzdHmEKw10Jn/tXLtyDz4fmVoI+LhUbZ/Y6h XG9QRYU5QZkBVInNazAmHjuSzxDXWulubjxPx3g2Fn0Tb4MU+vc70PKj3yDjFICw4Y4K 6c9po9b0z8pvi/AA1/Dl6fOhSWzm/wxQPYeDK0InuQLfrPzxqUaua2f75AHSb0jXT9qf 8fZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Y1TvGa/2v6EnSjxnp0r1HWOSDa8Y16SfdbFLGDrA8LU=; b=PZDnkS5BAsByv/0jr4k1VOWdwaEAF5CRQekm5hI+/Dc/UrG240OjKipepB/la/6M7j q1zbqa7bp+Rj2JEdStfHAnSRfXLppelo4c5aNDq3BA3cjOe/QoLTrajImHD6U5vAbiyu yKrA6pTypV95V8/Mx7i61U2cKfQhegkMfGWgFOsFlI34MYwPInichf2oV539SvCVxmjl 2jwOs8aq+TXpGhkKk/kY4zNA9qlS+j656TOZDqAOiFWJFwuCkn2fkeZgkOBSutFtYf40 I7pGVeqFbqMKpterGMweSGn1GLHL0kiPf3SsSLBsWyfWWFfLNWqdnYaWgzx4Kdh1gONo ogiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Wz3TgdYi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k25si880358edf.34.2021.09.21.17.46.21; Tue, 21 Sep 2021 17:46:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Wz3TgdYi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230017AbhIUXWU (ORCPT + 99 others); Tue, 21 Sep 2021 19:22:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbhIUXWT (ORCPT ); Tue, 21 Sep 2021 19:22:19 -0400 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C5AFC061574; Tue, 21 Sep 2021 16:20:50 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id f130so3189604qke.6; Tue, 21 Sep 2021 16:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Y1TvGa/2v6EnSjxnp0r1HWOSDa8Y16SfdbFLGDrA8LU=; b=Wz3TgdYiU7IihXDeb7xvijnbKXH7DTeRZVStGY5+n8K8y4iXFvLk+lBACaoFKbhrmy VxZOPA1/3UGFtzvk33yXkPbMsSrfet5adIx2lzY4u+R8Ho9/10yNAc6psE2zWlXsD32k WqgdXWUfNkAOIU4hUntBaMrZEeruZcKPMTDjeIaOA6jSI/XQ0vfWkik9FUdKm2spNbQ9 oZUiwK12Xfmy4BW2Cs1ZhNnf05K35D6OB0QsP1It/gSFtiGkNjg/Iq1vEDJ97RAlwOEz ZXRXZJ/uPKzcCLqGodVtVRpAg+lYkp72cEH/KXhIsqtRJrJc6NrRqMVBF09mBTXEEdW4 DDlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Y1TvGa/2v6EnSjxnp0r1HWOSDa8Y16SfdbFLGDrA8LU=; b=8KyNyFlATp59Fstl1WuSRIgqquOs30KuTNXr2jV2qzQsZ2CDC1vYuJFbX51ceC8ogp xL7EYdlkEslBJzDRkm60yawxCn/zyRQCySTa/VNhkhr2O0LOvd5jQa3yrhvyaP3T+q4e AgvGDcIq2V1JbDBDXps4JAvBRk8S+8cpmOmH+Oo2qVY7NVGgPjHnFvYC6p1fkqMvi2m8 o/d89NHegqAafRivjBxhExd2UJ5mu39monPZ2N4xPSZXnDWwN9ddgvTP4GoiF+Rv328u hKzyT2qdtKq7IrW208HA/nbN519GzXZMZk1QKWXkfYcWPJuN8runW1nO99vJ8TQP9LKX Dm1g== X-Gm-Message-State: AOAM531BNye1m/kRz1ffGhGFCfWnR4/K35FZG32zseRkUQJUOv08b/yE YFwSnjUKndGXkW3YgKBNbVzQd2ORa10afM+ZdYrchPlTSwQ= X-Received: by 2002:a25:1bc5:: with SMTP id b188mr40964801ybb.267.1632266449664; Tue, 21 Sep 2021 16:20:49 -0700 (PDT) MIME-Version: 1.0 References: <20210921060434.26732-1-falakreyaz@gmail.com> In-Reply-To: <20210921060434.26732-1-falakreyaz@gmail.com> From: Andrii Nakryiko Date: Tue, 21 Sep 2021 16:20:38 -0700 Message-ID: Subject: Re: [PATCH] libbpf: Use sysconf to simplify libbpf_num_possible_cpus To: Muhammad Falak R Wani Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Networking , bpf , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 20, 2021 at 11:04 PM Muhammad Falak R Wani wrote: > > Simplify libbpf_num_possible_cpus by using sysconf(_SC_NPROCESSORS_CONF) > instead of parsing a file. > This patch is a part of libbpf-1.0 milestone. > > Reference: https://github.com/libbpf/libbpf/issue/383 I've been asking people to use a reference style like this, so that we don't confuse this with proper Linux tags. It's also useful to use "Closes: " keyword to let Github auto-close the issue when this patch eventually is synced into Github. So in this case I'd phrase everything as: "This patch is a part ([0]) of libbpf-1.0 milestone. [0] Closes: https://github.com/libbpf/libbpf/issue/383 Please update in the next revision. Also, keep in mind that we ask to use "[PATCH bpf-next]" prefix when submitting patches against the bpf-next kernel tree. It makes the intent clear and our BPF CI system knows which tree to test against. Thanks. > > Signed-off-by: Muhammad Falak R Wani > --- > tools/lib/bpf/libbpf.c | 16 +++------------- > 1 file changed, 3 insertions(+), 13 deletions(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index da65a1666a5e..1d730b08ee44 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -10765,25 +10765,15 @@ int parse_cpu_mask_file(const char *fcpu, bool **mask, int *mask_sz) > > int libbpf_num_possible_cpus(void) > { > - static const char *fcpu = "/sys/devices/system/cpu/possible"; > static int cpus; > - int err, n, i, tmp_cpus; > - bool *mask; > + int tmp_cpus; > > tmp_cpus = READ_ONCE(cpus); > if (tmp_cpus > 0) > return tmp_cpus; > > - err = parse_cpu_mask_file(fcpu, &mask, &n); > - if (err) > - return libbpf_err(err); > - > - tmp_cpus = 0; > - for (i = 0; i < n; i++) { > - if (mask[i]) > - tmp_cpus++; > - } > - free(mask); > + tmp_cpus = sysconf(_SC_NPROCESSORS_CONF); > + /* sysconf sets errno; no need to use libbpf_err */ I'd say it's still a good idea for explicitness and to show that we didn't forget about it :) Plus, if it actually ever fails, we don't want to WRITE_ONCE() here, so please follow the same error handling logic as it was previously with parse_cpu_mask_file. > > WRITE_ONCE(cpus, tmp_cpus); > return tmp_cpus; > -- > 2.17.1 >