Skip to content

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] [Alibaba] [ARM] Support CMN700 PMU metric for Neoverse (CMN PMU metric回合6.6内核)#832

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

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] [Alibaba] [ARM] Support CMN700 PMU metric for Neoverse (CMN PMU metric回合6.6内核)#832
opsiff merged 6 commits into
deepin-community:linux-6.6.yfrom
Avenger-285714:cmn_pmu

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=8601

回合CMN700 PMU metric 到 6.6 内核。

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

deepin: Drop ("perf pmu: "Compat" supports regular expression matching identifiers") because of merged before.

Summary by Sourcery

Add CMN700 PMU metric support in perf by extending event generator, updating matching logic, and adding test coverage

New Features:

  • Add support for CMN700 uncore PMU event sys_cmn_pmu.hnf_cache_miss with EventidCode parsing

Enhancements:

  • Extend jevents tool to handle EventidCode and NodeType fields and map 'arm_cmn' unit to PMU
  • Switch metricgroup matching to regex-based pmu_uncore_identifier_match for compat ID comparison

Tests:

  • Add perf tests and PMU entries for uncore_sys_cmn_pmu0 with various event IDs

Jing Zhang added 6 commits June 2, 2025 01:52
ANBZ: #8601

commit 5440999 upstream.

The jevent "Compat" is used for uncore PMU alias or metric definitions.

The same PMU driver has different PMU identifiers due to different
hardware versions and types, but they may have some common PMU metric.
Since a Compat value can only match one identifier, when adding the
same metric to PMUs with different identifiers, each identifier needs
to be defined once, which is not streamlined enough.

So let "Compat" support using regular expression to match multiple
identifiers for uncore PMU metric.

Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Tested-by: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Shuai Xue <xueshuai@linux.alibaba.com>
Cc: Zhuo Song <zhuo.song@linux.alibaba.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-doc@vger.kernel.org
Link: https://lore.kernel.org/r/1695794391-34817-3-git-send-email-renyu.zj@linux.alibaba.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
ANBZ: #8601

commit e3e42e2 upstream.

The previous code assumes an event has either an "event=" or "config"
field at the beginning. For CMN neither of these may be present, as an
event is typically "type=xx,eventid=xxx".

So add EventidCode and NodeType to support CMN event description.

I compared pmu_event.c before and after compiling with JEVENT_ARCH=all,
they are consistent.

Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Tested-by: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Shuai Xue <xueshuai@linux.alibaba.com>
Cc: Zhuo Song <zhuo.song@linux.alibaba.com>
Cc: John Garry <john.g.garry@oracle.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-doc@vger.kernel.org
Link: https://lore.kernel.org/r/1695794391-34817-4-git-send-email-renyu.zj@linux.alibaba.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
ANBZ: #8601

commit 3bb59e7 upstream.

The perf_pmu_test_event.matching_pmu didn't work. No matter what its
value is, it does not affect the test results. So let matching_pmu be
used for matching perf_pmu_test_pmu.pmu.name.

Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Tested-by: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Shuai Xue <xueshuai@linux.alibaba.com>
Cc: Zhuo Song <zhuo.song@linux.alibaba.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-doc@vger.kernel.org
Link: https://lore.kernel.org/r/1695794391-34817-5-git-send-email-renyu.zj@linux.alibaba.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
ANBZ: #8601

commit 7fded33 upstream.

Add new event test for uncore system event which is used to verify the
functionality of "Compat" matching multiple identifiers and the new event
fields "EventidCode" and "NodeType".

Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Tested-by: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Shuai Xue <xueshuai@linux.alibaba.com>
Cc: Zhuo Song <zhuo.song@linux.alibaba.com>
Cc: John Garry <john.g.garry@oracle.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-doc@vger.kernel.org
Link: https://lore.kernel.org/r/1695794391-34817-6-git-send-email-renyu.zj@linux.alibaba.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
ANBZ: #8601

