厦门莫格电气自动化有限公司销售
ABB SPFCS01/IMHSS03
欢迎来电咨询!
SPFCS01/IMHSS03
SPFCS01/IMHSS03
您迈开询价的一小步,我还您成功的一大步。
E***6802是英创公司推出的基于Freescale i.MX6DL双核处理器(ARM Cortex-A9,主频1GHz)的高性能工控主板,预装正版Windows Embedded Compact 7(WEC7)嵌入式操作系统,WEC7一个***重要的特性就是对多核处理器的支持(Symmetric Multi-Processing(***P)),下面将通过应用程序来测试在单核和多核情况下系统的执行情况,为了更直观的比较,同时参与测试的还有E***3354,E***3354是基于TI Coertex-A8处理器的工控主板,CPU主频1GHz,同样预装WEC7操作系统。
所设计的测试程序代码如下,其中的Test***p函数有两个输入参数,***参数表示要创建测试线程的数量,第二个参数为所创建线程的运行时长。cbTest***p是被创建的测试线程,测试线程主要是在一个while循环中,反复读取内存变量然后与预设值进行比较,在运行设定的时间后自动退出循环,其中的threadParam->loops变量会记录下while循环总共执行的次数。
typedef struct _***P_THREAD_PARAM
{
UINT32 durationMs;
UINT32 threadId;
UINT64 loops;
BOOL bSetAffinity;
UINT32 sandBoxSize;
LPVOID sandBoxStart;
}***P_THREAD_PARAM, *P***P_THREAD_PARAM;
ULONG cbTest***p(LPVOID param)
{
P***P_THREAD_PARAM threadParam = (P***P_THREAD_PARAM)param;
DWORD tStart = GetTickCount();
UINT8 *buffer = (UINT8 *)threadParam->sandBoxStart;
wprintf(L"Ahou, Thread %d, running for %d ms\r\n", threadParam->threadId,
threadParam->durationMs);
// Write to sandbox
for (UINT32 i = 0; i < threadParam->sandBoxSize; i++)
{
buffer[i] = (UINT8)(i);
}
while ( (GetTickCount() - tStart) < threadParam->durationMs)
{
// Read back from sandbox
for (UINT32 i = 0; i < threadParam->sandBoxSize; i++)
{
if (buffer[i] != (UINT8)(i))
{
wprintf(L"Thread %d : error at byte %d for loop %I64d !!\r\n",
threadParam->threadId, i, threadParam->loops);
}
}
threadParam->loops++;
}
wprintf(L"Thread %d : terminating\r\n", threadParam->threadId);
return 0;
}
void Test***p(UINT32 nNumOfThread, UINT32 durationMs)
{
UINT32 i;
P***P_THREAD_PARAM threadParams;
HANDLE *threadHandles;
UINT64 totalLoops = 0;
UINT32 sandBoxSize = 1024 * 128; // 128 kB
HANDLE h_array[1];
threadParams = (P***P_THREAD_PARAM)malloc(nNumOfThread * sizeof(***P_THREAD_PARAM));
if (threadParams == NULL)
{
wprintf(L"Failed allocating thread params !\r\n");
return;
}
threadHandles = (HANDLE *)malloc(nNumOfThread * sizeof(HANDLE));
if (threadHandles == NULL)
{
wprintf(L"Failed allocating thread handles !\r\n");
return;
}
for (i = 0; i < nNumOfThread; i++)
{
threadParams[i].bSetAffinity = TRUE;
threadParams[i].threadId = i;
threadParams[i].durationMs = durationMs;
threadParams[i].loops = 0;
threadParams[i].sandBoxSize = sandBoxSize;
threadParams[i].sandBoxStart = malloc(sandBoxSize);
threadHandles[i] = CreateThread(NULL, 0, cbTest***p, &threadParams[i], 0, NULL);
wprintf(L"Thread handle %d : 0x%x\r\n", i, threadHandles[i]);
}
h_array[0] = threadHandles[0];
DWORD res = WaitForSingleObject(h_array[0], INFINITE);
Sleep(500);
if (res == WAIT_TIMEOUT)
{
wprintf(L"Timeout waiting for threads !\r\n");
}
else
{
wprintf(L"All threads exited\r\n");
}
for (i = 0; i < nNumOfThread; i++)
{
wprintf(L"Thread %d did run %I64d loops\r\n", i, threadParams[i].loops);
totalLoops += threadParams[i].loops;
free(threadParams[i].sandBoxStart);
CloseHandle(threadHandles[i]);
}
wprintf(L"Total number of loops %I64d (%I64d milli***)\r\n", totalLoops,
totalLoops / 1000000);
free(threadHandles);
free(threadParams);
}
将上述测试代码编译生成为exe文件,分别在E***3354和E***6802上运行,设置while循环的执行时间均为10000ms,测试结果如下:
1、创建单个线程
测试主板与线程E***3354(1GHz单核 Cortex-A8)E***6802(1GHz双核Cortex-A9)
循环次数67917493
当测试程序只创建一个测试线程时,E***3354的while循环执行了6791次,E***6802执行7493次,虽然E***6802为双核处理器,但由于程序只有一个线程,即同一时刻只有一个线程在运行,所以在相同的时间内,循环的次数仅略多于E***3354。由于E***3354和E***6802的CPU主频同样都是1GHz,所以可以认为E***6802多出的循环次数也就是Cortex-A8与Cortex-A9在代码执行效率上的差别。
功能随主板型号的不同而有所不同