From nobody Thu Dec 18 00:07:22 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C267D193426 for ; Fri, 6 Dec 2024 04:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460044; cv=none; b=K3sOLKKgRtzd9bRCll5VShCY6KkYhs/qEMjjjNyqxjAcNp+mtq6qccnjZm4DiKpiPdiO8vLEUV+uqbBa1U5fdXIBINV01oV6021evmF2EX/C8lZUyJOHwOl3pJr53xOthbSqCXO13dC5DmLolGfIVUO0KuvrFv2r694EK69h58U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460044; c=relaxed/simple; bh=NvHv1JvgCIj4wxEXi2qnifVrg5VM8kZfYBZjSzBa3dg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=IOAuy4HNt/VDOc5TeNB8/Nm5gngErU+tfO0hUoEQF5FQDCxgjFwVIGtUaXDOn5G/dcOsZNKdH/rW/hKntjc1g0DTzQSqCQfljqaj5b1r+t/cjR5YsDfc3rT7VVYhj1SAhffZVzCEjgCGbESRQt9xNHL8/H7i9tFFNMVWcFMYVXY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ITPvaYeR; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ITPvaYeR" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e3a109984a5so309546276.3 for ; Thu, 05 Dec 2024 20:40:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733460041; x=1734064841; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=7HooQRn/pxrZs6KSP4MCRwKNyrc2n5wJOPs3/bci4Uk=; b=ITPvaYeRcgVc38hqEm+Bpq2IJRYcrWPrEtidw63fxdkb4xkrQrGPRGkr3eMrUd65PP NT+brCB7suidmG6yIuhtu25HYz+RJTo9UpLHMim2ALkqkbOZ7+FTHuZfWgMBZODnkA72 Vzk/r3l+m7zQsGT1QeMy3+yXQDi7tcZ1ksDjQfDd8yXzNRWVVE3gSHBbwf6cYB/LNS5W TEfGX15BR4/8Ko7oUm5VWveuA1LUq6VsIog0l99rEDb1sO0NOzTpdhZyIXmNtq/YmSx5 atpmoPDWX+vlonPr8KrmyP6g+B+ewbdBeQOoPMvrV9i+JYh9exa+rTVsmIILhKxZpU3l khAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733460041; x=1734064841; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7HooQRn/pxrZs6KSP4MCRwKNyrc2n5wJOPs3/bci4Uk=; b=CXcH2gaKNEmOlKxf3JKE4Nzc8ULxBjeH1M3CWVvCfSSdHY7kqwsDKLAW9Hargk/gZz VxNpx4oo7hhKG9zsn+cTicd0c98D8N8WXE3vbF39nL/hszB98t13MeSolRWrHUz13SEK 204McSZptuNhrc7+WELT+gFCDetcyEpTsJjFTjFjwiN17v1KUmGEROhoD5BN9aShrmQ/ y8ekS65HlRmfmeAQ2OWT3wFu9zdtZdeoWxE2thmUtQaZbBCTeVpudoBzN7hHzg3b88BB UluUqW72bWOQYvVEe3KEsk3Yi8QsTWVhMJjk9wzt9RO7yrQvnyaSqOHOmopIQQRKdjEh WGpw== X-Forwarded-Encrypted: i=1; AJvYcCWmuZVh0ArFRUBcK/22/hAiLeiny6g+sumeG2jdUEpo8jN+p8lBHc9PDhUup3CPlfaZuC5iiZcOFHY0dJA=@vger.kernel.org X-Gm-Message-State: AOJu0YzfqsUciM8YkQp8y2v/7LQV+i1KibmJ7FwBqwvmx6RThFFrZ1ft P41q5l5gDqDEI3YrTTHWYwFNmfOkdPYw5o/CNCQ/6bN53GJlB5zDZMlRddSnq0P/yzJAWGjXz1U oIscalQ== X-Google-Smtp-Source: AGHT+IHIgCIgWFyGcAWDY7516J4vjQr1pq+XRf6N+uB0/z07nFo7rInpoiDluy+8thojGoFnFz9roVvtzpil X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:eb75:393:2a8c:1440]) (user=irogers job=sendgmr) by 2002:a25:7c06:0:b0:e38:d1e:af86 with SMTP id 3f1490d57ef6-e3a0b07413dmr731276.2.1733460040757; Thu, 05 Dec 2024 20:40:40 -0800 (PST) Date: Thu, 5 Dec 2024 20:40:28 -0800 In-Reply-To: <20241206044035.1062032-1-irogers@google.com> Message-Id: <20241206044035.1062032-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241206044035.1062032-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v1 1/8] perf: Increase MAX_NR_CPUS to 4096 From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Kyle Meyer , Ben Gainey , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kyle Meyer Systems have surpassed 2048 CPUs. Increase MAX_NR_CPUS to 4096. Bitmaps declared with MAX_NR_CPUS bits will increase from 256B to 512B, cpus_runtime will increase from 81960B to 163880B, and max_entries will increase from 8192B to 16384B. Signed-off-by: Kyle Meyer Reviewed-by: Ian Rogers Reviewed-by: Leo Yan --- tools/lib/perf/include/internal/cpumap.h | 2 +- tools/perf/perf.h | 2 +- tools/perf/util/bpf_skel/kwork_top.bpf.c | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/incl= ude/internal/cpumap.h index 49649eb51ce4..3cf28522004e 100644 --- a/tools/lib/perf/include/internal/cpumap.h +++ b/tools/lib/perf/include/internal/cpumap.h @@ -22,7 +22,7 @@ DECLARE_RC_STRUCT(perf_cpu_map) { }; =20 #ifndef MAX_NR_CPUS -#define MAX_NR_CPUS 2048 +#define MAX_NR_CPUS 4096 #endif =20 struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus); diff --git a/tools/perf/perf.h b/tools/perf/perf.h index c004dd4e65a3..3cb40965549f 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -3,7 +3,7 @@ #define _PERF_PERF_H =20 #ifndef MAX_NR_CPUS -#define MAX_NR_CPUS 2048 +#define MAX_NR_CPUS 4096 #endif =20 enum perf_affinity { diff --git a/tools/perf/util/bpf_skel/kwork_top.bpf.c b/tools/perf/util/bpf= _skel/kwork_top.bpf.c index 594da91965a2..73e32e063030 100644 --- a/tools/perf/util/bpf_skel/kwork_top.bpf.c +++ b/tools/perf/util/bpf_skel/kwork_top.bpf.c @@ -18,7 +18,9 @@ enum kwork_class_type { }; =20 #define MAX_ENTRIES 102400 -#define MAX_NR_CPUS 2048 +#ifndef MAX_NR_CPUS +#define MAX_NR_CPUS 4096 +#endif #define PF_KTHREAD 0x00200000 #define MAX_COMMAND_LEN 16 =20 --=20 2.47.0.338.g60cca15819-goog From nobody Thu Dec 18 00:07:22 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7892194C7A for ; Fri, 6 Dec 2024 04:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460045; cv=none; b=F2JrA0o/mvdojQIdYJZA3bsjbQCruww+51394GCX9VTG9aLcfoN/TMHjRuTiT6Sa4vDylEy7lklELlRkcP19Tmv49Ra/AsclVSUfLE9pFJnSJMDxCUufm1cet6qHwEe8OqKe6la9+goOPeTHqSaPv1kUpgjti/ICsH2Zov5CcG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460045; c=relaxed/simple; bh=l8qUIHya3K31WTRvVu1jv39b7mumPyblakLVFf0XyaY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BqibnZ/16MqLhsXrLiVn3x6HBgOoMUphpZKYG5aREK6DniJvOeqceucJNCQsEeBS0Nnh7HnvcZSpybxuEIyWiRkcMJ3+sdFARXW1HQMsTBxHMa8wp8XQJNcquyGHJi2yQLa8ua/nm3qOylKZs1oM0cDui+ELijw9Brxn5uRyv6c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1MuVUJKi; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1MuVUJKi" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e30cf48435fso2517541276.0 for ; Thu, 05 Dec 2024 20:40:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733460043; x=1734064843; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=T/6KuZeoA9hfQ8w7qTpUnYSr+3QNWIClGfYo5QkRc1U=; b=1MuVUJKi5UrHeOEQC5WBonUv1rVreiVF+yrEXxIELhpNZHd91idgxwQPxOqD/yW+T4 J9JMHpQCR6ZLg69nAIGFDv3Ce9CgvIe2V6Sc6ROWYIUyubZsGmeQofSZRzHEl693VASq ZAn6s1t+WUFQ706KlB3D3EOBrndssbXUvEB5tj1ckm0XZ6GqBSIud7L3CuMNTJOIydii GbfxRMGxWiLXdgU+w6zDSKnF4x5Hb4rsUdJypPrbeX454GblunC8ygRudeLw8xnYLujp y960TV0aKEVm+4P5gNjNXCEzSIfo2s7LAHAT0L1YX2obptG7PydxJYENWG9SIxCcK89E wVyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733460043; x=1734064843; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T/6KuZeoA9hfQ8w7qTpUnYSr+3QNWIClGfYo5QkRc1U=; b=iHZD7F3Pi4IxupqcOOwGCVEIZPHATLbxkXDTGYZ2KMsFOQ9+kw9lRql940EdQBOB1S +rzxnx71qpV4nkNlm6LXI7O3z5rRVahZsoaF5571s5OzagKE60DRingVyqzMWEhLeGGv xHTuFfQGbatiKPG3Yr+muuTs9sWp8G7+Q3Y8pXk565uy07FpJxpAPoieQmDfU3PaD2TZ Plo3s0++5XiwTyJXys6xrWIx94+b6OZGrbf1uRlf1I8ot9eL93ZpkRujolplrNo0x7Pj k+rc5aRkR2SAiG4fFTrI/4bQkcJRMfonHcXbVMnyXeKULASCqgbM4OP1C5b/RVJ0dxSX WoYA== X-Forwarded-Encrypted: i=1; AJvYcCWk1vgkzM6iNgCcOKoS4jUwsReiM/34mhZfCvyv5QlPY8G8rQGPwx2gTV2a6gq4BedoZO7y29YS8BiAp9M=@vger.kernel.org X-Gm-Message-State: AOJu0YwGuVnDtslcNFxNjEYs6zxXeqta+k80gAEIyKX6yEfa/l+ebnTF d5W/0y3svfoOLqnIFfQCNx0xgSIqUgrXhq/w5JDXk6pbfTdlOhRJwxvg1ZfQB3ODNQ/pc6oKCF6 r2tGYig== X-Google-Smtp-Source: AGHT+IERX0y+SrjaaB6yLsinmWuyNnCNJB6CooagJGk19unTJTWsreDzrfz5zQi5ugSeemAO8BjhrdkKmd0f X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:eb75:393:2a8c:1440]) (user=irogers job=sendgmr) by 2002:a25:fc1c:0:b0:e33:111b:c6a4 with SMTP id 3f1490d57ef6-e3a0b073bbdmr734276.1.1733460042968; Thu, 05 Dec 2024 20:40:42 -0800 (PST) Date: Thu, 5 Dec 2024 20:40:29 -0800 In-Reply-To: <20241206044035.1062032-1-irogers@google.com> Message-Id: <20241206044035.1062032-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241206044035.1062032-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v1 2/8] perf cpumap: Reduce transitive dependencies on libperf MAX_NR_CPUS From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Kyle Meyer , Ben Gainey , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" libperf exposes MAX_NR_CPUS via tools/lib/perf/include/internal/cpumap.h which is internal. The preferred dependency should be the definition in tools/perf/perf.h. Add the includes of perf.h so that MAX_NR_CPUS can be hidden in libperf. Signed-off-by: Ian Rogers Reviewed-by: Leo Yan --- tools/perf/builtin-annotate.c | 1 + tools/perf/builtin-diff.c | 1 + tools/perf/builtin-kwork.c | 1 + tools/perf/builtin-mem.c | 1 + tools/perf/builtin-sched.c | 1 + tools/perf/util/kwork.h | 1 + tools/perf/util/session.c | 1 + tools/perf/util/svghelper.c | 1 + 8 files changed, 8 insertions(+) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index bb87e6e7687d..836ae0122dab 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -7,6 +7,7 @@ * a histogram of results, along various sorting keys. */ #include "builtin.h" +#include "perf.h" =20 #include "util/color.h" #include diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 82fb7773e03e..196969538e58 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -6,6 +6,7 @@ * DSOs and symbol information, sort them and produce a diff. */ #include "builtin.h" +#include "perf.h" =20 #include "util/debug.h" #include "util/event.h" diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 8234410cba4c..233ca3c3895c 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -6,6 +6,7 @@ */ =20 #include "builtin.h" +#include "perf.h" =20 #include "util/data.h" #include "util/evlist.h" diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index 651188c1d825..99d5e1491a28 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -4,6 +4,7 @@ #include #include #include "builtin.h" +#include "perf.h" =20 #include #include "util/auxtrace.h" diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 7049c60ebf77..26ece6e9bfd1 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "builtin.h" +#include "perf.h" #include "perf-sys.h" =20 #include "util/cpumap.h" diff --git a/tools/perf/util/kwork.h b/tools/perf/util/kwork.h index 76fe2a821bcf..596595946a06 100644 --- a/tools/perf/util/kwork.h +++ b/tools/perf/util/kwork.h @@ -1,6 +1,7 @@ #ifndef PERF_UTIL_KWORK_H #define PERF_UTIL_KWORK_H =20 +#include "perf.h" #include "util/tool.h" #include "util/time-utils.h" =20 diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 507e6cba9545..c06e3020a976 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -37,6 +37,7 @@ #include "arch/common.h" #include "units.h" #include "annotate.h" +#include "perf.h" #include =20 static int perf_session__deliver_event(struct perf_session *session, diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index 2b04f47f4db0..b1d259f590e9 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -21,6 +21,7 @@ #include =20 #include "env.h" +#include "perf.h" #include "svghelper.h" =20 static u64 first_time, last_time; --=20 2.47.0.338.g60cca15819-goog From nobody Thu Dec 18 00:07:22 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54D021CCEE2 for ; Fri, 6 Dec 2024 04:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460047; cv=none; b=In/3nve9jZ309kktcxrhJd3iQ5DvxVBrOkuNTMGch6obSyyfybjFx1UQuDJKZpFLuy9UhNaC04KeRie4gvmWc38REWXy52g4qluBDLKRK/GHuGtyTD9+4v5R+qqxvFBFzPjL0MfuAWFVBYpkpPwtwDATXGT3aEmxdmrD9RlVZLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460047; c=relaxed/simple; bh=sNrG9Ry1Ixsz3Iw2Cir6bSd/AcmJIt/1w3p+Zn0bR2k=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Gusno5h3r506EO78AZXvvvi6ymZ7nw40YHAJIfskvqj0pgjd2Zgu1VpzQH2u169OQSx0AxxxggJA4CONyw66VFH4/X/sCbw2kTluI5STX4eYmWcRM0paMv4C99EDIHDlLksY0/XRV+M4WfbiAKDkDw9lLXVmY2Sn8Dub2CVrn0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aEGG85QZ; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aEGG85QZ" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ef66fd6e78so18227267b3.0 for ; Thu, 05 Dec 2024 20:40:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733460045; x=1734064845; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Zxiu9g2tnYAaehM/09JR47eYFX/Tpdp15RNfcOT5D1I=; b=aEGG85QZnkte0ReldoZqNQ5FkEHDuZDWuhaLPJIX5af3UFwDQJUKiOJ6olL9xAWGrT JWyRQCwmciPwz0xbNXTsqfe1MZ6sorSJDOf1kjvxfjC0kYZOKHiZ9xI/dm4VGAgoxAOQ f7Xc9nEjPw3jaRykEEqc/NHEV6gxozcobxqWx8mIGwtA9NoDaJzio0SUK0HhKoFAw15E qTrxUfqwDmP3aACBqMBJiqMqUbmsNGmzGanrdLPRjPjxDO/BTHxvGibCi2v+Fxch86DA AJjNHLEWtMfVveZ4eNMS3A/EQUj9ndBm2SwXO/IK3i87uyVV9+8dDxO19OZvnn71TdSE +kTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733460045; x=1734064845; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Zxiu9g2tnYAaehM/09JR47eYFX/Tpdp15RNfcOT5D1I=; b=C8eRthXnT3yqFV60a5FfpdZTHhgpPUjgUU6tg6Enu6AHbJE3eN/up7TOvNMO/4FapD 0a9dPn3V0muviiYYcTmmEWlX2XWnk28/EmHzDE1P8iJV3TTZy4nTErGJUpbEtcKvM1V2 yBY2qH0/orbQyfFrrZON2sSxdMeHIUubRwV6yXd6CAVIuxqyA9TxgB33dGub1fx4ES+e fzxhGqjM7BUO/8CCUSA57VSSYmnxanYCeWZ8I+t4EIDB5rzgmv8fqkoNvJ2oURZKd9NN IvfNmSJHIwG7zRaV9+Y+Px7APneXMyAouSMbATxXRZXzFJt9kRQcD3qfYrJf+J666gZf /H1g== X-Forwarded-Encrypted: i=1; AJvYcCV/YVd2qPrNjKkPYJ0S3GD0TUSdqxuXdorVccWzgfST7Xz/jObtCDgRmk4rNrw61Dni6TlORCM8SHM4F5c=@vger.kernel.org X-Gm-Message-State: AOJu0YzobWae3rCbNyx0jJZvtXuydAFdXbsiOBJwLdCXFlo6ya0diVzB khwugjEBDmtFFxL1nr4AYdgb7mGGUVWxoq/bP8K8gHpT/n2tFUJDymf2+0zMBIyDFipyt2QVx34 GroSnCQ== X-Google-Smtp-Source: AGHT+IHoyqw3/FLlGrXxAG+PamnShXsumtQls5He4Er5Rpy3RIlaO66WUpmsOzXBH4IQRbPpNZn7bhv41hiA X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:eb75:393:2a8c:1440]) (user=irogers job=sendgmr) by 2002:a05:690c:700b:b0:6d3:e7e6:8460 with SMTP id 00721157ae682-6efe38de0f3mr210687b3.1.1733460045224; Thu, 05 Dec 2024 20:40:45 -0800 (PST) Date: Thu, 5 Dec 2024 20:40:30 -0800 In-Reply-To: <20241206044035.1062032-1-irogers@google.com> Message-Id: <20241206044035.1062032-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241206044035.1062032-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v1 3/8] libperf cpumap: Hide/reduce scope of MAX_NR_CPUS From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Kyle Meyer , Ben Gainey , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid redefinition of MAX_NR_CPUS as a global constant, the original definition is tools/perf/perf.h. Signed-off-by: Ian Rogers Reviewed-by: Leo Yan --- tools/lib/perf/cpumap.c | 2 ++ tools/lib/perf/include/internal/cpumap.h | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index cae799ad44e1..3ea06865d4b0 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -11,6 +11,8 @@ #include #include "internal.h" =20 +#define MAX_NR_CPUS 4096 + void perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus) { RC_CHK_ACCESS(map)->nr =3D nr_cpus; diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/incl= ude/internal/cpumap.h index 3cf28522004e..e2be2d17c32b 100644 --- a/tools/lib/perf/include/internal/cpumap.h +++ b/tools/lib/perf/include/internal/cpumap.h @@ -21,10 +21,6 @@ DECLARE_RC_STRUCT(perf_cpu_map) { struct perf_cpu map[]; }; =20 -#ifndef MAX_NR_CPUS -#define MAX_NR_CPUS 4096 -#endif - struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus); int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu= ); bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct pe= rf_cpu_map *b); --=20 2.47.0.338.g60cca15819-goog From nobody Thu Dec 18 00:07:22 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 902FB1D5172 for ; Fri, 6 Dec 2024 04:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460050; cv=none; b=XrTSc3ZI1KZFHvYaBDjJWTfvpFgXIS+S/4SwaTL0bvhpFgzsng1zQPrngG12l2FZZUBD4XqAvl5OUTUNrBVutAb/Q1tBdDeq9hWl7ykCnpy0YhMVxZ34T3KJFMN6J1rRe0eDYxTgAoBU/C5BIM3OUEq/FwbwKhJycEsu8wBG2co= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460050; c=relaxed/simple; bh=sy3VlSAHvcJviVgcFZMJmc7WftJUr4tw3K+lsQD12d0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=OsPY2GLRTRGcfkZH3ZQqVCpfZHwpnmOeBpzZwgglJ1dbp3ebGPQ7Xuqiv31MOgnD9DHUavXQpY2XxAbEKT5hO491mVfG6++ywdIQ7pSnjdTw4RBIi+S9f3SYu4efMvzUPfyXo2vyHT4ZNQSYtygDMsKbkMEgFVnoVSKdYXgmTUQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=3fFqmvrw; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3fFqmvrw" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e38d8aaeb4aso2750295276.1 for ; Thu, 05 Dec 2024 20:40:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733460047; x=1734064847; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=9TRhSW9l3K7YWslNZkoYOdpdUsj4ahnHxjZdZRRIcDQ=; b=3fFqmvrwIGiqy9GF1+OOOU9cW46/4/c2gQuloJRjqkfKedsYnPKoyOFK3NcgVFz19s atHTan8zq30epiOa6Bl6Awf04/U8wEG6tputXb7kTs2byk5IjlcrMVyj8F9BdxVuqLbr Rgjo00hwmaoMEvnS58rtCBFTUcAkuru6ARbP9Cv+7iAxF91lIdHJLOqjwI9i0R5JlMkt DiaQWZaInzcV8yTEsTMZJYcw75YX2ADdVtXeE5v/9Ib6gkACqqbNQxhfgidWffZSuKkG 0rud4wZdGCVjwNU7Xj0B8Rr7bea85dyNVVJ39y+eVD2CFxQfy7kS+Tae4kcKgrv01H9i 7cTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733460047; x=1734064847; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9TRhSW9l3K7YWslNZkoYOdpdUsj4ahnHxjZdZRRIcDQ=; b=pFT6D8GGk/1xqMzpasAFDYVkT5Z8EGg8YzrLVuzKOLAlGVwzChKVFj9q1WkRpRaUIP h8AI1jPTYUGECw22FHosxCPeBGtLS6Rargx5GGHJIh2nE7cIhH67pX0dI3ELAJl5OvlL UQxYlkCXxBAhmqp849w8Z3XJdyTz0LhJlgEHxhvtwRDEDjUvzzsfkVnIcJEgyT1e36hd VYQBX7oZmOCBpl6MKp60mGSHA386aBBgJM5bPAy2ai6lDQV8v/+gIO4jmrTBEC2ZxiRE GhDgPwbM8w4EboW/PMxD93Ow8iB7768AeYBz9wu7AmihqTA7P8rm/bRnLLzsuYOGQ0vm AygQ== X-Forwarded-Encrypted: i=1; AJvYcCV48aXz66tYPAGWq7GtZhmBuNCs3BBJ9SBxh3uYkq6A3hz//ttU3EuByY8GJFrEgaYnprNe9/GjNtJxn8M=@vger.kernel.org X-Gm-Message-State: AOJu0YxCxqhqfW6aEW+LXSzsdbh21FNcgtgWZnK5g1Q5GudYOduY3KTF 7rHQfWObYZ5sJC60IPcpRQIYhPcLsdqXn52TN+Fl3qLsItlr7AYppHZSUMTmXQmtpFPkk2AylxE 3pDTi8w== X-Google-Smtp-Source: AGHT+IFE2LwLNaSTO62nxIL6A+u7AnZGRX7WeJwZhuOzG3htBmKYKjKvD2BCbNixg616M4EERkMINqDwdmlK X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:eb75:393:2a8c:1440]) (user=irogers job=sendgmr) by 2002:a25:c5d4:0:b0:e39:8087:42aa with SMTP id 3f1490d57ef6-e3a0b07a87emr817276.1.1733460047449; Thu, 05 Dec 2024 20:40:47 -0800 (PST) Date: Thu, 5 Dec 2024 20:40:31 -0800 In-Reply-To: <20241206044035.1062032-1-irogers@google.com> Message-Id: <20241206044035.1062032-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241206044035.1062032-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v1 4/8] libperf cpumap: Be tolerant of newline at the end of a cpumask From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Kyle Meyer , Ben Gainey , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" File cpumasks often have a newline that shouldn't trigger the invalid parsing case in perf_cpu_map__new. Signed-off-by: Ian Rogers Reviewed-by: Leo Yan --- tools/lib/perf/cpumap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 3ea06865d4b0..20d9ee9308c6 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -240,7 +240,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_= list) p =3D NULL; start_cpu =3D strtoul(cpu_list, &p, 0); if (start_cpu >=3D INT_MAX - || (*p !=3D '\0' && *p !=3D ',' && *p !=3D '-')) + || (*p !=3D '\0' && *p !=3D ',' && *p !=3D '-' && *p !=3D '\n')) goto invalid; =20 if (*p =3D=3D '-') { @@ -248,7 +248,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_= list) p =3D NULL; end_cpu =3D strtoul(cpu_list, &p, 0); =20 - if (end_cpu >=3D INT_MAX || (*p !=3D '\0' && *p !=3D ',')) + if (end_cpu >=3D INT_MAX || (*p !=3D '\0' && *p !=3D ',' && *p !=3D '\n= ')) goto invalid; =20 if (end_cpu < start_cpu) --=20 2.47.0.338.g60cca15819-goog From nobody Thu Dec 18 00:07:22 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3AA51D63D7 for ; Fri, 6 Dec 2024 04:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460052; cv=none; b=ceehHBQdi27JnfunF8a3cBptBiL1esWYogNsUPEv016NF5NPfzZY+EvllNgb0Y++5mHte+ATGFflQu1e83dYKziGh+aiqzNM2Ywqe4oPKkA7tCmmZ0zhBHadbg3XE1KqblQyJzB2IFC3fIYR+neriXStz9WLAnxLz40cP1TQR9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460052; c=relaxed/simple; bh=tL5UcvcaUuHSFNHf+2eJphHFXMLILMHZEi5NFaOiUOk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=WdIWjqn2TdyS2rN/IXnrW00cQq2FyPtiBVIjRbyhJ6kZWWC6ucYx2ymV0QWCcWGj418Uq+CWoNiwWMHlA6hL0c3k0EeXYBU+GhYW8pMjbSHzeBNWQzUqodedx0VRtnP9eG8s1nioNkiPZguh/yJswrwp6ekYj7wYj8XO/Rlc3wE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RqV5UwmR; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RqV5UwmR" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ef6e33c182so16792937b3.2 for ; Thu, 05 Dec 2024 20:40:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733460050; x=1734064850; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=hxKOwJDxb0nbB94Cpeqs1MqiCtTfBA0AAYbHAMWSNGo=; b=RqV5UwmRQyRrrvxjZCab6+A9fzd/cWzjS65qnhe24N7iR3AZDihfOcdA+gv/IuI0Ju OaLErCYYVdVDVoCPoEfcWWQnb0LtGpz6bj/Jt3DDlB+lEWyNsum3vqrDlOle1faZtJPm O2DTd3+5dlxBKa4ucZzZ8YLFp+Cq9sEMjkImkqefcD9fssOBAAWKoIS++NVvpfHCKrhY TZ0f8wDvJHtZKGHU7J9uQigWNX8ArxJLUva2daHQV+TCsdp2WbEPQcycafMIux+lhGx+ pBku6+m0PjECwDz18qpSYHIVfYuOpZYqsu4ZF4WhZdPTZrbv/KUu913D4oyiox3Ooucl /R1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733460050; x=1734064850; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hxKOwJDxb0nbB94Cpeqs1MqiCtTfBA0AAYbHAMWSNGo=; b=Vp9/pvlRJt60fwJopfovgu5+2jIBvfgy5ku2uTOrgGjgZLZ0klfF5Tw5pgmH7UpQbj XdlgUuNmUMa6Gt/FQRhSSJRXqKyoSGSFcw9K1Z9cu2DeJENNcbaI6Vl5bomyp6P2ktzr T51UuuYCL0MVOOrXplKGZ7mJpxA0TTsjTUafCDKV/pHE5ysrS+/Oix+2cUaPn978+iOd NIMKF0SV8zhPBc5bDKoHNnYFzfW1/KDkh2KicBA0ALr2BbDQ4xgzlrKkHvyMy/7oUPBc ZxzfEMtDYrQlrBCcYn1iaJD+H3QGj5x5usMEpuEIbzD7tEUUnRhDbXBiSW1gkIJKMgBX ym2A== X-Forwarded-Encrypted: i=1; AJvYcCXKgbel1Dw0w+sK74HzZTTnaDkh7c0/MtpqlExZA5zGIOIdcLT0Xf8TvKbFkUFbr8nj9/s/IS0ZVJeqUDk=@vger.kernel.org X-Gm-Message-State: AOJu0YxI8IrSMUSMhVNucxYdKsMEruTpe1kgy1t8PZSCMX/50KGO5oxM Jz3cEDamp/veWPNdY5AXpg335bi+Arpv6PmqYjorIXqX7KqE+SRhPJ13bD8Bw8W4CqoacgKYm33 rjexqNg== X-Google-Smtp-Source: AGHT+IEITj0IZXGOHRW2OjbGAsUtPzL7lWINzqsu/4f+Dqz6jJr8cNOz1t9vJB6+EjMUbfKp4lW+UCKDWNZf X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:eb75:393:2a8c:1440]) (user=irogers job=sendgmr) by 2002:a05:690c:4782:b0:6ef:5e7a:aa72 with SMTP id 00721157ae682-6efe3cb751bmr8277b3.8.1733460049675; Thu, 05 Dec 2024 20:40:49 -0800 (PST) Date: Thu, 5 Dec 2024 20:40:32 -0800 In-Reply-To: <20241206044035.1062032-1-irogers@google.com> Message-Id: <20241206044035.1062032-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241206044035.1062032-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v1 5/8] perf pmu: Remove use of perf_cpu_map__read From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Kyle Meyer , Ben Gainey , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove use of a FILE and switch to reading a string that is then passed to perf_cpu_map__new. Being able to remove perf_cpu_map__read avoids duplicated parsing logic. Signed-off-by: Ian Rogers Reviewed-by: Leo Yan --- tools/perf/util/pmu.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 08a9d0bd9301..891c905d08a1 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -748,26 +749,35 @@ static int pmu_alias_terms(struct perf_pmu_alias *ali= as, int err_loc, struct lis * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/ar= m64) * may have a "cpus" file. */ -static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name, bool = is_core) +static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *pmu_name, b= ool is_core) { - struct perf_cpu_map *cpus; const char *templates[] =3D { "cpumask", "cpus", NULL }; const char **template; - char pmu_name[PATH_MAX]; - struct perf_pmu pmu =3D {.name =3D pmu_name}; - FILE *file; =20 - strlcpy(pmu_name, name, sizeof(pmu_name)); for (template =3D templates; *template; template++) { - file =3D perf_pmu__open_file_at(&pmu, dirfd, *template); - if (!file) + struct io io; + char buf[128]; + char *cpumask =3D NULL; + size_t cpumask_len; + ssize_t ret; + struct perf_cpu_map *cpus; + + io.fd =3D perf_pmu__pathname_fd(dirfd, pmu_name, *template, O_RDONLY); + if (io.fd < 0) continue; - cpus =3D perf_cpu_map__read(file); - fclose(file); + + io__init(&io, io.fd, buf, sizeof(buf)); + ret =3D io__getline(&io, &cpumask, &cpumask_len); + close(io.fd); + if (ret < 0) + continue; + + cpus =3D perf_cpu_map__new(cpumask); + free(cpumask); if (cpus) return cpus; } --=20 2.47.0.338.g60cca15819-goog From nobody Thu Dec 18 00:07:22 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D81A1D90D7 for ; Fri, 6 Dec 2024 04:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460054; cv=none; b=qs/eUzvUrW6N93YsALetdBFPk+m8JlCtxk72/iOl4uvtX+hCXdIqHJd9RZZ2oDNpG300c7nC/2OkkTxYtx9t8rDIXefNhKCfglF1v5x3TApuscgi+Bi/QJJzbVB9803JTxMLAVynR90Vgrk5lHBOu9lHyhRN6v9CwkL2GhWtSpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460054; c=relaxed/simple; bh=zAYbTToy7miM8tLMLMB1fAi9ERVwZv7WSJg6LoWxSwo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ZzxvLdo9pt6blaovB4Fp49Rcpp6mFxtkdqSrdS7kzHwIQvLgKnjfWEO2SndfRr0wJQAigu/uxXq3/vzqcrM8/0OGKhPgecVaux87TB9zGEF4f8ZRLgr6GV3JmskJZLEgdDvnpq5Z+osonH+l1scSnhDmlRbN1ofJuP50W2U65t0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0xFSBuAS; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0xFSBuAS" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6efe45a2405so5984337b3.0 for ; Thu, 05 Dec 2024 20:40:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733460052; x=1734064852; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=jXXuS2o2j6xQTgeWYL+xQ1vIazksKTne/XbLVeScbI4=; b=0xFSBuAS59PoKkpftK1g3OnJdqM96MzP5i8UliVFoD/9WRAZFfTz2YJySTFKJgbfEZ w4E7pyWkF/sASTH1htbGOjXm7HlH353NgavyTfKoKQMszdi/JDg04Z4obSVugkTNw5RL 0b6F4P5iJfN4gttFcyz6JfD5QdjUzddPWqyyQE5MZDAXerS0ABi0YvsRwRfUOXfetlTg 3OFCDcP9A0aVnRVOvsZQ27HfdtjHbDOiB0m3XqmvpoTnOdtQq6pSq2kTqAIdJk0KE/gu IKJtJXQRG1KNNIn4hblkVhmwXSgnMe5ln73BFE+D81tsaJ52zEAGA2B/5W4htMymil7x oV9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733460052; x=1734064852; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jXXuS2o2j6xQTgeWYL+xQ1vIazksKTne/XbLVeScbI4=; b=iU19QECT0DNI0WNNfmKK1qCdvieF4+1dNUtU7QKVhidBBoTohzd+iP9RfiktjsDTCA 4GOF7a9mYg5indlSMFN1+a4MVpfeVtbDR/R2Om+o2WIndE4GCa2YB+QE9U0O+i61VjoH 6P7gUDttkeXzW/mwBYjd9jryjitUnvQuf6Z7yzxruXeHnbXsnCAG0tDffl9PnuwNPI9P cfMCKg1EDN+C0OaQtP6FucAfOBbELVMhorITc6nUBerqSevhl0piisWMU8k9OoCY8Tub Ug3YiclyMIMyp0SYO2siiEPZriajoNG6g7L1Gvn4nbxV4NQTF2uidBlLPDK5JTjZDk2g OoQg== X-Forwarded-Encrypted: i=1; AJvYcCVrJra+Mm+VDKe6KkzyCFjyie+NxL0kSZSRzuGMNTk4P+QvXRI1KhAVOo13Uy8n+rMXKJF/z8aBk273bUc=@vger.kernel.org X-Gm-Message-State: AOJu0YyYfAquLJI3aESMoTceOraeaPjHVmNtG5ryQUfo4Xr7wH6AgGXW w0c1vZq/m5jG4y8FaJtxghIunL3A1c3xyHXfJtOWyyF9+hN+acF6H+TieDtpKVuidryQJkvxb71 bC57Qsg== X-Google-Smtp-Source: AGHT+IH6pJSsb1JmXS5B9BULKcXqWLb4MGTO9GRL3/aT9G9AWPq77Czm66g8jckJzv8epZvzw9L7H8e/LggM X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:eb75:393:2a8c:1440]) (user=irogers job=sendgmr) by 2002:a05:690c:2a88:b0:6ef:7a23:afbd with SMTP id 00721157ae682-6efe3c83279mr17827b3.8.1733460051702; Thu, 05 Dec 2024 20:40:51 -0800 (PST) Date: Thu, 5 Dec 2024 20:40:33 -0800 In-Reply-To: <20241206044035.1062032-1-irogers@google.com> Message-Id: <20241206044035.1062032-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241206044035.1062032-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v1 6/8] libperf cpumap: Remove use of perf_cpu_map__read From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Kyle Meyer , Ben Gainey , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove use of a FILE and switch to reading a string that is then passed to perf_cpu_map__new. Being able to remove perf_cpu_map__read avoids duplicated parsing logic. Signed-off-by: Ian Rogers Reviewed-by: Leo Yan --- tools/lib/perf/cpumap.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 20d9ee9308c6..60ef8eea42ee 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -10,6 +10,7 @@ #include #include #include "internal.h" +#include =20 #define MAX_NR_CPUS 4096 =20 @@ -102,12 +103,12 @@ static struct perf_cpu_map *cpu_map__new_sysconf(void) static struct perf_cpu_map *cpu_map__new_sysfs_online(void) { struct perf_cpu_map *cpus =3D NULL; - FILE *onlnf; + char *buf =3D NULL; + size_t buf_len; =20 - onlnf =3D fopen("/sys/devices/system/cpu/online", "r"); - if (onlnf) { - cpus =3D perf_cpu_map__read(onlnf); - fclose(onlnf); + if (sysfs__read_str("devices/system/cpu/online", &buf, &buf_len) >=3D 0) { + cpus =3D perf_cpu_map__new(buf); + free(buf); } return cpus; } --=20 2.47.0.338.g60cca15819-goog From nobody Thu Dec 18 00:07:22 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1373D1DA31D for ; Fri, 6 Dec 2024 04:40:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460056; cv=none; b=tTuKX5DQobk32cJpU4sGVq7cSRdYwH+0ePrWNOHBJkDexslrfYcMvQ+l819tnNU8rAmFl1QO81e5uWTlb5R9gKUiiAZwX92E64Ay7cVm6+rj/SiJAby8vdt3RAzW/G3l9P/VTwIFlr/eh7qvoQ54c0pdkppMptBWoz4FUguBpak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460056; c=relaxed/simple; bh=6qQMnPoV7toq2InjiyqPN49G1JW//BJ3BW+cL78lXpk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=WOhAosyk6iBNYtOOUP2BP5rvXjY21Aryzs+uZWorGrv0s5Yu8jUlEioIexq9GIybhEnpI0w82pYKZaqHVNiJ97o3ETVpeYz8BhJn8FVzNDtdCJlqFikb8+Uff/HmUIFazP9vob3sy+xgstn7Kimc8AIY7cAQoCLkxEuSgmkgZyc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=P6bQjJlF; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="P6bQjJlF" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e39735ccf1aso2883019276.2 for ; Thu, 05 Dec 2024 20:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733460054; x=1734064854; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=4PLDQ9cMJwyt8LLu+m8FYi+OjRqKatCbRkdPuiWR/4w=; b=P6bQjJlFbhFZWfQ6XenH1y8deOqZ2RSENJxQ1iYR2F8EA1CEUTaFkyLEft0tg6Akaw z14LqzAS25OpLqLjSiw2TsqQJ8dztwjI+qL5e+Yd6jniCH1x6aIgCzDCsWMJFg12wkGs GDRh9EoRqFiQmN9isPdFZVCEC6c2jY0Owo5g91Cobxfa4UMwFsWHQut4s0KwOuZZGdjp g6MBDxR6sRrlltcbkkb/xmteZt9sJcsEcgDyDhaKNsu3mLSBd3EDWrUg73UAhE8akUqN kxZx9cNzqWxnjkZJDNcl8zCRgJMeLoiTY35yDayXlZG8vNzPTqEQWCB6PaertIMVKTII amKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733460054; x=1734064854; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4PLDQ9cMJwyt8LLu+m8FYi+OjRqKatCbRkdPuiWR/4w=; b=VABODHKslhrXiieXPZs+MS9bjZ55XqrtrHdN6Ao2EbvwvI3R4/h9YOfvIcvifRVsuC teGRWvvrYIHj/ALSHtTy18YbcvPyL8oj3O7Q6oiFCc+p+2OhCHylzq6Z1T9XBEsKhZ3X Pv4ZZHcHl6biY8OOY2pffwMWmi6KosHu+JLC1tNWRFJ5qJ8zMMkO1PaRpzoZPB5rYMa6 q0YIIYToQpQzu1S8j93Q2OdqRlO2g26xxp4jxENATZfLTrYIpFYXsrqS8XJPXjVXOxBh HJEvRWVzPEB1yGvZFah9rqPEZ5y2aye63je5Yw1kqu8RdgTYAyq4DinytK4X7pP+dsT3 XbvA== X-Forwarded-Encrypted: i=1; AJvYcCXRsa7lSdhBgXKY3e2PgGnBOOS9zRg82qe2xB2usGhFf2diccv2ays2Ipq3VyhdASSk4/tzrvn2brvCAkg=@vger.kernel.org X-Gm-Message-State: AOJu0YyralJvvTFzBHKH2b1Mtq2IqwHVoKKHA/MxEyKC+AUDi2uqhZXV h4gzdlIQF8a4am0F9R9ajsXIUgHS6cxCCGikbZMFt1958Ct0fFbeTWbW7pxB9/c7BYitLQe/cPt cDv2pjQ== X-Google-Smtp-Source: AGHT+IGLwIotlj7ZIG269cEmwqa4ILVBPe9NX3i6hHv+wncSepxMVPXgIEEsA2H9UUJWcX9Ob7d2QOTkOVMz X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:eb75:393:2a8c:1440]) (user=irogers job=sendgmr) by 2002:a25:d352:0:b0:e39:3168:53be with SMTP id 3f1490d57ef6-e3a0b4a2261mr1162276.9.1733460053972; Thu, 05 Dec 2024 20:40:53 -0800 (PST) Date: Thu, 5 Dec 2024 20:40:34 -0800 In-Reply-To: <20241206044035.1062032-1-irogers@google.com> Message-Id: <20241206044035.1062032-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241206044035.1062032-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v1 7/8] libperf cpumap: Remove perf_cpu_map__read From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Kyle Meyer , Ben Gainey , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Function is no longer used and duplicates the parsing logic from perf_cpu_map__new. Remove to allow simplification. Signed-off-by: Ian Rogers Reviewed-by: Leo Yan --- tools/lib/perf/Documentation/libperf.txt | 1 - tools/lib/perf/cpumap.c | 56 ------------------------ tools/lib/perf/include/perf/cpumap.h | 2 - tools/lib/perf/libperf.map | 1 - 4 files changed, 60 deletions(-) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Docu= mentation/libperf.txt index fcfb9499ef9c..59aabdd3cabf 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -39,7 +39,6 @@ SYNOPSIS =20 struct perf_cpu_map *perf_cpu_map__new_any_cpu(void); struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); - struct perf_cpu_map *perf_cpu_map__read(FILE *file); struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, struct perf_cpu_map *other); diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 60ef8eea42ee..17413d3a2221 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -161,62 +161,6 @@ static struct perf_cpu_map *cpu_map__trim_new(int nr_c= pus, const struct perf_cpu return cpus; } =20 -struct perf_cpu_map *perf_cpu_map__read(FILE *file) -{ - struct perf_cpu_map *cpus =3D NULL; - int nr_cpus =3D 0; - struct perf_cpu *tmp_cpus =3D NULL, *tmp; - int max_entries =3D 0; - int n, cpu, prev; - char sep; - - sep =3D 0; - prev =3D -1; - for (;;) { - n =3D fscanf(file, "%u%c", &cpu, &sep); - if (n <=3D 0) - break; - if (prev >=3D 0) { - int new_max =3D nr_cpus + cpu - prev - 1; - - WARN_ONCE(new_max >=3D MAX_NR_CPUS, "Perf can support %d CPUs. " - "Consider raising MAX_NR_CPUS\n", MAX_NR_CPUS); - - if (new_max >=3D max_entries) { - max_entries =3D new_max + MAX_NR_CPUS / 2; - tmp =3D realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu)); - if (tmp =3D=3D NULL) - goto out_free_tmp; - tmp_cpus =3D tmp; - } - - while (++prev < cpu) - tmp_cpus[nr_cpus++].cpu =3D prev; - } - if (nr_cpus =3D=3D max_entries) { - max_entries +=3D MAX_NR_CPUS; - tmp =3D realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu)); - if (tmp =3D=3D NULL) - goto out_free_tmp; - tmp_cpus =3D tmp; - } - - tmp_cpus[nr_cpus++].cpu =3D cpu; - if (n =3D=3D 2 && sep =3D=3D '-') - prev =3D cpu; - else - prev =3D -1; - if (n =3D=3D 1 || sep =3D=3D '\n') - break; - } - - if (nr_cpus > 0) - cpus =3D cpu_map__trim_new(nr_cpus, tmp_cpus); -out_free_tmp: - free(tmp_cpus); - return cpus; -} - struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) { struct perf_cpu_map *cpus =3D NULL; diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/= perf/cpumap.h index 90457d17fb2f..cbb65e55fc67 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -3,7 +3,6 @@ #define __LIBPERF_CPUMAP_H =20 #include -#include #include =20 /** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map'= s indices. */ @@ -37,7 +36,6 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__new_online= _cpus(void); * perf_cpu_map__new_online_cpus is returned. */ LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); -LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file); LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *ma= p); LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *= orig, struct perf_cpu_map *other); diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 2aa79b696032..fdd8304fe9d0 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -6,7 +6,6 @@ LIBPERF_0.0.1 { perf_cpu_map__get; perf_cpu_map__put; perf_cpu_map__new; - perf_cpu_map__read; perf_cpu_map__nr; perf_cpu_map__cpu; perf_cpu_map__has_any_cpu_or_is_empty; --=20 2.47.0.338.g60cca15819-goog From nobody Thu Dec 18 00:07:22 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2EC01DC05F for ; Fri, 6 Dec 2024 04:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460058; cv=none; b=kaYnLr46N0VdqXApj8uv0RF0voXbMOxWWq8lS6MuH3kZZkos7Wa4hXrMOtsp/iQ6a09xtDFrD5G0RsDCVXooNX6gN1e88g+1cRDdJVsYpZaYYltidd1A7WxX8MTqc56OUmGYalRgNjrbmaNQPulQgTyf2B7YZ+YiMZa5mHVCvyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733460058; c=relaxed/simple; bh=hQiLh7sZsGgCUtv2UvPu2RN6VeSmcwXkb3yt5YfihOU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=LRZQYG6Y5ExvXWcT+N+eilosla0ZWqsFH9F67nQAPRlM+W7bDXenZx1gGTqZ1b82OxaaNpK6/6V+Z8LLspadYvM6qszQAh4WpgbfGpipfAUsUCA9FVWh2FuW9REnpksI5CoReUsg/8BK1qaxIYeM7PFUPNNcJN0WQZ72CXLPQ5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ROMvm6rU; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ROMvm6rU" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ef55d44f73so12161667b3.3 for ; Thu, 05 Dec 2024 20:40:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733460056; x=1734064856; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=K8aGNRfDoJ3pTcSjnS5URRoovO9dVtKuYf6NSgPnrbk=; b=ROMvm6rUdD9dsWLRuB3lfH4USFakpAbru4HDP7Y6Wgf2lH9DBrDsXaTZDuVbpcnGvS JPO/c8GSxjBZmxcMWzLjoFJrz5UdseC9WP6bnyQCa2WQcAc33QQ6/xQSb6oq9Lcgt1Em aVU7PTiaHRJG+xf1hxt+Lc0CpKSvXu/r9vdgef1/UaLD90yMQB7Pt6WFfDhqBMkLbT3H nN07dJN0NDBv487E/FsueRpYM/YWRqkXnnSR9DneLVCXKKO6xvEBYrwoN1nMxlz7ggHU 5P5kA7oXj3uIPBxf7ndfxE7SbdN3hfAngtkRSfqRuaKhyVa1RrMQrG8k6JdChituyiEk JW2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733460056; x=1734064856; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K8aGNRfDoJ3pTcSjnS5URRoovO9dVtKuYf6NSgPnrbk=; b=YM5OLPrsHhZbdSIqHvYC9DIX17TY986VrNagTBdazfPpzD7k6aVkkzxikPmMqfmf0s zA6PsKHXd1wM2wcHee8FMdkFeTAF6UcGyXC0NmpNB2KRR2XfPm0EciTOeXdPr48TTZWZ 3EiCUUr5GvevGsRBToi2RqEgER0NpY2kjcQwY2JEQk4oM7aigLOnH4/AVi/o9QkniFq/ 5wp/lWfLoSmVByrcYN3hkPXTX6Df7QG81Qv3NmIrEfBu/3cBrwjN2oQ4CNGskXzNUUOX Q9a6evM13cQ+XNZ87guz5UeWz6e0nNefsUGn1Jt5oUyNvI6S/6ZOZoF5Op5m1y4ie7i2 jEjQ== X-Forwarded-Encrypted: i=1; AJvYcCUIJtLAZzaGgaKD5mxoh5X/j7+T+ZbWUc1enthNfCO3bWw7SKIA7NsOn5FW1bXqAtCr61k1lN5eI60BaKA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2ta9Z7Nw3coSeEN/ZA+8mTFEvW/jCkVIxkkbMNYuF885LsYLE t7xueS1mimdVrLn6HdpxGGq/XFph7gpaa7si6Sum5Qi80f8Ef+lX9f7iw1gUbOfAyKU4xX5gt53 RQ718WA== X-Google-Smtp-Source: AGHT+IHJTt6SspkYnMxQ2Ijr/i1yhHjbdWhgk+WnF1TdoCAiqORktrvqvdoCtq+W9OWyaq0CG9W7W6zO7Ul9 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:eb75:393:2a8c:1440]) (user=irogers job=sendgmr) by 2002:a05:690c:7007:b0:6eb:ac7:b1ef with SMTP id 00721157ae682-6efe3bf2e89mr384737b3.1.1733460056007; Thu, 05 Dec 2024 20:40:56 -0800 (PST) Date: Thu, 5 Dec 2024 20:40:35 -0800 In-Reply-To: <20241206044035.1062032-1-irogers@google.com> Message-Id: <20241206044035.1062032-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241206044035.1062032-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v1 8/8] libperf cpumap: Grow array of read CPUs in smaller increments From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Kyle Meyer , Ben Gainey , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of growing the array by 2048, grow by the larger of the current range or 16. As ranges are typical for things like the online CPUs this will mean a single allocation happens. While uncore CPU maps will grow 16 at a time which is a value that is generous except say on large servers. Signed-off-by: Ian Rogers Reviewed-by: Leo Yan --- tools/lib/perf/cpumap.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 17413d3a2221..2237505f8f5f 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -212,7 +212,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_= list) goto invalid; =20 if (nr_cpus =3D=3D max_entries) { - max_entries +=3D MAX_NR_CPUS; + max_entries +=3D max(end_cpu - start_cpu + 1, 16UL); tmp =3D realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu)); if (tmp =3D=3D NULL) goto invalid; @@ -226,14 +226,15 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cp= u_list) cpu_list =3D p; } =20 - if (nr_cpus > 0) + if (nr_cpus > 0) { cpus =3D cpu_map__trim_new(nr_cpus, tmp_cpus); - else if (*cpu_list !=3D '\0') { + } else if (*cpu_list !=3D '\0') { pr_warning("Unexpected characters at end of cpu list ('%s'), using onlin= e CPUs.", cpu_list); cpus =3D perf_cpu_map__new_online_cpus(); - } else + } else { cpus =3D perf_cpu_map__new_any_cpu(); + } invalid: free(tmp_cpus); out: --=20 2.47.0.338.g60cca15819-goog