> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 影响性能的功能

Qualcomm<sup>®</sup> Linux<sup>®</sup> 内核包含 CPU 调度器、CPU 频率调节器、动态电压和频率调节（DVFS）以及内存管理等功能。本指南提供了每项功能的概述及相关参考链接。此外，Qualcomm 使用一项称为用户空间资源管理器（URM）的功能来提升 Qualcomm Linux 的性能。

## **了解 CPU 调度器**

CPU 调度器管理 CPU 时间在 Linux 系统上运行的进程之间的分配方式。

CPU 调度器使用由 Linux 内核提供的 [An earliest eligible virtual deadline first (EEVDF) CPU scheduler for Linux](https://lwn.net/Articles/925371/)。EEVDF CPU 调度器使用 [Per-entity load tracking \[](https://lwn.net/Articles/531853/)[LWN.net](http://LWN.net)[\]](https://lwn.net/Articles/531853/) 来监控任务负载。

[利用率钳制（UCLAMP 或 util clamp）](https://docs.kernel.org/scheduler/sched-util-clamp.html)是一种帮助管理任务性能需求的调度器功能。

更多信息请参见[定制 CPU 调度器](./customize-for-performance-tuning#customize-cpu-scheduler)。

## **了解 CPU 频率调节器**

CPU 频率调节器根据任务负载调整 CPU 频率。CPU 调度器为此过程提供必要的输入。

Qualcomm Linux 使用由 Linux 内核提供的 `schedutil` 调节器。

当系统负载较重时，此调节器会提高 CPU 频率；当负载较低时则降低频率，从而确保功耗与性能之间的最佳平衡。

更多信息请参见以下内容：

* [CPU frequency and voltage scaling code in the Linux kernel](https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt)
* [配置 CPU](./configure-cpu-gpu-and-memory#configure-cpu)
* [定制 CPU 频率调节器](./customize-for-performance-tuning#customize-cpu-frequency-governor)

## **了解 DVFS 调节器**

DVFS 调节器根据系统工作负载控制 CPU 缓存（L3）、末级缓存控制器（LLCC）和 DDR 的频率。

这些调节器在工作负载高时提高频率，在工作负载低时降低频率，确保功耗与性能之间的最佳平衡。

Qualcomm Linux 为 L3 缓存支持以下两种类型的 DVFS 调节器：

* LLCC
* DDR

### **配置静态映射 DVFS 调节器**

此调节器将 CPU L3 缓存和 DDR 的频率与当前 CPU 频率对齐，以平衡功耗和性能需求。

例如，如果 CPU 频率处于最大值，则 L3 缓存和 DDR 频率也必须处于最高水平。

静态映射位于源代码的 `arch/arm64/boot/dts/qcom/<target>.dtsi` 中。

有关定制选项，请参见[定制静态映射 DVFS 调节器](./customize-for-performance-tuning#customize-static-map-dvfs-governor)。

### **了解 BWMON 调节器**

带宽监控（BWMON）调节器根据测量到的从 CPU 到 LLCC 再到 DDR 的流量，动态调整 LLCC 和 DDR 的频率。

BWMON 硬件模块负责测量此流量。它在指定的采样窗口内监控内存与其他子系统之间的数据吞吐量，并利用这些信息来调节 LLCC 和 DDR 频率以满足所需带宽。

BWMON 调节器驱动位于源代码的 `drivers/soc/qcom/icc-bwmon.c` 中。

更多信息请参见以下内容：

* [\[PATCH v3 0/4\] soc/arm64: qcom: Add initial version of bwmon](https://lwn.net/ml/linux-kernel/20220531105137.110050-1-krzysztof.kozlowski@linaro.org/)
* [定制 BWMON 调节器](./customize-for-performance-tuning#customize-bwmon-governor)

## **了解用户空间资源管理器**

用户空间资源管理器（URM）是一个开源、轻量级且可扩展的框架，旨在从用户空间智能地管理和调配系统资源。

现代工作负载在服务器、计算、XR、移动和 IoT 等不同细分领域之间差异显著，每个用例都表现出不同的特征。有些工作负载需要高 CPU 频率，有些需要持续的 GPU 吞吐量，还有许多依赖高效的缓存或更高的内存带宽。同时，这些工作负载运行在能力、功耗范围和用户期望各不相同的各种硬件平台上。因此，统一的调优方法不足以满足此类环境中多样化的性能和功耗需求。

URM 通过提供以下能力来应对这些挑战：

* 支持应用级调优
* 支持用例和工作负载级调优
* 提供信号和调优 API

URM 会自动检测用例，并应用在按应用或按用例 YAML 配置文件中指定的调优参数。可以通过扩展定制用例检测。

URM 还可以修改系统行为，以高效管理间歇性工作负载。可以在特定代码段中调用 Signal API 或 Tune API，以临时提升或限制系统资源。例如，关键代码路径可以在定义的持续时间内以更高的 CPU 频率执行。URM 可高效处理来自多个客户端的并发请求。当多个请求针对同一资源时，URM 会将它们聚合，以确定并应用设备所需的最佳性能水平。

更多信息请参见 [Userspace Resource Manager](https://qualcomm.github.io/userspace-resource-manager/) 和 [Userspace Resource Manager Extensions](https://github.com/qualcomm/userspace-resource-manager-extensions/)。

## **了解内存管理**

Qualcomm Linux 所做的所有内存分配都使用 RAM。必须对 RAM 进行管理，以满足性能需求并确保应用行为流畅。下图展示了内存分区：

<div className="flex flex-col items-center gap-2">
  <img src="https://mintcdn.com/qualcomm-prod/OKFyShYzKWv2bmj8/System/Performance/media/k2l-performance/memory_partitioning.svg?fit=max&auto=format&n=OKFyShYzKWv2bmj8&q=85&s=0004eeee61529fd1b5f3b8c78ebd4c70" alt="图：内存分区" width="600" height="343" data-path="System/Performance/media/k2l-performance/memory_partitioning.svg" />

  <p className="text-sm text-gray-700">
    图：内存分区
  </p>
</div>

该图展示了同时支持 Linux 和非 Linux 环境的系统中的 RAM 分配。

* 系统 RAM 在非 Linux 组件和 Linux 组件之间进行分区。
* 非 Linux 部分包括一个标记为 Reserved 的大块，表示为非 Linux 操作分配的内存。
* Linux 部分在总内存（系统 RAM）下分为四个块：
  * 内核静态（Kernel static）
  * 内核动态（Kernel dynamic）
  * 用户空间进程（User space process）
  * 空闲内存（Free memory）

RAM 的某些部分独立于 Linux 系统进行管理。例如，调制解调器、视频和音频等固件运行在这些特定的 RAM 分区中。Linux 内核管理所有其他 RAM 分区。

Linux 内核拥有自己的内存管理子系统，其中包括：

* 虚拟内存和按需分页的实现
* 为内核内部结构和用户空间程序分配内存
* 将文件映射到进程的地址空间
* 其他内存管理操作

### **配置 RAM 内存分区**

下表描述了各种类型的内存分配。

<Note>
  下表中指定的命令应在设备上运行。
</Note>

**表：RAM 分类**

| RAM 分类        | 内存段  | 分配类型            | 说明                                                                                                                                                                                                                        |                                                                                                      |
| ------------- | ---- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| 非 Linux       | 无    | 无               | 内存由 Linux 之外的各个子系统以 carveout 形式保留。这些 carveout 在相应的 DTSI 文件中指定。                                                                                                                                                            |                                                                                                      |
| Linux（系统 RAM） | 内核静态 | Vmlinux + 内核页结构 | 内核在启动时为自身使用保留此内存。**Vmlinux** 是用于存储 vmlinux 镜像的内存。vmlinux 镜像的大小和明细可在启动时从 `dmesg` 日志中获取。内核页结构内存按**每 GB RAM 大小 16 MB** 计算。                                                                                                   |                                                                                                      |
| Linux（系统 RAM） | 内核动态 | Slab            | 内核使用 slab 来更快、更高效地使用常用数据结构的内存。<br /><br />**检查 slab 使用情况：**<br />\`\`\`text cat /proc/meminfo                                                                                                                             | grep -i slab `<br />**详细 slab 信息：**启用`CONFIG\_SLUB\_DEBUG` 并运行：<br />`text cat /proc/slabinfo \`\`\` |
| Linux（系统 RAM） | 内核动态 | 内核栈             | 内核栈存储每个进程的调用栈。<br /><br />**检查内核栈使用情况：**<br />\`\`\`text cat /proc/meminfo                                                                                                                                                | grep -i kernelstack \`\`\`                                                                           |
| Linux（系统 RAM） | 内核动态 | PageTables      | 内核使用内存来存储将虚拟地址映射到物理地址的 PageTables。<br /><br />**检查 PageTables 使用情况：**<br />\`\`\`text cat /proc/meminfo                                                                                                                   | grep -i PageTables \`\`\`                                                                            |
| Linux（系统 RAM） | 内核动态 | 模块              | 表示以内核模块形式动态加载的内核实体。<br /><br />**列出已加载的内核模块：**<br />`text cat /proc/modules `                                                                                                                                             |                                                                                                      |
| Linux（系统 RAM） | 内核动态 | Vmalloc         | 用于分配连续内存。<br /><br />**检查 Vmalloc 明细：**<br />`text cat /proc/vmallocinfo `                                                                                                                                                |                                                                                                      |
| Linux（系统 RAM） | 内核动态 | 缓存（内核 + 用户空间）   | 驻留在 RAM 中的文件后备内存量。<br /><br />**检查缓存内存使用情况：**<br />\`\`\`text cat /proc/meminfo                                                                                                                                           | grep -i cached \`\`\`                                                                                |
| Linux（系统 RAM） | 内核动态 | 缓冲区             | 包含从磁盘读取或写入磁盘的信息块的固定大小缓冲区。<br /><br />**检查缓冲区内存使用情况：**<br />\`\`\`text cat /proc/meminfo                                                                                                                                   | grep -i buffers \`\`\`                                                                               |
| Linux（系统 RAM） | 内核动态 | Shmem           | 映射到两个或多个进程地址空间的共享内存。<br /><br />**检查 shmem 使用情况：**<br />\`\`\`text cat /proc/meminfo                                                                                                                                      | grep -i shmem \`\`\`                                                                                 |
| Linux（系统 RAM） | 用户空间 | ZUSED（ZRAM）     | 经 ZRAM 压缩后的匿名内存。                                                                                                                                                                                                          |                                                                                                      |
| Linux（系统 RAM） | 用户空间 | CMA             | 通常映射到视频和显示等硬件 IP 但在运行时分配的连续物理内存。只有可移动的分配（如用户空间进程分配）可以使用 CMA 空闲内存；内核分配不能使用。                                                                                                                                                |                                                                                                      |
| Linux（系统 RAM） | 用户空间 | ANON            | 用户空间应用使用 `malloc()` 或 `new()` 分配的内存。<br /><br />**检查每个进程的 ANON 使用情况：**<br />`text cat /proc/<pid>/smaps `                                                                                                                 |                                                                                                      |
| Linux（系统 RAM） | 用户空间 | ION             | 支持视频、摄像头等硬件 IP 与 Qualcomm Linux 之间的缓冲区共享。ION 管理启动时保留的内存池。<br /><br />**挂载 debugfs：**<br />`text mount -t debugfs none /sys/kernel/debug `<br />**检查 ION 缓冲区使用情况：**<br />\`\`\`text cat /sys/kernel/debug/dma\_buf/bufinfo | grep bytes \`\`\`                                                                                    |
| Linux（系统 RAM） | 用户空间 | KGSL            | 图形驱动分配的内存。<br /><br />**KGSL 整体使用情况：**<br />`text cat /sys/class/kgsl/kgsl/page_alloc `<br />**进程级明细：**<br />`text cat /sys/class/kgsl/kgsl/proc/<pid>/kernel `                                                           |                                                                                                      |
| 空闲内存          | 无    | 无               | 可用于任何分配的空闲内存。<br /><br />**检查可用内存：**<br />\`\`\`text cat /proc/meminfo                                                                                                                                                    | grep -i MemFree \`\`\`                                                                               |

## **了解实时（RT）内核**

实时系统是一种确定性系统，要求在设定的时间内对事件做出响应。

满足以下条件的系统被归类为兼容 RT：

* 不存在无界延迟。
* 可精确计算最大响应时间。
* 满足任务调度的设定标准（延迟和截止时间）。

Linux 可以配置为实时操作系统（RTOS），其中实时任务具有明确定义的周期性执行周期（周期时间），并在指定限制（抖动）内满足执行标准。

要安装补丁，请参见 [Versions of PREEMPT\_RT patches](https://wiki.linuxfoundation.org/realtime/start)。

<Note>
  实时支持面向内核空间进程，而非用户空间。
</Note>

<Note>
  本节不适用于 QCS5430。
</Note>

<div className="flex flex-col items-center gap-2">
  <img src="https://mintcdn.com/qualcomm-prod/rpHTx_a6zriKQll9/System/Performance/media/k2l-performance/RT-kernel-build-sequence.svg?fit=max&auto=format&n=rpHTx_a6zriKQll9&q=85&s=76a94ecaf7720317c891468a3b20c5c6" alt="图：构建顺序" width="1062" height="161" data-path="System/Performance/media/k2l-performance/RT-kernel-build-sequence.svg" />

  <p className="text-sm text-gray-700">图：构建顺序</p>
</div>

### **设置工作区**

Qualcomm Linux 内核支持 LTS RT 内核（6.18.x），通过 `meta-qcom` 层中 `recipes-kernel/linux/linux-qcom-rt_6.18.bb` 文件里的 Yocto recipe 进行维护。

有关克隆工作区并获取所有 Qualcomm Linux meta 层以使用 Qualcomm RT Linux 的更多信息，请参见 [Sync](https://docs.qualcomm.com/doc/80-80022-254/topic/build_from_source_github_intro.html#sync)。

### **启用 RT 内核**

Qualcomm Linux `meta-qcom` 层支持 `linux-qcom-rt_6.18.bb` recipe，该 recipe 默认为受支持的机器获取并构建 Qualcomm Linux 内核。

`meta-qcom` 层在现有层之上应用更改。在内核构建期间，`meta-qcom` 层会根据内核版本使用 `rt.config` 启用 `PREEMPT_RT`，并允许实时配置。

<Note>
  * 对于 QLI.2.0，使用 `linux-qcom-rt_6.18.bb`。
  * 对于 `qcom-next`，使用 `linux-qcom-next-rt_git.bb`。
</Note>

有关受支持机器的更多信息，请参见[选择 MACHINE、DISTRO 和镜像](https://dragonwingdocs.qualcomm.com/Key-Documents/Yocto-Guide/build-qualcomm-linux#selecting-machine-distro-and-image)。

### **定制 RT 内核**

* 如果您为 RT 内核携带了任何更改，请按如下所示在 recipe 中维护它们：
  * 将补丁文件维护在 `recipes-kernel/linux/linux-qcom-6.18/<your_patch_file>.patch` 下
  * 将补丁文件附加到 `recipes-kernel/linux/linux-qcom-rt_6.18.bb` 文件中的 `SRC_URI`。

```text theme={null}
SRC_URI += " \
    file://<your_patch_file>.patch \
    "
```

* 要在 RT 内核上应用任何外部配置：
  * 将配置文件维护在 `recipes-kernel/linux/linux-qcom-6.18/configs/<your_config>.cfg` recipe 中。
  * 将配置文件附加到 `recipes-kernel/linux/linux-qcom-rt_6.18.bb` 文件中的 `SRC_URI`。

```text theme={null}
SRC_URI += " \
    file://configs/qcom_rt.cfg \
"
```

* 要修改内核命令行，请将命令行参数添加到 `meta-qcom/ci/base.yml` 文件中的 `KERNEL_CMDLINE_EXTRA` 变量。

```text theme={null}
KERNEL_CMDLINE_EXTRA:append = " qcom_scm.download_mode=1 <new_parameter>"
```

### **为 RT 内核配置内核设置**

RT 内核中使用可选和必需的内核配置。

要在 RT 内核中启用完全抢占，请使用 `CONFIG_PREEMPT_RT`。

`CONFIG_PREEMPT_RT` 标志作为 `linux-qcom-rt_6.18.bb` recipe 中使用的 `rt.config` 的一部分默认启用。

以下示例展示了内核配置：

```text theme={null}
zcat proc/config.gz | grep CONFIG_PREEMPT
# CONFIG_PREEMPT_NONE is not set
# CONFIG_PREEMPT_VOLUNTARY is not set
# CONFIG_PREEMPT is not set
CONFIG_PREEMPT_RT=y
```

在为 RT 任务设置亲和性时，请设置以下内核配置选项：

* `CONFIG_NO_HZ_COMMON` - 启用后，为无滴答（tickless）运行配置内核基础设施。
* `CONFIG_NO_HZ_FULL` - 启用后，配置内核以避免向只有单个可运行任务的 CPU 发送调度时钟中断。
* `CONFIG_CPUSETS` - 使用 `CONFIG_CPUSETS` 配置选项启用 `cpuset`，将 CPU 分组形成一个集合。

<div className="flex flex-col items-center gap-2">
  <img src="https://mintcdn.com/qualcomm-prod/rpHTx_a6zriKQll9/System/Performance/media/k2l-performance/compile-RT-kernel.svg?fit=max&auto=format&n=rpHTx_a6zriKQll9&q=85&s=7b49eeb849dafcc643c6c6173a059a48" alt="图：RT 内核验证" width="1059" height="196" data-path="System/Performance/media/k2l-performance/compile-RT-kernel.svg" />

  <p className="text-sm text-gray-700">图：RT 内核验证</p>
</div>

### **构建 RT 内核**

要构建 RT 内核，请运行以下命令：

1. 要确保处于 KAS shell 中，请运行以下命令：

```text theme={null}
kas shell meta-qcom/ci/qcs6490-rb3gen2-core-kit.yml:meta-qcom/ci/linux-qcom-rt-6.18.yml:meta-qcom/ci/qcom-distro-kvm.yml:meta-qcom/ci/lock.yml
```

<Note>
  `qcom-distro-kvm.yml` 配置仅在 QLI 2.0 中与 KVM 一起受支持。RT 内核（`PREEMPT_RT`）与虚拟机管理程序（hypervisor）无关。KVM 被选为 QLI 2.0 的默认虚拟机管理程序，原因如下：

  * **上游社区支持** — KVM 及其驱动是主线 Linux 内核的一部分，可实现更广泛的生态系统贡献和长期支持。
  * **标准 VirtIO 支持** — KVM 支持所有上游 VirtIO 设备，并兼容 QEMU 等标准 VMM。
  * **开放开发** — 活跃的上游社区，开发者熟悉度更高。
</Note>

kas 构建命令会自动将 `xbl_config_kvm.elf` 包含在生成的 `qcomflash` 软件包中。无需手动进行 UEFI BDS 配置。

<Note>
  将 kas lock 文件从 meta-qcom-releases 复制到 meta-qcom，请参见 [Build a BSP image](https://docs.qualcomm.com/doc/80-80022-254/topic/build_from_source_github_intro.html#build-a-bsp-image)。
</Note>

2. 要编译 BitBake Qualcomm Linux 多媒体镜像，请运行以下命令：

```text theme={null}
bitbake qcom-multimedia-image
```

### **调优 RT 内核**

调优 RT 内核，以使设备中的 RT 任务获得确定性的延迟。

将运行 RT 任务的 CPU 核心设置为以最大运行频率运行，同时防止 CPU 频率的热缓解。例如，在空闲休眠场景中，RT 任务会因 CPU 唤醒时间延迟而面临调度延迟。

<Note>
  当启动 RT 测试（cyclictest）时，这些优化会由 [URM](./features-impacting-performance#understand-the-userspace-resource-manager) 自动应用。

  > 在正常运行时**不需要**手动配置。
  > 以下步骤仅供参考、调试或自定义设置使用。

  要在运行测试之前配置系统，请对 QCS6490、Qualcomm Dragonwing<sup>™</sup> IQ-9075 和 Qualcomm Dragonwing<sup>™</sup> IQ-615 开发套件执行以下操作：

  1. 禁用定时器迁移：
     ```text theme={null}
     echo 0 > /proc/sys/kernel/timer_migration
     ```
  2. 将 `/sys/devices/virtual/workqueue/*` 中的所有内核工作队列亲和到 housekeeping CPU：
     ```text theme={null}
     for wq in /sys/devices/virtual/workqueue/*; do
        [ -w "$wq/cpumask" ] && echo 7F > "$wq/cpumask"
     done
     # 7F = CPUs 0-6 (binary 0111 1111)
     ```
  3. 将 CPU 频率调节器设置为 performance：
     ```text theme={null}
     for policy in /sys/devices/system/cpu/cpufreq/policy*; do
        [ -w "$policy/scaling_governor" ] && echo performance > "$policy/scaling_governor"
     done
     ```
  4. 禁用 RT 计账/限流：
     ```text theme={null}
     echo -1 > /proc/sys/kernel/sched_rt_runtime_us
     ```
  5. 将 IRQ 亲和性设置到 housekeeping CPU：
     ```text theme={null}
     ALLOW_CPUS="0,1,2,3,4,5,6"
     cpu_list_to_mask() {
        MASK=0
        for cpu in $(echo $1 | tr ',' ' '); do
           MASK=$((MASK | (1 << cpu)))
        done
        printf "%x\n" "$MASK"
     }
     MASK=$(cpu_list_to_mask "$ALLOW_CPUS")
     echo "Setting IRQ affinity to CPUs: $ALLOW_CPUS (mask=0x$MASK)"
     for irq in /proc/irq/[0-9]*; do
        smp_file="$irq/smp_affinity"
        [ -w "$smp_file" ] && echo "$MASK" > "$smp_file" 2>/dev/null
     done
     ```

  要在运行测试之前配置系统，请对 Dragonwing<sup>™</sup> IQ-8275 开发套件执行以下操作：

  1. 禁用定时器迁移：
     ```text theme={null}
     echo 0 > /proc/sys/kernel/timer_migration
     ```
  2. 将 `/sys/devices/virtual/workqueue/*` 中的所有内核工作队列亲和到 housekeeping CPU：
     ```text theme={null}
     for wq in /sys/devices/virtual/workqueue/*; do
        [ -w "$wq/cpumask" ] && echo F7 > "$wq/cpumask"
     done
     # F7 = CPUs 0–2,4-7 (binary 1111 0111)
     ```
  3. 将 CPU 频率调节器设置为 performance：
     ```text theme={null}
     for policy in /sys/devices/system/cpu/cpufreq/policy*; do
        [ -w "$policy/scaling_governor" ] && echo performance > "$policy/scaling_governor"
     done
     ```
  4. 禁用 RT 计账/限流：
     ```text theme={null}
     echo -1 > /proc/sys/kernel/sched_rt_runtime_us
     ```
  5. 将 IRQ 亲和性设置到 housekeeping CPU：
     ```text theme={null}
     ALLOW_CPUS="0,1,2,4,5,6,7"
     cpu_list_to_mask() {
        MASK=0
        for cpu in $(echo $1 | tr ',' ' '); do
           MASK=$((MASK | (1 << cpu)))
        done
        printf "%x\n" "$MASK"
     }
     MASK=$(cpu_list_to_mask "$ALLOW_CPUS")
     echo "Setting IRQ affinity to CPUs: $ALLOW_CPUS (mask=0x$MASK)"
     for irq in /proc/irq/[0-9]*; do
        smp_file="$irq/smp_affinity"
        [ -w "$smp_file" ] && echo "$MASK" > "$smp_file" 2>/dev/null
     done
     ```

  以下示例展示了如何在 `meta-qcom/conf/machine/<machine-name.conf>` 中添加内核命令行参数以禁用 RCU 回调（**rcu\_nocbs**）：

  * CPU 核心 7
  * IRQ 亲和到核心 0-6
  * RCU 无回调 7

  ```text theme={null}
  QCOM_RT_CPU        = "7"
  QCOM_IRQAFF        = "0-6"
  QCOM_RCU_NOCBS     = "7"
  QCOM_RCU_EXPEDITED = "1"
  QCOM_CPUIDLE_OFF   = "1"
  ```
</Note>

### **测试 RT 内核**

Linux 基金会 RT 测试套件中提供了一套测试。RT Linux 内核测试可获取以下信息：

* RT Linux 内核的实时性能
* RT Linux 内核延迟和关键性能指标（KPI）

<Note>
  在 RT Linux 内核测试期间请勿重启系统，因为它需要运行超过 24 小时。
</Note>

Cyclictest 工具用于对 RT Linux 内核系统进行基准测试。它用于评估实时系统的相对性能。Qualcomm Linux 构建包含 cyclictest 工具。更多信息请参见 [Cyclictest](https://wiki.linuxfoundation.org/realtime/documentation/howto/tools/cyclictest/start)。

本指南介绍以下 cyclictest：

* 无负载 cyclictest：执行此测试时不添加系统负载。
* 带 stress-ng（next-generation）的 cyclictest：执行此测试时添加特定百分比的负载，以测量最坏情况下的系统延迟。

1. 对 QCS6490、Qualcomm Dragonwing<sup>™</sup> IQ-9075 和 Qualcomm Dragonwing<sup>™</sup> IQ-615 开发套件运行以下 cyclic 测试：
   ```text theme={null}
   cyclictest -a 7 -t 1 -m -l 100000000 -i 1000 -p 99 -h 100
   # -a 7 → pin threads to CPU 7 (RT cores)
   # -t 1 → 1 threads
   # -m → lock memory (avoid page faults)
   # -l 100000000 → long run
   # -i 1000 → 1 ms interval
   # -p 99 → RT priority
   # -h 100 → histogram up to 100 µs
   ```
2. 对 Dragonwing<sup>™</sup> IQ-8275 开发套件运行以下 cyclic 测试：
   ```text theme={null}
   cyclictest -a 3 -t 1 -m -l 100000000 -i 1000 -p 99 -h 100
   ```

要访问 RT 测试套件源代码，请参见 [rt-tests/rt-tests.git](https://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git/)。更多信息请参见 [RT-Tests](https://wiki.linuxfoundation.org/realtime/documentation/howto/tools/rt-tests)。

3. 记录延迟。

要在 QCS6490、Qualcomm Dragonwing IQ-9075 和 Qualcomm Dragonwing<sup>™</sup> IQ-615 上运行带 stress-ng 的 cyclic 测试，请执行以下操作：

1. 设置目标 CPU 负载。定义所需的 CPU 负载百分比。如果未指定，默认负载为 60%：
   ```text theme={null}
   LOAD=60
   ```
2. 在后台在选定的 CPU 核心上运行 stress-ng。使用 stress-ng 在核心 0、1、2、4、5、6 和 7 上施加 CPU 负载。每个实例运行一天并固定到特定的 CPU 核心：
   ```text theme={null}
   for cpu in 0 1 2 3 4 5 6; do
       taskset -c $cpu stress-ng --cpu 1 --cpu-load "$LOAD" \
       --temp-path . -t 1d &
   done
   ```
3. 运行 cyclic 延迟测试。以高优先级执行 cyclictest 来测量调度延迟。测试运行约 27.78 小时：
   ```text theme={null}
   cyclictest -a 7 -t 1 -m -l 100000000 -i 1000 -p 99 -h 100 --mainaffinity 6
   ```
4. 记录最坏情况延迟。

要在 Dragonwing IQ-8275 上运行带 stress-ng 的 cyclic 测试，请执行以下操作：

1. 设置目标 CPU 负载：
   ```text theme={null}
   LOAD=60
   ```
2. 在选定的 CPU 核心上运行 stress-ng：
   ```text theme={null}
   for cpu in 0 1 2 4 5 6 7; do
        taskset -c $cpu stress-ng --cpu 1 --cpu-load "$LOAD" \
        --temp-path . -t 1d &
   done
   ```
3. 运行 cyclic 延迟测试：
   ```text theme={null}
   cyclictest -a 3 -t 1 -m -l 100000000 -i 1000 -p 99 -h 100 --mainaffinity 2
   ```
4. 记录最坏情况延迟。

### **RT 测试结果**

<table style={{ width: '100%', borderCollapse: 'collapse' }}>
  <thead>
    <tr>
      <th style={{ textAlign: 'center' }}>设备</th>
      <th style={{ textAlign: 'center' }}>发行版和镜像</th>
      <th style={{ textAlign: 'center' }}><span style={{ whiteSpace: 'nowrap' }}>Cyclic 测试用例</span> <br />（时长：24 小时）</th>
      <th style={{ textAlign: 'center' }}>最小延迟（µs）</th>
      <th style={{ textAlign: 'center' }}>平均延迟（µs）</th>
      <th style={{ textAlign: 'center' }}>最大延迟（µs）</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td rowSpan={2} style={{ textAlign: 'center', verticalAlign: 'middle' }}>
        QCS6490<br />
        RT 核心：7<br />
        启动流程 - KVM
      </td>

      <td rowSpan={2} style={{ textAlign: 'center', verticalAlign: 'middle' }}>
        performance\_linux-qcom-rt-6.18\_qcom-distro-kvm<br />
        和 qcom-multimedia-image
      </td>

      <td style={{ textAlign: 'center' }}>无负载</td>
      <td style={{ textAlign: 'center' }}>1</td>
      <td style={{ textAlign: 'center' }}>1</td>
      <td style={{ textAlign: 'center' }}>6</td>
    </tr>

    <tr>
      <td style={{ textAlign: 'center' }}>Stress-NG</td>
      <td style={{ textAlign: 'center' }}>1</td>
      <td style={{ textAlign: 'center' }}>1</td>
      <td style={{ textAlign: 'center' }}>6</td>
    </tr>

    <tr>
      <td rowSpan={2} style={{ textAlign: 'center', verticalAlign: 'middle' }}>
        <span style={{ whiteSpace: 'nowrap' }}>Dragonwing IQ-615</span><br />
        RT 核心：7<br />
        启动流程 - KVM
      </td>

      <td rowSpan={2} style={{ textAlign: 'center', verticalAlign: 'middle' }}>
        performance\_linux-qcom-rt-6.18\_qcom-distro-kvm<br />
        和 qcom-multimedia-image
      </td>

      <td style={{ textAlign: 'center' }}>无负载</td>
      <td style={{ textAlign: 'center' }}>1</td>
      <td style={{ textAlign: 'center' }}>2</td>
      <td style={{ textAlign: 'center' }}>7</td>
    </tr>

    <tr>
      <td style={{ textAlign: 'center' }}>Stress-NG</td>
      <td style={{ textAlign: 'center' }}>1</td>
      <td style={{ textAlign: 'center' }}>2</td>
      <td style={{ textAlign: 'center' }}>9</td>
    </tr>
  </tbody>
</table>

## **后续步骤**

* [针对性能调优进行定制](./customize-for-performance-tuning)
* [使用工具分析性能](./analyze-performance-with-tools)
