From nobody Wed Sep 27 16:40:12 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 4Rwj5S3CLhz4vgQ6; Wed, 27 Sep 2023 16:40:12 +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 4Rwj5S2XJBz3RqL; Wed, 27 Sep 2023 16:40:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695832812; 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=shOQgMS7tcGWaj0zGIVhOT6lRnTgFPcljNcFfso09/E=; b=iKmn8TZI2d7Qni6NumaaUfUXOjGue2FOw1SMzTJJxiytga8DBekpwoMnMuOSaRFGS8LRF/ TVMumGgPGum3wkYbda7fkvAB+BFDyqTtuky1wVmU/taS/OmaO2eQdeGdYc0NHqWf+AhHYQ AU5LG8zfclWDC+0dYe8hbdTDKeLOueAddxtm+dd2b4uZIAUBSKv6MetMcUX3A0TLVgsDRU fLhssI4T7BN6O4z383dGt6ChultpYk96QGLlF55OL3Kup3yrOajO1rWJTRA4rcYY8KHysA WdDUgGKj1h0OzFg+YNp/WwgHfxAB7/ZOnWgdnPLUjJ4SIsr3E3wnu7qnJ79swg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695832812; a=rsa-sha256; cv=none; b=Apbtc27/iq0D38/05x6S2T6Anm/Oaq3AMoJXsLxk2CR0jbMSg67V+rYdlwM71mbfajPN5S KB2In3U1bW+VCZZapUJ/whqYcUdIZ/LNJxHdnPOHGr80+quygcv8bVFOeg3erjDIrNxXE2 IJ1JBJBUueU2ksIDbc07AcnwhDL9aqQIhHjFaDILULsiZvFaLt2tEtJvRI8AECrEfCqt+s QKGRFMTCdtwEMhjvoI+S5KVRIVZtj3BBSvXfMn+jm6Yw13dDhYBzp+Ioq2AlJXYjF/ej6y EbvIMZ/qHzz/1kwixRa40o/L2k+HorVOBTPFD5blWMs5Lwh/fxV0o67fAXWW8g== 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=1695832812; 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=shOQgMS7tcGWaj0zGIVhOT6lRnTgFPcljNcFfso09/E=; b=HlwUu0VHz0bZLMfQvgN3ozqRHduhTLm/gXUWxZUxetTtWaC+czIJaA9f7rsAx6qDiIRpD/ EkPePt3ya4RpCREdHGQFVOsKAsS/7+Hda9dyAoNcez6/00mm0hNgCrT5JTsZqEeGXvextZ kx4o+DXbmVqOuovJrMFJIPe2V8AF/mJQJydQzenXaMt4SZg0+DYHllnJmlW6z3oRIBrHN1 sSHjRgcZo+ZZhTnRwTxbvLlv6nbjmZC7+NowOkNTKMabum07cJfzDzs4O5suPhZt4fJ6yb Ils2FMErq0RGYU3FeVkyZ+ug1Sgk0LB+6DsVHLT5Ar873pOTNSqVo9wok7mP3A== 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 4Rwj5S1SVyzmXd; Wed, 27 Sep 2023 16:40:12 +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 38RGeC2M099550; Wed, 27 Sep 2023 16:40:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38RGeCPl099542; Wed, 27 Sep 2023 16:40:12 GMT (envelope-from git) Date: Wed, 27 Sep 2023 16:40:12 GMT Message-Id: <202309271640.38RGeCPl099542@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: c362fe939f6f - main - pmcstat: fix duplicate event allocation on CPU 0 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c362fe939f6fe52056fb7506be9e5cbd0a5ef60b Auto-Submitted: auto-generated The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=c362fe939f6fe52056fb7506be9e5cbd0a5ef60b commit c362fe939f6fe52056fb7506be9e5cbd0a5ef60b Author: Mitchell Horne AuthorDate: 2023-09-27 16:37:46 +0000 Commit: Mitchell Horne CommitDate: 2023-09-27 16:39:56 +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. Reported by: alc, kevans Reviewed by: jkoshy, ray MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41978 --- 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); }