From nobody Tue Oct 17 14:11:38 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 4S8wrq03GBz4xYTF; Tue, 17 Oct 2023 14:11:39 +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 4S8wrp6HJfz3QQl; Tue, 17 Oct 2023 14:11:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697551898; 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=6TEJGU48EYtQxO2IKktlubyKZi1eYqVRnuVtiDhoQZk=; b=p6CQ/3qJcIQEeZjyhGeYPQKvHCJClhJX82x8KGKMCgsDM5nW9frrON7UrwW+mk2nGUwpSb lflwz71VhDZB5rGICIzoyyx/s3OP+hOPKqWaHUdGSLMqrgWzTNTbtJJyI6wztMTv04GjXB kTPVrC/9XsOaenlep+pjPrUUPomTYEW3Y2rHiZREEYtbx3p1N+jzNkgAwDRKV2ARMdjzVe sH3EkglWyCNiXq1k6iREen638nNu8meOpVNwEQ3Fx+hZwxJmEGqPsWa9h7WNxwPdx2BPgZ S5VVxiUjitGasFueNodXS2sDvIabMQYBcKfCkWEvlfTj6DZAZ4YMoVFrE9ZziQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697551898; a=rsa-sha256; cv=none; b=TEborb6zDXyOpxY2Rg8h7VPMXyBL3eI/L/CGnwuVu6PBwLbhYgmCzxLmxrg2MnwaVws75T AT/IPS1vA2fcSNhc000xIk9sTETTsayzhFsOTlNxf64rOIKZr+xt6VTOILjQnGUdVWXU9h sQ13QrPMFrZSVHlrgsFCF/JHep2+Sds0LTU1VsHR1sN6ygkE6vjDQqJvZc2QZ2vU3BpGFQ uzbv01M1XXZ5+UbkkU0YsmfsrdrSSr2dxWlh27HI2ti7Qx/4O+2O6jGhDmIN6IRy9dSKEw kOCFtJJpq+tPFCSNBCjOqc5Y4+GB/ZWmG5uF1eNNB7MGE7pc6ErT7JAK9E/RxQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697551898; 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=6TEJGU48EYtQxO2IKktlubyKZi1eYqVRnuVtiDhoQZk=; b=wWPUPiJkaOm7X2bWgNEBxIf6ly6qqtZMTCGP1ij8QEze0b5s9FjyNg9T3RyxoTrc9V6ogh DipWOAC+um49pF47ojJPvRK8rUuIkenYru6dNdiGpcyVk6pQQNk+qJ7ULE/I24/R5HhAFl aDZjVNfOSKcqLzJv+d4zuNXxL4jN5Ik6KiHXYlRudy7N/0mC1muaCjvSxOHWy2C2E8A0II AKrMXspfA09mZ9rF7rLwqbqO+ukwLAsNHhx9r+oZSEB+eKe71uPhmJJ2ab8+4RK2ck3ttA tcuKWEND1xYRMnuAvd3ysRvLJcjP/7DHe62TpIVKn8cYBeAfX814F7XRRki45A== 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 4S8wrp5Ld1zC4r; Tue, 17 Oct 2023 14:11:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39HEBcRB058947; Tue, 17 Oct 2023 14:11:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39HEBcsO058944; Tue, 17 Oct 2023 14:11:38 GMT (envelope-from git) Date: Tue, 17 Oct 2023 14:11:38 GMT Message-Id: <202310171411.39HEBcsO058944@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 1ffcc2983834 - releng/14.0 - pmcstat: fix duplicate event allocation on CPU 0 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 1ffcc2983834accfd21089daa116ec802e90e088 Auto-Submitted: auto-generated The branch releng/14.0 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=1ffcc2983834accfd21089daa116ec802e90e088 commit 1ffcc2983834accfd21089daa116ec802e90e088 Author: Mitchell Horne AuthorDate: 2023-09-27 16:37:46 +0000 Commit: Mitchell Horne CommitDate: 2023-10-17 14:11:13 +0000 pmcstat: fix duplicate event allocation on CPU 0 Commit b6e28991bf3a modified the allocation path for system scope PMCs so that the event was allocated early for CPU 0. The reason is so that the PMC's capabilities could be checked, to determine if pmcstat should allocate the event on every CPU, or just on one CPU in each NUMA domain. In the current scheme, there is no way to determine this information without performing the PMC allocation. This broke the established use-case of log analysis, and so 0aa150775179a was committed to fix the assertion. The result was what appeared to be functional, but in normal counter measurement pmcstat was silently allocating two counters for CPU 0. This cuts the total number of counters that can be allocated from a CPU in half. Additionally, depending on the particular hardware/event, we might not be able to allocate the same event twice on a single CPU. The simplest solution is to release the early-allocated PMC once we have obtained its capabilities, and reallocate it later on. This restores the event list logic to behave as it has for many years, and partially reverts commit b6e28991bf3a. Approved by: re (karels) Reported by: alc, kevans Reviewed by: jkoshy, ray Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41978 (cherry picked from commit c362fe939f6fe52056fb7506be9e5cbd0a5ef60b) (cherry picked from commit 5a2849bc3c60426039ff2aeef1d2b54940152927) --- usr.sbin/pmcstat/pmcstat.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/usr.sbin/pmcstat/pmcstat.c b/usr.sbin/pmcstat/pmcstat.c index fd4be99f83c8..c36cee436e55 100644 --- a/usr.sbin/pmcstat/pmcstat.c +++ b/usr.sbin/pmcstat/pmcstat.c @@ -713,8 +713,16 @@ main(int argc, char **argv) errx(EX_SOFTWARE, "ERROR: Out of memory."); (void) strncpy(ev->ev_name, optarg, c); *(ev->ev_name + c) = '\0'; + libpmc_initialize(&npmc); + if (args.pa_flags & FLAG_HAS_SYSTEM_PMCS) { + /* + * We need to check the capabilities of the + * desired event to determine if it should be + * allocated on every CPU, or only a subset of + * them. This requires allocating a PMC now. + */ if (pmc_allocate(ev->ev_spec, ev->ev_mode, ev->ev_flags, ev->ev_cpu, &ev->ev_pmcid, ev->ev_count) < 0) @@ -726,8 +734,14 @@ main(int argc, char **argv) err(EX_OSERR, "ERROR: Cannot get pmc " "capabilities"); } - } + /* + * Release the PMC now that we have caps; we + * will reallocate shortly. + */ + pmc_release(ev->ev_pmcid); + ev->ev_pmcid = PMC_ID_INVALID; + } STAILQ_INSERT_TAIL(&args.pa_events, ev, ev_next); @@ -751,10 +765,7 @@ main(int argc, char **argv) } if (option == 's' || option == 'S') { CPU_CLR(ev->ev_cpu, &cpumask); - pmc_id_t saved_pmcid = ev->ev_pmcid; - ev->ev_pmcid = PMC_ID_INVALID; pmcstat_clone_event_descriptor(ev, &cpumask, &args); - ev->ev_pmcid = saved_pmcid; CPU_SET(ev->ev_cpu, &cpumask); }