From nobody Fri Jun 09 17:21:30 2023 X-Original-To: dev-commits-src-branches@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 4Qd7Ct5DRsz4bb7X; Fri, 9 Jun 2023 17:21:30 +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 4Qd7Ct4DwZz3s9g; Fri, 9 Jun 2023 17:21:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686331290; 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=GbkaDNPcOsJvwngW72l0j4IK+goTuRx6wjK+vIbaPTI=; b=dFK2XzZ/d/kOeXQz5VPmbsaAS37jp3nq5pdyW+Kww79Ea/8MYs+iF80KjkvzmSOMrzLU2l IzDdjM0wpvju3mHq2GcstgRwrubsXbfgW1P/bADbjHgPlnhyOTu6nvBJ3Egr+xTTWP3Eew e6ZSLF8P3GQajdQsowWBwgQRNgU5sRGc2CKt4s3TmUBSHcWG+uVT+4exjqjIEZUIpj6mYA XXlZbrhVucau/fwxSzQFRsiO/ekZhpsUZ3C3mCd9ZT/qcV7bHQ7pBfkheaEZeWxBM4pKk8 nBhVQZL3NVbVzD6RkKOVdozgCU6Ud+QB8X0PDH9EFr+hYTA4CSh7IobNi7OW6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686331290; 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=GbkaDNPcOsJvwngW72l0j4IK+goTuRx6wjK+vIbaPTI=; b=ukgc0pQv0V6hqkvk7bkLgxX2pweIDPfZ8UEBF7Sooy/BdBbINVK9chI9NFDxXv7w6LTknb h1PmT0YoZbU4OXffe96teCcioAVJ94w1+dkFZJPhfnOkI0LgahAldaDcHEVhs7XQJ9ViT3 shOdGyepQpMjacahbaClFMjGW2Zg3RoWE2Qrw651Rdsn+z+WaHzXtfd7rXkrfBQO5RzHUU OWdA4R2/dBD/xsN8M72amStjme0DTqjULl9fxtoGEpLlu5sCBFejZLXiPK9pD8OQC5x8Lu UPUxBLhsm+D5d2M4EePF4IbML3ANfHKu+vWYp4Q2gXtgWFWoau6IvW2WMns9iw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686331290; a=rsa-sha256; cv=none; b=C7H0OHCcFO9qGUXsEwfPH5zLvQFYBGIiOlDaZa8pQveP05uGoT8A540QFhD6P+AyUXxIoS XZlpsloxZSrUGTRwlTr4VPZvb4m/63ixEt/DyzuQOHR6UcJka+wPXcK5WKDTsveVe10egN ASurT3RNWiK1GT9XFqlcryOEZSIoTlvB54sbYffiI2SJPg66PJQt5bQuBfrsJ87rbx4oab rsB69q7To7jqzYsbHtGjuarHno4zh47+Z1keBEZ3uawBitly9V+meQLIKiB6gll1OaRhi9 zbcKRrRQ9eA8naOKPfd8oy6+fH/bJTlN1JfE7TRXP8JHdZWjXTKRJjkGzhb3aA== 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 4Qd7Ct3HqKzkSj; Fri, 9 Jun 2023 17:21:30 +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 359HLUB6019756; Fri, 9 Jun 2023 17:21:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 359HLU1c019755; Fri, 9 Jun 2023 17:21:30 GMT (envelope-from git) Date: Fri, 9 Jun 2023 17:21:30 GMT Message-Id: <202306091721.359HLU1c019755@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: e81a864ddaad - stable/13 - top: Use a cpuset_t to represent a CPU mask List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: e81a864ddaad0f0cdb4a3da0fd9d43c4448679c4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e81a864ddaad0f0cdb4a3da0fd9d43c4448679c4 commit e81a864ddaad0f0cdb4a3da0fd9d43c4448679c4 Author: Mark Johnston AuthorDate: 2023-05-26 19:14:21 +0000 Commit: Mark Johnston CommitDate: 2023-06-09 17:20:40 +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 (cherry picked from commit e96ed177465ee59fcc43dd0696106e5342e28c27) --- 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],