From nobody Tue Oct 10 17:07:01 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 4S4j4Q0Pg6z4x36l; Tue, 10 Oct 2023 17:07:02 +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 4S4j4P71nzz4g6H; Tue, 10 Oct 2023 17:07:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696957622; 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=amM0cXF3GqasgAqkxwCDQqnGb53YkqhQrg3MycOALIw=; b=xquIGzPUOuO7TyXPLoSkXLXoxpKsgWdSAlZQS4iUgRhH3UlaYi5pCjYg/y+8niAAfGVZAT WLZw40ExhMhI92X7x2NTwwd5W1scttkkn1/nVzFfbv/MbrEhTy83ySxsGFSPvOk+qli5X4 JxInB8JvjbjZAKpxR9f0tOXXYTsPw5VB92JLFYzFLSlBjAZIwcgJ2MKFlHmCd4ahqSgYgz RarheL2bRg3iJWMfNK+XyvASMkT+QO17KfVNXrokGJ+PuGTihFrTC3BFXMWnQwWZ4/B8p7 0+QuB7SouFdWImZ8Zj/nKsH/Qysqei/1IrFLGM3Lc8Zc714s2Hs7vJZ+QvAF6Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696957622; a=rsa-sha256; cv=none; b=RVKZpr9oSTys0n5H8VyRhGagwMUuf2gW6Mokxs1FH1bRuaO48nS01bLBddhm49hM0IQ/um J2Bx7XrEQQe8EEl6FCBOuMPCzw8ndxxKScFMD3Y+Mr584RCeNPJPBN0DmNvH9hpOvlwjKI ygLBdU74v1ZlHc7L7BM2dYAmC80oQ3mXtGLccdCDr7QcVI1pNQRKADPNfQeUMKguTM2ZaY TDRkS5OM1ighFDHxB4Xd1XpBFgYz3q1ewz8FggiZ9vBE6DunWI4TOvvN8JcaCzQn5fIGc8 admQ26KytvAmbk1fPuIePAkvrjMIRAXSU4DaCZcTghG6EA5ajB1QGBabIr5Gpg== 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=1696957622; 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=amM0cXF3GqasgAqkxwCDQqnGb53YkqhQrg3MycOALIw=; b=GUdUORUA7qPP6PkzT0CSRGPOuLNiLiWn1QIVZRAF0b6Uc4LzgEIyuhcIHN0OZiF1h5iKQy Eiw6wB+57sJ4BOhJcsctwpX0YPJ/g3g7WJsqj+Ku8rmR+eUs0zLy4uOj6kpP4RfIhZK6dN 2LAgzV1J5uQjJS8FMrSfrcoOrLG+U+74dCaKRBJcTM43bfcuRaR32Nx3yV3HKn6pXSbsyP HPwf2jLSLsXVXYwL0t2UILqIpJjjJsLwHZHQNxURNfY2sgzvip9TQuZfclnr4w/3MzPKqU San8X56EBPmhktgmGPYKeZeCc03yi2nWKABDH0cAPC0s1ipxPqlOU7MrkXkkhQ== 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 4S4j4P65fWzmNW; Tue, 10 Oct 2023 17:07:01 +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 39AH71O8054659; Tue, 10 Oct 2023 17:07:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39AH71eP054657; Tue, 10 Oct 2023 17:07:01 GMT (envelope-from git) Date: Tue, 10 Oct 2023 17:07:01 GMT Message-Id: <202310101707.39AH71eP054657@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: 5a2849bc3c60 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 5a2849bc3c60426039ff2aeef1d2b54940152927 Auto-Submitted: auto-generated The branch stable/14 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=5a2849bc3c60426039ff2aeef1d2b54940152927 commit 5a2849bc3c60426039ff2aeef1d2b54940152927 Author: Mitchell Horne AuthorDate: 2023-09-27 16:37:46 +0000 Commit: Mitchell Horne CommitDate: 2023-10-10 17:06:12 +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 (cherry picked from commit c362fe939f6fe52056fb7506be9e5cbd0a5ef60b) --- 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); }