1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
ESM6802是英创公司推出的基于Freescale i.MX6DL双核处理器(ARM Cortex-A9,主频1GHz)的高性能工控主板,预装正版Windows Embedded Compact 7(WEC7)嵌入式操作系统,WEC7一个最重要的特性就是对多核处理器的支持(Symmetric Multi-Processing(SMP)),下面将通过应用程序来测试在单核和多核情况下系统的执行情况,为了更直观的比较,同时参与测试的还有ESM3354,ESM3354是基于TI Coertex-A8处理器的工控主板,CPU主频1GHz,同样预装WEC7操作系统。 所设计的测试程序代码如下,其中的TestSmp函数有两个输入参数,第一参数表示要创建测试线程的数量,第二个参数为所创建线程的运行时长。cbTestSmp是被创建的测试线程,测试线程主要是在一个while循环中,反复读取内存变量然后与预设值进行比较,在运行设定的时间后自动退出循环,其中的threadParam->loops变量会记录下while循环总共执行的次数。 typedef struct _SMP_THREAD_PARAM { UINT32 durationMs; UINT32 threadId; UINT64 loops; BOOL bSetAffinity; UINT32 sandBoxSize; LPVOID sandBoxStart; }SMP_THREAD_PARAM, *PSMP_THREAD_PARAM;
ULONG cbTestSmp(LPVOID param) { PSMP_THREAD_PARAM threadParam = (PSMP_THREAD_PARAM)param; DWORD tStart = GetTickCount(); UINT8 *buffer = (UINT8 *)threadParam->sandBoxStart;
wprintf(L"Ahou, Thread %d, running for %d msrn", threadParam->threadId, threadParam->durationMs);
// Write to sandbox for (UINT32 i = 0; i < threadParam->sandBoxSize; i++) { buffer = (UINT8)(i); }
while ( (GetTickCount() - tStart) < threadParam->durationMs) { // Read back from sandbox for (UINT32 i = 0; i < threadParam->sandBoxSize; i++) { if (buffer != (UINT8)(i)) { wprintf(L"Thread %d : error at byte %d for loop %I64d !!rn", threadParam->threadId, i, threadParam->loops); } }
threadParam->loops++; }
wprintf(L"Thread %d : terminatingrn", threadParam->threadId);
return 0; }
void TestSmp(UINT32 nNumOfThread, UINT32 durationMs) { UINT32 i;
PSMP_THREAD_PARAM threadParams; HANDLE *threadHandles; UINT64 totalLoops = 0; UINT32 sandBoxSize = 1024 * 128; // 128 kB
HANDLE h_array[1];
threadParams = (PSMP_THREAD_PARAM)malloc(nNumOfThread * sizeof(SMP_THREAD_PARAM));
if (threadParams == NULL) { wprintf(L"Failed allocating thread params !rn"); return; }
threadHandles = (HANDLE *)malloc(nNumOfThread * sizeof(HANDLE));
if (threadHandles == NULL) { wprintf(L"Failed allocating thread handles !rn"); return; }
for (i = 0; i < nNumOfThread; i++) { threadParams.bSetAffinity = TRUE; threadParams.threadId = i; threadParams.durationMs = durationMs; threadParams.loops = 0; threadParams.sandBoxSize = sandBoxSize; threadParams.sandBoxStart = malloc(sandBoxSize); threadHandles = CreateThread(NULL, 0, cbTestSmp, &threadParams, 0, NULL); wprintf(L"Thread handle %d : 0x%xrn", i, threadHandles); }
h_array[0] = threadHandles[0]; DWORD res = WaitForSingleObject(h_array[0], INFINITE);
Sleep(500);
if (res == WAIT_TIMEOUT) { wprintf(L"Timeout waiting for threads !rn"); } else { wprintf(L"All threads exitedrn"); }
for (i = 0; i < nNumOfThread; i++) { wprintf(L"Thread %d did run %I64d loopsrn", i, threadParams.loops); totalLoops += threadParams.loops; free(threadParams.sandBoxStart); CloseHandle(threadHandles); }
wprintf(L"Total number of loops %I64d (%I64d millions)rn", totalLoops, totalLoops / 1000000);
free(threadHandles); free(threadParams); } 将上述测试代码编译生成为exe文件,分别在ESM3354和ESM6802上运行,设置while循环的执行时间均为10000ms,测试结果如下: 1、创建单个线程
当测试程序只创建一个测试线程时,ESM3354的while循环执行了6791次,ESM6802执行7493次,虽然ESM6802为双核处理器,但由于程序只有一个线程,即同一时刻只有一个线程在运行,所以在相同的时间内,循环的次数仅略多于ESM3354。由于ESM3354和ESM6802的CPU主频同样都是1GHz,所以可以认为ESM6802多出的循环次数也就是Cortex-A8与Cortex-A9在代码执行效率上的差别。 2、创建两个线程
当测试程序创建了两个线程时,ESM3354会将CPU资源大约平均的分配给两个线程,如上表中线程1执行了3390次,线程2执行了3442次,两个线程总共执行的次数与只创建单个线程测试时的循环次数相当。ESM6802为双核CPU,在测试程序有两个线程的情况下,在同一时刻两个线程可以同时运行,所以总的循环次数大约是单个线程测试时的两倍。 通过上面的测试可以看到,在多线程情况下,如果操作系统支持多核处理器,那么双核CPU的运算能力将是单核CPU的两倍。 成都英创信息技术有限公司 http://www.emtronix.com |
||
相关推荐 |
||
只有小组成员才能发言,加入小组>>
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 22:41 , Processed in 0.600012 second(s), Total 59, Slave 44 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号