commit 0b4de7b upstream.

Currently just add aliases for part of Arm CMN PMU events which
are general and compatible for any SoC and CMN-ANY.

"Compat" value "(434|436|43c|43a).*" means it is compatible with
all CMN600/CMN650/CMN700/Ci700, which can be obtained from
commit 7819e05 ("perf/arm-cmn: Revamp model detection").

The arm-cmn PMU events got from:
[0] https://developer.arm.com/documentation/100180/0302/?lang=en
[1] https://developer.arm.com/documentation/101408/0100/?lang=en
[2] https://developer.arm.com/documentation/102308/0302/?lang=en
[3] https://developer.arm.com/documentation/101569/0300/?lang=en

Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Tested-by: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Shuai Xue <xueshuai@linux.alibaba.com>
Cc: Zhuo Song <zhuo.song@linux.alibaba.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-doc@vger.kernel.org
Link: https://lore.kernel.org/r/1695794391-34817-7-git-send-email-renyu.zj@linux.alibaba.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
ANBZ: #8601

commit 4f3ee7d upstream.

Add JSON metrics for Arm CMN. Currently just add part of CMN PMU
metrics which are general and compatible for any SoC with CMN-ANY.

Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Tested-by: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Shuai Xue <xueshuai@linux.alibaba.com>
Cc: Zhuo Song <zhuo.song@linux.alibaba.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-doc@vger.kernel.org
Link: https://lore.kernel.org/r/1695794391-34817-8-git-send-email-renyu.zj@linux.alibaba.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
@Avenger-285714 Avenger-285714 requested a review from Copilot June 1, 2025 17:56
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 1, 2025

Reviewer's Guide

Integrates CMN700 PMU metric support for ARM by extending perf tests, event generator, empty definitions, JSON descriptors, and identifier matching logic to accommodate new eventid-based uncore events.

ER Diagram: Enhanced PMU Event Definition Structure (JSON and C)

