From nobody Fri Dec 19 06:34:42 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 B897B21C184 for ; Fri, 20 Dec 2024 18:52:11 +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=1734720733; cv=none; b=bCAm3haAt/2qfkF4Pmvl9yzq+lFWtSXpjYBlM4n5/nQAZoUhgpSEZ4qMNJOeKOS9cbEHvGRvqTjbsgSpF8QEKUU3Uo2eOyMUgeBdQ7HwgyBbzkTBFFYEPxxUUsL3dFlpdX/AqmXSIhl3uVzEg6aXJ80oZCTZmON3KTTbwDwNALU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734720733; c=relaxed/simple; bh=DUYLUfquG98uQq+kXpeAFU3xFpmomSDyKuleQtmrMEE=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=gnE7HgIcC0H8W+6y4hrVABAXuaub4tPyHjnt0C9Clq8BUIMsmEPIxD7zCuua9WsaZdpDf7AbgcfVozWg9k38E5LmXtmU2u9TCMf/A1El3hXcqY1j+lShnN9MhIfp2emRT6gP6uWn2W8vYrNNXfiLT9rwGC8GmjhQc8bQm0hIH34= 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=a994VDSO; 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="a994VDSO" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6f28f5f2c5eso27301487b3.0 for ; Fri, 20 Dec 2024 10:52:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734720731; x=1735325531; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=3RjYZWYjU7P3d8ZH5N5N+LTCqyHJ1b2TYWiGLWSmoA4=; b=a994VDSOt1lmfscTiVHLGczfnUksxGdVGLxizjSlipDX2MBzF0ypLprLssSVTuz0BC D9BUdQzwuERsxhgnV6LvW0VKgW4ZFzaJfRmQcWIB2vMFbUmFOSFye18XTJ9eAoLoT/wp Nn24dVDYCSE8FFSyESxRPvO45YMt3hAdmLmK9jUTO3rXnUBURrF5NrKUKZoXQXMeYWCR T/Ae0RfmveUJoiYrXv+ShZsLT/LAcY6ygv/weeLhDqdjY1EzrYPAOxzXFM2zTa5a91pq MbXhUfxeO0Wt/Dvq2CTDs/y9+dbCL11B2SEAWVcGTpc8lusot+1wbhWsxCjfIKB3gJyS o1Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734720731; x=1735325531; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3RjYZWYjU7P3d8ZH5N5N+LTCqyHJ1b2TYWiGLWSmoA4=; b=BT2fFqeGiN+f2hytWRpglaWr4PZbZaVXVZWi0vCRfbfplnBQ67J4Grsc66ewMbgqV/ +5vT/CW9eM6i2OvLkOdJ2DgqZLJxOovpUve2XmdS3CphgwC68nsitOIxxkoWRkN7ESkR xE9MGfB5ffynBpMxllfoGKM66PuwJxt1rLb+0mcR+tXJ8qDF6odzqRuKgRQbvlV0TYYd YQkdWo0+OZFzLNwhVzpmKD/KCb4RF75D2JQmo9FwqGwtX6S1Hw/0EBcIhzGPyI9mTJ31 rk5gfJrof21fxbj3nrVaAbuFIa8rcqAo44/0P+NC+z2OMiM/bCV8AiPhwXMl3ybGQRe4 MLLA== X-Forwarded-Encrypted: i=1; AJvYcCUKnQiXlbLajw8HxhWlCohcFIquqhnPIiZY8orKi8QHEOjf7+NW5qb/kGsYZqI8y7vn9z3smFQ5iesPE64=@vger.kernel.org X-Gm-Message-State: AOJu0YxtP6oD252ZLZLtqR/boK00ggFHQ0T0p6YnDC8X0cx/7eY43hPq wzI6fQv/xiF7ncb0Tro4maVxt7TIyM18OletWyW5IIV0QiFBgTKZNTrUyBy5sdO2ZCzMCxHVgb+ H/jgkqA== X-Google-Smtp-Source: AGHT+IEtRVmaAuKRfic+UiyV02GKALJgnkq9gQfUbfzzW8ptoa0HAMbGM1hEnduwrk/PNQXb3sU2j16Vdtdy X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:2801:ca8b:1bd0:e38d]) (user=irogers job=sendgmr) by 2002:a05:690c:ed4:b0:6e3:b08:92c7 with SMTP id 00721157ae682-6f3f7f26de6mr93897b3.0.1734720730748; Fri, 20 Dec 2024 10:52:10 -0800 (PST) Date: Fri, 20 Dec 2024 10:52:07 -0800 Message-Id: <20241220185207.106161-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v2] perf cpumap: Reduce cpu size from int to int16_t 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 , Tim Chen , Yicong Yang , Ravi Bangoria , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Leo Yan , Kyle Meyer Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fewer than 32k logical CPUs are currently supported by perf. A cpumap is indexed by an integer (see perf_cpu_map__cpu) yielding a perf_cpu that wraps a 4-byte int for the logical CPU - the wrapping is done deliberately to avoid confusing a logical CPU with an index into a cpumap. Using a 4-byte int within the perf_cpu is larger than required so this patch reduces it to the 2-byte int16_t. For a cpumap containing 16 entries this will reduce the array size from 64 to 32 bytes. For very large servers with lots of logical CPUs the size savings will be greater. Signed-off-by: Ian Rogers Reviewed-by: Tim Chen --- v2. Rebase and tweak commit message. --- tools/lib/perf/include/perf/cpumap.h | 3 ++- tools/perf/util/cpumap.c | 13 ++++++++----- tools/perf/util/env.c | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/= perf/cpumap.h index 188a667babc6..8c1ab0f9194e 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -4,10 +4,11 @@ =20 #include #include +#include =20 /** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map'= s indices. */ struct perf_cpu { - int cpu; + int16_t cpu; }; =20 struct perf_cache { diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 27094211edd8..85e224d8631b 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -427,7 +427,7 @@ static void set_max_cpu_num(void) { const char *mnt; char path[PATH_MAX]; - int ret =3D -1; + int max, ret =3D -1; =20 /* set up default */ max_cpu_num.cpu =3D 4096; @@ -444,10 +444,12 @@ static void set_max_cpu_num(void) goto out; } =20 - ret =3D get_max_num(path, &max_cpu_num.cpu); + ret =3D get_max_num(path, &max); if (ret) goto out; =20 + max_cpu_num.cpu =3D max; + /* get the highest present cpu number for a sparse allocation */ ret =3D snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt); if (ret >=3D PATH_MAX) { @@ -455,8 +457,9 @@ static void set_max_cpu_num(void) goto out; } =20 - ret =3D get_max_num(path, &max_present_cpu_num.cpu); - + ret =3D get_max_num(path, &max); + if (!ret) + max_present_cpu_num.cpu =3D max; out: if (ret) pr_err("Failed to read max cpus, using default of %d\n", max_cpu_num.cpu= ); @@ -606,7 +609,7 @@ size_t cpu_map__snprint(struct perf_cpu_map *map, char = *buf, size_t size) #define COMMA first ? "" : "," =20 for (i =3D 0; i < perf_cpu_map__nr(map) + 1; i++) { - struct perf_cpu cpu =3D { .cpu =3D INT_MAX }; + struct perf_cpu cpu =3D { .cpu =3D INT16_MAX }; bool last =3D i =3D=3D perf_cpu_map__nr(map); =20 if (!last) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 610c57da5b37..961a92545039 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -543,7 +543,7 @@ int perf_env__numa_node(struct perf_env *env, struct pe= rf_cpu cpu) =20 for (i =3D 0; i < env->nr_numa_nodes; i++) { nn =3D &env->numa_nodes[i]; - nr =3D max(nr, perf_cpu_map__max(nn->map).cpu); + nr =3D max(nr, (int)perf_cpu_map__max(nn->map).cpu); } =20 nr++; --=20 2.47.1.613.gc27f4b7a9f-goog