Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "cpu_detect_core.h"
12 : #include <stdlib.h>
13 : #define __USE_GNU
14 : #define _GNU_SOURCE
15 : #include <sched.h>
16 : #include <stdio.h>
17 : #include <errno.h>
18 : #include <pthread.h>
19 : #include <limits.h>
20 : #include <sys/time.h>
21 : #include <sys/prctl.h>
22 : #include "cpu_detect_print.h"
23 : #include "cpu_detect_test.h"
24 : #include "ascend_hal.h"
25 :
26 : #define DEVICE_MAX_CPU_NUM 64U
27 : #define THREAD_NAME_LENGTH 16U
28 :
29 : typedef struct {
30 : int32_t cpuId;
31 : int32_t moduleType;
32 : } CpuInfo;
33 :
34 : typedef struct {
35 : CpuInfo cpu;
36 : int32_t tid;
37 : pthread_t task;
38 : int32_t result;
39 : } CpuDetectThreadMgr;
40 :
41 : typedef struct {
42 : bool stop;
43 : uint32_t devNum;
44 : uint32_t cpuNum;
45 : uint32_t timeout;
46 : struct timeval startTime;
47 : CpuDetectThreadMgr thread[DEVICE_MAX_CPU_NUM];
48 : } CpuDetectMgr;
49 :
50 : STATIC CpuDetectMgr g_cpuDetectMgr = {0};
51 :
52 800 : STATIC INLINE bool CpuDetectIsStop(void)
53 : {
54 800 : return g_cpuDetectMgr.stop;
55 : }
56 :
57 0 : STATIC INLINE void CpuDetectSetStop(void)
58 : {
59 0 : if (!g_cpuDetectMgr.stop) {
60 0 : g_cpuDetectMgr.stop = true;
61 : }
62 0 : }
63 :
64 808 : STATIC INLINE struct timeval *CpuDetectGetStartTime(void)
65 : {
66 808 : return &g_cpuDetectMgr.startTime;
67 : }
68 :
69 800 : STATIC INLINE uint32_t CpuDetectGetTimeout(void)
70 : {
71 800 : return g_cpuDetectMgr.timeout;
72 : }
73 :
74 1 : STATIC INLINE CpudStatus CpuDetectGetResult(void)
75 : {
76 1 : CpudStatus ret = CPUD_SUCCESS;
77 9 : for (uint32_t i = 0; i < g_cpuDetectMgr.cpuNum && i < DEVICE_MAX_CPU_NUM; i++) {
78 8 : if (g_cpuDetectMgr.thread[i].result != CPUD_SUCCESS) {
79 0 : ret = (g_cpuDetectMgr.thread[i].result > ret) ? g_cpuDetectMgr.thread[i].result : ret;
80 : }
81 : }
82 1 : return ret;
83 : }
84 :
85 8 : STATIC INLINE int32_t CpuDetectGetTid(void)
86 : {
87 8 : return (int32_t)syscall(SYS_gettid);
88 : }
89 :
90 8 : STATIC CpudStatus CpuDetectBindCgroup(int32_t moduleType)
91 : {
92 8 : if (moduleType == MODULE_TYPE_AICPU) {
93 6 : drvError_t drvRet = halBindCgroup(BIND_AICPU_CGROUP);
94 6 : if (drvRet != DRV_ERROR_NONE) {
95 0 : ADETECT_ERR("bind aicpu cgroup failed, ret[%d].", drvRet);
96 0 : return CPUD_FAILURE;
97 : }
98 6 : ADETECT_INF("bind aicpu cgroup success.");
99 6 : return CPUD_SUCCESS;
100 2 : } else if (moduleType == MODULE_TYPE_DCPU) {
101 1 : drvError_t drvRet = halBindCgroup(BIND_DATACPU_CGROUP);
102 1 : if (drvRet != DRV_ERROR_NONE) {
103 0 : ADETECT_ERR("bind datacpu cgroup failed, ret[%d]", drvRet);
104 0 : return CPUD_FAILURE;
105 : }
106 1 : ADETECT_INF("bind datacpu cgroup success.");
107 1 : return CPUD_SUCCESS;
108 : } else {
109 1 : ADETECT_INF("use default cgroup: ccpu_cgroup.");
110 1 : return CPUD_SUCCESS;
111 : }
112 : }
113 :
114 8 : STATIC CpudStatus CpuDetectSetAffinity(const CpuInfo *info)
115 : {
116 8 : CpudStatus ret = CpuDetectBindCgroup(info->moduleType);
117 8 : if (ret != CPUD_SUCCESS) {
118 0 : return CPUD_ERROR_CGROUP_BIND;
119 : }
120 :
121 : cpu_set_t mask;
122 8 : CPU_ZERO(&mask);
123 8 : CPU_SET(info->cpuId, &mask);
124 8 : int32_t err = pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask);
125 8 : if (err != 0) {
126 0 : ADETECT_ERR("thread(%d) can not set cpu(%d) setaffinity, errno:%d, err:%s", CpuDetectGetTid(), info->cpuId, errno, strerror(errno));
127 0 : return CPUD_ERROR_CPU_AFFINITY;
128 : }
129 8 : ADETECT_INF("thread(%d) set cpu(%d) setaffinity success", CpuDetectGetTid(), info->cpuId);
130 8 : return CPUD_SUCCESS;
131 : }
132 :
133 800 : STATIC INLINE bool CpuDetectCheckTime(struct timeval *start, uint32_t timeout)
134 : {
135 800 : struct timeval end = {0};
136 800 : gettimeofday(&end, NULL);
137 800 : if ((end.tv_sec - start->tv_sec) >= timeout) {
138 8 : return true;
139 : }
140 792 : return false;
141 : }
142 :
143 8 : STATIC INLINE int64_t CpuDetectGetRuntime(struct timeval *start)
144 : {
145 8 : struct timeval end = {0};
146 8 : gettimeofday(&end, NULL);
147 8 : int64_t time = end.tv_sec - start->tv_sec;
148 8 : return (time == 0 ? 1 : time);
149 : }
150 :
151 8 : STATIC CpudStatus CpuDetectThreadEntry(CpuInfo *info)
152 : {
153 8 : uint32_t *regValues = (uint32_t *)malloc(TEMP_BUF_SIZE);
154 8 : if (regValues == NULL) {
155 0 : ADETECT_ERR("malloc regValues failed.");
156 0 : return CPUD_ERROR_MALLOC;
157 : }
158 :
159 8 : uint32_t *loadStoreBuf = (uint32_t *)malloc(TEMP_BUF_SIZE);
160 8 : if (loadStoreBuf == NULL) {
161 0 : ADETECT_ERR("malloc loadStoreBuf failed.");
162 0 : free(regValues);
163 0 : return CPUD_ERROR_MALLOC;
164 : }
165 :
166 8 : int64_t cycle = 0;
167 8 : CpudStatus ret = CPUD_SUCCESS;
168 800 : while (!CpuDetectIsStop()) {
169 800 : cycle++;
170 800 : ret = CpuDetectGroup(regValues, loadStoreBuf, info->cpuId);
171 800 : if (ret != CPUD_SUCCESS) {
172 0 : int64_t run = CpuDetectGetRuntime(CpuDetectGetStartTime());
173 0 : ADETECT_ERR("cpu(%d) detect failed and exit after running %lld cycles for %lld seconds.", info->cpuId, cycle, run);
174 0 : break;
175 : }
176 :
177 800 : bool result = CpuDetectCheckTime(CpuDetectGetStartTime(), CpuDetectGetTimeout());
178 800 : if (result || (cycle >= INT_MAX)) {
179 8 : int64_t run = CpuDetectGetRuntime(CpuDetectGetStartTime());
180 8 : ADETECT_RUN_INF("cpu(%d) detect success and exit after running %lld cycles for %lld seconds.", info->cpuId, cycle, run);
181 8 : break;
182 : }
183 : }
184 8 : free(regValues);
185 8 : free(loadStoreBuf);
186 8 : return ret;
187 : }
188 :
189 15 : STATIC INLINE void CpuDetectSetName(const char *name)
190 : {
191 15 : int32_t ret = prctl(PR_SET_NAME, (unsigned long)(uintptr_t)name);
192 15 : ADETECT_CHK_EXPR(ret != EOK, "cpu detect set name(%s) failed with %d.", name, ret);
193 15 : }
194 :
195 8 : STATIC INLINE void CpuDetectSetThreadName(int32_t cpuId)
196 : {
197 8 : char threadName[THREAD_NAME_LENGTH] = {0};
198 8 : int32_t ret = snprintf_s(threadName, THREAD_NAME_LENGTH, THREAD_NAME_LENGTH - 1U, "cpu_detect_%d", cpuId);
199 8 : ADETECT_CHK_EXPR(ret == -1, "cpu detect set thread name(%s) failed, snprintf_s err=%d.", threadName, ret);
200 :
201 8 : CpuDetectSetName((const char *)threadName);
202 8 : }
203 :
204 8 : STATIC void *CpuDetectThread(void *arg)
205 : {
206 8 : ADETECT_CHK_NULL_PTR(arg, return NULL);
207 :
208 8 : CpuDetectThreadMgr *thread = (CpuDetectThreadMgr *)arg;
209 8 : ADETECT_CHK_EXPR_ACTION(thread->cpu.cpuId < 0, return NULL, "cpu detect thread(%d), cpuId(%d) is invalid.", thread->tid, thread->cpu.cpuId);
210 8 : thread->tid = CpuDetectGetTid();
211 8 : ADETECT_INF("cpu(%d) detect thread(%d) create success.", thread->cpu.cpuId, thread->tid);
212 8 : CpuDetectSetThreadName(thread->cpu.cpuId);
213 :
214 8 : CpudStatus ret = CpuDetectSetAffinity(&thread->cpu);
215 8 : if (ret != CPUD_SUCCESS) {
216 0 : thread->result = ret;
217 0 : CpuDetectSetStop();
218 0 : return NULL;
219 : }
220 :
221 8 : ret = CpuDetectThreadEntry(&thread->cpu);
222 8 : if (ret != CPUD_SUCCESS) {
223 0 : thread->result = ret;
224 0 : CpuDetectSetStop();
225 0 : return NULL;
226 : }
227 8 : return NULL;
228 : }
229 :
230 8 : STATIC CpudStatus CpuDetectCreateThread(CpuDetectThreadMgr *thread)
231 : {
232 8 : int32_t ret = pthread_create(&thread->task, NULL, CpuDetectThread, (void *)thread);
233 8 : if (ret != 0) {
234 0 : CpuDetectSetStop();
235 0 : thread->result = CPUD_ERROR_CREATE_THREAD;
236 0 : return CPUD_ERROR_CREATE_THREAD;
237 : }
238 :
239 8 : return CPUD_SUCCESS;
240 : }
241 :
242 8 : STATIC void CpuDetectReleaseThread(CpuDetectThreadMgr *thread)
243 : {
244 8 : if (thread->task != 0) {
245 8 : int32_t ret = pthread_join(thread->task, NULL);
246 8 : ADETECT_CHK_EXPR_ACTION(ret != 0, return, "cpu(%d) detect can not join thread(%d), error=%d, strerr=%s.",
247 : thread->cpu.cpuId, thread->tid, errno, strerror(errno));
248 8 : ADETECT_INF("cpu(%d) detect thread(%d) release success.", thread->cpu.cpuId, thread->tid);
249 : }
250 : }
251 :
252 7 : STATIC CpudStatus CpuDetectGetDevNum(uint32_t *deviceNum)
253 : {
254 7 : drvError_t drvRet = drvGetDevNum(deviceNum);
255 7 : if (drvRet != DRV_ERROR_NONE) {
256 1 : ADETECT_ERR("call drvGetDevNum failed with %d.", (int32_t)drvRet);
257 1 : return CPUD_FAILURE;
258 : }
259 6 : return CPUD_SUCCESS;
260 : }
261 :
262 1 : STATIC CpudStatus CpuDetectGetAicpuInfo(uint32_t deviceId, uint32_t cpuNum, CpuDetectThreadMgr *thread, uint32_t size)
263 : {
264 1 : int64_t aicpuNum = 0;
265 1 : int64_t cpuBitMap = 0;
266 1 : drvError_t ret = halGetDeviceInfo(deviceId, MODULE_TYPE_AICPU, INFO_TYPE_PF_CORE_NUM, &aicpuNum);
267 1 : ADETECT_CHK_EXPR_ACTION((ret != DRV_ERROR_NONE) || (aicpuNum <= 0) || (aicpuNum >= cpuNum), return CPUD_FAILURE,
268 : "device[%u] aicpu detect call halGetDeviceInfo failed with %d, cpu num(%lld).", deviceId, (int32_t)ret, aicpuNum);
269 :
270 1 : ret = halGetDeviceInfo(deviceId, MODULE_TYPE_AICPU, INFO_TYPE_PF_OCCUPY, &cpuBitMap);
271 1 : ADETECT_CHK_EXPR_ACTION(ret != DRV_ERROR_NONE, return CPUD_FAILURE, "device[%u] aicpu detect call halGetDeviceInfo failed with %d.", deviceId, (int32_t)ret);
272 :
273 1 : ADETECT_INF("device[%u] aicpu detect get info: cpuBitMap[%lld], cpuNum[%lld].", deviceId, cpuBitMap, aicpuNum);
274 65 : for (uint32_t i = 0; i < size; i++) {
275 64 : if ((cpuBitMap & 0x1LL) != 0LL) {
276 6 : uint32_t cpuId = (uint32_t)(deviceId * cpuNum) + i;
277 6 : ADETECT_CHK_EXPR_ACTION(cpuId >= size, return CPUD_FAILURE, "device[%u] aicpu detect get info failed, cpu num(%lld), cpu id(%u).", deviceId, aicpuNum, cpuId);
278 6 : thread[cpuId].cpu.moduleType = MODULE_TYPE_AICPU;
279 6 : thread[cpuId].cpu.cpuId = (int32_t)cpuId;
280 6 : ADETECT_INF("device[%u] cpu detect get info: aicpu id(%u).", deviceId, cpuId);
281 : }
282 64 : cpuBitMap = cpuBitMap >> 1;
283 : }
284 1 : return CPUD_SUCCESS;
285 : }
286 :
287 3 : STATIC CpudStatus CpuDetectGetCcpuInfo(uint32_t deviceId, uint32_t cpuNum, CpuDetectThreadMgr *thread, uint32_t size)
288 : {
289 3 : int64_t ccpuNum = 0;
290 3 : drvError_t ret = halGetDeviceInfo(deviceId, MODULE_TYPE_CCPU, INFO_TYPE_CORE_NUM, &ccpuNum);
291 3 : ADETECT_CHK_EXPR_ACTION((ret != DRV_ERROR_NONE) || (ccpuNum == 0), return CPUD_FAILURE,
292 : "device[%u] ccpu detect call halGetDeviceInfo failed with %d.", deviceId, (int32_t)ret);
293 :
294 6 : for (int32_t i = 0; i < ccpuNum; i++) {
295 3 : uint32_t cpuId = (uint32_t)(deviceId * cpuNum) + i;
296 3 : ADETECT_CHK_EXPR_ACTION(cpuId >= size, return CPUD_FAILURE, "device[%u] ccpu detect get info failed, cpu num(%lld), cpu id(%u).", deviceId, ccpuNum, cpuId);
297 3 : thread[cpuId].cpu.moduleType = MODULE_TYPE_CCPU;
298 3 : thread[cpuId].cpu.cpuId = (int32_t)cpuId;
299 3 : ADETECT_INF("device[%u] cpu detect get info: ccpu id(%u).", deviceId, cpuId);
300 : }
301 3 : return CPUD_SUCCESS;
302 : }
303 :
304 2 : STATIC CpudStatus CpuDetectGetDcpuInfo(uint32_t deviceId, uint32_t cpuNum, CpuDetectThreadMgr *thread, uint32_t size)
305 : {
306 2 : int64_t ccpuNum = 0;
307 2 : int64_t dcpuNum = 0;
308 :
309 2 : drvError_t ret = halGetDeviceInfo(deviceId, MODULE_TYPE_CCPU, INFO_TYPE_CORE_NUM, &ccpuNum);
310 2 : ADETECT_CHK_EXPR_ACTION(ret != DRV_ERROR_NONE, return CPUD_FAILURE, "device[%u] ccpu detect call halGetDeviceInfo failed with %d.", deviceId, (int32_t)ret);
311 :
312 2 : ret = halGetDeviceInfo(deviceId, MODULE_TYPE_DCPU, INFO_TYPE_CORE_NUM, &dcpuNum);
313 2 : ADETECT_CHK_EXPR_ACTION(ret != DRV_ERROR_NONE, return CPUD_FAILURE, "device[%u] dcpu detect call halGetDeviceInfo failed with %d.", deviceId, (int32_t)ret);
314 :
315 4 : for (int32_t i = 0; i < dcpuNum; i++) {
316 2 : uint32_t cpuId = (uint32_t)(deviceId * cpuNum) + ccpuNum + i;
317 2 : ADETECT_CHK_EXPR_ACTION(cpuId >= size, return CPUD_FAILURE, "device[%u] dcpu detect get info failed, cpu num(%lld), cpu id(%u).", deviceId, dcpuNum, cpuId);
318 :
319 2 : thread[cpuId].cpu.moduleType = MODULE_TYPE_DCPU;
320 2 : thread[cpuId].cpu.cpuId = (int32_t)cpuId;
321 2 : ADETECT_INF("device[%u] cpu detect get info: dcpu id(%u).", deviceId, cpuId);
322 : }
323 2 : return CPUD_SUCCESS;
324 : }
325 :
326 6 : STATIC int32_t CpuDetectGetCpuNum(uint32_t deviceId)
327 : {
328 6 : int64_t cpuNum = 0;
329 6 : int32_t totalCpuNum = 0;
330 :
331 6 : drvError_t ret = halGetDeviceInfo(deviceId, MODULE_TYPE_AICPU, INFO_TYPE_PF_CORE_NUM, &cpuNum);
332 6 : ADETECT_CHK_EXPR_ACTION((ret != DRV_ERROR_NONE) || (cpuNum == 0), return CPUD_FAILURE, "device[%u] get aicpu num failed with %d.", deviceId, (int32_t)ret);
333 4 : totalCpuNum += (int32_t)cpuNum;
334 4 : ADETECT_INF("device[%u] cpu detect get info: aicpu cpu num(%lld).", deviceId, cpuNum);
335 :
336 4 : ret = halGetDeviceInfo(deviceId, MODULE_TYPE_CCPU, INFO_TYPE_CORE_NUM, &cpuNum);
337 4 : ADETECT_CHK_EXPR_ACTION((ret != DRV_ERROR_NONE) || (cpuNum == 0), return CPUD_FAILURE, "device[%u] get ccpu num failed with %d.", deviceId, (int32_t)ret);
338 4 : totalCpuNum += (int32_t)cpuNum;
339 4 : ADETECT_INF("device[%u] cpu detect get info: ccpu cpu num(%lld).", deviceId, cpuNum);
340 :
341 4 : ret = halGetDeviceInfo(deviceId, MODULE_TYPE_DCPU, INFO_TYPE_CORE_NUM, &cpuNum);
342 4 : ADETECT_CHK_EXPR_ACTION(ret != DRV_ERROR_NONE, return CPUD_FAILURE, "device[%u] get dcpu num failed with %d.", deviceId, (int32_t)ret);
343 4 : totalCpuNum += (int32_t)cpuNum;
344 4 : ADETECT_INF("device[%u] cpu detect get info: dcpu cpu num(%lld).", deviceId, cpuNum);
345 4 : return totalCpuNum;
346 : }
347 :
348 6 : STATIC int32_t CpuDetectGetDeviceCpuInfo(uint32_t deviceId, CpuDetectThreadMgr *thread, uint32_t size)
349 : {
350 6 : int32_t num = CpuDetectGetCpuNum(deviceId);
351 6 : if (num <= 0) {
352 2 : ADETECT_ERR("device[%u] cpu detect get info failed with %d.", deviceId, num);
353 2 : return CPUD_FAILURE;
354 : }
355 4 : ADETECT_INF("device[%u] cpu detect get info: total cpu num(%d).", deviceId, num);
356 4 : uint32_t cpuNum = (uint32_t)num;
357 : // cpu分段为:ccpu - dcpu - aicpu
358 4 : int32_t ret = CpuDetectGetCcpuInfo(deviceId, cpuNum, thread, size);
359 4 : if (ret == CPUD_FAILURE) {
360 1 : return CPUD_FAILURE;
361 : }
362 :
363 3 : ret = CpuDetectGetDcpuInfo(deviceId, cpuNum, thread, size);
364 3 : if (ret == CPUD_FAILURE) {
365 1 : return CPUD_FAILURE;
366 : }
367 :
368 2 : ret = CpuDetectGetAicpuInfo(deviceId, cpuNum, thread, size);
369 2 : if (ret == CPUD_FAILURE) {
370 1 : return CPUD_FAILURE;
371 : }
372 1 : return num;
373 : }
374 :
375 6 : STATIC CpudStatus CpuDetectGetCpuInfo(uint32_t deviceNum, uint32_t *cpuNum, CpuDetectThreadMgr *thread, uint32_t size)
376 : {
377 6 : uint32_t num = 0;
378 7 : for (uint32_t i = 0; i < deviceNum; i++) {
379 6 : int32_t ret = CpuDetectGetDeviceCpuInfo(i, thread, size);
380 6 : if (ret == CPUD_FAILURE) {
381 5 : return CPUD_FAILURE;
382 : }
383 1 : num += (uint32_t)ret;
384 : }
385 1 : *cpuNum = num;
386 1 : return CPUD_SUCCESS;
387 : }
388 :
389 7 : STATIC CpudStatus CpuDetectInit(uint32_t timeout)
390 : {
391 : // timeout校验
392 7 : g_cpuDetectMgr.stop = false;
393 7 : g_cpuDetectMgr.timeout = timeout;
394 7 : gettimeofday(&g_cpuDetectMgr.startTime, NULL);
395 :
396 : // 获取dev个数
397 7 : CpudStatus ret = CpuDetectGetDevNum(&g_cpuDetectMgr.devNum);
398 7 : ADETECT_CHK_EXPR_ACTION((ret != CPUD_SUCCESS) || (g_cpuDetectMgr.devNum == 0), return CPUD_FAILURE, "get dev num(%u) failed with %d.", g_cpuDetectMgr.devNum, ret);
399 :
400 : // 获取cpu个数和类型
401 6 : g_cpuDetectMgr.cpuNum = 0;
402 390 : for (uint32_t i = 0; i < DEVICE_MAX_CPU_NUM; i++) {
403 384 : g_cpuDetectMgr.thread[i].cpu.cpuId = -1;
404 384 : g_cpuDetectMgr.thread[i].cpu.moduleType = -1;
405 384 : g_cpuDetectMgr.thread[i].tid = 0;
406 384 : g_cpuDetectMgr.thread[i].task = 0;
407 384 : g_cpuDetectMgr.thread[i].result = 0;
408 : }
409 6 : ret = CpuDetectGetCpuInfo(g_cpuDetectMgr.devNum, &g_cpuDetectMgr.cpuNum, g_cpuDetectMgr.thread, DEVICE_MAX_CPU_NUM);
410 6 : ADETECT_CHK_EXPR_ACTION((ret != CPUD_SUCCESS) || (g_cpuDetectMgr.cpuNum == 0), return CPUD_FAILURE, "get cpu info failed with %d, num(%u).", ret, g_cpuDetectMgr.cpuNum);
411 :
412 1 : ADETECT_INF("cpu detect get info: devNum(%u), cpuNum(%u).", g_cpuDetectMgr.devNum, g_cpuDetectMgr.cpuNum);
413 1 : return CPUD_SUCCESS;
414 : }
415 :
416 1 : STATIC void CpuDetectExit(void)
417 : {
418 1 : size_t size = sizeof(CpuDetectMgr);
419 1 : (void)memset_s(&g_cpuDetectMgr, size, 0, size);
420 1 : return;
421 : }
422 :
423 7 : CpudStatus CpuDetectProcess(uint32_t timeout)
424 : {
425 7 : CpuDetectSetName("cpu_detect_process.");
426 7 : CpudStatus ret = CpuDetectInit(timeout);
427 7 : if (ret != CPUD_SUCCESS) {
428 6 : ADETECT_ERR("cpu detect init failed with %d.", ret);
429 6 : return CPUD_ERROR_INIT;
430 : }
431 :
432 : // 启动线程
433 9 : for (uint32_t i = 0; i < g_cpuDetectMgr.cpuNum && i < DEVICE_MAX_CPU_NUM; i++) {
434 8 : ret = CpuDetectCreateThread(&g_cpuDetectMgr.thread[i]);
435 8 : if (ret != CPUD_SUCCESS) {
436 0 : ADETECT_ERR("cpu(%d) create thread failed, err: %d(%s)", g_cpuDetectMgr.thread[i].cpu.cpuId, errno, strerror(errno));
437 0 : break;
438 : }
439 : }
440 :
441 : // 回收线程
442 9 : for (uint32_t j = 0; j < g_cpuDetectMgr.cpuNum && j < DEVICE_MAX_CPU_NUM; j++) {
443 8 : CpuDetectReleaseThread(&g_cpuDetectMgr.thread[j]);
444 : }
445 1 : ret = CpuDetectGetResult();
446 1 : CpuDetectExit();
447 1 : return ret;
448 : }
|