erDiagram
    JSON_EVENT_DEFINITION {
        string EventName PK
        string EventCode "Optional, hex"
        string ConfigCode "Optional, hex"
        string EventidCode "Optional, hex (New)"
        string UMask "Optional, hex"
        string NodeType "Optional, string (New)"
        string Compat "Optional, regex string"
        string Desc "Optional, string"
        string Topic "Optional, string"
        string PMU_Name "Optional, string"
        boolean Precise "Optional"
    }
    PMU_EVENT_C_STRUCT {
        string name PK
        string event_string "e.g., 'eventid=0x1,type=0x5' (New format capability)"
        string desc
        string compat
        string topic
        string pmu
    }
    JSON_EVENT_DEFINITION ||--|{ PMU_EVENT_C_STRUCT : "Defines content for"
Loading

Class Diagram: Updates to PMU Event Handling in jevents.py

classDiagram
  class EventDataInput {
    <<JSON data fields parsed by jevents.py>>
    # Existing fields: EventName, ConfigCode, EventCode etc.
    +EventidCode: any # New field expected from input JSON
    +NodeType: any # New field expected from input JSON
  }

  class JEventsPyModuleConfig {
    <<Data structures modified in jevents.py>>
    +unit_to_pmu_map: map~string, string~ # Modified: Added 'arm_cmn':'arm_cmn'
    +event_string_field_configs: list~tuple~ # Modified: Added ('NodeType', 'type=') for processing
  }
  EventDataInput --|> JEventsPyModuleConfig : Informs event processing logic and data structures
Loading

File-Level Changes

Change Details Files
Enhance perf test events for CMN uncore support
  • Adjusted existing DDR and CCN matching_pmu identifiers to include instance suffixes
  • Defined new sys_cmn_pmu_hnf_cache_miss test event with compat regex and alias fields
  • Added matching_pmu verification logic using strict name comparison
  • Populated test_pmus array with multiple CMN uncore entries covering various IDs
tools/perf/tests/pmu-events.c
Update event generator logic for CMN700 metrics
  • Mapped 'arm_cmn' unit to its PMU identifier
  • Parsed EventidCode field alongside ConfigCode for event definitions
  • Reworked event string assembly to prefer config, then eventid, then default code
  • Added NodeType handling for type field in event_fields
tools/perf/pmu-events/jevents.py
Add empty definition for CMN test event
  • Inserted static pmu_event entry for sys_cmn_pmu.hnf_cache_miss with eventid, type, compat and topic
tools/perf/pmu-events/empty-pmu-events.c
Enhance metricgroup matching for regex-compatible IDs
  • Replaced direct strcmp with pmu_uncore_identifier_match to allow regex-based matching of PMU IDs
tools/perf/util/metricgroup.c
Introduce new JSON descriptors for CMN sys events
  • Added ARM64 JSON definitions for CMN sys events and metrics under arch/arm64/arm/cmn/sys
tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json
tools/perf/pmu-events/arch/arm64/arm/cmn/sys/metric.json

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

[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

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

代码审查意见:

  1. 代码格式和风格:代码中存在一些格式问题,例如缩进不一致、逗号后缺少空格等。建议统一代码风格,以提高可读性。

  2. 事件描述和兼容性:在pmu-events文件中,每个事件的描述和兼容性信息应该更加详细,以便于理解每个事件的具体用途和适用的硬件版本。

  3. 重复代码:在jevents.py文件中,unit_to_pmu函数和Event类的构造函数中存在重复的代码,可以考虑将重复的代码提取出来,减少代码冗余。

  4. 兼容性检查:在metric.json文件中,每个指标的兼容性检查使用了正则表达式(434|436|43c|43a).*,这可能会导致一些不兼容的硬件版本被错误地匹配。建议使用更严格的兼容性检查,确保只有兼容的硬件版本才能使用这些指标。

  5. 单位和缩放:在metric.json文件中,有些指标的缩放单位使用了1e6,这可能会导致一些精度问题。建议使用更精确的缩放因子,例如1000000

  6. 事件ID和配置代码:在jevents.py文件中,Event类的构造函数中使用了EventidCodeConfigCode,但是没有对这两个字段进行验证,可能会导致错误的事件ID或配置代码被使用。建议添加对这两个字段的验证,确保它们是有效的。

  7. 测试用例:在pmu-events.ctests/pmu-events.c文件中,测试用例的描述和事件名称应该更加详细,以便于理解每个测试用例的目的和测试的内容。

  8. 代码注释:代码中缺少一些必要的注释,例如函数和变量的作用、复杂的逻辑处理等。建议添加更多的注释,以提高代码的可读性和可维护性。

以上是本次代码审查的主要意见,希望能够对您的代码改进有所帮助。

@Avenger-285714 Avenger-285714 requested a review from opsiff June 1, 2025 17:56
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

Adds support for ARM CMN700 uncore PMU metrics to Perf utilities and tests.

  • Extend metricgroup.c to use pmu_uncore_identifier_match for regex-based PMU ID matching
  • Introduce sys_cmn_pmu_hnf_cache_miss event in tests and JSON definitions
  • Update jevents.py to parse EventidCode/NodeType and map arm_cmn unit
  • Provide new metric definitions in tools/perf/pmu-events/arch/arm64/arm/cmn/sys/metric.json

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tools/perf/util/metricgroup.c Switch from strcmp to pmu_uncore_identifier_match
tools/perf/tests/pmu-events.c Add sys_cmn_pmu_hnf_cache_miss event and test entries
tools/perf/pmu-events/jevents.py Parse EventidCode/NodeType; add 'arm_cmn' mapping
tools/perf/pmu-events/empty-pmu-events.c Add empty PMU event for CMN700
tools/perf/pmu-events/arch/test/test_soc/sys/uncore.json Add JSON entry for hnf_cache_miss event
tools/perf/pmu-events/arch/arm64/arm/cmn/sys/metric.json New metric definitions for CMN700
tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json New event definitions for CMN700
Comments suppressed due to low confidence (2)

tools/perf/pmu-events/jevents.py:292

  • The unit-to-PMU mapping for 'arm_cmn' returns 'arm_cmn', which may not match the actual perf PMU name (e.g., 'uncore_sys_cmn_pmu'). Consider updating this mapping to the correct PMU identifier.
'arm_cmn': 'arm_cmn',

tools/perf/pmu-events/arch/arm64/arm/cmn/sys/metric.json:8

  • The 'Unit' field is set to 'arm_cmn', which may not align with other CMN PMU units (e.g., 'sys_cmn_pmu'). Verify that consumers will recognize this unit name or adjust it for consistency.
"Unit": "arm_cmn",

},
{
"MetricName": "rni_actual_read_bandwidth.all",
"BriefDescription": "This event measure the actual bandwidth that RN-I bridge sends to the interconnect.",
Copy link

Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

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

Grammar: 'This event measure' should be 'This event measures' to match subject–verb agreement.

Suggested change
"BriefDescription": "This event measure the actual bandwidth that RN-I bridge sends to the interconnect.",
"BriefDescription": "This event measures the actual bandwidth that RN-I bridge sends to the interconnect.",

Copilot uses AI. Check for mistakes.
},
{
"MetricName": "sbsx_actual_write_bandwidth.all",
"BriefDescription": "sbsx actual write bandwidth.",
Copy link

Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

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

[nitpick] Documentation could be more descriptive—consider adding an article and clarifying context (e.g., 'The SBSX actual write bandwidth for channel X').

Copilot uses AI. Check for mistakes.
.count = &matched_count,
};

if (strcmp(pmu_name, test_event.matching_pmu)) {
Copy link

Copilot AI Jun 1, 2025

Choose a reason for hiding this comment

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

[nitpick] Use an explicit comparison (strcmp(...) != 0) to make the intent of the mismatch check clearer.

Suggested change
if (strcmp(pmu_name, test_event.matching_pmu)) {
if (strcmp(pmu_name, test_event.matching_pmu) != 0) {

Copilot uses AI. Check for mistakes.
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 - here's some feedback:

  • The four nearly identical sys_cmn_pmu_hnf_cache_miss test entries could be refactored into a parameterized loop or table to reduce duplication and ease future updates.
  • Consider anchoring or refining the compat regex (e.g. adding ^/$) to prevent unintended ID matches in pmu_uncore_identifier_match.
  • Double-check that mapping 'arm_cmn' in unit_to_pmu aligns with the existing uncore naming convention (e.g. using 'uncore_arm_cmn') for consistency across target units.
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
Copy link
Copy Markdown
Member

opsiff commented Jun 2, 2025

Checkdepends:
commit 457caad
Author: Jing Zhang renyu.zj@linux.alibaba.com
Date: Thu Dec 21 14:03:13 2023 +0800

perf vendor events: Remove UTF-8 characters from cmn.json

cmn.json contains UTF-8 characters in brief description which
could break the perf build on some distros.

Fix this issue by removing the UTF-8 characters from cmn.json.

without this fix:

  $find tools/perf/pmu-events/ -name "*.json" | xargs file -i | grep -v us-ascii
  tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json:                   application/json; charset=utf-8

with it:

  $ file -i tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json
  tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json: text/plain; charset=us-ascii

Fixes: 0b4de7bdf46c5215 ("perf jevents: Add support for Arm CMN PMU aliasing")
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.com>
Signed-off-by: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Link: https://lore.kernel.org/r/1703138593-50486-1-git-send-email-renyu.zj@linux.alibaba.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

@opsiff opsiff merged commit 772921f into deepin-community:linux-6.6.y Jun 2, 2025
6 of 7 checks passed
@Avenger-285714 Avenger-285714 deleted the cmn_pmu branch June 2, 2025 05:23
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