From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796441670; b=t/WG8SQNct61woyfyFxPMJWo+TSd0mKFfwtKUunfxz+45XwAc78IBab8zEfgI35LljO0 b4LnNJY1cli0rj7AjlbT2MIQbpszePp/qQ0vw8xjsuryty3+k+Fj3XcyZq0agr91/VAud aT2U3DALKIa73cRAuFaevDGBAwB0DkEIDbnTxthjgZDmXC1dQ86P0xDoJyX5V4h2GsA6f Yk6vyKwLqFK41IV8oPHLuYOGkO4c9OhjJeHK96xb3NWWx0U66134LOvczeIKIVv7zCc/q FU+sU+6yd0vE8CQg6DrghaBzvlUVKJsqaAb615YQfYc6XrRSl+5wgSThOmkrznmrdhA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796441670; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=IbWx8/qXnYSKAMTSKBz7rOTCiJylfAfzb981IsyPJHE=; b=FTZ2UgkUEjWLvkOTcRb2vzHjO0ikJ8Nj+l2jxqtRjOBAU/pBHQgqikh8O8ooD64m5/xo tNmUfF7dmRuonlk3AL1eHa20GNAFILfXtxv+Iaw2eM5nLtUkUrlNoLJJjy8tDoYvHp+vw l8eL5IqW1eUK8zogDbgivlORAz7B3YgVKqVu3WXPIzgqWDFca3eSDJQrZAqMdSBMZqJzf 93qybmXBchrl8Wl34dmBm95Hio2sUrHZkReYHUtq1Gb5yWJ1JkK2H1G0sJ/QwzsKqwoMk jqmeqZP6K9ZnxagjVXuiOpfkDDCqk6iCIKJfzditGOwVHgSaD/qnIAI3lvLAoF4njFg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=cSK671KQ; arc=none smtp.remote-ip=192.198.163.17 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43D81606A695; Sat, 5 Dec 2026 03:34:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 43D81606A695 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=cSK671KQ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796441671; x=1827977671; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IbWx8/qXnYSKAMTSKBz7rOTCiJylfAfzb981IsyPJHE=; b=cSK671KQQF55j2CH9VFGbkDAbyPtoOBOjnZ0XEQfUPKpQW5aNK8Qq2QG hJlMQoQX71ca0qD3mRVqMkUEMR+kBsMcF+d3JYfEYVbd+iIw0JrSrquxD 8/z6vvkcDcryOaiXBPnJ2UwId/NNlob6IRBzVdFGKfEUVB7+c3UPOzAXr nq3ELbrujg9L/4H2wps1wheiZR7vMut1XGcNggYXf35Cwpm307+Gwj/yh HTCQ1aOYGNTln4k1fkDSMPLj8qIiq8uc2fgqB1h9qbpf06R800pkyM5Kv bcpJuBR2jIvE0GxyPy4vD6Fcq4YaRXe8tYT9Hiy+oY10kZuC/Kk6W3TYa Q==; X-CSE-ConnectionGUID: n551eeh4TIiU7WYs1zHYhg== X-CSE-MsgGUID: prU7uqNiTnO6znK/8JMfvQ== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5439722" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5439722" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 19:34:29 -0800 X-CSE-ConnectionGUID: BI6dBLRoQFWRrjacSWgMlg== X-CSE-MsgGUID: HExq3sVgRkurmxQR2TjdLw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14787698" Received: from 9cc2c43eec6b.jf.intel.com ([10.54.77.29]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 19:34:29 -0800 From: Zide Chen To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Adrian Hunter , Alexander Shishkin , Andi Kleen , Eranian Stephane Cc: Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dapeng Mi , Zide Chen Subject: [PATCH 07/12] perf/x86/intel/uncore: Program upper dword in generic ops Date: Fri, 4 Dec 2026 20:22:48 -0700 Message-ID: <20261205032253.258646-8-zide.chen@intel.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261205032253.258646-1-zide.chen@intel.com> References: <20261205032253.258646-1-zide.chen@intel.com> X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Generic MMIO and PCI {enable,disable}_event() callbacks only write to the lower 32 bits of counter control registers, forcing extra custom ops to write to the upper 32 bits for types that support 64-bit registers. Add uncore_box_has_ext_event_ctl() to check whether a box supports upper control dwords: event_mask_ext indicates that the type supports it, while ctl_offs8 serves as a safety guard against clobbering neighboring registers on 4-byte stride units. Add uncore_{pci,mmio}_{write,clear}_event_ctl() helpers and use them in the generic PCI and MMIO ops to safely write and clear the upper 32 bits. This allows custom ops like spr_uncore_pci_ops to be dropped, and 64-bit control registers to be handled in a generic way for any type that sets both ctl_offs8 and event_mask_ext. Signed-off-by: Zide Chen --- arch/x86/events/intel/uncore.h | 46 ++++++++++++++++++++++++ arch/x86/events/intel/uncore_discovery.c | 14 +++----- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index c88949387b7c..449512cab817 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -338,6 +338,52 @@ unsigned uncore_pci_perf_ctr(struct intel_uncore_box *box, int idx) return idx * 8 + box->pmu->type->perf_ctr; } +static inline bool uncore_box_has_ext_event_ctl(struct intel_uncore_box *box) +{ + return box->pmu->type->ctl_offs8 && box->pmu->type->event_mask_ext; +} + +static inline void uncore_pci_write_event_ctl(struct intel_uncore_box *box, + struct hw_perf_event *hwc, u64 config) +{ + /* Upper dword first so the counter does not use stale filters. */ + if (uncore_box_has_ext_event_ctl(box)) + pci_write_config_dword(box->pci_dev, hwc->config_base + 4, + upper_32_bits(config)); + pci_write_config_dword(box->pci_dev, hwc->config_base, + lower_32_bits(config)); +} + +static inline void uncore_pci_clear_event_ctl(struct intel_uncore_box *box, + struct hw_perf_event *hwc) +{ + /* Stop the counter before clearing upper dword filters. */ + pci_write_config_dword(box->pci_dev, hwc->config_base, 0); + if (uncore_box_has_ext_event_ctl(box)) + pci_write_config_dword(box->pci_dev, hwc->config_base + 4, 0); +} + +static inline void uncore_mmio_write_event_ctl(struct intel_uncore_box *box, + struct hw_perf_event *hwc, u64 config) +{ + /* Upper dword first so the counter does not use stale filters. */ + if (uncore_box_has_ext_event_ctl(box)) + writel(upper_32_bits(config), + box->io_addr + hwc->config_base + 4); + writel(lower_32_bits(config), box->io_addr + hwc->config_base); +} + +static inline void uncore_mmio_clear_event_ctl(struct intel_uncore_box *box, + struct hw_perf_event *hwc) +{ + /* Stop the counter before clearing upper dword filters. */ + writel(0, box->io_addr + hwc->config_base); + + /* Fixed counter controls are 32-bit with no upper dword filters. */ + if (!uncore_pmc_fixed(hwc->idx) && uncore_box_has_ext_event_ctl(box)) + writel(0, box->io_addr + hwc->config_base + 4); +} + static inline unsigned uncore_msr_box_offset(struct intel_uncore_box *box) { struct intel_uncore_pmu *pmu = box->pmu; diff --git a/arch/x86/events/intel/uncore_discovery.c b/arch/x86/events/intel/uncore_discovery.c index 979d3da466e3..07df52e2e265 100644 --- a/arch/x86/events/intel/uncore_discovery.c +++ b/arch/x86/events/intel/uncore_discovery.c @@ -609,19 +609,15 @@ void intel_generic_uncore_pci_enable_box(struct intel_uncore_box *box) static void intel_generic_uncore_pci_enable_event(struct intel_uncore_box *box, struct perf_event *event) { - struct pci_dev *pdev = box->pci_dev; struct hw_perf_event *hwc = &event->hw; - pci_write_config_dword(pdev, hwc->config_base, hwc->config); + uncore_pci_write_event_ctl(box, hwc, hwc->config); } void intel_generic_uncore_pci_disable_event(struct intel_uncore_box *box, struct perf_event *event) { - struct pci_dev *pdev = box->pci_dev; - struct hw_perf_event *hwc = &event->hw; - - pci_write_config_dword(pdev, hwc->config_base, 0); + uncore_pci_clear_event_ctl(box, &event->hw); } u64 intel_generic_uncore_pci_read_counter(struct intel_uncore_box *box, @@ -708,18 +704,16 @@ void intel_generic_uncore_mmio_enable_event(struct intel_uncore_box *box, return; } - writel(hwc->config, box->io_addr + hwc->config_base); + uncore_mmio_write_event_ctl(box, hwc, hwc->config); } void intel_generic_uncore_mmio_disable_event(struct intel_uncore_box *box, struct perf_event *event) { - struct hw_perf_event *hwc = &event->hw; - if (!box->io_addr) return; - writel(0, box->io_addr + hwc->config_base); + uncore_mmio_clear_event_ctl(box, &event->hw); } static struct intel_uncore_ops generic_uncore_mmio_ops = { -- 2.56.1