[英]Is there an equivalent instruction to rdtsc in ARM?
對於我的項目,我必須使用諸如rdtsc 之類的內聯匯編指令來計算某些 C/C++ 指令的執行時間。
以下代碼似乎適用於 Intel 但不適用於 ARM 處理器:
{unsigned a, d;asm volatile("rdtsc" : "=a" (a), "=d" (d)); t0 = ((unsigned long)a) | (((unsigned long)d) << 32);}
//The C++ statement to measure its execution time
{unsigned a, d;asm volatile("rdtsc" : "=a" (a), "=d" (d)); t1 = ((unsigned long)a) | (((unsigned long)d) << 32);}
time = t1-t0;
我的問題是:
如何編寫類似於上述的內聯匯編代碼(計算一條指令的執行時間)以在 ARM 處理器上工作?
對於 Arm64,系統寄存器CNTVCT_EL0
可用於從用戶空間檢索計數器。
// SPDX-License-Identifier: GPL-2.0
u64 rdtsc(void)
{
u64 val;
/*
* According to ARM DDI 0487F.c, from Armv8.0 to Armv8.5 inclusive, the
* system counter is at least 56 bits wide; from Armv8.6, the counter
* must be 64 bits wide. So the system counter could be less than 64
* bits wide and it is attributed with the flag 'cap_user_time_short'
* is true.
*/
asm volatile("mrs %0, cntvct_el0" : "=r" (val));
return val;
}
有關更多詳細信息,請參閱此補丁https://lore.kernel.org/patchwork/patch/1305380/ 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.