From nobody Thu Apr 16 06:06:31 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 4fx6w84CZtz6Z0jy for ; Thu, 16 Apr 2026 06:06:32 +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 "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fx6w80jkjz3hty for ; Thu, 16 Apr 2026 06:06:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776319592; 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=qOhKr4eUTi2V8GrxMTWb8JHFb4OzwbG2O6P/oYiyssc=; b=H8DpU/+/vuH3gtgELFoPpPClCsb9Bdei06xqgVG5DRRL9/3OK+RWR+MkHjbGxSv8w1sg6O P/1PUSAA/JmK8dPrOxFPy+YspEBKTtvJELLs0daQ4BmkD6SZCaV9q0iSnZJKFK9NlLGchn LWSx9w9/HgyIuWl+9jsZV8JCGO/+/tTJgEob507l6RwRriaKnTaxIDjlmgy4Vof6tVsZok CDTPYa/aWlRVEozRHBo8Cz1lm4xuzrUaUcmIydY89nigMFg0sfA3zN0E+AUqlvsV2EdjPJ +Jo5QoHb73PtYeKKRkXwXsNCLduSvprVFE5bg4m24R0r++Mx+mY65sKtjrDg0Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776319592; a=rsa-sha256; cv=none; b=fpu9gPRUs2RWqwalFuPzLZdgl3Begta2dO19s79wqG2sugTHroX5I/TZfrFtNFeDNSO3JO YoGTEywaFiR1BXmKoHJLHpDt2rTWwKM7FP+LiJEsLy0Ny3J/OK8dA2zT3D8WITdK1MRH1m 3hpBAvybEGY6PjmAqichTEFKDa6xgJpcj/cX0RpHlSatrk8uayd0VH4r0zupIZtRHRVJJ+ Z1x29oE3dg97hFV+p55jJ0mlIa8NdESH8nmSmBSprs20E3pTJL41ZiOBF/kk9E9G6hjgR0 i4kptGHBkqieeNCB1Q8wwcIz5o7WVSIV+zKznQoTOxbv2JmCAmhdvGN2smVYVQ== 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=1776319592; 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=qOhKr4eUTi2V8GrxMTWb8JHFb4OzwbG2O6P/oYiyssc=; b=siNmx/RbMdUJhF38FVt6lOLxi/758BK1xz8njYzMK6mX9ZaZNuxdOMWAp4G2gCKkw5uMgg L6KIFfNDMIoxCJKWNjsucbu7DALtiVhPpPiN+falUp99P2Uju1Sp8ZcGgJQU6jEbWzMjyO oEM7HmzPGDAGCf7hC/MrjhUXxOFqs8MXGKwIhFcFyn9MzeMHs0LKh7TtAClWooNMURFXMB +XuKSVyXT0PeVKR6yeycTCMPZMLc6ZlrYJfb42w3lpwwzzaT931zF2LDYAJdFUXM2UqhSk slGPyXHdNf2YrqFh7BNz/TlmrtEDtbtQ41sdvJXjvlYng5VPMcmClMhKtN/E5Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fx6w76lP1zvwt for ; Thu, 16 Apr 2026 06:06:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3d0b3 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 16 Apr 2026 06:06:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Andre Silva From: Warner Losh Subject: git: fbbf71f5813b - main - libpmc: surface raw TSC in pmclog events 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fbbf71f5813b041526c4d439d9961e8a8281d291 Auto-Submitted: auto-generated Date: Thu, 16 Apr 2026 06:06:31 +0000 Message-Id: <69e07c67.3d0b3.4ce909c1@gitrepo.freebsd.org> The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=fbbf71f5813b041526c4d439d9961e8a8281d291 commit fbbf71f5813b041526c4d439d9961e8a8281d291 Author: Andre Silva AuthorDate: 2026-03-31 20:28:04 +0000 Commit: Warner Losh CommitDate: 2026-04-16 06:05:21 +0000 libpmc: surface raw TSC in pmclog events The pmclog record header carries the raw TSC for each event. Export it in struct pmclog_ev, fix JSON output to emit it unsigned, and preserve the installed header ABI by overlaying pl_tsc with the legacy pl_ts storage. Update pmclog(3) to document the TSC semantics and the legacy alias. Sponsored by: AMD Signed-off-by: Andre Silva Reviewed by: imp, mhorne, Ali Mashtizadeh Pull Request: https://github.com/freebsd/freebsd-src/pull/2085 --- lib/libpmc/libpmc_json.cc | 5 ++--- lib/libpmc/pmclog.3 | 29 +++++++++++++++++++++++++++-- lib/libpmc/pmclog.c | 4 ++-- lib/libpmc/pmclog.h | 6 ++++-- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/libpmc/libpmc_json.cc b/lib/libpmc/libpmc_json.cc index 90881f22971e..1ac0b3a50a6c 100644 --- a/lib/libpmc/libpmc_json.cc +++ b/lib/libpmc/libpmc_json.cc @@ -74,8 +74,8 @@ startentry(struct pmclog_ev *ev) { char eventbuf[128]; - snprintf(eventbuf, sizeof(eventbuf), "%s, \"tsc\": \"%jd\"", - typenames[ev->pl_type], (uintmax_t)ev->pl_ts.tv_sec); + snprintf(eventbuf, sizeof(eventbuf), "%s, \"tsc\": \"%ju\"", + typenames[ev->pl_type], (uintmax_t)ev->pl_tsc); return (string(eventbuf)); } @@ -393,4 +393,3 @@ event_to_json(struct pmclog_ev *ev){ errx(EX_USAGE, "ERROR: unrecognized event type: %d\n", ev->pl_type); } } - diff --git a/lib/libpmc/pmclog.3 b/lib/libpmc/pmclog.3 index 4af4150d60a9..452a14f42f55 100644 --- a/lib/libpmc/pmclog.3 +++ b/lib/libpmc/pmclog.3 @@ -77,7 +77,10 @@ struct pmclog_ev { enum pmclog_state pl_state; /* parser state after 'get_event()' */ off_t pl_offset; /* byte offset in stream */ size_t pl_count; /* count of records so far */ - struct timespec pl_ts; /* log entry timestamp */ + union { + uint64_t pl_tsc; /* TSC timestamp */ + struct timespec pl_ts; /* log entry timestamp (legacy) */ + }; enum pmclog_type pl_type; /* log entry kind */ union { /* log entry data */ struct pmclog_ev_callchain pl_cc; @@ -136,8 +139,30 @@ Field .Va pl_count contains the serial number of this event. Field +.Va pl_tsc +carries the raw CPU Time Stamp Counter (TSC) value recorded at the time +of the event. +This is not a wall-clock time; to convert to nanoseconds divide the TSC +delta between two events by the TSC frequency +.Pq Va pl_u.pl_i.pl_tsc_freq +reported in the +.Dv PMCLOG_TYPE_INITIALIZE +record. +The legacy .Va pl_ts -contains a timestamp with the system time when the event occurred. +member aliases the same storage for ABI compatibility, but its contents +no longer represent a wall-clock timestamp. +.Pp +Note that TSC-based timestamps and +.Va pl_u.pl_i.pl_tsc_freq +are only meaningful on x86 architectures +.Pq amd64 and i386 . +On all other architectures +.Pq including arm64 and powerpc , +.Va pl_tsc +and +.Va pl_u.pl_i.pl_tsc_freq +are set to zero. Field .Va pl_type denotes the kind of the event returned in argument diff --git a/lib/libpmc/pmclog.c b/lib/libpmc/pmclog.c index 22ff50b10ee0..c3587af46c7b 100644 --- a/lib/libpmc/pmclog.c +++ b/lib/libpmc/pmclog.c @@ -287,8 +287,8 @@ pmclog_get_event(void *cookie, char **data, ssize_t *len, return -1; } - /* copy out the time stamp */ - ev->pl_ts.tv_sec = ph->pl_tsc; + /* copy out the TSC from the event header */ + ev->pl_tsc = ph->pl_tsc; le += sizeof(*ph)/4; evlen = PMCLOG_HEADER_TO_LENGTH(h); diff --git a/lib/libpmc/pmclog.h b/lib/libpmc/pmclog.h index 72e73e3928d2..a79d33529890 100644 --- a/lib/libpmc/pmclog.h +++ b/lib/libpmc/pmclog.h @@ -169,7 +169,10 @@ struct pmclog_ev { enum pmclog_state pl_state; /* state after 'get_event()' */ off_t pl_offset; /* byte offset in stream */ size_t pl_count; /* count of records so far */ - struct timespec pl_ts; /* log entry timestamp */ + union { + uint64_t pl_tsc; /* TSC timestamp */ + struct timespec pl_ts; /* log entry timestamp (legacy) */ + }; enum pmclog_type pl_type; /* type of log entry */ void *pl_data; int pl_len; @@ -229,4 +232,3 @@ void pmclog_close(void *_cookie); __END_DECLS #endif -