Skip to content

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] [Intel] Intel: Backport GNR/SRF PMU uncore support to kernel v6.6#826

Merged
opsiff merged 2 commits into
deepin-community:linux-6.6.yfrom
Avenger-285714:linux-6.6.y
Jun 1, 2025
Merged

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] [Intel] Intel: Backport GNR/SRF PMU uncore support to kernel v6.6#826
opsiff merged 2 commits into
deepin-community:linux-6.6.yfrom
Avenger-285714:linux-6.6.y

Conversation

@Avenger-285714
Copy link
Copy Markdown
Member

@Avenger-285714 Avenger-285714 commented Jun 1, 2025

Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=8008

To support platform specific uncore PMU events for next Intel Xeon platforms Granite Rapids(GNR) and Sierra Forest(SRF), below upstream commits from v6.8-rc1 should be backported to kernel v6.6:
388d761 perf/x86/intel/uncore: Support IIO free-running counters on GNR
b560e0c perf/x86/uncore: Use u64 to replace unsigned for the uncore offsets array

Backported patches are identical with upstream version.

The backported patches have been verified on GNR and SRF that with this PR, uncore PMU devices with meaningful names will be available under /sys/devices/ instead of general names like uncore_type_x_y.

Link: https://gitee.com/anolis/cloud-kernel/pulls/2682

Summary by Sourcery

Backport upstream uncore PMU enhancements for Intel Granite Rapids and Sierra Forest to kernel v6.6, enabling named uncore PMU devices and support for free-running IIO counters

New Features:

  • Introduce IIO free-running counters support for Granite Rapids and Sierra Forest uncore PMU devices

Enhancements:

  • Replace unsigned integer types with u64 for MSR, PCI, MMIO, and discovery box offset arrays in intel uncore code

Kan Liang added 2 commits June 1, 2025 21:24
…rray

ANBZ: #8008

commit b560e0c upstream.

The current perf doesn't save the complete address of an uncore unit.
The complete address of each unit is calculated by the base address +
offset. The type of the base address is u64, while the type of offset is
unsigned.
In the old platforms (without the discovery table method), the base
address and offset are hard coded in the driver. Perf can always use the
lowest address as the base address. Everything works well.

In the new platforms (starting from SPR), the discovery table provides
a complete address for all uncore units. To follow the current
framework/codes, when parsing the discovery table, the complete address
of the first box is stored as a base address. The offset of the
following units is calculated by the complete address of the unit minus
the base address (the address of the first unit). On GNR, the latter
units may have a lower address compared to the first unit. So the offset
is a negative value. The upper 32 bits are lost when casting a negative
u64 to an unsigned type.

Use u64 to replace unsigned for the uncore offsets array to correct the
above case. There is no functional change.

Intel-SIG: commit b560e0c perf/x86/uncore: Use u64 to replace unsigned for the uncore offsets array
Backport GNR/SRF uncore PMU support to kernel v6.6

Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Ammy Yi <ammy.yi@intel.com>
Link: https://lore.kernel.org/r/20231117163939.2468007-2-kan.liang@linux.intel.com
[ Yunying Sun: amend commit log ]
Signed-off-by: Yunying Sun <yunying.sun@intel.com>
ANBZ: #8008

commit 388d761 upstream.

The free-running counters for IIO uncore blocks on Granite Rapids are
similar to Sapphire Rapids. The key difference is the offset of the
registers. The number of the IIO uncore blocks can also be retrieved
from the discovery table.

Intel-SIG: commit 388d761 perf/x86/intel/uncore: Support IIO free-running counters on GNR
Backport GNR/SRF uncore PMU support to kernel v6.6

Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Ammy Yi <ammy.yi@intel.com>
Link: https://lore.kernel.org/r/20231117163939.2468007-4-kan.liang@linux.intel.com
[ Yunying Sun: amend commit log ]
Signed-off-by: Yunying Sun <yunying.sun@intel.com>
@Avenger-285714 Avenger-285714 requested a review from Copilot June 1, 2025 13:31
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 1, 2025

Reviewer's Guide

Backports Intel uncore PMU support for Granite Rapids and Sierra Forest from kernel v6.8 to v6.6 by updating array types to 64-bit and wiring in IIO free-running counters for new platforms.

Sequence Diagram: Initialization Logic in gnr_uncore_cpu_init

sequenceDiagram
  participant InitFunc as gnr_uncore_cpu_init
  participant GetUncores as uncore_get_uncores
  participant GlobalUncores as uncore_msr_uncores (global var)
  participant FreeRunningGlobal as spr_uncore_iio_free_running (global var)
  participant MaxBoxesFunc as uncore_type_max_boxes

  InitFunc->>GetUncores: Call(UNCORE_ACCESS_MSR, UNCORE_SPR_MSR_EXTRA_UNCORES, spr_msr_uncores, UNCORE_GNR_NUM_UNCORE_TYPES, gnr_uncores)
  GetUncores-->>InitFunc: uncore_data
  InitFunc->>GlobalUncores: uncore_msr_uncores = uncore_data
  InitFunc->>MaxBoxesFunc: Call(uncore_msr_uncores, UNCORE_SPR_IIO)
  MaxBoxesFunc-->>InitFunc: num_boxes
  InitFunc->>FreeRunningGlobal: .num_boxes = num_boxes
  InitFunc->>FreeRunningGlobal: .freerunning = gnr_iio_freerunning (new static array)
Loading

Class Diagram: Updated Kernel Structures for Uncore PMU Data Types

classDiagram
  class intel_uncore_type {
    +u64* msr_offsets (changed from unsigned*)
    +u64* pci_offsets (changed from unsigned*)
    +u64* mmio_offsets (changed from unsigned*)
    %% Other members omitted for brevity
  }

  class intel_uncore_discovery_type {
    +u64* box_offset (changed from unsigned int*)
    %% Other members omitted for brevity
  }
