From nobody Fri May 26 20:06:55 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QSbYD2VFrz4Crd4; Fri, 26 May 2023 20:06:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QSbYD1SBfz3Crk; Fri, 26 May 2023 20:06:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685131616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RzUinnj3oiHoWZ9l5avTSklByP/UeQiJ1np2nSBpf/U=; b=ItziecaGDiehmIr/+RwzrCzQVYIcKBr1NIM1nPQJtbwc0sRWaaKZC/nhx0xZv1Dw020uEh ehKH/fPhk0gzOhNL2AVTJtJFb/DQufMPo3dBjjGsuijIws+u6LtBOlssNMnsSkE8xe2urh 1EMXL516g/X5XiQXjPy606CVcLMtOQk0BbtNov0Fcb4I2+2g7nRMhrvw5m8WW9nTXMQV19 xu+GCUMpeQW3LfJRGDkBWNlbeCz5+Z6gOXNmjRhpLzCytWW05kHibZEOkBWsjODLyQvmIF uAcWG6Egos9ttx1DpV+fFhVahjGSJxD2Y5hFiTwjElNEVmb+QHqCX3nYgDMEcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685131616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RzUinnj3oiHoWZ9l5avTSklByP/UeQiJ1np2nSBpf/U=; b=xrdTfpjnJmucmoeqOqx1r6tPzB5Wb3FZw2TDHLxWcDinHXPUO4iZ/VwqeNzlu/vWzyv3vN 3mkmwDYXlQYzXNwxkH746ydMGsDTBg+ZnTOBrJNlQWjR3SjGzptxivUR9hZtdLgnIPmg/U P7xcn/KVF7MRozPU85Fp7mt2a1yAQNZjIvIXBVDlx91FY/A+PERUfOz2YIi8IHzwLXyztb y1Hmzv44KFM1wsvuvYUoTxy1ie58e5suBOIojI+EQu7v/O264KEWVr2oyZhGBH6E5AVEN4 MUVCijTKBSwv0U73LT0M6e/igyzCqfUPOEth/Qu+3jYsXLPlYkB1/B5YIY7d3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685131616; a=rsa-sha256; cv=none; b=nNJ3vAkvJT+da3mXBCP/xCU+2MORWAZEtDTDhCJLaXC6TkgBIfeCCT1P/3kVwODyp2PRmj mDU47CArbBk+0F9bF7e/vWdALVqhQ4Lnrm5FFo8DomDB82aU4VjYU0CD1/qAq0BfmVQy+R NbXkFCHZKqYcd2r8mZdJauWidEnc00oRdXGBeVJscG+h+zSLCIm73VG/ePX1BrrrZerkoi 3hCDuWlk7wJG3T8TNtoE+nkF5zlhDZZYD/J52s8x6DWd8i2oYvwoJPhfXXmJcrih+lXyH1 Kwxie+OFclGvdoXFRBza5uUCqiZcxxKzd7bMba1ilnn8HNt6paQr1kGZQwdFHA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QSbYD05hHzKZT; Fri, 26 May 2023 20:06:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34QK6tMS098191; Fri, 26 May 2023 20:06:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34QK6tIw098190; Fri, 26 May 2023 20:06:55 GMT (envelope-from git) Date: Fri, 26 May 2023 20:06:55 GMT Message-Id: <202305262006.34QK6tIw098190@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: e96ed177465e - main - top: Use a cpuset_t to represent a CPU mask List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e96ed177465ee59fcc43dd0696106e5342e28c27 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e96ed177465ee59fcc43dd0696106e5342e28c27 commit e96ed177465ee59fcc43dd0696106e5342e28c27 Author: Mark Johnston AuthorDate: 2023-05-26 19:14:21 +0000 Commit: Mark Johnston CommitDate: 2023-05-26 19:38:08 +0000 top: Use a cpuset_t to represent a CPU mask The code attempts to detect holes in the CPU ID space, but previously this would only work for up to sizeof(long)*8 CPUs. MFC after: 2 weeks --- usr.bin/top/machine.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index be667ec0e461..2fbdb8551bb0 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -16,9 +16,10 @@ * $FreeBSD$ */ +#include +#include #include #include -#include #include #include #include @@ -204,7 +205,7 @@ static const char *ordernames[] = { static int maxcpu; static int maxid; static int ncpus; -static unsigned long cpumask; +static cpuset_t cpumask; static long *times; static long *pcpu_cp_time; static long *pcpu_cp_old; @@ -347,8 +348,6 @@ machine_init(struct statics *statics) statics->order_names = ordernames; /* Allocate state for per-CPU stats. */ - cpumask = 0; - ncpus = 0; GETSYSCTL("kern.smp.maxcpus", maxcpu); times = calloc(maxcpu * CPUSTATES, sizeof(long)); if (times == NULL) @@ -357,18 +356,18 @@ machine_init(struct statics *statics) if (sysctlbyname("kern.cp_times", times, &size, NULL, 0) == -1) err(1, "sysctlbyname kern.cp_times"); pcpu_cp_time = calloc(1, size); - maxid = (size / CPUSTATES / sizeof(long)) - 1; + maxid = MIN(size / CPUSTATES / sizeof(long) - 1, CPU_SETSIZE - 1); + CPU_ZERO(&cpumask); for (i = 0; i <= maxid; i++) { empty = 1; for (j = 0; empty && j < CPUSTATES; j++) { if (times[i * CPUSTATES + j] != 0) empty = 0; } - if (!empty) { - cpumask |= (1ul << i); - ncpus++; - } + if (!empty) + CPU_SET(i, &cpumask); } + ncpus = CPU_COUNT(&cpumask); assert(ncpus > 0); pcpu_cp_old = calloc(ncpus * CPUSTATES, sizeof(long)); pcpu_cp_diff = calloc(ncpus * CPUSTATES, sizeof(long)); @@ -466,7 +465,7 @@ get_system_info(struct system_info *si) /* convert cp_time counts to percentages */ for (i = j = 0; i <= maxid; i++) { - if ((cpumask & (1ul << i)) == 0) + if (!CPU_ISSET(i, &cpumask)) continue; percentages(CPUSTATES, &pcpu_cpu_states[j * CPUSTATES], &pcpu_cp_time[j * CPUSTATES],