From patchwork Fri Jun 26 11:33:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Claudiu Zissulescu Ianculescu X-Patchwork-Id: 137868 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ABB1F4BA799F for ; Fri, 26 Jun 2026 11:39:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABB1F4BA799F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=W49GKw1x X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id C19AA4BA7990 for ; Fri, 26 Jun 2026 11:38:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C19AA4BA7990 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C19AA4BA7990 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782473933; cv=none; b=LgMka8nLcMpVX9AYofj7d//HI7eMmfiPeD8LHl8qWEdsZ6+rD8S0z1d5Vboe/52DOvmNrAsnbt0YIXKQWx3xabBW1Yl6jHRk4xArt+imEabWHciBg7PBOqVOKQGOp42PtC8bEQmX/ZqxPkTXy8LlywdNAJm4JF1A1iQ4QA0cgl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782473933; c=relaxed/simple; bh=huZYXXM8hdhUL7AM3i5rJSIfUec64HNkVJeq13/gn3k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=h18GVL3A50p5VnfNIy1W9wRC7Ge0VYfaeApgm63rRF7V80+ZkzZXjaHd8/4oQ3VV8oOMC/Z96DIW2j03xXPxqjDyyTkSjupfjudmiw0dHHCrUGk7QfbhuYrGhgR2mE4W+XJbLTB3Bllo0jcnufkROG+3y6QF1goYNtVwefLu9f0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=W49GKw1x DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C19AA4BA7990 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-490bc6a7958so14436645e9.1 for ; Fri, 26 Jun 2026 04:38:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782473932; x=1783078732; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=csThuCkUiqL7Xh0IMVDR1ezQzDfmSq5SBH+SRdPYoMg=; b=W49GKw1xSBCMNs1p2doxbsaRwAFQQABdiweGTQR4ruSQcfAfz3lC1lrmvpHAjUVhrq DxsLNNzGootgJcFx2OKebmOUrBVz/7RKIla8hRR5Mc1RrzabeTHExRPDtjsDH+CWOurU Ay1N/2LQC0j5BwLJuqnh7Q3AfLFgt0SfwXlI9rMCSqqW5qtd4AV9me7DGMKlQrF9uyth p0e6ENy+jzWk17nkSUU705y0q7O02JtHKB5ffAFl4roeGDQTPgCfFrTkOE9VBJBkfjrr JCowYlaiCQF6rqDuv4jc2E8PWJRrOxy9DxlMYK+LH5TrU8p2AtgyFrtfDp+Oa+iFUuJY J65w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473932; x=1783078732; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=csThuCkUiqL7Xh0IMVDR1ezQzDfmSq5SBH+SRdPYoMg=; b=WAwJzYniYZ0WKZoZJwIsrMSO8gBC056jWU5UzCcVuIvQz53yTl4cYgq1MZj0bed75w pLONqJCGuwQlmtm3gdsauikcWCOWElRt97NpRJD4xU3472LG1cjZ57U7yK1WT8wAFImF Q61v3stkrKsSWVnQGnZwbSlXVdIkl15/pUgVh8ERcTVVEVelUJjGOPj/KX/Hlc07dYel oWMmr4osCBnIGUs7uZhH4inHFBkkJWE5dv9DMUCIZyycaTHSO6qHw2a6wv1rwpO9OppL n0eCY5OkeEHKw3daGczl2a3GoiTl+5E7joV0qhwWuZGswDyuSzc2QVCzl79fHASRjINb ME2g== X-Gm-Message-State: AOJu0YxgUF48VpV/r9Vk6lQ0q+9sAUhv2YD/a0hs1eWwd7zjgbRsGPNX du5ScfAVzer7/cZv0JzY55M3rprYGQdHvUP1r+OBwwkFFib1M9NffbHvjCgrYV6q X-Gm-Gg: AfdE7cnT5h2pFMoNzGEYeENK7ieXCdct9KiRV4w902uP6U4y8HgunTHXUROmc6PimrX Ski2QA5Du7QPxBgQEOKt0sWb6q3OCoWSNs6PnoIsmHtI2y8B1jOkCdNY9LdKMs+z/hdLbzimo3b zdv9O/dCOMNZudBtOl9B1CYBgb1gHDPZFjn/hjInQLkWmkdNBZrkH3JlPD1CPconJs08oo0tmu3 Y9zm3XMmKclLFakPzf9y3T0g8QFXAeUuOa4HfQcF+AOIL4u040Kj7mg/QJR3FSncLKY7qPn8gDf tB9l86ZKjSqbrt1JUzsXNw5rCoVaPMpeVXgTc9bXCPuj/s/3+L4Mfql1b9MzfJx5jnekbazGiLy w1uL1iZkrCZu4VQzgmofv86JBJV3bbh3dwjtJ/b+zr54TvBBphOXwUr4YufyR93QSBq3DT7IHiB Do3h7SaxY85Qo= X-Received: by 2002:a05:600c:4e8e:b0:492:4a1a:a96a with SMTP id 5b1f17b1804b1-4926641b68fmr80200245e9.11.1782473931450; Fri, 26 Jun 2026 04:38:51 -0700 (PDT) Received: from fedora ([5.12.139.217]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492690a1a85sm124466935e9.15.2026.06.26.04.38.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:38:50 -0700 (PDT) From: Claudiu Zissulescu To: binutils@sourceware.org Cc: jemarch@gnu.org, simone_maione@yahoo.com Subject: [PATCH 1/4] gprofng: group precise vs. non-precise HW counters Date: Fri, 26 Jun 2026 14:33:19 +0300 Message-ID: <20260626113840.44715-2-claziss@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260626113840.44715-1-claziss@gmail.com> References: <20260626113840.44715-1-claziss@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org The -h listing prints all available HW counters in a single, undifferentiated block. In that view, "type" column shows "memoryspace" for PEBS/IBS events. Users can't tell from listing alone that "memoryspace" means precise sample attribution, while other event types may attribute samples slightly "late". This mismatch is the most common source of confusion when reading source-view reports. To make this clearer, split the "std-ctrs" and "raw-ctrs" listings into two sub-sections each ("Precise events" and "Standard events"), and append "(precise)" to the type label for ABST_EXACT / ABST_EXACT_PEBS_PLUS1 counters. This change is only a reordering of existing entries—no counters are added, removed, or renamed. gprofng/ * common/hwctable.c (hwc_memop_string): Tag ABST_EXACT and ABST_EXACT_PEBS_PLUS1 as precise. (hwc_usage_internal): Emit std and raw counter lists in two passes: precise events and standard events. --- gprofng/common/hwctable.c | 78 ++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/gprofng/common/hwctable.c b/gprofng/common/hwctable.c index 52b28f21dc5..cb8a5e43763 100644 --- a/gprofng/common/hwctable.c +++ b/gprofng/common/hwctable.c @@ -2946,7 +2946,7 @@ hwc_memop_string (ABST_type memop) break; case ABST_EXACT_PEBS_PLUS1: case ABST_EXACT: - s = GTXT ("memoryspace "); + s = GTXT ("memoryspace (precise) "); break; case ABST_COUNT: s = GTXT ("count "); @@ -3656,31 +3656,83 @@ hwc_usage_internal (int forKernel, FILE *f_usage, const char *cmd, const char *d /* long listings */ char tmp[1024]; + /* Counters whose memop is ABST_EXACT or ABST_EXACT_PEBS_PLUS1 deliver + precise PC attribution (IBS on AMD, PEBS on Intel). All others can + skid forward by several instructions, which is the single most common + source of user confusion when reading source-view reports. Group the + listing so the precise events are visible and labeled. */ +#define HWC_IS_PRECISE(ctr) \ + (HWCENTRY_USES_SAMPLING (ctr) || (ctr)->memop == ABST_EXACT) + if (has_std_ctrs) { - fprintf (f_usage, GTXT ("\nAliases for most useful HW counters:\n\n")); - format_columns (tmp, 1024, "alias", "raw name", "type ", "units", "description"); - fprintf (f_usage, NTXT (" %s\n\n"), tmp); + int n_precise = 0; for (Hwcentry **pctr = std_ctrs; *pctr; pctr++) + if (HWC_IS_PRECISE (*pctr)) + n_precise++; + + fprintf (f_usage, GTXT ("\nAliases for most useful HW counters:\n")); + if (n_precise) { - Hwcentry *ctr = *pctr; - hwc_hwcentry_string_internal (tmp, sizeof (tmp), ctr, 0); - fprintf (f_usage, NTXT (" %s\n"), tmp); + fprintf (f_usage, GTXT ("\n Precise events (recommended for accurate" + " instruction/line attribution):\n\n")); + format_columns (tmp, 1024, "alias", "raw name", "type ", "units", "description"); + fprintf (f_usage, NTXT (" %s\n\n"), tmp); + for (Hwcentry **pctr = std_ctrs; *pctr; pctr++) + if (HWC_IS_PRECISE (*pctr)) + { + hwc_hwcentry_string_internal (tmp, sizeof (tmp), *pctr, 0); + fprintf (f_usage, NTXT (" %s\n"), tmp); + } } + + fprintf (f_usage, GTXT ("\n Standard events (sample location may" + " skid forward several instructions):\n\n")); + format_columns (tmp, 1024, "alias", "raw name", "type ", "units", "description"); + fprintf (f_usage, NTXT (" %s\n\n"), tmp); + for (Hwcentry **pctr = std_ctrs; *pctr; pctr++) + if (!HWC_IS_PRECISE (*pctr)) + { + hwc_hwcentry_string_internal (tmp, sizeof (tmp), *pctr, 0); + fprintf (f_usage, NTXT (" %s\n"), tmp); + } } if (has_raw_ctrs) { - fprintf (f_usage, GTXT ("\nRaw HW counters:\n\n")); + int n_precise = 0; + for (Hwcentry **pctr = raw_ctrs; *pctr; pctr++) + if (HWC_IS_PRECISE (*pctr)) + n_precise++; + + fprintf (f_usage, GTXT ("\nRaw HW counters:\n")); hwc_usage_raw_overview_sparc (f_usage, cpuver); + + if (n_precise) + { + fprintf (f_usage, GTXT ("\n Precise events (recommended for accurate" + " instruction/line attribution):\n\n")); + format_columns (tmp, 1024, "name", NULL, "type ", "units", "description"); + fprintf (f_usage, NTXT (" %s\n\n"), tmp); + for (Hwcentry **pctr = raw_ctrs; *pctr; pctr++) + if (HWC_IS_PRECISE (*pctr)) + { + hwc_hwcentry_string_internal (tmp, sizeof (tmp), *pctr, show_short_desc); + fprintf (f_usage, NTXT (" %s\n"), tmp); + } + } + + fprintf (f_usage, GTXT ("\n Standard events (sample location may" + " skid forward several instructions):\n\n")); format_columns (tmp, 1024, "name", NULL, "type ", "units", "description"); fprintf (f_usage, NTXT (" %s\n\n"), tmp); for (Hwcentry **pctr = raw_ctrs; *pctr; pctr++) - { - Hwcentry *ctr = *pctr; - hwc_hwcentry_string_internal (tmp, sizeof (tmp), ctr, show_short_desc); - fprintf (f_usage, NTXT (" %s\n"), tmp); - } + if (!HWC_IS_PRECISE (*pctr)) + { + hwc_hwcentry_string_internal (tmp, sizeof (tmp), *pctr, show_short_desc); + fprintf (f_usage, NTXT (" %s\n"), tmp); + } } +#undef HWC_IS_PRECISE /* documentation notice */ hwc_get_docref (tmp, 1024); From patchwork Fri Jun 26 11:33:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Zissulescu Ianculescu X-Patchwork-Id: 137867 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B2634BA79A4 for ; Fri, 26 Jun 2026 11:39:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B2634BA79A4 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=G3Qf3Trn X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 8AD7F4BA7991 for ; Fri, 26 Jun 2026 11:38:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8AD7F4BA7991 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8AD7F4BA7991 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::433 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782473933; cv=none; b=WKBfpASkYJePuTXKfMvScYpJLmZjhjsiJbw0sitjjitVPbKKOYmr6z4A/zge48mgaoxw1y4hMiM6LM4GKA2Phv06HPVd0oWifD7saAPWs1SIFbyLOg2gMR4DTArtTRtoOgFvy3PmdNJcOkz/RrZAXm1q+i9o4oWibA0i8SSf3bU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782473933; c=relaxed/simple; bh=yUxGGu+/Ee3Ie+cfgoESQ5DVBf3LU862g9kofB7yP0g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ijKUwlKgGUweIYado1UbSombKY1TdAY/Vd0BDEpbBWoyQGG2zyCx2uCu3Qq/VSdqTWVhBKY1LmnpXIHd9Jd8rnc+N9EfHnszZ4jhUMiDtDSuS8U/ziVqXdd96fqlSh+xs49QfP2XDHrthbz4fDMCKtr2KUiC54RuTPulJoT9yQs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=G3Qf3Trn DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8AD7F4BA7991 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-46ed4f66256so674635f8f.3 for ; Fri, 26 Jun 2026 04:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782473932; x=1783078732; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q7inhLlBX8KAWeN7fib5RLMGqQ3Ox6BBecG8nAS8cNQ=; b=G3Qf3TrnBJ0r6fOmv+4d2qpo6TJWPjmyngNqFJWMsJlE/YtV8attLw/vGCFXSA4Tus XfigB0S5Di6BcL03yel2+EL+xy/IB2VFCNkvH6dz2BWc1+2IcNMWHA5GVg8dFXt2a/V/ VEYzNW+TksOWpiccZVWJODKDbRYf6sM/v2sm18kHcvAIUlZbTlKDeRd2/I4LxcQHeB8D HDTVL2DMOzWmtsS+Dbe1hlcje820c3GpcEfKYQ8F43cb9C7CO/HdiZq7ny/+ZEWtSx/I LvF3p1i976nZssMLS+KyQu/CTrluXrFPwM7V964fMPeZjUfC2ps55FffV+G4zIvKnZMG +Azw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473932; x=1783078732; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Q7inhLlBX8KAWeN7fib5RLMGqQ3Ox6BBecG8nAS8cNQ=; b=eti02p6y7WNTSW48n1aA94zAX5czKMhMc0HSqHpRTOFxrkUoEYdxQQ/yPSgbDg4A8l 77Kcj2QCOzD35QTtR78dKwSkwg7M1KqCp/85zajdQa2sz1hy60fFZ63jSdouWA2/TvrN n4sN/ARZSVFAf8fp+FWXC1uKXy0QC4WAzTz7BGNSeZjeyN0cCfc5/D9lvweFWwDLGGPy RnRofurmbXCqtVaSUCSp3rKdn+oX20UpOVCzKnu8gW+yff3Ryy7LsPyCzI3JgUOAPtxG 57jUS5KRTJBa4pJj0cq6qB+rPJIu/5kbAbJVaskOJ3h4/2j1VOq+5iqlpsd8klAnZrQy /e6g== X-Gm-Message-State: AOJu0YxhKNH5Pwd4nVx5+REBhqP7swVCe9kaAnlGDiNoyeLVRO3QbYFW 4e3Oi/o0McG/qtT+OY/e22PonNq4bAfU+TfwQhzdDrVT3j706QPCcCD753mBinWq X-Gm-Gg: AfdE7cmQnVRJFV/8ZjUWtyLGIMs0SnQBf4Ms/airDKJfazpir+XrxPdgFhBDCZh8ZEH umn9km0ahkRTDxYmhaqPE3ERtcRSxb/tTZGt3BXhV1ZmtdJkdJtCy5h9uJjY182qh3JFvCelqFp GbS+MGas/2nWQZiNyj6kaHOAxPRAAZQ1VQTYuuDqm4i2SyVgvR3N8FhTuNZaaht/1bNI6FfeO+D IbMt7ZVpyiBTFKyVHWjxZuB18FQdG6bySp++zbX5BiKg4KfdTMmwsMAJ+Y5WZsW3hBGGlZBv+yw 0okrWHRAKMBiqtP+2XYuMQTB944BWvygypoSPZU7a3uz/QOc9nxsBuykKXmxdHOFyqMQVbwrE5a x5NOZbmSJU49uF7iWn1VZjiQb3I0r+rkvRDfk/S2e0md+JcxzslimDntqNEGSYqZfJUxcQ//b4V 6s X-Received: by 2002:a05:600c:4baa:b0:489:5022:39a4 with SMTP id 5b1f17b1804b1-49266869e2cmr59877075e9.9.1782473932314; Fri, 26 Jun 2026 04:38:52 -0700 (PDT) Received: from fedora ([5.12.139.217]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492690a1a85sm124466935e9.15.2026.06.26.04.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:38:51 -0700 (PDT) From: Claudiu Zissulescu To: binutils@sourceware.org Cc: jemarch@gnu.org, simone_maione@yahoo.com Subject: [PATCH 2/4] gprofng: mark non-precise HW counter columns Date: Fri, 26 Jun 2026 14:33:20 +0300 Message-ID: <20260626113840.44715-3-claziss@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260626113840.44715-1-claziss@gmail.com> References: <20260626113840.44715-1-claziss@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, PROLO_LEO2, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org Mark the column header of any non-precise HW counter metric with "(*)" and emit a single explanatory footnote below the column header block when at least one displayed metric is non-precise. Precise PEBS/IBS events (ABST_EXACT, ABST_EXACT_PEBS_PLUS1) are left unmarked. Also point the user at the "Precise events" section of -h output. gprofng/ * src/Metric.cc (Metric::set_name): Append "*" marker. * src/Print.cc (print_label): Emit a footnote explaining the "*" marker. * src/Hist_data.cc (Hist_data::print_label): Likewise. --- gprofng/src/Hist_data.cc | 27 +++++++++++++++++++++++++++ gprofng/src/Metric.cc | 16 +++++++++++++--- gprofng/src/Print.cc | 26 ++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/gprofng/src/Hist_data.cc b/gprofng/src/Hist_data.cc index 41e3edf3ae4..8818e84f215 100644 --- a/gprofng/src/Hist_data.cc +++ b/gprofng/src/Hist_data.cc @@ -863,6 +863,33 @@ Hist_data::print_label (FILE *out_file, Metric::HistMetric *hist_metric, sb1.toFileLn (out_file); sb2.toFileLn (out_file); sb3.toFileLn (out_file); + + /* Footnote for non-precise HW counters (marked with " (*)" by + Metric::set_name). Emit once if any visible metric uses such a + counter, so users understand source-line attribution may skid. + Mirrors the equivalent block in the free print_label() in Print.cc. */ + bool any_non_precise = false; + for (int i = 0; i < nmetrics && !any_non_precise; i++) + { + Metric *m = metrics->get (i); + if (!m->is_any_visible ()) + continue; + if (m->get_type () != Metric::HWCNTR) + continue; + Hwcentry *hwc = m->get_hw_ctr (); + if (hwc != NULL + && !HWCENTRY_USES_SAMPLING (hwc) + && hwc->memop != ABST_EXACT) + any_non_precise = true; + } + if (any_non_precise) + fprintf (out_file, GTXT ( + "%*s(*) Non-precise HW event: sample location may skid forward by\n" + "%*s several instructions, so cache/branch misses are often\n" + "%*s attributed to the next basic block (e.g. a loop header).\n" + "%*s For exact line attribution, prefer precise events\n" + "%*s (see the \"Precise events\" section of `gprofng collect app -h`).\n"), + space, "", space, "", space, "", space, "", space, ""); return name_offset; } diff --git a/gprofng/src/Metric.cc b/gprofng/src/Metric.cc index a72bdaef6a3..f4264277bf9 100644 --- a/gprofng/src/Metric.cc +++ b/gprofng/src/Metric.cc @@ -306,7 +306,8 @@ Metric::set_subtype (SubType st) case HWCNTR: { char *sstr, *estr1, *estr2; - if (get_hw_ctr () == NULL) + Hwcentry *hwc = get_hw_ctr (); + if (hwc == NULL) abort (); sstr = get_username (); if (st == EXCLUSIVE) @@ -335,8 +336,17 @@ Metric::set_subtype (SubType st) get_aux (), st); estr2 = dbe_strdup (NTXT ("??")); } - name = dbe_sprintf (NTXT ("%s%s"), estr1, sstr); - abbr = dbe_sprintf (NTXT ("%s%s"), estr2, sstr); + /* Mark non-precise counters so users don't over-trust source-line + attribution. Only PEBS/EXACT events tag the retiring instruction; + everything else may skid forward by several instructions. The (*) + should be explained by a footnote at report-print time. */ + const char *mark = ""; + if ((st == EXCLUSIVE || st == INCLUSIVE || st == DATASPACE) + && !HWCENTRY_USES_SAMPLING (hwc) + && hwc->memop != ABST_EXACT) + mark = " (*)"; + name = dbe_sprintf (NTXT ("%s%s%s"), estr1, sstr, mark); + abbr = dbe_sprintf (NTXT ("%s%s%s"), estr2, sstr, mark); break; } diff --git a/gprofng/src/Print.cc b/gprofng/src/Print.cc index 564e3a638bc..8d3cef4ede4 100644 --- a/gprofng/src/Print.cc +++ b/gprofng/src/Print.cc @@ -306,6 +306,32 @@ print_label (FILE *out_file, MetricList *metrics_list, fprintf (out_file, NTXT ("%*s%s\n"), space, NTXT (""), delTrailingBlanks (line1)); fprintf (out_file, NTXT ("%*s%s\n"), space, NTXT (""), delTrailingBlanks (line2)); fprintf (out_file, NTXT ("%*s%s\n"), space, NTXT (""), delTrailingBlanks (line3)); + + /* Footnote for non-precise HW counters (marked with " (*)" by + Metric::set_name). Emit once if any visible metric uses such a + counter, so users understand source-line attribution may skid. */ + bool any_non_precise = false; + for (int i = 0, n = mlist->size (); i < n && !any_non_precise; i++) + { + Metric *m = mlist->fetch (i); + if (!(m->is_visible () || m->is_tvisible () || m->is_pvisible ())) + continue; + if (m->get_type () != Metric::HWCNTR) + continue; + Hwcentry *hwc = m->get_hw_ctr (); + if (hwc != NULL + && !HWCENTRY_USES_SAMPLING (hwc) + && hwc->memop != ABST_EXACT) + any_non_precise = true; + } + if (any_non_precise) + fprintf (out_file, GTXT ( + "%*s(*) Non-precise HW event: sample location may skid forward by\n" + "%*s several instructions, so cache/branch misses are often\n" + "%*s attributed to the next basic block (e.g. a loop header).\n" + "%*s For exact line attribution, prefer precise events\n" + "%*s (see the \"Precise events\" section of `gprofng collect app -h`).\n"), + space, "", space, "", space, "", space, "", space, ""); return name_offset; } From patchwork Fri Jun 26 11:33:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Zissulescu Ianculescu X-Patchwork-Id: 137870 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8E4E44BA799B for ; Fri, 26 Jun 2026 11:41:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E4E44BA799B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=RtG7rd8A X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id BD0AB4BA7993 for ; Fri, 26 Jun 2026 11:38:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD0AB4BA7993 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BD0AB4BA7993 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::331 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782473934; cv=none; b=rIucjA42Q2W8OAUV2cbWaJUoWI/UXAkzXK9y4wzwM8CdhXIsg5YSv4RMn0w8+4N+8Vfmn9Qejli8R//F1NEep6lMh2v2XAY2BBZQZqXW1mOye+HN58IXP7mr7xlS2cwuPiAV7ay10sKsV5DC4aBZ2SadhYFHyGsPEcz6eb8w+uo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782473934; c=relaxed/simple; bh=VmcUKwCwkORaDHjDMxoid4KqwlkaDyJEOHOiP0lWb64=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=n5Z+azYg1dZuMbHdRE2byX+zo++bPS2UI4/OzgFeNYXmwq13AnmoWeH9VSMVjKBRw04GRw5Txfg4gqL8z1hPQMyf73gxF3qf17H2Bp2aePLlN6nrBESjSz2OxNHEx1ZwLwOkVjEKNwpQvYs1AZ2nvBiNO5TFFYbizZgfVTkqKSQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=RtG7rd8A DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD0AB4BA7993 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-49258ac7294so5787765e9.0 for ; Fri, 26 Jun 2026 04:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782473934; x=1783078734; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U7ARGTKDVpVOqLyF/0GjJPVgAhqQdOY4tR0YXTLEnQ4=; b=RtG7rd8AN/PSn4MyL8Vn2UV7fFoozdMEE/xJnQaooZApzQ1yz+nlmP10INnOS8Tdfx Bq91nG/A8ivcoAzhptyuHP8KHp4tbOEAxOCvnGb8qQRTA16eXB1juC2rhfSKpFnNbuoR YWhwe8kAWDfBXBg9CHNNReLPvlqHPbgEC61e/1mFs/JbAHV4c+61Pswily+KRL/+f/Tg KRrOkInw7Suh/zYFBU+MYFhNIrUA9JVSq28Z+gPaoWqP4BIL8R6SWryAMdcTutKdhZK+ +h9VfVJ84GxYlRMPEKLsSSx6MPWR8sEQ5/KPRPP1lWu0uJW5VACzrwxavpJfUdbVo/Ct pq3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473934; x=1783078734; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=U7ARGTKDVpVOqLyF/0GjJPVgAhqQdOY4tR0YXTLEnQ4=; b=WjXTBSxxceRX0eYnG34+F2ki9iCoRCvP0AEKM0kAN707I7NaFeghDssjZykOLPIJP6 3XneLH+UGe7gEkCF/hjoNf1ClFQQqQH7Drcn8DB276zRMXow61lq/vxL2aLLw/KWxUx7 hoqPoYSkF7CFrCUa80bag9fP5YBatm8L5nJ6XDC9GLya5y1MukbHeFe25oMvZb7DvKmG ZSDU+9AtS9YAIbaA6/ca9kDZ8ihq4DllemFG2hp4gsbtV9uWS0RfmLDxNxGtT1jr/jdF Wuh4A9NQ9iC+nzkyB3QDsINqr+ClDE9y/BVTln7nSFw4ex1UPywGSFua5W5DtpGIKDJE Zokg== X-Gm-Message-State: AOJu0YzDWkLCsaVEPMqBulS/i8gpfYg3/WgaoM6lvoACt2YHDu/IkNj9 2jvvCTjezxsYrwozJLcsYR5ui7O+//h4F1Bu16fyIiNP8jocCXYW38DjqQvy4L0P X-Gm-Gg: AfdE7ck0do8FosT7jSeiNzu82DUFScyBzXydfY67hpw9sPQNMzR3WEvyRm9CZmk3rXb i2mCvT+QIfBnCU22zpVN3wbHz2ZMjURPOOBH5NmJiBzwfQ9DFeRdx/xIsrPnXy4Xwm1S7UgSRPh wWRs2J6UPBvbmUNpCx2gR1Ej2uQR/sGdVBGUIkeJkAWzFmMmX9Z84lb9iUk19gWSdtRYuQi3D/i XCdbJLaPYH0rHlcE5MsyKtfoG6g5zcDfR7laSO4HqBlet8E7Jk2Dw35oaY7SpCn0tC1mG30s4CL csIZuXCp5eLVMH1h5Efe35wtg/K1ji9dakzClad99gRjw48uS++TnMr5b6KY6SsDl1PODNJS614 mIOJ2nTtAxqwWbie58nH/GiB6DtXVUWdOT+u1n5EibGIal7+x3GHaHoCnjosgja8gQ1CL6AE78N DP X-Received: by 2002:a05:600c:e54a:20b0:492:28be:6098 with SMTP id 5b1f17b1804b1-49266864257mr65340065e9.11.1782473933337; Fri, 26 Jun 2026 04:38:53 -0700 (PDT) Received: from fedora ([5.12.139.217]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492690a1a85sm124466935e9.15.2026.06.26.04.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:38:53 -0700 (PDT) From: Claudiu Zissulescu To: binutils@sourceware.org Cc: jemarch@gnu.org, simone_maione@yahoo.com Subject: [PATCH 3/4] gprofng: testsuite coverage for HW-counter precision markings Date: Fri, 26 Jun 2026 14:33:21 +0300 Message-ID: <20260626113840.44715-4-claziss@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260626113840.44715-1-claziss@gmail.com> References: <20260626113840.44715-1-claziss@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org Add two DejaGnu tests that pin the user-facing output added by the previous two commits. hwc_listing.exp verifies that "gprofng collect app -h" groups counters into "Precise events" and "Standard events" sections, and that precise counters carry the "memoryspace (precise)" type tag. hwc_precision_marker.exp records an HW-counter experiment with the default counter set, runs "display text", and asserts that the column header marker "(*)" and the explanatory footnote. A marker without a footnote, or vice versa, is a regression. gprofng/ * testsuite/gprofng.display/hwc_listing.exp: New test. * testsuite/gprofng.display/hwc_precision_marker.exp: New test. --- .../testsuite/gprofng.display/hwc_listing.exp | 60 ++++++++++++++++ .../gprofng.display/hwc_precision_marker.exp | 72 +++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 gprofng/testsuite/gprofng.display/hwc_listing.exp create mode 100644 gprofng/testsuite/gprofng.display/hwc_precision_marker.exp diff --git a/gprofng/testsuite/gprofng.display/hwc_listing.exp b/gprofng/testsuite/gprofng.display/hwc_listing.exp new file mode 100644 index 00000000000..c70b7ea8695 --- /dev/null +++ b/gprofng/testsuite/gprofng.display/hwc_listing.exp @@ -0,0 +1,60 @@ +# Copyright (C) 2026 Free Software Foundation, Inc. +# +# This file is part of the GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. +# + +# Verify that "gprofng collect app -h" groups the available HW counters +# into a "Precise events" section and a "Standard events" section, and +# tags precise counters as "memoryspace (precise)" in the type column. +# This pins the user-facing output added to gprofng/common/hwctable.c +# so a future refactor cannot silently drop the section split. + +set gprofng $::env(GPROFNG) +set testname "hwc_listing" + +set output [run_native_host_cmd "$gprofng collect app -h"] +set out [lindex $output 1] + +if { [string first "not supported on this system" $out] >= 0 } then { + unsupported $testname + return +} + +# Standard events block is always emitted when any counter is listed. +if { [string first "Standard events" $out] < 0 } then { + send_log "missing 'Standard events' section in -h output:\n$out\n" + fail $testname + return +} + +# If any precise counters are present (type column shows "memoryspace"), +# the "(precise)" tag and the "Precise events" heading must both appear. +if { [string first "memoryspace" $out] >= 0 } then { + if { [string first "memoryspace (precise)" $out] < 0 } then { + send_log "'memoryspace' type without '(precise)' tag:\n$out\n" + fail $testname + return + } + if { [string first "Precise events" $out] < 0 } then { + send_log "missing 'Precise events' heading despite memoryspace counters:\n$out\n" + fail $testname + return + } +} + +pass $testname diff --git a/gprofng/testsuite/gprofng.display/hwc_precision_marker.exp b/gprofng/testsuite/gprofng.display/hwc_precision_marker.exp new file mode 100644 index 00000000000..0d38b7b3f83 --- /dev/null +++ b/gprofng/testsuite/gprofng.display/hwc_precision_marker.exp @@ -0,0 +1,72 @@ +# Copyright (C) 2026 Free Software Foundation, Inc. +# +# This file is part of the GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. +# + +# Verify that "display text" on an HW-counter experiment marks +# non-precise counter columns with " (*)" and emits the explanatory +# footnote. This pins the behavior introduced in gprofng/src/Metric.cc +# and gprofng/src/Print.cc that addresses the most common user +# confusion (cache misses attributed to a loop-header line because of +# PMU skid). + +global srcdir CC CLOCK_GETTIME_LINK +set gprofng $::env(GPROFNG) +set testname "hwc_precision_marker" +set tdir "tmpdir/hwc_precision_marker" + +run_native_host_cmd "mkdir -p $tdir" + +# Build and try to record with the default HW counter set. If the +# host has no PMU access the collect step will fail with a message +# containing "not supported"; treat that as unsupported, not a fail. +set output [run_native_host_cmd "cd $tdir && \ + cp $srcdir/lib/smalltest.c t.c && \ + $CC -g t.c $CLOCK_GETTIME_LINK && \ + $gprofng collect app -p off -h on -a off -O exp.er ./a.out"] +set status [lindex $output 0] +set out [lindex $output 1] +if { $status != 0 } then { + if { [string first "not supported" $out] >= 0 \ + || [string first "HW counter" $out] >= 0 \ + || [string first "perf_event" $out] >= 0 } then { + unsupported $testname + return + } + send_log "collect with -h on failed unexpectedly:\n$out\n" + fail $testname + return +} + +set output [run_native_host_cmd "$gprofng display text -functions $tdir/exp.er"] +set out [lindex $output 1] + +set have_mark [expr {[string first "(*)" $out] >= 0}] +set have_footnote [expr {[string first "Non-precise HW event:" $out] >= 0}] + +# The marker and the footnote must be consistent. Both present means a +# non-precise counter was selected and explained; both absent means the +# default set was entirely precise (rare but valid). One without the +# other is a regression. +if { $have_mark != $have_footnote } then { + send_log "marker/footnote inconsistency (mark=$have_mark footnote=$have_footnote):\n$out\n" + fail $testname + return +} + +pass $testname From patchwork Fri Jun 26 11:33:22 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Zissulescu Ianculescu X-Patchwork-Id: 137869 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 83EF34BA7990 for ; Fri, 26 Jun 2026 11:41:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83EF34BA7990 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=Bx7L9ck2 X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 735754BA799D for ; Fri, 26 Jun 2026 11:38:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 735754BA799D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 735754BA799D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782473935; cv=none; b=IntNy0OWn+qSdtC4GP+EMNuWyey9IMcCUZMDzojqQLkGB1F/H+/M44x3lzuf1eAh+voypjSlS8uUasBa9xG2DQerZgSHnoXvP/N+MyNajpvnj85WYxpoihM8Lst29xuWkAXQ95HCi9H8+IZe6Ix5aJWhxazCp7kVx0i0xZ6yu/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782473935; c=relaxed/simple; bh=JjBn/fTcybNOJeMUrnc6voQfvQm4GrlwwPNuHFVd000=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=E6CJP/GpbsbEWKn2BBYFLHHvLMTdM87h35gdTAzFxF6lG2WZ/XsZ18gdAode44qi0kEUZfHxSLKYzKm02b3Owo5DfTUCcOPcVYql6R42sRiBBzcwbgOScmMasvAWk/JpV2mvB+bNtgzk4FGYaI6esT5REIlwOHtl7Ew7oCZ6/Kc= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=Bx7L9ck2 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 735754BA799D Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-49222fb062bso8985645e9.1 for ; Fri, 26 Jun 2026 04:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782473934; x=1783078734; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ARAIWSzAfYU5PshaHOC3evglBUr/lJIyO7EPgTfugsE=; b=Bx7L9ck2EXuMq4QQ3KP4AT62MF/jskBiAEHQ4SqaGivGl4kkGpQFergdiDS3vrZZEq EJyK+BbdQFW0MKLFoeKp7EwzK3J5LbpC+bX+B6EDbBddAQ8oIqRaG+kEHMUs8qSrnBNl tbWBVgcU6G0FsU96ITWa4f7Kpnca+614KtSvlqn3y0wSwlb/w6ATuKow6SjzuMrboYOV RcsjDooWfel0pemnuFXC5ZrNcJuA+ZKGPeeeZFwUzxKXQ15PRWtG4aRb1Gte5GN7rmxq HA4w4IbAAVLQgr9vymRVPmWf5WZPqF7/pkbEyhKHMP6rIi+iJt/pVCsLX1cyaZh89hBD uoRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782473934; x=1783078734; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ARAIWSzAfYU5PshaHOC3evglBUr/lJIyO7EPgTfugsE=; b=O94dHwylCC2wahx2oPknWPXtqTkyxB4BMcce8sz4dWDPjz2y53m2m9ngTBgZyh4m9M OcVWHFcKwg4XR5mUW3FxRWMFzqlpOyi+W3meeBCm1s5wndDhxRKfUSXqOlK9G+vZlt6Y IKKrzBz6WaoouFuG33v/4mKqqz32zrSsQ1NCR4TQDI7/SDi/DB3mpkjFR3p91hwz80OE VVX4q8RmBYJq314tka3mT8BWvon4dNUHOiRkVGm04EU/vrEn3CdfSMhZr0pn7f8fa5oW /VX7U2k0qrf72UtsIF/9KCleSjtrvn45FvwKOdyEd18Fr++VkdviL49zIqvVz4BhA+8w LE5Q== X-Gm-Message-State: AOJu0YwSAaR7u7s6SCs1hLxzwc8RNHvQJhe2ni7Z4ROcnDWNrz2UF2Bw L3KH6WCmIE7prAIDGRs9HlvRCrWbxbtBD8z9jvq/3ejhVDPpho9wSdJIuJv5T2Sb X-Gm-Gg: AfdE7ck1zCos6pV3zo0WSmcXiij5ZSJcdR4LD9VLCsx9tY8KoFxVpiIS5ib+IxQ9BSW rW+2EtPnZUzs3fcxoB12/cP0exSeykPeOjZ4JjWQwDsnyW7dMUMeb5IKO7Q6yp8ZMtgkK90PfMG 6sV8XikcSxC6gfgVY4ILKVDKEAHzsvLv/ekSZ0iobdgkY1vIHCFMWLf3/bHg+Y9QiyvSkojhc/Q Vxb32m+7uH7Y8Y2FbP71rJMu1Ktl38jtukAqZxmWr+YlemACqZNGHaFyVCvljNpgvlEbkKiUhic 1XwqsFuJ2lLa+QEY5mX3ddK4E0WQbtBULea9uFoUT1yFimbKzAg53B4/131R7EZXdb0or+UksXN GogBjqoVTT9icRSsI451g9q11/6OVuxkLbeNRPcnJoghWUShLoFfKdjgV5qlRtRJTA//7ft4guX uY X-Received: by 2002:a05:600c:c059:10b0:492:433a:53af with SMTP id 5b1f17b1804b1-4926686ab79mr74622905e9.16.1782473934167; Fri, 26 Jun 2026 04:38:54 -0700 (PDT) Received: from fedora ([5.12.139.217]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492690a1a85sm124466935e9.15.2026.06.26.04.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 04:38:53 -0700 (PDT) From: Claudiu Zissulescu To: binutils@sourceware.org Cc: jemarch@gnu.org, simone_maione@yahoo.com Subject: [PATCH 4/4] gprofng: document HW-counter interface Date: Fri, 26 Jun 2026 14:33:22 +0300 Message-ID: <20260626113840.44715-5-claziss@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260626113840.44715-1-claziss@gmail.com> References: <20260626113840.44715-1-claziss@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org The existing "Inclusive and Exclusive Metrics" section explains the distinction at the function level but does not state that the same reasoning applies in source/disassembly views, where a line without a call necessarily has Excl == Incl. The "Hardware Event Counters Explained" appendix lists the limitations of HW counters but does not mention sample skid nor the distinction between precise (PEBS/IBS) and standard events. gprofng/ * doc/gprofng_ug.texi (Inclusive and Exclusive Metrics): Note that lines without function calls have identical inclusive and exclusive values in source/disassembly views. (Hardware Event Counters Explained): Add an note describing the precise/standard-event distinction. (Getting Information on the Counters Supported): Describe the Precise events/Standard events grouping. --- gprofng/doc/gprofng_ug.texi | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/gprofng/doc/gprofng_ug.texi b/gprofng/doc/gprofng_ug.texi index 97abcaec44d..88d83e77f9b 100644 --- a/gprofng/doc/gprofng_ug.texi +++ b/gprofng/doc/gprofng_ug.texi @@ -2595,6 +2595,27 @@ Raw HW counters: As can be seen, these names are not always easy to correlate to a specific event of interest. The processor manual should provide more clarity on this. +@cindex Precise event +The alias listing and the raw-counter listing are each split into two +subsections labeled ``Precise events'' and ``Standard events''. Precise +events (PEBS on Intel, IBS on AMD) tag the sample with the program counter +of the retiring instruction, and should be preferred for source-line and +instruction-level analysis. Standard events are subject to skid: the +reported program counter may be several instructions past the one that +caused the event, which most commonly shows up as counts attributed to the +control statement of a hot loop rather than to the instruction in the loop +body that actually missed. @xref{Hardware Event Counters Explained} for +more on skid and the precise/standard distinction. In the column labeled +@code{type}, precise events are tagged @code{memoryspace (precise)}, while +standard events show types such as @code{load}, @code{store}, or are left +blank when no backtracking is supported. + +When the marker @code{(*)} appears in a column header of a +@code{gprofng display text} report, it indicates that the counter feeding +that column is a standard (non-precise) event and that source-line +attribution for that column may skid. A footnote below the column header +block describes the marker and points back to this section. + @c -- A new node -------------------------------------------------------------- @node Examples Using Hardware Event Counters @subsection Examples Using Hardware Event Counters @@ -3940,6 +3961,13 @@ In case of a @emph{leaf function}, the inclusive and exclusive values for the metric are the same since by definition, it is not calling any other function(s). +The same reasoning applies in the @emph{source} and @emph{disassembly} views, +which attribute metrics to individual lines or instructions. A line that +contains no function call has no callees, so its inclusive and exclusive +values are identical. This is expected and not a defect of the report; the +two columns only diverge for lines (such as a function-call statement) whose +inclusive value rolls up the cost incurred inside the callee. + Why do we use these two different values? The inclusive metric shows the most expensive path, in terms of this metric, in the application. For example, if the metric is cache misses, the function with the highest inclusive metric @@ -4273,6 +4301,30 @@ to cover all the events of interest. The names of the events may also not be easy to interpret. In such cases, the description can be found in the architecture manual for the processor. +@cindex Skid +@cindex Precise event +@item +For most hardware events, the program counter (PC) sampled when the counter +overflows is not the PC of the instruction that actually caused the event. +The interrupt is delivered several instructions later, after the relevant +instruction has already retired. This delay is called @emph{skid} and +typically pushes the sampled PC forward, often onto the next basic block. +In a hot loop, for example, cache misses originating in the loop body may +be reported against the loop's control statement (the @code{for} or +@code{while} line at the top of the loop). When the report shows +unexpectedly high counts on a line that does little observable work, skid +is the most likely explanation; consulting the @emph{disassembly} view +will show on which individual instruction the samples actually landed. + +Some processors provide a second class of events, called @emph{precise} +events, that do not skid. On Intel processors this mechanism is called +@emph{PEBS}, and on AMD processors it is called @emph{IBS}. When precise +events are available for the metric of interest, they should be preferred +for source-line and instruction-level analysis. @ToolName{} lists precise +events in a dedicated subsection of the output of +@code{gprofng collect app -h}, separately from the skid-prone standard +events; @xref{Getting Information on the Counters Supported}. + @end itemize Despite these drawbacks, hardware event counters are extremely useful and