From nobody Thu Nov 19 17:40:10 2026 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 4jVm2L2HTgz71Wvd for ; Thu, 19 Nov 2026 17:40:10 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jVm2L1f15z4PrR for ; Thu, 19 Nov 2026 17:40:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795110010; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8Ncu4HTGxan73JLuCDELBVRHsha/nsBzz+2ezwbYrbE=; b=syyDI6nzVn8KL8RHk67KRjrBymj+ukY5S4EJRz2AcMfCQtTYzglfiAwLjSMr9WZHERv4Sy eYwzUkxoHmH38O7PFMJzXQUN+P4UP1VIKAJ/CIKJRNCnjM88z1nym0OK4mEyzRcEFvrj5u dqO1qskpBlNrnGb5CYsciGN/eSbZPxEiiRm7Zm1hAE8UpEYzPRUIa/h4zSZQhGulZgdckm 02UGjqqqdWrXVPxQd5BZEnD43MF0bU7LZ8wHKbd6jCnz2aFg4kc/4TRIItVU9CV1wKoOCs ueSJ69aWDOTPAdrVly0dTeQkq46pGZav/gBg6fwALi3DUN7lgCNu83q0RRFi3w== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795110010; b=bNTt61IMJGDN0rpEvaF1e3wbloZ/C6WoQL/h55mLULtOMeUUqNHgHfJXTuGcCM5pxQvvkP WxaMQMVUTU2ppU6rQULtsZYqsicf01qclGd5Go9/wRAlOReMJF9etMnKmcXv7dCU1EamEE XvnrWmCyCP19HfYucBWBXuHcofrEIlDiN1JboSAaxGH1U5B15WidcKXAc4eMtFnzqqurNp TYuG3XPvsS4WD1zqCih/MWEEOrbLIsoaYTFOQreAQO9F/AGqYpCg9jP0t0xotQZ3UBwZwW XZIEpRkJVAX18SS1BwmFcFp3+oPwsmtG/BRtkzlBxPwMgeM3xNTUt3o+n85aEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795110010; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8Ncu4HTGxan73JLuCDELBVRHsha/nsBzz+2ezwbYrbE=; b=AIME8vQeLH8vlht+XJNv7VridE1D3xNCaCt77o9LvzyhaqkVqdgCHNMoTmu/Ixe3li6ckh XY1pjQ9cQYVuUWGzS5tIudecdMACUpe/8btkANIJHrvNd8kO9DBwOXBj5cBbwfcTm2QUeu mmnX8/yYhZabG5Ioxw/r49EPbtunrrLLCnb5x3ubVozqyqOmGi4SlliGH8DIEsqtMsYbAF U/duJd9UcRc9/8V0OWW7EKVhD0W/gJxlP8Sx5zW7qE0PRxeySihxHzsr6iHorw03bn+/ZG z1Ha0Ju8vK7e2/Ci4ujSRp6eDvOWQQ9WR4xtLDsawer0ay/Phax46XcKp2gy+Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jVm2L12Zzz19JZ for ; Thu, 19 Nov 2026 17:40:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 19da8 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 19 Nov 2026 17:40:10 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Osvaldo Janeri Filho From: Mitchell Horne Subject: git: 1768d483ef9d - main - hwpmc: keep AMD UMC counters from saturating List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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: 1768d483ef9dedd6ea5652401c5a693f49b2066c Auto-Submitted: auto-generated Date: Thu, 19 Nov 2026 17:40:10 +0000 Message-Id: <6aff347a.19da8.70346155@gitrepo.freebsd.org> The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=1768d483ef9dedd6ea5652401c5a693f49b2066c commit 1768d483ef9dedd6ea5652401c5a693f49b2066c Author: Osvaldo Janeri Filho AuthorDate: 2026-11-19 17:36:51 +0000 Commit: Mitchell Horne CommitDate: 2026-11-19 17:37:53 +0000 hwpmc: keep AMD UMC counters from saturating UMC counters saturate at 2^48 instead of wrapping, after about a day and a half of memory clock cycles. Clear bit 47 on a read once it is set and count the carries in the per-CPU overflow count of the PMC, like the arm64 and armv7 drivers do for their 32-bit counters. Reviewed by: mhorne Sponsored by: Advanced Micro Devices, Inc. Signed-off-by: Osvaldo Janeri Filho Differential Revision: https://reviews.freebsd.org/D60771 --- sys/dev/hwpmc/hwpmc_amd.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_amd.c b/sys/dev/hwpmc/hwpmc_amd.c index 7f505e568c68..101c583352fd 100644 --- a/sys/dev/hwpmc/hwpmc_amd.c +++ b/sys/dev/hwpmc/hwpmc_amd.c @@ -413,6 +413,7 @@ static int amd_read_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t *v) { const struct amd_descr *pd; + struct pmc_pcpu_state *pps; pmc_value_t tmp; enum pmc_mode mode; @@ -431,7 +432,19 @@ amd_read_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t *v) tmp = rdmsr(pd->pm_perfctr); /* RDMSR serializes */ PMCDBG2(MDP, REA, 2, "amd-read (pre-munge) id=%d -> %jd", ri, tmp); - if (PMC_IS_SAMPLING_MODE(mode)) { + if (pd->pm_subclass == PMC_AMD_SUB_CLASS_UMC) { + /* + * UMC counters saturate at 2^48 instead of wrapping. Clear + * bit 47 once it is set and keep the carries in software. + */ + pps = &pm->pm_pcpu_state[cpu]; + if ((tmp & (1ULL << 47)) != 0) { + tmp &= ~(1ULL << 47); + wrmsr(pd->pm_perfctr, tmp); + pps->pps_overflowcnt++; + } + tmp += (pmc_value_t)pps->pps_overflowcnt << 47; + } else if (PMC_IS_SAMPLING_MODE(mode)) { /* * Clamp value to 0 if the counter just overflowed, * otherwise the returned reload count would wrap to a @@ -469,9 +482,14 @@ amd_write_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t v) pd = &amd_pmcdesc[ri]; mode = PMC_TO_MODE(pm); - /* use 2's complement of the count for sampling mode PMCs */ - if (PMC_IS_SAMPLING_MODE(mode)) + if (pd->pm_subclass == PMC_AMD_SUB_CLASS_UMC) { + /* Bits 47 and up are kept in software, see amd_read_pmc(). */ + pm->pm_pcpu_state[cpu].pps_overflowcnt = v >> 47; + v &= (1ULL << 47) - 1; + } else if (PMC_IS_SAMPLING_MODE(mode)) { + /* use 2's complement of the count for sampling mode PMCs */ v = AMD_RELOAD_COUNT_TO_PERFCTR_VALUE(v); + } PMCDBG3(MDP, WRI, 1, "amd-write cpu=%d ri=%d v=%jx", cpu, ri, v);