---
title: GetCpuFreq
description: "获取CPU频率："
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2300/accel/kunpengaccel_hmpp_06_0036.html
sourcePath: /source/zh/kunpengboostkithistory/2300/accel/kunpengaccel_hmpp_06_0036.html
indexId: ea5100a297f1911e2afb9f3947c849f60b0f147124d729e13474d3cd3f9697a775
---
# GetCpuFreq

获取CPU频率：

HmppResult HMPP_GetCpuFreqMhz (int32_t *mhz);

#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| mhz | 目标地址，指向地址存放CPU频率值。 | 非空 | 输出 |


#### 返回值

- 成功：返回HMPP_STS_NO_ERR。
- 失败：返回错误码。


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| HMPP\_STS\_NULL\_PTR\_ERR | mhz指针为空指针。 |
| HMPP\_STS\_NOT\_SUPPORT | 获取信息失败。 |


#### 示例

```
void  GetCpuFreq_Example()
{
int32_t mhz;
HmppResult result = HMPP_GetCpuFreqMhz(&mhz);
printf("%s\n", HMPP_GetStatusString(result));
printf("cpu frequency = %d Mhz\n", mhz);
}
```

运行结果：

```
No Error
cpu frequency = 2600 Mhz
```

- 此接口需要在root用户下，才能有正确返回值。
- 实际输出可能上述结果不同，可调用dmidecode -t processor | grep "Current" 对比输出值。