Loading

Class Diagram: New and Updated Data Structures for GNR/SRF PMU

classDiagram
  class freerunning_counters {
    <<New Struct>>
    +u64 reg_off
    +u8 event
    +u8 umask
    +u8 num_ctrs
    +u8 bit_width
  }

  class gnr_iio_freerunning {
    <<New Static Array>>
    +type: freerunning_counters[]
  }
  gnr_iio_freerunning "1" o-- "0..*" freerunning_counters : elements are

  class icx_cha_msr_offsets {
    <<Updated Static Array>>
    +type: u64[] (changed from unsigned[])
  }

  class icx_msr_offsets {
    <<Updated Static Array>>
    +type: u64[] (changed from unsigned[])
  }

  class spr_upi_pci_offsets {
    <<Updated Static Array>>
    +type: u64[] (changed from unsigned int[])
  }

  class nhmex_cbox_msr_offsets {
    <<Updated Static Array>>
    +type: u64[] (changed from unsigned[])
  }
Loading

File-Level Changes

Change Details Files
Migrate all uncore offset arrays to 64-bit
  • Convert static offset arrays from unsigned/int to u64
  • Update uncore.h union members to use u64 pointers
  • Adjust kcalloc allocations for u64 box_offset
arch/x86/events/intel/uncore_snbep.c
arch/x86/events/intel/uncore.h
arch/x86/events/intel/uncore_discovery.c
arch/x86/events/intel/uncore_discovery.h
arch/x86/events/intel/uncore_nhmex.c
Add IIO free-running counters for GNR/SRF
  • Introduce gnr_iio_freerunning counter definitions
  • Modify gnr_uncore_cpu_init to configure freerunning tables
  • Pass extra MSR uncores flag into uncore_get_uncores
arch/x86/events/intel/uncore_snbep.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

代码审查意见:

  1. uncore.h文件中,将unsigned类型改为u64类型,这可能是为了处理64位系统上的地址偏移。但是,需要确保所有使用这些偏移的代码都已经更新为处理64位值,并且没有引入任何潜在的溢出问题。

  2. uncore_discovery.c文件中,kcalloc函数的调用中,将unsigned int改为u64,这同样是为了处理64位系统上的地址偏移。需要检查所有相关的代码,确保这一改动不会导致逻辑错误。

  3. uncore_discovery.h文件中,将unsigned int改为u64,这同样是为了处理64位系统上的地址偏移。需要检查所有相关的代码,确保这一改动不会导致逻辑错误。

  4. uncore_nhmex.cuncore_snbep.cgnr_uncores.c文件中,将unsigned类型改为u64,这可能是为了处理64位系统上的地址偏移。需要检查所有相关的代码,确保这一改动不会导致逻辑错误。

  5. gnr_uncore_cpu_init函数中,添加了对spr_uncore_iio_free_running的初始化,这可能是为了支持新的64位地址偏移。需要确保这一改动不会导致逻辑错误,并且相关的数据结构已经正确初始化。

  6. 代码中没有明显的语法错误或逻辑错误,但是需要确保所有的改动都已经经过充分的测试,并且不会对现有的功能产生负面影响。

  7. 代码风格和格式需要保持一致,例如在uncore_nhmex.cuncore_snbep.c文件中,static unsignedstatic u64的声明应该保持一致的缩进和格式。

  8. 代码注释应该更加详细,特别是在处理64位地址偏移的地方,应该解释为什么需要使用u64类型,以及这一改动对整个系统的影响。

  9. 需要确保所有的改动都已经通过了代码审查流程,并且得到了适当的批准。

  10. 需要确保所有的改动都已经记录在代码的提交信息中,以便其他开发者了解这一改动的背景和目的。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from avenger-285714. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR backports upstream commits to add Granite Rapids (GNR) and Sierra Forest (SRF) uncore PMU support on kernel v6.6 by replacing 32-bit offset arrays with 64-bit types and registering new free-running I/O counters.

  • Replace all uncore MSR/PCI/MMIO offset arrays from unsigned to u64
  • Add GNR IIO free-running counter definitions and initialize them in gnr_uncore_cpu_init()
  • Update discovery tables to handle 64-bit box offsets

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
arch/x86/events/intel/uncore_snbep.c Switched ICX/SR offsets to u64 and added GNR IIO counters
arch/x86/events/intel/uncore_nhmex.c Switched NHMEX CBOX offsets to u64
arch/x86/events/intel/uncore_discovery.h Changed box_offset member to u64 *
arch/x86/events/intel/uncore_discovery.c Updated allocation of box_offset to use u64 size
arch/x86/events/intel/uncore.h Updated union offset pointers to u64 *
Comments suppressed due to low confidence (3)

arch/x86/events/intel/uncore_discovery.h:128

  • [nitpick] Field name box_offset suggests a single offset, but it represents an array; consider renaming it to box_offsets for clarity.
u64		*box_offset;	/* Box offset */

arch/x86/events/intel/uncore_nhmex.c:309

  • [nitpick] Comment refers to "msr offset" in singular; update to "msr offsets" to reflect that it's an array of offsets.
/* msr offset for each instance of cbox */

arch/x86/events/intel/uncore_snbep.c:6573

  • New GNR IIO free-running counters have been added without corresponding tests; consider adding unit or integration tests to validate registration and event reporting.
static struct freerunning_counters gnr_iio_freerunning[] = {

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Avenger-285714 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@opsiff opsiff merged commit 1d7e454 into deepin-community:linux-6.6.y Jun 1, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants