ARM上的 Windows 10 IoT 企業版支持仿真 x86 應用程序,而 ARM上的 Windows 11 IoT 企業版則支持仿真 x86 和 x64 應用程序。英創推出的名片尺寸ARM64工控主板ESM8400,可預裝正版Windows 10 IoT企業版操作系統,x86程序可無需修改而直接在ESM8400上運行。
下會將編寫一個小程序,分別構建成x86和ARM64格式來測試其運行效率。所設計的測試程序代碼如下,其中的TestSmp函數有兩個輸入參數,第一參數表示要創建測試線程的數量,第二個參數為所創建線程的運行時長。cbTestSmp是被創建的測試線程,測試線程主要是在一個while循環中,反復讀取內存變量然后與預設值進行比較,在運行設定的時間后自動退出循環,其中的threadParam->loops變量會記錄下while循環總共執行的次數。
typedef struct _SMP_THREAD_PARAM { UINT32 durationMs; UINT32 cpuId; UINT64 loops; BOOL bSetAffinity; UINT32 sandBoxSize; LPVOID sandBoxStart; }SMP_THREAD_PARAM, * PSMP_THREAD_PARAM; DWORD WINAPI 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 ms\r\n", threadParam->cpuId, threadParam->durationMs); // Write to sandbox for (UINT32 i = 0; i < threadParam->sandBoxSize; i++) { buffer[i] = (UINT8)(i);// * (UINT32)threadParam->loops); } while ((GetTickCount() - tStart) < threadParam->durationMs) { // Read back from sandbox for (UINT32 i = 0; i < threadParam->sandBoxSize; i++) { //if (buffer[i] != (UINT8)(i * (UINT32)threadParam->loops) ) if (buffer[i] != (UINT8)(i))// * (UINT32)threadParam->loops) ) { wprintf(L"Thread %d : error at byte %d for loop %I64d !!\r\n", threadParam->cpuId, i, threadParam->loops); } } threadParam->loops++; } wprintf(L"Thread %d : terminating\r\n", threadParam->cpuId); return 0; } void TestSmp(UINT32 nCpus, 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(nCpus * sizeof(SMP_THREAD_PARAM)); if (threadParams == NULL) { wprintf(L"Failed allocating thread params !\r\n"); return; } threadHandles = (HANDLE*)malloc(nCpus * sizeof(HANDLE)); if (threadHandles == NULL) { wprintf(L"Failed allocating thread handles !\r\n"); return; } for (i = 0; i < nCpus; i++) { threadParams[i].bSetAffinity = TRUE; threadParams[i].cpuId = i; threadParams[i].durationMs = durationMs; threadParams[i].loops = 0; threadParams[i].sandBoxSize = sandBoxSize; threadParams[i].sandBoxStart = malloc(sandBoxSize); threadHandles[i] = CreateThread(NULL, 0, cbTestSmp, &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 < nCpus; 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 millions)\r\n", totalLoops, totalLoops / 1000000); free(threadHandles); free(threadParams); }
將上述代碼分別編譯構建成x86格式和ARM64模式,設置while循環執行10000ms,在ESM8400上的測試結果如下:
ESM8400 Win10 ARM工控主板運行x86和ARM64程序效率對比
可以看到相同的代碼,構建成本機ARM64格式的運行效率是x86格式的2.2倍以上。
基于微軟系統以及其開發工具良好的兼容性,我很容易做了另一個對比實驗,將上述代碼不經修改直接在VS2008中編譯成WEC7應用程序,在英創的幾款WEC7工控主板上做了同樣的測試,測試結果如下:
ESM3354是英創10年前推出的第一款預裝WEC7的工控主板,主CPU采用了TI的單核Cortex-A8芯片——AM3354,ESM3354目前仍在批量供貨。而安裝Windows 10 IoT的ESM8400工控主板,主CPU為NXP的i.MX8M Plus四核Cortex-A53,與10年前的ESM3354相比,ESM8400的性能有超過10倍的提升。
ARM上的 Windows IoT 企業版可以讓習慣使用 x86/x64 的設備開發人員快速進行軟件開發,大多數適用于 Windows IoT 企業版的文檔都適用于 ARM64 和 x86/x64。通過仿真技術,ARM上的 Windows IoT可按原樣運行x86/x64程序而無需修改,而直接構建本機ARM64應用程序能獲得最佳的性能、響應能力和能耗。
成都英創信息技術有限公司 028-8618 0660