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

# 使用 clk-debug-tools 测量时钟频率

[clk-debug-tools-for-qualcomm-linux](https://github.com/qualcomm-linux/clk-debug-tools-for-qualcomm-linux) 仓库托管了针对 `linux-next` 的树外 Linux 内核 `clk` 调试补丁，以及在 Qualcomm SoC 上驱动基于时钟测量的调试的脚本。这些工具通过 `debugfs` 公开硬件时钟测量支持，从而可以将时钟的实际测量频率与配置的频率进行比对。

## **前提条件**

在使用这些工具之前，请确保您具备以下条件：

* 针对目标设备的 `linux-next` 内核检出，已应用 `patches/` 目录中的 DebugCC `clk` 调试补丁，并已构建和烧写到目标设备。
* 在目标设备上将 `debugfs` 挂载到 `/sys/kernel/debug`。
* 目标设备上的 root shell 访问权限。
* 目标设备上有符合 POSIX 标准的 shell（`sh`），用于运行位于 `scripts/` 中的辅助脚本。

## **应用内核补丁**

1. 在 `linux-next` 检出中，按顺序使用 `git am` 先应用通用补丁集，再应用目标特定的补丁系列：
   * 应用 `common/` 目录中的补丁。
     ```text theme={null}
     git am common/*.patch
     ```
   * 应用相应 `soc/<target>/` 目录中的补丁。例如，对于 SA8775P：
     ```text theme={null}
     git am soc/sa8775p/*.patch
     ```
2. 使用应用了补丁的内核进行构建，并使用您的标准构建和烧写流程将其烧写到目标设备。
3. 将 `scripts/` 目录中的脚本复制到目标设备上。

## **测量时钟频率**

针对您的目标平台运行辅助脚本，并传入要测量的时钟名称。例如，在 SA8775P 上：

```text theme={null}
sh scripts/clk_measure_sa8775p.sh <clock_name>
```

* `<clock_name>` 必须与脚本内部支持的时钟列表中的条目匹配。
* 脚本会以 Hz 为单位打印测量到的时钟频率。

有关完整源代码、分支和目标特定补丁集，请参阅 [clk-debug-tools-for-qualcomm-linux 仓库](https://github.com/qualcomm-linux/clk-debug-tools-for-qualcomm-linux)。
